Skip to content

Commit

Permalink
feat: Stargate max decimals error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Halibao-Lala committed Jan 14, 2025
1 parent 660e448 commit 273db6f
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,21 @@ export const useGetStargateFees = () => {
const receiver = address || DEFAULT_ADDRESS;
const bridgeAddress = selectedToken?.stargate?.raw?.address as `0x${string}`;
const decimal = selectedToken?.stargate?.raw?.token?.decimals ?? (18 as number);
const maxDecimals = selectedToken?.stargate?.raw?.sharedDecimals ?? 18;
const allowedMin = Number(formatUnits(fees[0].minAmountLD, decimal));
const allowedMax = Number(formatUnits(fees[0].maxAmountLD, decimal));
const amount = parseUnits(sendValue, decimal);

// Can not retrieve other fees if token amount is out of range
if (Number(sendValue) >= allowedMin && Number(sendValue) <= allowedMax && !!args) {
if (sendValue.split('.')[1]?.length > maxDecimals) {
dispatch(
setRouteError({
stargate: `The amount exceeds the maximum of ${maxDecimals} decimals`,
}),
);
return { isDisplayError: true };
}
if (!!Number(fees?.[2].amountReceivedLD)) {
if (fees?.[2].amountReceivedLD) {
args.minAmountLD = BigInt(fees[2].amountReceivedLD);
Expand Down Expand Up @@ -144,6 +153,7 @@ export const useGetStargateFees = () => {
isDisplayError = true;
}
}

try {
if (chain && fromChain?.id === chain?.id && address && selectedToken?.address) {
// gas fee
Expand Down

0 comments on commit 273db6f

Please sign in to comment.