From 8a1e599d592ab68b0c6cc870f806f010cf005b7e Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Thu, 9 Feb 2023 18:22:40 +0100 Subject: [PATCH] Fix: spending limit max amount (#1657) * Fix: spending limit max amount * Rm "Problem connecting to the RPC provider." --- .../tx/modals/TokenTransferModal/SendAssetsForm.tsx | 11 +++++++++-- src/hooks/coreSDK/useInitSafeCoreSDK.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/tx/modals/TokenTransferModal/SendAssetsForm.tsx b/src/components/tx/modals/TokenTransferModal/SendAssetsForm.tsx index 55d86d0cac..4df8775c17 100644 --- a/src/components/tx/modals/TokenTransferModal/SendAssetsForm.tsx +++ b/src/components/tx/modals/TokenTransferModal/SendAssetsForm.tsx @@ -128,6 +128,12 @@ const SendAssetsForm = ({ const spendingLimit = useSpendingLimit(selectedToken?.tokenInfo) const isSpendingLimitType = type === SendTxType.spendingLimit const spendingLimitAmount = spendingLimit ? BigNumber.from(spendingLimit.amount).sub(spendingLimit.spent) : undefined + const totalAmount = BigNumber.from(selectedToken?.balance || 0) + const maxAmount = spendingLimitAmount + ? totalAmount.gt(spendingLimitAmount) + ? spendingLimitAmount + : totalAmount + : totalAmount const balancesItems = useMemo(() => { return isOnlySpendingLimitBeneficiary @@ -235,8 +241,9 @@ const SendAssetsForm = ({ required: true, validate: (val) => { const decimals = selectedToken?.tokenInfo.decimals - const max = isSpendingLimitType ? spendingLimitAmount?.toString() : selectedToken?.balance - return validateLimitedAmount(val, decimals, max) || validateDecimalLength(val, decimals) + return ( + validateLimitedAmount(val, decimals, maxAmount.toString()) || validateDecimalLength(val, decimals) + ) }, })} /> diff --git a/src/hooks/coreSDK/useInitSafeCoreSDK.ts b/src/hooks/coreSDK/useInitSafeCoreSDK.ts index d8c2663860..fed0975714 100644 --- a/src/hooks/coreSDK/useInitSafeCoreSDK.ts +++ b/src/hooks/coreSDK/useInitSafeCoreSDK.ts @@ -26,7 +26,7 @@ export const useInitSafeCoreSDK = () => { .catch((e) => { dispatch( showNotification({ - message: 'Problem connecting to the RPC provider. Please try connecting your wallet again.', + message: 'Please try connecting your wallet again.', groupKey: 'core-sdk-init-error', variant: 'error', detailedMessage: (e as Error).message,