Skip to content

Commit 242b9c2

Browse files
CP-12583: adjust delegation start date and end date (#3366)
1 parent 3638ea0 commit 242b9c2

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

packages/core-mobile/app/contexts/DelegationContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ type TransactionHash = string
1717

1818
export type Delegate = ({
1919
steps,
20+
startDate,
2021
endDate,
2122
nodeId
2223
}: {
2324
steps: Step[]
25+
startDate: Date
2426
endDate: Date
2527
nodeId: string
2628
}) => Promise<TransactionHash>

packages/core-mobile/app/hooks/earn/useDelegation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const useDelegation = (): {
108108

109109
const delegate: Delegate = useCallback(
110110
// eslint-disable-next-line @typescript-eslint/no-shadow
111-
async ({ steps, endDate, nodeId }) => {
111+
async ({ steps, startDate, endDate, nodeId }) => {
112112
if (activeAccount === undefined) {
113113
throw new Error('No active account')
114114
}
@@ -136,11 +136,19 @@ export const useDelegation = (): {
136136
// otherwise, the transaction will fail with a "Start date must be in future" error
137137
const delegateStartDate = new Date(Date.now() + 1 * 60 * 1000)
138138

139+
// get the difference in milliseconds between the original start date and the fresh start date
140+
const differenceInMilliseconds =
141+
delegateStartDate.getTime() - startDate.getTime()
142+
// add the difference in milliseconds to the original end date, so the duration is the same as the original
143+
const delegateEndDate = new Date(
144+
endDate.getTime() + differenceInMilliseconds
145+
)
146+
139147
txHash = await EarnService.issueAddDelegatorTransaction({
140148
walletId: activeWallet.id,
141149
walletType: activeWallet.type,
142150
activeAccount,
143-
endDate,
151+
endDate: delegateEndDate,
144152
isDevMode: isDeveloperMode,
145153
nodeId,
146154
stakeAmountNanoAvax: step.amount,

packages/core-mobile/app/hooks/earn/useIssueDelegation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ export const useIssueDelegation = ({
1515
}): {
1616
issueDelegation: ({
1717
nodeId,
18+
startDate,
1819
endDate,
1920
recomputeSteps
2021
}: {
2122
nodeId: string
23+
startDate: Date
2224
endDate: Date
2325
recomputeSteps?: boolean
2426
}) => Promise<void>
@@ -28,24 +30,28 @@ export const useIssueDelegation = ({
2830
const mutationFn = useCallback(
2931
async ({
3032
nodeId,
33+
startDate,
3134
endDate,
3235
recomputeSteps = false
3336
}: {
3437
nodeId: string
38+
startDate: Date
3539
endDate: Date
3640
recomputeSteps?: boolean
3741
}) => {
3842
if (recomputeSteps) {
3943
const newSteps = await compute(stakeAmount.toSubUnit())
4044
return delegate({
4145
steps: newSteps,
46+
startDate,
4247
endDate,
4348
nodeId
4449
})
4550
}
4651

4752
return delegate({
4853
steps,
54+
startDate,
4955
endDate,
5056
nodeId
5157
})

packages/core-mobile/app/new/routes/(signedIn)/(modals)/addStake/confirm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const StakeConfirmScreen = (): JSX.Element => {
8282
}
8383
return 0
8484
}, [validator?.endTime])
85-
const { validatedStakingEndTime, validatedStakingDuration } =
85+
const { minStartTime, validatedStakingEndTime, validatedStakingDuration } =
8686
useValidateStakingEndTime(stakeEndTimeInMilliseconds, validatorEndTimeUnix)
8787

8888
const localValidatedStakingEndTime = useMemo(() => {
@@ -299,11 +299,12 @@ const StakeConfirmScreen = (): JSX.Element => {
299299

300300
issueDelegation({
301301
nodeId: validator.nodeID,
302+
startDate: minStartTime,
302303
endDate: validatedStakingEndTime,
303304
recomputeSteps
304305
})
305306
},
306-
[issueDelegation, validatedStakingEndTime, validator]
307+
[issueDelegation, minStartTime, validatedStakingEndTime, validator]
307308
)
308309

309310
usePreventScreenRemoval(isIssueDelegationPending)

0 commit comments

Comments
 (0)