diff --git a/src/families/polkadot/js-getTransactionStatus.ts b/src/families/polkadot/js-getTransactionStatus.ts index a2feed207d..2ed1a9db4f 100644 --- a/src/families/polkadot/js-getTransactionStatus.ts +++ b/src/families/polkadot/js-getTransactionStatus.ts @@ -36,6 +36,7 @@ import { calculateAmount, getMinimumAmountToBond, getMinimumBalance, + EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN, } from "./logic"; import { isValidAddress } from "./address"; import { getCurrentPolkadotPreloadData } from "./preload"; @@ -78,6 +79,12 @@ const getSendTransactionStatus = async ( const leftover = a.spendableBalance.minus(totalSpent); if ( + a.spendableBalance.lte( + EXISTENTIAL_DEPOSIT.plus(EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN) + ) + ) { + errors.amount = new NotEnoughBalance(); + } else if ( minimumBalanceExistential.gt(0) && leftover.lt(minimumBalanceExistential) && leftover.gt(0) diff --git a/src/families/polkadot/js-signOperation.ts b/src/families/polkadot/js-signOperation.ts index 565d321614..c0f204aa08 100644 --- a/src/families/polkadot/js-signOperation.ts +++ b/src/families/polkadot/js-signOperation.ts @@ -29,6 +29,7 @@ const MODE_TO_TYPE = { }; const MODE_TO_PALLET_METHOD = { send: "balances.transferKeepAlive", + sendMax: "balances.transfer", bond: "staking.bond", bondExtra: "staking.bondExtra", unbond: "staking.unbond", @@ -41,16 +42,15 @@ const MODE_TO_PALLET_METHOD = { }; const getExtra = (type: string, account: Account, transaction: Transaction) => { - const extra = MODE_TO_PALLET_METHOD[transaction.mode] - ? { - palletMethod: - MODE_TO_PALLET_METHOD[ - transaction.mode === "bond" && !isFirstBond(account) - ? "bondExtra" - : transaction.mode - ], - } - : {}; + const extra = { + palletMethod: MODE_TO_PALLET_METHOD[transaction.mode], + }; + + if (transaction.mode == "send" && transaction.useAllAmount) { + extra.palletMethod = MODE_TO_PALLET_METHOD["sendMax"]; + } else if (transaction.mode === "bond" && !isFirstBond(account)) { + extra.palletMethod = MODE_TO_PALLET_METHOD["bondExtra"]; + } switch (type) { case "OUT": diff --git a/src/families/polkadot/logic.ts b/src/families/polkadot/logic.ts index a701e685d6..daaa26383a 100644 --- a/src/families/polkadot/logic.ts +++ b/src/families/polkadot/logic.ts @@ -4,6 +4,7 @@ import type { Transaction } from "./types"; import { getCurrentPolkadotPreloadData } from "./preload"; export const EXISTENTIAL_DEPOSIT = new BigNumber(10000000000); +export const EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN = new BigNumber(1000000000); // Polkadot recommended Existential Deposit error margin export const MAX_NOMINATIONS = 16; export const MAX_UNLOCKINGS = 32; export const PRELOAD_MAX_AGE = 60 * 1000;