Skip to content

Commit

Permalink
chore: refactored vesting
Browse files Browse the repository at this point in the history
  • Loading branch information
GarageInc committed Dec 16, 2024
1 parent 8f2e526 commit 0f5e9fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
21 changes: 15 additions & 6 deletions apps/vesting/src/components/liquid-vesting/liquid-vesting.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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;
Expand All @@ -328,7 +329,7 @@ function LiquidVesting({
);

if (normalizedAmount) {
onAmountChange(normalizedAmount);
onAmountChange(parseUnits(normalizedAmount.toString(), 18));
}
}
},
Expand Down Expand Up @@ -366,6 +367,14 @@ function LiquidVesting({
[onSubmit],
);

const liquidationAmountNumber = useMemo(() => {
if (liquidationAmount) {
return Number.parseFloat(formatUnits(liquidationAmount, 18));
}

return undefined;
}, [liquidationAmount]);

return (
<Card className="mx-auto w-full max-w-lg overflow-hidden">
<div className="px-[16px] pt-[24px]">
Expand All @@ -383,7 +392,7 @@ function LiquidVesting({
required
label="Amount"
placeholder={`Min ${formatLocaleNumber(MIN_AMOUNT)} ISLM`}
value={liquidationAmount}
value={liquidationAmountNumber}
onChange={handleInputChange}
{...hintAndState}
/>
Expand Down
5 changes: 4 additions & 1 deletion apps/vesting/src/components/vesting-account-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function VestingAccountInfo({
{/* <DaoParticipate address={ethAddress} /> */}

{isLiquidVestingVisible && (
<LiquidVestingHooked balance={balances.total} haqqAddress={address} />
<LiquidVestingHooked
balance={balances.totalBn}
haqqAddress={address}
/>
)}

{isClawbackVestingAccount(accountInfo) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function useLiquidVestingActions() {
const getLiquidateParams = useCallback(
(
liquidateTo: string,
amount: number,
balance: number,
amount: bigint,
balance: bigint,
fee: Fee,
): MsgLiquidateParams => {
return {
Expand All @@ -59,16 +59,16 @@ 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 = '';

if (sender && address && haqqChain) {
const params = getLiquidateParams(
address,
amount ?? 0,
balance ?? 0,
amount ?? 0n,
balance ?? 0n,
VESTING_DEFAULT_FEE,
);

Expand Down

0 comments on commit 0f5e9fb

Please sign in to comment.