diff --git a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx index 493335598..252239214 100644 --- a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx +++ b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx @@ -23,6 +23,8 @@ function UnstakeFormModal({ const { decimals } = getCurrencyByType("bitcoin") const inputPlaceholder = `Minimum ${fixedPointNumberToString(minTokenAmount, decimals)} BTC` const tokenAmountLabel = "Acre balance" + const defaultAmount = + status === PROCESS_STATUSES.REFINE_AMOUNT ? balance : undefined return ( Withdraw diff --git a/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx b/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx index 07c559a1b..98107eb8b 100644 --- a/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx +++ b/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx @@ -1,32 +1,24 @@ -import React, { useEffect } from "react" +import React from "react" import { useFormField } from "#/hooks" import TokenBalanceInput, { TokenBalanceInputProps } from "../TokenBalanceInput" export type FormTokenBalanceInputProps = { name: string - defaultValue?: bigint -} & Omit +} & Omit export function FormTokenBalanceInput({ name, - defaultValue, ...restProps }: FormTokenBalanceInputProps) { const { field, value, errorMsgText, hasError, onChange } = useFormField< bigint | undefined >(name) - useEffect(() => { - if (defaultValue) { - onChange(defaultValue) - } - }, [defaultValue, onChange]) - return ( {children} diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index c9e67d55c..cd92ff160 100644 --- a/dapp/src/components/shared/TokenBalanceInput/index.tsx +++ b/dapp/src/components/shared/TokenBalanceInput/index.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState } from "react" +import React, { useEffect, useRef, useState } from "react" import { Box, Button, @@ -61,6 +61,7 @@ function FiatCurrencyBalance({ export type TokenBalanceInputProps = { amount?: bigint + defaultAmount?: bigint currency: CurrencyType tokenBalance: bigint placeholder?: string @@ -75,6 +76,7 @@ export type TokenBalanceInputProps = { export default function TokenBalanceInput({ amount, + defaultAmount, currency, tokenBalance, placeholder, @@ -114,6 +116,16 @@ export default function TokenBalanceInput({ typeof errorMsgText === "string" && isFormError("EXCEEDED_VALUE", errorMsgText) + const defaultValue = defaultAmount + ? fixedPointNumberToString(defaultAmount, decimals) + : undefined + + useEffect(() => { + if (!defaultAmount) return + + setAmount(defaultAmount) + }, [defaultAmount, setAmount]) + return ( @@ -144,6 +156,7 @@ export default function TokenBalanceInput({ {...inputProps} isInvalid={hasError} value={displayedValue} + defaultValue={defaultValue} onValueChange={onValueChange} onChange={onChange} /> diff --git a/dapp/src/hooks/useAcrePoints.ts b/dapp/src/hooks/useAcrePoints.ts index f1445b655..49e0097da 100644 --- a/dapp/src/hooks/useAcrePoints.ts +++ b/dapp/src/hooks/useAcrePoints.ts @@ -1,5 +1,5 @@ import { useMutation, useQuery } from "@tanstack/react-query" -import { acreApi, bigIntToUserAmount } from "#/utils" +import { acreApi } from "#/utils" import { queryKeysFactory } from "#/constants" import { MODAL_TYPES } from "#/types" import { useWallet } from "./useWallet" @@ -38,8 +38,8 @@ export default function useAcrePoints(): UseAcrePointsReturnType { await userPointsDataQuery.refetch() }, onSuccess: (data) => { - const claimedAmount = bigIntToUserAmount(data.claimed, 0) - const totalAmount = bigIntToUserAmount(data.total, 0) + const claimedAmount = Number(data.claimed) + const totalAmount = Number(data.total) openModal(MODAL_TYPES.ACRE_POINTS_CLAIM, { claimedAmount, @@ -50,13 +50,9 @@ export default function useAcrePoints(): UseAcrePointsReturnType { // onError: (error) => {}, }) - const { data } = userPointsDataQuery - const totalBalance = bigIntToUserAmount(data?.claimed ?? 0n, 0) - const claimableBalance = bigIntToUserAmount(data?.unclaimed ?? 0n, 0) - return { - totalBalance, - claimableBalance, + totalBalance: userPointsDataQuery.data?.claimed ?? 0, + claimableBalance: userPointsDataQuery.data?.unclaimed ?? 0, nextDropTimestamp: pointsDataQuery.data?.dropAt, isCalculationInProgress: pointsDataQuery.data?.isCalculationInProgress, claimPoints, diff --git a/dapp/src/utils/acreApi.ts b/dapp/src/utils/acreApi.ts index 5bbed9acb..c174cbd13 100644 --- a/dapp/src/utils/acreApi.ts +++ b/dapp/src/utils/acreApi.ts @@ -60,8 +60,8 @@ const getPointsDataByUser = async (address: string) => { const response = await axios.get(url) return { - claimed: BigInt(response.data.claimed), - unclaimed: BigInt(response.data.unclaimed), + claimed: Number(response.data.claimed), + unclaimed: Number(response.data.unclaimed), isEligible: response.data.isEligible, } }