From 58ed7ce4b9bf45fd066b3fd632fd49aa5afc7f09 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 24 Oct 2023 15:23:35 +0800 Subject: [PATCH] Fix USDT decimals (#545) * fix usdt decimals * valid fee rate check * fix FEE_RATE_MAX * update FeeRateInput placeholder --- packages/apps/src/components/fee-rate-input.tsx | 4 ++-- packages/apps/src/components/relayer-manage-modal.tsx | 4 ++-- packages/apps/src/components/relayer-register.tsx | 7 ++++--- packages/apps/src/config/chains/arbitrum.ts | 2 +- packages/apps/src/config/chains/mantle.ts | 2 +- packages/apps/src/config/constant.ts | 3 +++ packages/apps/src/utils/misc.ts | 6 +++++- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/apps/src/components/fee-rate-input.tsx b/packages/apps/src/components/fee-rate-input.tsx index 06e9dd75a..9c107fb2e 100644 --- a/packages/apps/src/components/fee-rate-input.tsx +++ b/packages/apps/src/components/fee-rate-input.tsx @@ -1,5 +1,5 @@ import Input from "@/ui/input"; -import { parseFeeRate } from "@/utils/misc"; +import { isValidFeeRate, parseFeeRate } from "@/utils/misc"; export default function FeeRateInput({ placeholder, @@ -10,7 +10,7 @@ export default function FeeRateInput({ value?: { formatted: number; value: string }; onChange?: (value: { formatted: number; value: string }) => void; }) { - const invalid = (value?.formatted || 0) < 0 || 100000 < (value?.formatted || 0); + const invalid = !isValidFeeRate(value?.formatted || 0); return (
import("@/ui/modal"), { ssr: false }); @@ -207,7 +207,7 @@ export default function RelayerManageModal({ relayerInfo, isOpen, onClose, onSuc busy={busy} disabledCancel={busy} disabledOk={ - activeKey === "update" && baseFee.formatted === 0n && feeRate.formatted === 0 + activeKey === "update" && !(baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted)) ? true : activeKey === "deposit" && margin.formatted === 0n ? true diff --git a/packages/apps/src/components/relayer-register.tsx b/packages/apps/src/components/relayer-register.tsx index d75106c4a..edf1cedc4 100644 --- a/packages/apps/src/components/relayer-register.tsx +++ b/packages/apps/src/components/relayer-register.tsx @@ -11,7 +11,7 @@ import { Token, TokenSymbol } from "@/types/token"; import { BridgeCategory } from "@/types/bridge"; import { useAccount, useNetwork, useSwitchNetwork } from "wagmi"; import Image from "next/image"; -import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc } from "@/utils/misc"; +import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc, isValidFeeRate } from "@/utils/misc"; import Tooltip from "@/ui/tooltip"; import StepCompleteItem from "./step-complete-item"; import { BalanceInput } from "./balance-input"; @@ -321,7 +321,7 @@ export default function RelayerRegister() { label="Liquidity Fee Rate" tips="The percentage deducted by the relayer from the transfer amount in a transaction" > - + @@ -372,7 +372,8 @@ export default function RelayerRegister() { } }} disabled={ - (sourceChain?.id === chain?.id && (!margin.formatted || !baseFee.formatted || !feeRate.formatted)) || + (sourceChain?.id === chain?.id && + !(margin.value && baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted))) || (bridgeCategory === "lnbridgev20-default" && !completeMargin) } busy={busy} diff --git a/packages/apps/src/config/chains/arbitrum.ts b/packages/apps/src/config/chains/arbitrum.ts index 6ae44bf0a..24691fc58 100644 --- a/packages/apps/src/config/chains/arbitrum.ts +++ b/packages/apps/src/config/chains/arbitrum.ts @@ -44,7 +44,7 @@ export const arbitrumChain: ChainConfig = { cross: [{ target: { network: "ethereum", symbol: "RING" }, bridge: { category: "lnbridgev20-opposite" } }], }, { - decimals: 18, + decimals: 6, symbol: "USDT", name: "USDT", type: "erc20", diff --git a/packages/apps/src/config/chains/mantle.ts b/packages/apps/src/config/chains/mantle.ts index 38f2af4d8..e34da86d5 100644 --- a/packages/apps/src/config/chains/mantle.ts +++ b/packages/apps/src/config/chains/mantle.ts @@ -28,7 +28,7 @@ export const mantleChain: ChainConfig = { }, tokens: [ { - decimals: 18, + decimals: 6, symbol: "USDT", name: "USDT", type: "erc20", diff --git a/packages/apps/src/config/constant.ts b/packages/apps/src/config/constant.ts index 69b4f9dab..5a3eb1b8b 100644 --- a/packages/apps/src/config/constant.ts +++ b/packages/apps/src/config/constant.ts @@ -2,3 +2,6 @@ * If the fee rate is 10.123%, its value in the contract is 10123 (10.123 * 1000) */ export const FEE_RATE_BASE = 1000; + +export const FEE_RATE_MIN = 0; +export const FEE_RATE_MAX = 0.25 * FEE_RATE_BASE; // 0.25% diff --git a/packages/apps/src/utils/misc.ts b/packages/apps/src/utils/misc.ts index 4cbca975c..6505719b6 100644 --- a/packages/apps/src/utils/misc.ts +++ b/packages/apps/src/utils/misc.ts @@ -1,4 +1,4 @@ -import { FEE_RATE_BASE } from "@/config/constant"; +import { FEE_RATE_BASE, FEE_RATE_MAX, FEE_RATE_MIN } from "@/config/constant"; import { RecordStatus } from "@/types/graphql"; export function formatRecordStatus(status: RecordStatus) { @@ -37,3 +37,7 @@ export function parseFeeRate(rate: string) { export function formatFeeRate(rate: number) { return Number((rate / FEE_RATE_BASE).toFixed(3)); } + +export function isValidFeeRate(formatted: number) { + return FEE_RATE_MIN <= formatted && formatted <= FEE_RATE_MAX; +}