From e8d45239509f28fa0821280ebc1dff151b3c4109 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 24 Oct 2024 13:18:17 +0200 Subject: [PATCH 1/4] Fix points amount casting issue The `bigIntToUserAmount` function was used unintentionally. The points amount is not user amount. It can be casted directly to numbers via `Number()` constructor. --- dapp/src/hooks/useAcrePoints.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dapp/src/hooks/useAcrePoints.ts b/dapp/src/hooks/useAcrePoints.ts index f1445b655..5c6d2dd1e 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, @@ -51,8 +51,8 @@ export default function useAcrePoints(): UseAcrePointsReturnType { }) const { data } = userPointsDataQuery - const totalBalance = bigIntToUserAmount(data?.claimed ?? 0n, 0) - const claimableBalance = bigIntToUserAmount(data?.unclaimed ?? 0n, 0) + const totalBalance = Number(data?.claimed ?? 0n) + const claimableBalance = Number(data?.unclaimed ?? 0n) return { totalBalance, From e66c526385fcf0e3c871cd9d240fccc72d76b80b Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Thu, 24 Oct 2024 16:31:19 +0200 Subject: [PATCH 2/4] Remove unncessary casting --- dapp/src/hooks/useAcrePoints.ts | 8 ++------ dapp/src/utils/acreApi.ts | 8 ++++---- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dapp/src/hooks/useAcrePoints.ts b/dapp/src/hooks/useAcrePoints.ts index 5c6d2dd1e..49e0097da 100644 --- a/dapp/src/hooks/useAcrePoints.ts +++ b/dapp/src/hooks/useAcrePoints.ts @@ -50,13 +50,9 @@ export default function useAcrePoints(): UseAcrePointsReturnType { // onError: (error) => {}, }) - const { data } = userPointsDataQuery - const totalBalance = Number(data?.claimed ?? 0n) - const claimableBalance = Number(data?.unclaimed ?? 0n) - 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 a5836d9b3..a3e6c15d6 100644 --- a/dapp/src/utils/acreApi.ts +++ b/dapp/src/utils/acreApi.ts @@ -51,8 +51,8 @@ const getPointsData = async () => { type PointsDataByUserResponse = { isEligible: boolean - claimed: string - unclaimed: string + claimed: number + unclaimed: number } const getPointsDataByUser = async (address: string) => { @@ -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, } } From 6d026527ba18f83c71332c3cd9f3c7e07095b420 Mon Sep 17 00:00:00 2001 From: Karolina Kosiorowska Date: Mon, 28 Oct 2024 11:35:10 +0100 Subject: [PATCH 3/4] Set the amount to max MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the user clicks “Withdraw all funds” and is redirected to the deposit form, the “Amount” field should be pre-filled with the maximum value. --- .../UnstakeFormModal/index.tsx | 6 +++--- .../shared/Form/FormTokenBalanceInput.tsx | 14 +++----------- .../TokenAmountForm/TokenAmountFormBase.tsx | 2 +- .../components/shared/TokenBalanceInput/index.tsx | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx index 6aad91f7f..5137be55e 100644 --- a/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx +++ b/dapp/src/components/TransactionModal/ActiveUnstakingStep/UnstakeFormModal/index.tsx @@ -22,6 +22,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 fc922ea8c..a7787739f 100644 --- a/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx +++ b/dapp/src/components/shared/Form/FormTokenBalanceInput.tsx @@ -1,16 +1,14 @@ -import React, { useCallback, useEffect } from "react" +import React, { useCallback } from "react" import { useField } from "formik" import { logPromiseFailure } from "#/utils" import TokenBalanceInput, { TokenBalanceInputProps } from "../TokenBalanceInput" export type FormTokenBalanceInputProps = { name: string - defaultValue?: bigint -} & Omit +} & Omit export function FormTokenBalanceInput({ name, - defaultValue, ...restProps }: FormTokenBalanceInputProps) { const [field, meta, helpers] = useField(name) @@ -25,17 +23,11 @@ export function FormTokenBalanceInput({ [helpers, meta.touched, meta.error], ) - useEffect(() => { - if (defaultValue) { - setAmount(defaultValue) - } - }, [defaultValue, setAmount]) - return ( {children} diff --git a/dapp/src/components/shared/TokenBalanceInput/index.tsx b/dapp/src/components/shared/TokenBalanceInput/index.tsx index 9a7c13b86..1ab3d6a32 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, @@ -102,6 +102,7 @@ function FiatCurrencyBalance({ export type TokenBalanceInputProps = { amount?: bigint + defaultAmount?: bigint currency: CurrencyType tokenBalance: bigint placeholder?: string @@ -116,6 +117,7 @@ export type TokenBalanceInputProps = { export default function TokenBalanceInput({ amount, + defaultAmount, currency, tokenBalance, placeholder, @@ -155,6 +157,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 ( @@ -185,6 +197,7 @@ export default function TokenBalanceInput({ allowNegative={false} {...inputProps} value={displayedValue} + defaultValue={defaultValue} onValueChange={onValueChange} onChange={onChange} /> From 7ea155bc2386291808fe46f3ed84f1809b499d61 Mon Sep 17 00:00:00 2001 From: Kamil Pyszkowski Date: Tue, 29 Oct 2024 10:15:34 +0100 Subject: [PATCH 4/4] Update type definition --- dapp/src/utils/acreApi.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dapp/src/utils/acreApi.ts b/dapp/src/utils/acreApi.ts index a3e6c15d6..e3d1d7ed5 100644 --- a/dapp/src/utils/acreApi.ts +++ b/dapp/src/utils/acreApi.ts @@ -51,8 +51,8 @@ const getPointsData = async () => { type PointsDataByUserResponse = { isEligible: boolean - claimed: number - unclaimed: number + claimed: string + unclaimed: string } const getPointsDataByUser = async (address: string) => {