How to use the @polkadot/types.Balance function in @polkadot/types

To help you get started, we’ve selected a few @polkadot/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / apps / packages / app-transfer / src / Fees.tsx View on Github external
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;
github paritytech / substrate-light-ui / packages / transfer-app / src / SendBalance.tsx View on Github external
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;
    }
github polkadot-js / apps / packages / app-transfer / src / Fees.tsx View on Github external
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
github polkadot-js / apps / packages / ui-api / src / derive / balances / votingBalance.ts View on Github external
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))
          )
        });
      };
github polkadot-js / apps / packages / ui-api / src / derive / balances / validatingBalance.ts View on Github external
], ([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)
        )
      });
    });
}
github polkadot-js / apps / packages / ui-api / src / derive / balances / votingBalance.ts View on Github external
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))
          )
        });
      };
github polkadot-js / apps / packages / ui-api / src / derive / balances / votingBalance.ts View on Github external
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))
          )
        });
      };
github polkadot-js / apps / packages / ui-api / src / derive / balances / votingBalance.ts View on Github external
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))
          )
        });
      };
github polkadot-js / apps / packages / ui-api / src / derive / balances / votingBalance.ts View on Github external
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))
          )
        });
      };
github polkadot-js / apps / packages / ui-api / src / derive / democracy / referendumVotesFor.ts View on Github external
votersFor.map((accountId, index): DerivedReferendumVote => ({
            accountId,
            balance: balances[index].votingBalance || new Balance(0),
            vote: votes[index] || new Vote(0)
          }))
        )