Skip to content

Commit 58ed7ce

Browse files
authored
Fix USDT decimals (#545)
* fix usdt decimals * valid fee rate check * fix FEE_RATE_MAX * update FeeRateInput placeholder
1 parent 7ac9210 commit 58ed7ce

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

packages/apps/src/components/fee-rate-input.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Input from "@/ui/input";
2-
import { parseFeeRate } from "@/utils/misc";
2+
import { isValidFeeRate, parseFeeRate } from "@/utils/misc";
33

44
export default function FeeRateInput({
55
placeholder,
@@ -10,7 +10,7 @@ export default function FeeRateInput({
1010
value?: { formatted: number; value: string };
1111
onChange?: (value: { formatted: number; value: string }) => void;
1212
}) {
13-
const invalid = (value?.formatted || 0) < 0 || 100000 < (value?.formatted || 0);
13+
const invalid = !isValidFeeRate(value?.formatted || 0);
1414
return (
1515
<div
1616
className={`gap-small bg-app-bg p-small lg:p-middle normal-input-wrap flex items-center justify-between ${

packages/apps/src/components/relayer-manage-modal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useNetwork, useSwitchNetwork } from "wagmi";
1010
import { formatBalance } from "@/utils/balance";
1111
import { useRelayer } from "@/hooks/use-relayer";
1212
import dynamic from "next/dynamic";
13-
import { formatFeeRate } from "@/utils/misc";
13+
import { formatFeeRate, isValidFeeRate } from "@/utils/misc";
1414

1515
type TabKey = "update" | "deposit" | "withdraw";
1616
const Modal = dynamic(() => import("@/ui/modal"), { ssr: false });
@@ -207,7 +207,7 @@ export default function RelayerManageModal({ relayerInfo, isOpen, onClose, onSuc
207207
busy={busy}
208208
disabledCancel={busy}
209209
disabledOk={
210-
activeKey === "update" && baseFee.formatted === 0n && feeRate.formatted === 0
210+
activeKey === "update" && !(baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted))
211211
? true
212212
: activeKey === "deposit" && margin.formatted === 0n
213213
? true

packages/apps/src/components/relayer-register.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Token, TokenSymbol } from "@/types/token";
1111
import { BridgeCategory } from "@/types/bridge";
1212
import { useAccount, useNetwork, useSwitchNetwork } from "wagmi";
1313
import Image from "next/image";
14-
import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc } from "@/utils/misc";
14+
import { formatFeeRate, getChainLogoSrc, getTokenLogoSrc, isValidFeeRate } from "@/utils/misc";
1515
import Tooltip from "@/ui/tooltip";
1616
import StepCompleteItem from "./step-complete-item";
1717
import { BalanceInput } from "./balance-input";
@@ -321,7 +321,7 @@ export default function RelayerRegister() {
321321
label="Liquidity Fee Rate"
322322
tips="The percentage deducted by the relayer from the transfer amount in a transaction"
323323
>
324-
<FeeRateInput placeholder="Enter 0 ~ 100" value={feeRate} onChange={setFeeRate} />
324+
<FeeRateInput placeholder="Enter 0 ~ 0.25" value={feeRate} onChange={setFeeRate} />
325325
</LabelItem>
326326

327327
<Divider />
@@ -372,7 +372,8 @@ export default function RelayerRegister() {
372372
}
373373
}}
374374
disabled={
375-
(sourceChain?.id === chain?.id && (!margin.formatted || !baseFee.formatted || !feeRate.formatted)) ||
375+
(sourceChain?.id === chain?.id &&
376+
!(margin.value && baseFee.value && feeRate.value && isValidFeeRate(feeRate.formatted))) ||
376377
(bridgeCategory === "lnbridgev20-default" && !completeMargin)
377378
}
378379
busy={busy}

packages/apps/src/config/chains/arbitrum.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const arbitrumChain: ChainConfig = {
4444
cross: [{ target: { network: "ethereum", symbol: "RING" }, bridge: { category: "lnbridgev20-opposite" } }],
4545
},
4646
{
47-
decimals: 18,
47+
decimals: 6,
4848
symbol: "USDT",
4949
name: "USDT",
5050
type: "erc20",

packages/apps/src/config/chains/mantle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const mantleChain: ChainConfig = {
2828
},
2929
tokens: [
3030
{
31-
decimals: 18,
31+
decimals: 6,
3232
symbol: "USDT",
3333
name: "USDT",
3434
type: "erc20",

packages/apps/src/config/constant.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
* If the fee rate is 10.123%, its value in the contract is 10123 (10.123 * 1000)
33
*/
44
export const FEE_RATE_BASE = 1000;
5+
6+
export const FEE_RATE_MIN = 0;
7+
export const FEE_RATE_MAX = 0.25 * FEE_RATE_BASE; // 0.25%

packages/apps/src/utils/misc.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FEE_RATE_BASE } from "@/config/constant";
1+
import { FEE_RATE_BASE, FEE_RATE_MAX, FEE_RATE_MIN } from "@/config/constant";
22
import { RecordStatus } from "@/types/graphql";
33

44
export function formatRecordStatus(status: RecordStatus) {
@@ -37,3 +37,7 @@ export function parseFeeRate(rate: string) {
3737
export function formatFeeRate(rate: number) {
3838
return Number((rate / FEE_RATE_BASE).toFixed(3));
3939
}
40+
41+
export function isValidFeeRate(formatted: number) {
42+
return FEE_RATE_MIN <= formatted && formatted <= FEE_RATE_MAX;
43+
}

0 commit comments

Comments
 (0)