From 8ac16feabacc8cf7e5d58251ddcb813e87c06638 Mon Sep 17 00:00:00 2001 From: Sergej Sakac Date: Tue, 12 Sep 2023 10:13:50 +0200 Subject: [PATCH] Additional checks when transferring --- src/consts/index.ts | 4 ++-- src/pages/transfer.tsx | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/consts/index.ts b/src/consts/index.ts index 50f1cbe..8cb52b8 100644 --- a/src/consts/index.ts +++ b/src/consts/index.ts @@ -1,7 +1,7 @@ export type RELAY_CHAIN_OPTION = 'polkadot' | 'kusama'; const RELAY_CHAIN_ENDPOINTS = { - polkadot: "wss://polkadot.api.onfinality.io/public-ws", - kusama: "wss://kusama.api.onfinality.io/public-ws" + polkadot: "wss://rpc.polkadot.io", + kusama: "wss://kusama-rpc.polkadot.io" }; export const RELAY_CHAIN = (process.env.RELAY_CHAIN || 'polkadot') as RELAY_CHAIN_OPTION; export const RELAY_CHAIN_ENDPOINT = RELAY_CHAIN_ENDPOINTS[RELAY_CHAIN]; diff --git a/src/pages/transfer.tsx b/src/pages/transfer.tsx index 6142a9e..957f2f2 100644 --- a/src/pages/transfer.tsx +++ b/src/pages/transfer.tsx @@ -236,6 +236,21 @@ const TransferPage = () => { return; } + if (amount === 0) { + toastError("Transfer amount must be greater than 0"); + return; + } + + if (Number.isNaN(amount)) { + toastError("Amount must be specified") + return; + } + + if (countDecimalDigits(amount) > selectedAsset.decimals) { + toastError(`The asset can have only ${selectedAsset.decimals} decimals`); + return; + } + if (sourceChainId === destChainId) { // Just do a simple token transfer. const api = await getApi(chains[sourceChainId].rpc); @@ -316,6 +331,22 @@ const TransferPage = () => { setTransferring(false); }; + const countDecimalDigits = (n: number): number => { + const numberStr = n.toString(); + + // Check for scientific notation + if (numberStr.includes('e')) { + const parts = numberStr.split('e'); + const decimalPart = (parts[0].split('.')[1] || '').length; + const exponentPart = parseInt(parts[1], 10); + return decimalPart - exponentPart; + } else { + const decimalPart = (numberStr.split('.')[1] || '').length; + return decimalPart; + } + } + + const getParaIdFromXcmInterior = (xcmInterior: any): number => { if (xcmInterior.length > 1 && Object.hasOwn(xcmInterior[1], 'parachain')) { return xcmInterior[1].parachain;