How to use the @ledgerhq/errors.NotEnoughBalance function in @ledgerhq/errors

To help you get started, we’ve selected a few @ledgerhq/errors 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 LedgerHQ / ledger-live-common / src / families / tezos / test-dataset.js View on Github external
{
          raw: accountTZnew,
          test: (expect, account) => {
            expect(account.operations).toEqual([]);
          },
          transactions: [
            {
              name: "send 10% to existing tz",
              transaction: t => ({
                ...t,
                recipient: addressTZregular,
                useAllAmount: true
              }),
              expectedStatus: {
                errors: {
                  amount: new NotEnoughBalance()
                },
                warnings: {}
              }
            }
          ]
        }

        // FIXME libcore bugs
        /*
        {
          raw: accountTZwithKT,
          transactions: [
            {
              name: "from KT 1, send max to new account",
              transaction: (t, account) => (
                invariant(account.subAccounts, "subAccounts"),
github LedgerHQ / ledger-live-common / src / families / bitcoin / bridge / libcore.js View on Github external
error => {
        if (error.name === "NotEnoughBalance") {
          errors.amount = error;
        } else {
          throw error;
        }
      }
    );
  }

  const totalSpent = useAllAmount ? a.balance : t.amount.plus(estimatedFees);
  const amount = useAllAmount ? a.balance.minus(estimatedFees) : t.amount;

  // FIXME libcore have a bug that don't detect some cases like when doing send max!
  if (!errors.amount && useAllAmount && !amount.gt(0)) {
    errors.amount = new NotEnoughBalance();
  }

  if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
    warnings.feeTooHigh = new FeeTooHigh();
  }

  if (!errors.amount && amount.eq(0)) {
    errors.amount = new AmountRequired();
  }

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / mock.js View on Github external
? BigNumber(t.amount)
    : BigNumber(t.amount).plus(estimatedFees);

  const amount = useAllAmount
    ? tokenAccount
      ? BigNumber(t.amount)
      : account.balance.minus(estimatedFees)
    : BigNumber(t.amount);

  if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
    warnings.feeTooHigh = new FeeTooHigh();
  }

  // Fill up transaction errors...
  if (totalSpent.gt(account.balance)) {
    errors.amount = new NotEnoughBalance();
  }

  // Fill up recipient errors...
  if (!t.recipient) {
    errors.recipient = new RecipientRequired("");
  } else if (isInvalidRecipient(t.recipient)) {
    errors.recipient = new InvalidAddress("");
  }

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
  });
github LedgerHQ / ledger-live-common / src / families / bitcoin / bridge / mock.js View on Github external
const totalSpent = useAllAmount
    ? account.balance
    : BigNumber(t.amount).plus(estimatedFees);

  const amount = useAllAmount
    ? account.balance.minus(estimatedFees)
    : BigNumber(t.amount);

  if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
    warnings.feeTooHigh = new FeeTooHigh();
  }

  // Fill up transaction errors...
  if (totalSpent.gt(account.balance)) {
    errors.amount = new NotEnoughBalance();
  }

  // Fill up recipient errors...
  if (!t.recipient) {
    errors.recipient = new RecipientRequired("");
  } else if (isInvalidRecipient(t.recipient)) {
    errors.recipient = new InvalidAddress("");
  }

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
  });
github LedgerHQ / ledger-live-common / src / families / ethereum / test-specifics.js View on Github external
test("insufficient balance have an error", async () => {
      let t = {
        ...bridge.createTransaction(account),
        recipient: "0x5df0C369641B8Af3c7e9ae076E5466eF678319Cd",
        amount: BigNumber(
          9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
        )
      };
      t = await bridge.prepareTransaction(account, t);
      let status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.amount).toEqual(new NotEnoughBalance());
    });
  });
github LedgerHQ / ledger-live-common / src / families / bitcoin / test-specifics.js View on Github external
test("Amount to high should have a balanceError", async () => {
      let t = {
        ...bridge.createTransaction(account),
        recipient: "1FMpdbiC8dj7kHJ8tPWFcihvAcqEqramoN",
        feePerByte: BigNumber(1),
        amount: BigNumber(979079019)
      };
      let status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.recipient).toBeUndefined();
      let transaction = await bridge.prepareTransaction(account, t);
      status = await bridge.getTransactionStatus(account, transaction);
      expect(status.errors.amount).toEqual(new NotEnoughBalance());
      t = {
        ...t,
        feePerByte: BigNumber(9999999),
        amount: BigNumber(300)
      };
      status = await bridge.getTransactionStatus(account, t); //NB not used?
      transaction = await bridge.prepareTransaction(account, t);
      status = await bridge.getTransactionStatus(account, transaction);
      expect(status.errors.amount).toEqual(new NotEnoughBalance());
    });
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / js.js View on Github external
const warnings = {};
  const estimatedFees = (t.gasPrice || BigNumber(0)).times(getGasLimit(t));
  const totalSpent = BigNumber(t.amount || 0).plus(estimatedFees);
  const amount = BigNumber(t.amount || 0);

  if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
    warnings.feeTooHigh = new FeeTooHigh();
  }

  const gasLimit = getGasLimit(t);
  if (!t.gasPrice) {
    errors.gasPrice = new FeeNotLoaded();
  } else if (gasLimit.eq(0)) {
    errors.gasLimit = new FeeRequired();
  } else if (totalSpent.gt(a.balance)) {
    errors.amount = new NotEnoughBalance();
  }

  if (t.estimatedGasLimit && gasLimit.lt(t.estimatedGasLimit)) {
    warnings.gasLimit = new GasLessThanEstimate();
  }

  let recipientWarning = getRecipientWarning(a.currency, t.recipient);
  if (recipientWarning) {
    warnings.recipient = recipientWarning;
  }

  if (!t.recipient) {
    errors.recipient = new RecipientRequired("");
  } else if (!isRecipientValid(a.currency, t.recipient)) {
    errors.recipient = new InvalidAddress("", {
      currencyName: a.currency.name
github LedgerHQ / ledger-live-common / src / families / ethereum / libcore-buildTransaction.js View on Github external
);

  if (isCancelled()) return;
  const transactionBuilder = await ethereumLikeAccount.buildTransaction();
  if (isCancelled()) return;

  if (subAccount && subAccount.type === "TokenAccount") {
    const { balance, token } = subAccount;
    let amount;
    if (transaction.useAllAmount) {
      amount = balance;
    } else {
      if (!transaction.amount) throw new Error("amount is missing");
      amount = BigNumber(transaction.amount);
      if (amount.gt(subAccount.balance)) {
        throw new NotEnoughBalance();
      }
    }
    const to256 = Buffer.concat([
      Buffer.alloc(12),
      Buffer.from(recipient.replace("0x", ""), "hex")
    ]);
    invariant(to256.length === 32, "recipient is invalid");
    const amountHex = amount.toString(16);
    const amountBuf = Buffer.from(
      amountHex.length % 2 === 0 ? amountHex : "0" + amountHex,
      "hex"
    );
    const amount256 = Buffer.concat([
      Buffer.alloc(32 - amountBuf.length),
      amountBuf
    ]);
github LedgerHQ / ledger-live-common / src / bridge / LibcoreEthereumAccountBridge.js View on Github external
const checkValidTransaction = async (a, t) =>
  !t.gasPrice
    ? Promise.reject(new FeeNotLoaded())
    : t.useAllAmount ||
      getMaxAmount(a, t).then(max => t.amount.isLessThanOrEqualTo(max))
    ? Promise.resolve(null)
    : Promise.reject(new NotEnoughBalance());
github LedgerHQ / ledger-live-desktop / src / bridge / EthereumJSBridge.js View on Github external
checkValidTransaction: (a, t) =>
    !t.gasPrice
      ? Promise.reject(new FeeNotLoaded())
      : t.amount.isLessThanOrEqualTo(a.balance)
      ? Promise.resolve(null)
      : Promise.reject(new NotEnoughBalance()),