diff --git a/packages/bridge-ui/package.json b/packages/bridge-ui/package.json index 4a56cda0053..73448af8751 100644 --- a/packages/bridge-ui/package.json +++ b/packages/bridge-ui/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "start": "pnpm run dev", + "start:a3": "pnpm run dev --mode a3", "dev": "vite", "build": "vite build", "preview": "vite preview", diff --git a/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts b/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts index 31d61deb4ff..b0bcbeb6dd1 100644 --- a/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts +++ b/packages/bridge-ui/src/relayer-api/RelayerAPIService.ts @@ -18,6 +18,7 @@ import type { } from '../domain/relayerApi'; import type { BridgeTransaction } from '../domain/transaction'; import { getLogger } from '../utils/logger'; +import { toBigNumber } from '../utils/toBigNumber'; import { tokenVaults } from '../vault/tokenVaults'; const log = getLogger('RelayerAPIService'); @@ -212,14 +213,12 @@ export class RelayerAPIService implements RelayerAPI { memo: tx.data.Message.Memo, owner: tx.data.Message.Owner, sender: tx.data.Message.Sender, - gasLimit: BigNumber.from(tx.data.Message.GasLimit.toString()), - callValue: BigNumber.from(tx.data.Message.CallValue.toString()), + gasLimit: toBigNumber(tx.data.Message.GasLimit), + callValue: toBigNumber(tx.data.Message.CallValue), srcChainId: tx.data.Message.SrcChainId, destChainId: tx.data.Message.DestChainId, - depositValue: BigNumber.from(tx.data.Message.DepositValue.toString()), - processingFee: BigNumber.from( - tx.data.Message.ProcessingFee.toString(), - ), + depositValue: toBigNumber(tx.data.Message.DepositValue), + processingFee: toBigNumber(tx.data.Message.ProcessingFee), refundAddress: tx.data.Message.RefundAddress, }, }; diff --git a/packages/bridge-ui/src/utils/toBigNumber.spec.ts b/packages/bridge-ui/src/utils/toBigNumber.spec.ts new file mode 100644 index 00000000000..2fbba2c326b --- /dev/null +++ b/packages/bridge-ui/src/utils/toBigNumber.spec.ts @@ -0,0 +1,15 @@ +import { BigNumber } from "ethers"; + +import { toBigNumber } from "./toBigNumber"; + +describe('toBigNumber', () => { + it('should handle different notation for big ints', () => { + expect(toBigNumber('1000000000000000000000').toString()).toEqual('1000000000000000000000'); + expect(toBigNumber(2e+21).toString()).toEqual('2000000000000000000000'); + expect(toBigNumber(3e21).toString()).toEqual('3000000000000000000000'); + expect(toBigNumber(1000).toString()).toEqual('1000'); + + // Number.MAX_SAFE_INTEGER = 9007199254740991. Maximum safe integer (2^53 – 1) + expect(toBigNumber(BigInt(Number.MAX_SAFE_INTEGER) * 3n).toString()).toEqual('27021597764222973'); + }); +}); diff --git a/packages/bridge-ui/src/utils/toBigNumber.ts b/packages/bridge-ui/src/utils/toBigNumber.ts new file mode 100644 index 00000000000..c5934855b01 --- /dev/null +++ b/packages/bridge-ui/src/utils/toBigNumber.ts @@ -0,0 +1,6 @@ +import { BigNumber } from "ethers"; + +// This will also handle scientific notation (or e notation: 2e+21) +export function toBigNumber(value: string | number | bigint | boolean): BigNumber { + return BigNumber.from(BigInt(value).toString()); +}