Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

LIVE-1292 Cover Polkadot existential deposit edge case #1953

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/families/polkadot/js-getTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
calculateAmount,
getMinimumAmountToBond,
getMinimumBalance,
EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN,
} from "./logic";
import { isValidAddress } from "./address";
import { getCurrentPolkadotPreloadData } from "./preload";
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/families/polkadot/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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":
Expand Down
1 change: 1 addition & 0 deletions src/families/polkadot/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down