How to use the @ledgerhq/errors.FeeRequired 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 / bitcoin / test-specifics.js View on Github external
};
      let status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.recipient).toBeUndefined();
      expect(status.errors.feePerByte).toEqual(new FeeNotLoaded());
      t = await bridge.prepareTransaction(account, t);
      expect(t.feePerByte).toBeInstanceOf(BigNumber);
      t.feePerByte = BigNumber(1); // for predictible tests
      status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.feePerByte).toBeUndefined();
      t = {
        ...t,
        feePerByte: BigNumber(0)
      };
      t = await bridge.prepareTransaction(account, t);
      status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.feePerByte).toEqual(new FeeRequired());
    });
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / libcore.js View on Github external
if (recipientError) {
    errors.recipient = recipientError;
  }

  if (recipientWarning) {
    warnings.recipient = recipientWarning;
  }

  let estimatedFees = BigNumber(0);
  const gasLimit = getGasLimit(t);

  if (!t.gasPrice) {
    errors.gasPrice = new FeeNotLoaded();
  } else if (gasLimit.eq(0)) {
    errors.gasLimit = new FeeRequired();
  } else if (!errors.recipient) {
    await calculateFees(a, t).then(
      res => {
        estimatedFees = res.estimatedFees;
      },
      error => {
        if (error.name === "NotEnoughBalance") {
          errors.amount = error;
        } else if (error.name === "NotEnoughGas") {
          errors.gasPrice = error;
        } else {
          throw error;
        }
      }
    );
  }
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / js.js View on Github external
const getTransactionStatus = (a, t) => {
  const errors = {};
  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)) {
github LedgerHQ / ledger-live-common / src / families / bitcoin / bridge / libcore.js View on Github external
t.recipient
  );

  if (recipientError) {
    errors.recipient = recipientError;
  }

  if (recipientWarning) {
    warnings.recipient = recipientWarning;
  }

  let estimatedFees = BigNumber(0);
  if (!t.feePerByte) {
    errors.feePerByte = new FeeNotLoaded();
  } else if (t.feePerByte.eq(0)) {
    errors.feePerByte = new FeeRequired();
  } else if (!errors.recipient) {
    await calculateFees(a, t).then(
      res => {
        estimatedFees = res.estimatedFees;
      },
      error => {
        if (error.name === "NotEnoughBalance") {
          errors.amount = error;
        } else {
          throw error;
        }
      }
    );
  }

  const totalSpent = useAllAmount ? a.balance : t.amount.plus(estimatedFees);
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / js.js View on Github external
const reserveBaseXRP = parseAPIValue(r.validatedLedger.reserveBaseXRP);

  const estimatedFees = BigNumber(t.fee || 0);

  const totalSpent = BigNumber(t.amount).plus(estimatedFees);

  const amount = BigNumber(t.amount);

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

  if (!t.fee) {
    errors.fee = new FeeNotLoaded();
  } else if (t.fee.eq(0)) {
    errors.fee = new FeeRequired();
  } else if (totalSpent.gt(a.balance.minus(reserveBaseXRP))) {
    errors.amount = new NotEnoughSpendableBalance();
  } else if (
    t.recipient &&
    (await cachedRecipientIsNew(a.endpointConfig, t.recipient)) &&
    t.amount.lt(reserveBaseXRP)
  ) {
    const f = formatAPICurrencyXRP(reserveBaseXRP);
    errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
      minimalAmount: `${f.currency} ${BigNumber(f.value).toFixed()}`
    });
  }

  if (!t.recipient) {
    errors.recipient = new RecipientRequired("");
  } else if (a.freshAddress === t.recipient) {
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / libcore.js View on Github external
const estimatedFees = t.fee || BigNumber(0);

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

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

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

  if (!t.fee) {
    errors.fee = new FeeNotLoaded();
  } else if (t.fee.eq(0)) {
    errors.fee = new FeeRequired();
    totalSpent.gt(a.balance.minus(baseReserve));
  } else if (totalSpent.gt(a.balance.minus(baseReserve))) {
    errors.amount = new NotEnoughSpendableBalance();
  } else if (
    amount.lt(baseReserve) &&
    !(await isAddressActivated(a, t.recipient))
  ) {
    errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated();
  }

  if (a.freshAddress === t.recipient) {
    errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
  } else {
    let { recipientError, recipientWarning } = await validateRecipient(
      a.currency,
      t.recipient