From 0f5e9fbedcacd2765372202ea9cb279ed6e0d61a Mon Sep 17 00:00:00 2001 From: garageinc <9-b-rinat@rambler.ru> Date: Mon, 16 Dec 2024 17:22:25 +0300 Subject: [PATCH] chore: refactored vesting --- .../liquid-vesting/liquid-vesting.tsx | 21 +++++++++++++------ .../src/components/vesting-account-info.tsx | 5 ++++- .../use-liquidvesting-actions.tsx | 10 ++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/apps/vesting/src/components/liquid-vesting/liquid-vesting.tsx b/apps/vesting/src/components/liquid-vesting/liquid-vesting.tsx index cacebecb7..0f1cc88e0 100644 --- a/apps/vesting/src/components/liquid-vesting/liquid-vesting.tsx +++ b/apps/vesting/src/components/liquid-vesting/liquid-vesting.tsx @@ -1,5 +1,6 @@ import { FormEvent, useCallback, useEffect, useMemo, useState } from 'react'; import { Link } from 'react-router-dom'; +import { formatUnits, parseUnits } from 'viem'; import { useAccount } from 'wagmi'; import { haqqMainnet } from 'wagmi/chains'; import { BroadcastTxResponse, getChainParams } from '@haqq/data-access-cosmos'; @@ -66,11 +67,11 @@ export function LiquidVestingHooked({ balance, haqqAddress, }: { - balance: number; + balance: bigint; haqqAddress: string; }) { const [liquidationAmount, setLiquidationAmount] = useState< - number | undefined + bigint | undefined >(undefined); const [amountError, setAmountError] = useState< undefined | 'min' | 'max' | 'balance' @@ -307,8 +308,8 @@ function LiquidVesting({ addedTokens, onRedeemClick, }: { - liquidationAmount: number | undefined; - onAmountChange: (value: number) => void; + liquidationAmount: bigint | undefined; + onAmountChange: (value: bigint) => void; amountError?: 'min' | 'max' | 'balance'; isLiquidationEnabled: boolean; onSubmit: () => void; @@ -328,7 +329,7 @@ function LiquidVesting({ ); if (normalizedAmount) { - onAmountChange(normalizedAmount); + onAmountChange(parseUnits(normalizedAmount.toString(), 18)); } } }, @@ -366,6 +367,14 @@ function LiquidVesting({ [onSubmit], ); + const liquidationAmountNumber = useMemo(() => { + if (liquidationAmount) { + return Number.parseFloat(formatUnits(liquidationAmount, 18)); + } + + return undefined; + }, [liquidationAmount]); + return (
@@ -383,7 +392,7 @@ function LiquidVesting({ required label="Amount" placeholder={`Min ${formatLocaleNumber(MIN_AMOUNT)} ISLM`} - value={liquidationAmount} + value={liquidationAmountNumber} onChange={handleInputChange} {...hintAndState} /> diff --git a/apps/vesting/src/components/vesting-account-info.tsx b/apps/vesting/src/components/vesting-account-info.tsx index 0c41d6d05..125c271b1 100644 --- a/apps/vesting/src/components/vesting-account-info.tsx +++ b/apps/vesting/src/components/vesting-account-info.tsx @@ -52,7 +52,10 @@ export function VestingAccountInfo({ {/* */} {isLiquidVestingVisible && ( - + )} {isClawbackVestingAccount(accountInfo) && ( diff --git a/libs/shared/src/hooks/liquidvesting/use-liquidvesting-actions.tsx b/libs/shared/src/hooks/liquidvesting/use-liquidvesting-actions.tsx index 33ad129e9..2a6703566 100644 --- a/libs/shared/src/hooks/liquidvesting/use-liquidvesting-actions.tsx +++ b/libs/shared/src/hooks/liquidvesting/use-liquidvesting-actions.tsx @@ -35,8 +35,8 @@ export function useLiquidVestingActions() { const getLiquidateParams = useCallback( ( liquidateTo: string, - amount: number, - balance: number, + amount: bigint, + balance: bigint, fee: Fee, ): MsgLiquidateParams => { return { @@ -59,7 +59,7 @@ export function useLiquidVestingActions() { ); const handleLiquidate = useCallback( - async (address?: string, amount?: number, balance?: number) => { + async (address?: string, amount?: bigint, balance?: bigint) => { const pubkey = await getPubkey(ethAddress as string); const sender = await getSender(haqqAddress as string, pubkey); const memo = ''; @@ -67,8 +67,8 @@ export function useLiquidVestingActions() { if (sender && address && haqqChain) { const params = getLiquidateParams( address, - amount ?? 0, - balance ?? 0, + amount ?? 0n, + balance ?? 0n, VESTING_DEFAULT_FEE, );