From e0766eb447134e16ac1d2a0e201ce5a03a39fca4 Mon Sep 17 00:00:00 2001 From: Oleg Shilov <me@olegshilov.com> Date: Sat, 7 Oct 2023 22:06:13 +0700 Subject: [PATCH] fix(shell): use bigint to calculate vesting periods amount correctly --- .../create-vesting-account-page.tsx | 6 +++--- .../src/lib/use-vesting-actions/use-vesting-actions.tsx | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/shell/services-pages/src/lib/create-vesting-account-page/create-vesting-account-page.tsx b/libs/shell/services-pages/src/lib/create-vesting-account-page/create-vesting-account-page.tsx index 6748ad337..f8c233a02 100644 --- a/libs/shell/services-pages/src/lib/create-vesting-account-page/create-vesting-account-page.tsx +++ b/libs/shell/services-pages/src/lib/create-vesting-account-page/create-vesting-account-page.tsx @@ -343,8 +343,8 @@ function CreateVestingAccountForm() { placeholder="Deposit amount in ISLM" value={amount.toString()} onChange={(value) => { - const nextValue = !Number.isNaN(Number.parseInt(value)) - ? Number.parseInt(value) + const nextValue = !Number.isNaN(Number.parseFloat(value)) + ? Number.parseFloat(value) : 0; setAmount(nextValue); }} @@ -488,7 +488,7 @@ function Input({ required id={id} name={id} - value={value} + defaultValue={value} onChange={(event) => { onChange(event.currentTarget.value); }} diff --git a/libs/shell/services-pages/src/lib/use-vesting-actions/use-vesting-actions.tsx b/libs/shell/services-pages/src/lib/use-vesting-actions/use-vesting-actions.tsx index 0eeefcee1..516799a9a 100644 --- a/libs/shell/services-pages/src/lib/use-vesting-actions/use-vesting-actions.tsx +++ b/libs/shell/services-pages/src/lib/use-vesting-actions/use-vesting-actions.tsx @@ -80,8 +80,9 @@ export function useVestingActions() { const periods = vestingInDays; const denom = 'aISLM'; const lockupPeriods = []; - let restAmount = amount; - let unlockAmount = Math.floor(amount / periods); + const aislmAmount = BigInt(amount * 10 ** 18); + let restAmount = aislmAmount; + let unlockAmount = aislmAmount / BigInt(periods); let length: number = cliff; for (let i = 0; i < periods; i++) { @@ -91,7 +92,7 @@ export function useVestingActions() { const unlockCoins = { denom: denom, - amount: BigInt(unlockAmount * 10 ** 18).toString(), + amount: unlockAmount.toString(), }; const period = {