From 71aa4b3920442bd790aaff4abdc9a378d5dec995 Mon Sep 17 00:00:00 2001 From: Neven Date: Tue, 26 Nov 2024 17:09:37 +0100 Subject: [PATCH 1/4] Rename and fix wrong unit conversion --- .../app/hooks/earn/useIssueDelegation.ts | 4 ++-- .../app/services/earn/EarnService.ts | 10 +++++----- .../app/services/earn/exportC.test.ts | 20 +++++++++---------- .../core-mobile/app/services/earn/exportC.ts | 15 +++++++------- .../core-mobile/app/services/earn/types.ts | 10 ++-------- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts b/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts index 20bac5f68..c83ec1fa1 100644 --- a/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts +++ b/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts @@ -132,9 +132,9 @@ export const useIssueDelegation = ( Logger.trace('collectTokensForStaking...') await EarnService.collectTokensForStaking({ activeAccount, - cChainBalance: cChainBalanceWei, + cChainBalanceWei, isDevMode: isDeveloperMode, - requiredAmount: cChainRequiredAmountAvax.toSubUnit(), + requiredAmountWei: cChainRequiredAmountAvax.toSubUnit(), selectedCurrency, isDevnet: isDevnet(activeNetwork), feeState: getFeeState(data.gasPrice) diff --git a/packages/core-mobile/app/services/earn/EarnService.ts b/packages/core-mobile/app/services/earn/EarnService.ts index 7790044fb..6b3a1ba57 100644 --- a/packages/core-mobile/app/services/earn/EarnService.ts +++ b/packages/core-mobile/app/services/earn/EarnService.ts @@ -128,21 +128,21 @@ class EarnService { * Collect tokens for staking by moving Avax from C to P-chain */ async collectTokensForStaking({ - cChainBalance, - requiredAmount, + cChainBalanceWei, + requiredAmountWei, activeAccount, isDevMode, selectedCurrency, isDevnet, feeState }: CollectTokensForStakingParams & { isDevnet: boolean }): Promise { - if (requiredAmount === 0n) { + if (requiredAmountWei === 0n) { Logger.info('no need to cross chain') return } await exportC({ - cChainBalance, - requiredAmount, + cChainBalanceWei, + requiredAmountWei, activeAccount, isDevMode, isDevnet diff --git a/packages/core-mobile/app/services/earn/exportC.test.ts b/packages/core-mobile/app/services/earn/exportC.test.ts index 4529bfd00..0cb4d4f80 100644 --- a/packages/core-mobile/app/services/earn/exportC.test.ts +++ b/packages/core-mobile/app/services/earn/exportC.test.ts @@ -60,8 +60,8 @@ describe('earn/exportC', () => { it('should fail if cChainBalance is less than required amount', async () => { await expect(async () => { await exportC({ - cChainBalance: BigInt(1e18), - requiredAmount: BigInt(10e9), + cChainBalanceWei: BigInt(1e18), + requiredAmountWei: BigInt(10e18), isDevMode: false, activeAccount: {} as Account, isDevnet: false @@ -71,8 +71,8 @@ describe('earn/exportC', () => { it('should call avaxProvider.getApiC().getBaseFee()', async () => { await exportC({ - cChainBalance: BigInt(10e18), - requiredAmount: BigInt(1e9), + cChainBalanceWei: BigInt(10e18), + requiredAmountWei: BigInt(1e18), isDevMode: false, activeAccount: {} as Account, isDevnet: false @@ -83,8 +83,8 @@ describe('earn/exportC', () => { it('should call walletService.createExportCTx', async () => { expect(async () => { await exportC({ - cChainBalance: BigInt(10e18), - requiredAmount: BigInt(1e9), + cChainBalanceWei: BigInt(10e18), + requiredAmountWei: BigInt(1e18), isDevMode: false, activeAccount: {} as Account, isDevnet: false @@ -103,8 +103,8 @@ describe('earn/exportC', () => { it('should call walletService.signAvaxTx', async () => { expect(async () => { await exportC({ - cChainBalance: BigInt(10e18), - requiredAmount: BigInt(1e9), + cChainBalanceWei: BigInt(10e18), + requiredAmountWei: BigInt(1e18), isDevMode: false, activeAccount: {} as Account, isDevnet: false @@ -116,8 +116,8 @@ describe('earn/exportC', () => { it('should call networkService.sendTransaction', async () => { expect(async () => { await exportC({ - cChainBalance: BigInt(10e18), - requiredAmount: BigInt(1e9), + cChainBalanceWei: BigInt(10e18), + requiredAmountWei: BigInt(1e18), isDevMode: false, activeAccount: {} as Account, isDevnet: false diff --git a/packages/core-mobile/app/services/earn/exportC.ts b/packages/core-mobile/app/services/earn/exportC.ts index f60e3ec60..06060e2d4 100644 --- a/packages/core-mobile/app/services/earn/exportC.ts +++ b/packages/core-mobile/app/services/earn/exportC.ts @@ -11,20 +11,19 @@ import NetworkService from 'services/network/NetworkService' import { FundsStuckError } from 'hooks/earn/errors' import { AvaxC } from 'types/AvaxC' import { weiToNano } from 'utils/units/converter' -import { AvaxXP } from 'types/AvaxXP' import { maxTransactionStatusCheckRetries } from './utils' export type ExportCParams = { - cChainBalance: bigint - requiredAmount: bigint // in nAvax + cChainBalanceWei: bigint + requiredAmountWei: bigint activeAccount: Account isDevMode: boolean isDevnet: boolean } export async function exportC({ - cChainBalance, - requiredAmount, + cChainBalanceWei, + requiredAmountWei, activeAccount, isDevMode, isDevnet @@ -52,8 +51,8 @@ export async function exportC({ const instantBaseFeeAvax = WalletService.getInstantBaseFee(baseFeeAvax) - const cChainBalanceAvax = AvaxC.fromWei(cChainBalance) - const requiredAmountAvax = AvaxXP.fromNanoAvax(requiredAmount) + const cChainBalanceAvax = AvaxC.fromWei(cChainBalanceWei) + const requiredAmountAvax = AvaxC.fromWei(requiredAmountWei) const pChainFeeAvax = await calculatePChainFee(avaxXPNetwork) const amountAvax = requiredAmountAvax.add(pChainFeeAvax) @@ -62,7 +61,7 @@ export async function exportC({ } const unsignedTxWithFee = await WalletService.createExportCTx({ - amountInNAvax: amountAvax.toSubUnit(), + amountInNAvax: weiToNano(amountAvax.toSubUnit()), baseFeeInNAvax: weiToNano(instantBaseFeeAvax.toSubUnit()), accountIndex: activeAccount.index, avaxXPNetwork, diff --git a/packages/core-mobile/app/services/earn/types.ts b/packages/core-mobile/app/services/earn/types.ts index 689b7ae99..6e3e6ba27 100644 --- a/packages/core-mobile/app/services/earn/types.ts +++ b/packages/core-mobile/app/services/earn/types.ts @@ -20,14 +20,8 @@ export type UnixTimeMs = number export type UnixTime = number export type CollectTokensForStakingParams = { - /** - * In `Wei` - */ - cChainBalance: bigint - /** - * In `Wei` - */ - requiredAmount: bigint + cChainBalanceWei: bigint + requiredAmountWei: bigint activeAccount: Account isDevMode: boolean selectedCurrency: string From a9b4d738ee97ab661bbad6747963f67d44e140d3 Mon Sep 17 00:00:00 2001 From: Neven Date: Tue, 26 Nov 2024 18:04:12 +0100 Subject: [PATCH 2/4] Fix token unit conversion --- .../hooks/earn/useEarnCalcEstimatedRewards.ts | 8 ++--- .../earn/useGetAmountForCrossChainTransfer.ts | 15 ++++++++++ .../app/hooks/earn/useIssueDelegation.ts | 29 +++++++++---------- .../EarnScreenStack/StakeSetupScreenStack.tsx | 4 ++- .../earn/Confirmation/Confirmation.tsx | 7 +++-- .../app/screens/earn/StakingAmount.tsx | 2 +- .../earn/durationScreen/DurationScreen.tsx | 8 +++-- .../components/CustomDurationOptionItem.tsx | 7 ++--- .../components/DurationOptionItem.tsx | 7 ++--- .../app/services/earn/EarnService.test.ts | 4 +-- .../app/services/earn/EarnService.ts | 11 ++++--- .../core-mobile/app/services/earn/types.ts | 2 +- .../earn/handleStakeConfirmationGoBack.ts | 2 +- 13 files changed, 63 insertions(+), 43 deletions(-) diff --git a/packages/core-mobile/app/hooks/earn/useEarnCalcEstimatedRewards.ts b/packages/core-mobile/app/hooks/earn/useEarnCalcEstimatedRewards.ts index 37b7c5b68..7323bd540 100644 --- a/packages/core-mobile/app/hooks/earn/useEarnCalcEstimatedRewards.ts +++ b/packages/core-mobile/app/hooks/earn/useEarnCalcEstimatedRewards.ts @@ -12,20 +12,20 @@ import { isDevnet } from 'utils/isDevnet' import { useAvalancheXpProvider } from 'hooks/networks/networkProviderHooks' export type useEarnCalcEstimatedRewardsProps = { - amount: TokenUnit + amountNanoAvax: bigint duration: Seconds delegationFee: number } /** * - * @param amount nAVAX + * @param amountNanoAvax nAVAX * @param duration between current datetime to validator end time * @param delegationFee * @returns */ export const useEarnCalcEstimatedRewards = ({ - amount, + amountNanoAvax, duration, delegationFee }: useEarnCalcEstimatedRewardsProps): UseQueryResult< @@ -54,7 +54,7 @@ export const useEarnCalcEstimatedRewards = ({ }, select: ({ supply: currentSupply }: pvm.GetCurrentSupplyResponse) => { const reward = EarnService.calcReward( - amount, + amountNanoAvax, duration, new TokenUnit( currentSupply, diff --git a/packages/core-mobile/app/hooks/earn/useGetAmountForCrossChainTransfer.ts b/packages/core-mobile/app/hooks/earn/useGetAmountForCrossChainTransfer.ts index e20cf825c..09c8b9cfa 100644 --- a/packages/core-mobile/app/hooks/earn/useGetAmountForCrossChainTransfer.ts +++ b/packages/core-mobile/app/hooks/earn/useGetAmountForCrossChainTransfer.ts @@ -34,3 +34,18 @@ export const calculateAmountForCrossChainTransfer = ( : stakingAmount } } +/** + * Calculates how much Avax we need to transfer from C to P + */ +export const calculateAmountForCrossChainTransferBigint = ( + stakingAmount: bigint, + claimableBalance?: bigint +): bigint => { + if (claimableBalance !== undefined && claimableBalance > stakingAmount) { + return 0n + } else { + return claimableBalance !== undefined + ? stakingAmount - claimableBalance + : stakingAmount + } +} diff --git a/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts b/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts index c83ec1fa1..7f09429d0 100644 --- a/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts +++ b/packages/core-mobile/app/hooks/earn/useIssueDelegation.ts @@ -9,7 +9,7 @@ import EarnService from 'services/earn/EarnService' import { selectIsDeveloperMode } from 'store/settings/advanced' import { selectActiveAccount } from 'store/account' import { selectSelectedCurrency } from 'store/settings/currency' -import { calculateAmountForCrossChainTransfer } from 'hooks/earn/useGetAmountForCrossChainTransfer' +import { calculateAmountForCrossChainTransferBigint } from 'hooks/earn/useGetAmountForCrossChainTransfer' import Logger from 'utils/Logger' import { FundsStuckError } from 'hooks/earn/errors' import NetworkService from 'services/network/NetworkService' @@ -20,6 +20,7 @@ import { isTokenWithBalancePVM } from '@avalabs/avalanche-module' import { TokenUnit } from '@avalabs/core-utils-sdk' import { isDevnet } from 'utils/isDevnet' import { selectActiveNetwork } from 'store/network' +import { nanoToWei } from 'utils/units/converter' import { useCChainBalance } from './useCChainBalance' import { useGetFeeState } from './useGetFeeState' @@ -33,11 +34,11 @@ export const useIssueDelegation = ( Error, { nodeId: string - stakingAmount: TokenUnit + stakingAmountNanoAvax: bigint startDate: Date endDate: Date gasPrice?: bigint - requiredPFee?: TokenUnit + requiredPFeeNanoAvax?: bigint }, unknown > @@ -62,11 +63,11 @@ export const useIssueDelegation = ( const issueDelegationMutation = useMutation({ mutationFn: async (data: { nodeId: string - stakingAmount: TokenUnit + stakingAmountNanoAvax: bigint startDate: Date endDate: Date gasPrice?: bigint - requiredPFee?: TokenUnit + requiredPFeeNanoAvax?: bigint }) => { if (!activeAccount) { return Promise.reject('no active account') @@ -120,21 +121,19 @@ export const useIssueDelegation = ( : undefined Logger.trace('getPChainBalance: ', claimableBalance?.toDisplay()) - const cChainRequiredAmountAvax = calculateAmountForCrossChainTransfer( - data.stakingAmount.add(data.requiredPFee ?? 0), - claimableBalance - ) + const cChainRequiredAmountNanoAvax = + calculateAmountForCrossChainTransferBigint( + data.stakingAmountNanoAvax + (data.requiredPFeeNanoAvax ?? 0n), + claimableBalance?.toSubUnit() + ) - Logger.trace( - 'cChainRequiredAmount: ', - cChainRequiredAmountAvax.toDisplay() - ) + Logger.trace('cChainRequiredAmount: ', cChainRequiredAmountNanoAvax) Logger.trace('collectTokensForStaking...') await EarnService.collectTokensForStaking({ activeAccount, cChainBalanceWei, isDevMode: isDeveloperMode, - requiredAmountWei: cChainRequiredAmountAvax.toSubUnit(), + requiredAmountWei: nanoToWei(cChainRequiredAmountNanoAvax), selectedCurrency, isDevnet: isDevnet(activeNetwork), feeState: getFeeState(data.gasPrice) @@ -145,7 +144,7 @@ export const useIssueDelegation = ( endDate: data.endDate, isDevMode: isDeveloperMode, nodeId: data.nodeId, - stakeAmount: data.stakingAmount.toSubUnit(), + stakeAmountNanoAvax: data.stakingAmountNanoAvax, startDate: data.startDate, isDevnet: isDevnet(activeNetwork), feeState: getFeeState(data.gasPrice) diff --git a/packages/core-mobile/app/navigation/wallet/EarnScreenStack/StakeSetupScreenStack.tsx b/packages/core-mobile/app/navigation/wallet/EarnScreenStack/StakeSetupScreenStack.tsx index ae146d0e4..da4891307 100644 --- a/packages/core-mobile/app/navigation/wallet/EarnScreenStack/StakeSetupScreenStack.tsx +++ b/packages/core-mobile/app/navigation/wallet/EarnScreenStack/StakeSetupScreenStack.tsx @@ -21,7 +21,9 @@ import { UTCDate } from '@date-fns/utc' export type StakeSetupStackParamList = { [AppNavigation.StakeSetup.GetStarted]: undefined [AppNavigation.StakeSetup.SmartStakeAmount]: undefined - [AppNavigation.StakeSetup.StakingDuration]: { stakingAmount: TokenUnit } + [AppNavigation.StakeSetup.StakingDuration]: { + stakingAmountNanoAvax: bigint + } [AppNavigation.StakeSetup.AdvancedStaking]: { stakingEndTime: UTCDate stakingAmount: TokenUnit diff --git a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx index 5a4b91a35..f6d93e93d 100644 --- a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx +++ b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx @@ -53,6 +53,7 @@ import { isDevnet } from 'utils/isDevnet' import { selectActiveNetwork } from 'store/network' import NetworkService from 'services/network/NetworkService' import { useIsNetworkFeeExcessive } from 'hooks/earn/useIsNetworkFeeExcessive' +import { weiToNano } from 'utils/units/converter' import { ConfirmScreen } from '../components/ConfirmScreen' import UnableToEstimate from '../components/UnableToEstimate' import { useValidateStakingEndTime } from './useValidateStakingEndTime' @@ -126,7 +127,7 @@ export const Confirmation = (): JSX.Element | null => { }, [validatedStakingEndTime]) const { data } = useEarnCalcEstimatedRewards({ - amount: deductedStakingAmount, + amountNanoAvax: weiToNano(deductedStakingAmount.toSubUnit()), duration: validatedStakingDuration, delegationFee: Number(validator?.delegationFee) }) @@ -187,12 +188,12 @@ export const Confirmation = (): JSX.Element | null => { } AnalyticsService.capture('StakeIssueDelegation') issueDelegationMutation.mutate({ - stakingAmount: deductedStakingAmount, + stakingAmountNanoAvax: weiToNano(deductedStakingAmount.toSubUnit()), startDate: minStartTime, endDate: validatedStakingEndTime, nodeId, gasPrice, - requiredPFee + requiredPFeeNanoAvax: requiredPFee?.toSubUnit() }) } diff --git a/packages/core-mobile/app/screens/earn/StakingAmount.tsx b/packages/core-mobile/app/screens/earn/StakingAmount.tsx index 33fcc25f7..90d65713f 100644 --- a/packages/core-mobile/app/screens/earn/StakingAmount.tsx +++ b/packages/core-mobile/app/screens/earn/StakingAmount.tsx @@ -161,7 +161,7 @@ export default function StakingAmount(): JSX.Element { onPress={() => { AnalyticsService.capture('StakeOpenDurationSelect') navigate(AppNavigation.StakeSetup.StakingDuration, { - stakingAmount: inputAmount + stakingAmountNanoAvax: inputAmount.toSubUnit() }) }}> Next diff --git a/packages/core-mobile/app/screens/earn/durationScreen/DurationScreen.tsx b/packages/core-mobile/app/screens/earn/durationScreen/DurationScreen.tsx index ef4b18c93..ba9677480 100644 --- a/packages/core-mobile/app/screens/earn/durationScreen/DurationScreen.tsx +++ b/packages/core-mobile/app/screens/earn/durationScreen/DurationScreen.tsx @@ -34,6 +34,7 @@ import { } from 'date-fns' import { UTCDate } from '@date-fns/utc' import { UnixTime } from 'services/earn/types' +import { AvaxXP } from 'types/AvaxXP' import { CustomDurationOptionItem } from './components/CustomDurationOptionItem' import { DurationOptionItem } from './components/DurationOptionItem' @@ -58,7 +59,8 @@ export const StakingDuration = (): JSX.Element => { const { theme } = useApplicationContext() const { navigate, setOptions, goBack } = useNavigation() - const { stakingAmount } = useRoute().params + const { stakingAmountNanoAvax } = useRoute().params + const stakingAmount = AvaxXP.fromNanoAvax(stakingAmountNanoAvax) const isNextDisabled = stakeEndTime === undefined || (!!stakeEndTime && stakeEndTime < millisecondsToSeconds(UTCDate.now())) @@ -151,7 +153,7 @@ export const StakingDuration = (): JSX.Element => { return ( { const renderCustomOption = (): JSX.Element => ( void handleDateConfirm: (dateInput: UTCDate) => void @@ -62,7 +61,7 @@ export const CustomDurationOptionItem = ({ BigInt(stakeDurationMs) as MilliSeconds ) const { data } = useEarnCalcEstimatedRewards({ - amount: stakeAmount, + amountNanoAvax: stakingAmountNanoAvax, duration: stakeDurationSec, delegationFee: 2 }) diff --git a/packages/core-mobile/app/screens/earn/durationScreen/components/DurationOptionItem.tsx b/packages/core-mobile/app/screens/earn/durationScreen/components/DurationOptionItem.tsx index 63ce167e2..9a3d0e6e1 100644 --- a/packages/core-mobile/app/screens/earn/durationScreen/components/DurationOptionItem.tsx +++ b/packages/core-mobile/app/screens/earn/durationScreen/components/DurationOptionItem.tsx @@ -12,16 +12,15 @@ import { RadioButton } from 'components/RadioButton' import AvaText from 'components/AvaText' import { selectIsDeveloperMode } from 'store/settings/advanced' import { useSelector } from 'react-redux' -import { TokenUnit } from '@avalabs/core-utils-sdk' import { UNKNOWN_AMOUNT } from 'consts/amount' export const DurationOptionItem = ({ - stakeAmount, + stakingAmountNanoAvax, item, onRadioSelect, isSelected }: { - stakeAmount: TokenUnit + stakingAmountNanoAvax: bigint item: DurationOption onRadioSelect: (item: DurationOption) => void isSelected: boolean @@ -38,7 +37,7 @@ export const DurationOptionItem = ({ BigInt(stakeDurationUnixMs) as MilliSeconds ) const { data } = useEarnCalcEstimatedRewards({ - amount: stakeAmount, + amountNanoAvax: stakingAmountNanoAvax, duration: stakeDurationUnixSec, delegationFee: 2 }) diff --git a/packages/core-mobile/app/services/earn/EarnService.test.ts b/packages/core-mobile/app/services/earn/EarnService.test.ts index c9a197cab..0ae3cd943 100644 --- a/packages/core-mobile/app/services/earn/EarnService.test.ts +++ b/packages/core-mobile/app/services/earn/EarnService.test.ts @@ -27,7 +27,7 @@ describe('EarnService', () => { it('should return zero if current supply is max', () => { expect( EarnService.calcReward( - new TokenUnit(25 * 10 ** 9, 9, 'AVAX'), + BigInt(25 * 10 ** 9), Seconds(7 * 24 * Hour), new TokenUnit( MainnetParams.stakingConfig.RewardConfig.SupplyCap, @@ -43,7 +43,7 @@ describe('EarnService', () => { it('should return non zero if current supply is less than max', () => { expect( EarnService.calcReward( - new TokenUnit(2000000 * 10 ** 9, 9, 'AVAX'), + BigInt(2000000 * 10 ** 9), Seconds(7 * 24 * Hour), new TokenUnit(400_000_000 * 10 ** 9, 9, 'AVAX'), 2, diff --git a/packages/core-mobile/app/services/earn/EarnService.ts b/packages/core-mobile/app/services/earn/EarnService.ts index 6b3a1ba57..f4e6137c4 100644 --- a/packages/core-mobile/app/services/earn/EarnService.ts +++ b/packages/core-mobile/app/services/earn/EarnService.ts @@ -40,6 +40,7 @@ import AnalyticsService from 'services/analytics/AnalyticsService' import { TokenUnit } from '@avalabs/core-utils-sdk' import { Avalanche } from '@avalabs/core-wallets-sdk' import { Network } from '@avalabs/core-chains-sdk' +import { AvaxXP } from 'types/AvaxXP' import { getTransformedTransactions, maxGetAtomicUTXOsRetries, @@ -190,7 +191,7 @@ class EarnService { /** * - * @param amount + * @param amountNanoAvax in nAvax * @param duration in s * @param currentSupply * @param delegationFee in percent @@ -198,13 +199,15 @@ class EarnService { */ // eslint-disable-next-line max-params calcReward( - amount: TokenUnit, + amountNanoAvax: bigint, duration: Seconds, currentSupply: TokenUnit, delegationFee: number, isDeveloperMode: boolean, isDevnet: boolean ): TokenUnit { + const amount = AvaxXP.fromNanoAvax(amountNanoAvax) + const avaxPNetwork = NetworkService.getAvalancheNetworkP( isDeveloperMode, isDevnet @@ -250,7 +253,7 @@ class EarnService { async issueAddDelegatorTransaction({ activeAccount, nodeId, - stakeAmount, + stakeAmountNanoAvax, startDate, endDate, isDevMode, @@ -272,7 +275,7 @@ class EarnService { nodeId, startDate: startDateUnix, endDate: endDateUnix, - stakeAmountInNAvax: stakeAmount, + stakeAmountInNAvax: stakeAmountNanoAvax, isDevMode, feeState } as AddDelegatorProps) diff --git a/packages/core-mobile/app/services/earn/types.ts b/packages/core-mobile/app/services/earn/types.ts index 6e3e6ba27..61dcae1b0 100644 --- a/packages/core-mobile/app/services/earn/types.ts +++ b/packages/core-mobile/app/services/earn/types.ts @@ -6,7 +6,7 @@ export type AddDelegatorTransactionProps = { // Id of the node to delegate. starts with “NodeID-” nodeId: string //Amount to be delegated in nAVAX - stakeAmount: bigint + stakeAmountNanoAvax: bigint // The Date time when the delegation starts. startDate: Date // The Date time when the delegation ends. diff --git a/packages/core-mobile/app/utils/earn/handleStakeConfirmationGoBack.ts b/packages/core-mobile/app/utils/earn/handleStakeConfirmationGoBack.ts index 859922142..9c5875b46 100644 --- a/packages/core-mobile/app/utils/earn/handleStakeConfirmationGoBack.ts +++ b/packages/core-mobile/app/utils/earn/handleStakeConfirmationGoBack.ts @@ -30,7 +30,7 @@ export const handleStakeConfirmationGoBack = ( .params?.stakingAmount if (stakingAmount) { return navigate(AppNavigation.StakeSetup.StakingDuration, { - stakingAmount + stakingAmountNanoAvax: stakingAmount.toSubUnit() }) } return navigate(AppNavigation.StakeSetup.SmartStakeAmount) From cceaa52a5506be818d9eb71eff4c8c74d8316770 Mon Sep 17 00:00:00 2001 From: Neven Date: Tue, 26 Nov 2024 18:20:04 +0100 Subject: [PATCH 3/4] Fix wrong conversion when using PercentButtons --- .../app/screens/earn/Confirmation/Confirmation.tsx | 4 ++-- packages/core-mobile/app/screens/earn/StakingAmount.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx index f6d93e93d..9eabe6b42 100644 --- a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx +++ b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx @@ -127,7 +127,7 @@ export const Confirmation = (): JSX.Element | null => { }, [validatedStakingEndTime]) const { data } = useEarnCalcEstimatedRewards({ - amountNanoAvax: weiToNano(deductedStakingAmount.toSubUnit()), + amountNanoAvax: deductedStakingAmount.toSubUnit(), duration: validatedStakingDuration, delegationFee: Number(validator?.delegationFee) }) @@ -188,7 +188,7 @@ export const Confirmation = (): JSX.Element | null => { } AnalyticsService.capture('StakeIssueDelegation') issueDelegationMutation.mutate({ - stakingAmountNanoAvax: weiToNano(deductedStakingAmount.toSubUnit()), + stakingAmountNanoAvax: deductedStakingAmount.toSubUnit(), startDate: minStartTime, endDate: validatedStakingEndTime, nodeId, diff --git a/packages/core-mobile/app/screens/earn/StakingAmount.tsx b/packages/core-mobile/app/screens/earn/StakingAmount.tsx index 90d65713f..a5880c5b4 100644 --- a/packages/core-mobile/app/screens/earn/StakingAmount.tsx +++ b/packages/core-mobile/app/screens/earn/StakingAmount.tsx @@ -99,7 +99,7 @@ export default function StakingAmount(): JSX.Element { percent: (100 / factor).toString() }) if (!cumulativeBalance) return - setInputAmount(cumulativeBalance.div(factor)) + setInputAmount(zeroAvaxPChain().add(cumulativeBalance.div(factor))) } return ( From 54c1469856c15a376b32a226a756dad251de93d3 Mon Sep 17 00:00:00 2001 From: Neven Date: Tue, 26 Nov 2024 19:26:41 +0100 Subject: [PATCH 4/4] Minor fix --- .../core-mobile/app/screens/earn/Confirmation/Confirmation.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx index 9eabe6b42..6a9fd9a0a 100644 --- a/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx +++ b/packages/core-mobile/app/screens/earn/Confirmation/Confirmation.tsx @@ -53,7 +53,6 @@ import { isDevnet } from 'utils/isDevnet' import { selectActiveNetwork } from 'store/network' import NetworkService from 'services/network/NetworkService' import { useIsNetworkFeeExcessive } from 'hooks/earn/useIsNetworkFeeExcessive' -import { weiToNano } from 'utils/units/converter' import { ConfirmScreen } from '../components/ConfirmScreen' import UnableToEstimate from '../components/UnableToEstimate' import { useValidateStakingEndTime } from './useValidateStakingEndTime'