Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
type State = Fees;
type Props = I18nProps & {
accountId?: string | null,
amount: BN,
balanceFrom?: DerivedBalances,
balanceTo?: DerivedBalances,
extrinsic: Extrinsic | null,
fees?: DerivedBalancesFees,
recipientId?: string | null,
onChange: (fees: Fees) => void
};
const ZERO_BALANCE = {
freeBalance: new Balance(0),
reservedBalance: new Balance(0),
votingBalance: new Balance(0)
} as DerivedBalances;
const ZERO_FEES = {
transactionBaseFee: new BN(0),
transactionByteFee: new BN(0),
creationFee: new BN(0),
existentialDeposit: new BN(0),
transferFee: new BN(0)
} as DerivedBalancesFees;
const LENGTH_PUBLICKEY = 32 + 1; // publicKey + prefix
const LENGTH_SIGNATURE = 64;
const LENGTH_NONCE = 8;
const LENGTH_ERA = 1;
handleSubmit = () => {
const { history, match: { params: { currentAccount, recipientAddress } } } = this.props;
const { amount, balance } = this.state;
// Do validation on account/address
if (currentAccount === recipientAddress) {
this.handleError('You cannot send balance to yourself.');
return;
}
// Do validation on amount
const amountBn = new BalanceType(amount);
if (!balance) {
// FIXME Improve UX here
this.handleError("Please try again in a few seconds as we're fetching your balance.");
return;
}
if (amountBn.isNeg()) {
this.handleError('Please enter a positive amount to transfer.');
return;
}
if (amountBn.isZero()) {
this.handleError('Please make sure you are sending more than 0 balance.');
return;
}
type Props = I18nProps & {
accountId?: string | null,
amount: BN,
balanceFrom?: DerivedBalances,
balanceTo?: DerivedBalances,
extrinsic: Extrinsic | null,
fees?: DerivedBalancesFees,
recipientId?: string | null,
onChange: (fees: Fees) => void
};
const ZERO_BALANCE = {
freeBalance: new Balance(0),
reservedBalance: new Balance(0),
votingBalance: new Balance(0)
} as DerivedBalances;
const ZERO_FEES = {
transactionBaseFee: new BN(0),
transactionByteFee: new BN(0),
creationFee: new BN(0),
existentialDeposit: new BN(0),
transferFee: new BN(0)
} as DerivedBalancesFees;
const LENGTH_PUBLICKEY = 32 + 1; // publicKey + prefix
const LENGTH_SIGNATURE = 64;
const LENGTH_NONCE = 8;
const LENGTH_ERA = 1;
// FIXME Hardcoded signature size. This _should_ be ok for the poc-3 version, however in reality is needs to
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
cb({
accountId: accountId || EMPTY_ACCOUNT,
freeBalance: freeBalance || new Balance(0),
nominatedBalance: new Balance(0),
reservedBalance: reservedBalance || new Balance(0),
stakingBalance: new Balance(0),
votingBalance: new Balance(
(freeBalance || new Balance(0)).add(reservedBalance || new Balance(0))
)
});
};
], ([balance, nominators]) => {
const nominatedBalance = nominators.reduce((total: BN, nominatorBalance: DerivedBalances) => {
return total.add(nominatorBalance.votingBalance);
}, new BN(0));
cb({
...balance,
nominators,
nominatedBalance: new Balance(nominatedBalance),
stakingBalance: new Balance(
nominatedBalance.add(balance.votingBalance)
)
});
});
}
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
cb({
accountId: accountId || EMPTY_ACCOUNT,
freeBalance: freeBalance || new Balance(0),
nominatedBalance: new Balance(0),
reservedBalance: reservedBalance || new Balance(0),
stakingBalance: new Balance(0),
votingBalance: new Balance(
(freeBalance || new Balance(0)).add(reservedBalance || new Balance(0))
)
});
};
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
cb({
accountId: accountId || EMPTY_ACCOUNT,
freeBalance: freeBalance || new Balance(0),
nominatedBalance: new Balance(0),
reservedBalance: reservedBalance || new Balance(0),
stakingBalance: new Balance(0),
votingBalance: new Balance(
(freeBalance || new Balance(0)).add(reservedBalance || new Balance(0))
)
});
};
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
cb({
accountId: accountId || EMPTY_ACCOUNT,
freeBalance: freeBalance || new Balance(0),
nominatedBalance: new Balance(0),
reservedBalance: reservedBalance || new Balance(0),
stakingBalance: new Balance(0),
votingBalance: new Balance(
(freeBalance || new Balance(0)).add(reservedBalance || new Balance(0))
)
});
};
const handler = (freeBalance?: Balance, reservedBalance?: Balance) => {
cb({
accountId: accountId || EMPTY_ACCOUNT,
freeBalance: freeBalance || new Balance(0),
nominatedBalance: new Balance(0),
reservedBalance: reservedBalance || new Balance(0),
stakingBalance: new Balance(0),
votingBalance: new Balance(
(freeBalance || new Balance(0)).add(reservedBalance || new Balance(0))
)
});
};
votersFor.map((accountId, index): DerivedReferendumVote => ({
accountId,
balance: balances[index].votingBalance || new Balance(0),
vote: votes[index] || new Vote(0)
}))
)