How to use the @ledgerhq/errors.FeeNotLoaded 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
test("Missing Fees should have a FeeError", async () => {
      let t = {
        ...bridge.createTransaction(account),
        recipient: "bc1qwqfns0rs5zxrrwf80k4xlp4lpnuyc69feh2r3d"
      };
      let status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.feePerByte).toEqual(new FeeNotLoaded());
    });
github LedgerHQ / ledger-live-common / src / families / ethereum / libcore-buildTransaction.js View on Github external
? account.subAccounts &&
      account.subAccounts.find(t => t.id === subAccountId)
    : null;
  const ethereumLikeAccount = await coreAccount.asEthereumLikeAccount();

  await isValidRecipient({
    currency: account.currency,
    recipient: transaction.recipient
  });

  const recipient = eip55.encode(transaction.recipient);

  const gasLimit = getGasLimit(transaction);

  if (!gasPrice || !gasLimit || !BigNumber(gasLimit).gt(ZERO)) {
    throw new FeeNotLoaded();
  }

  const gasPriceAmount = await bigNumberToLibcoreAmount(
    core,
    coreCurrency,
    BigNumber(gasPrice)
  );
  const gasLimitAmount = await bigNumberToLibcoreAmount(
    core,
    coreCurrency,
    BigNumber(gasLimit)
  );

  if (isCancelled()) return;
  const transactionBuilder = await ethereumLikeAccount.buildTransaction();
  if (isCancelled()) return;
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) {
github LedgerHQ / ledger-live-common / src / bridge / LibcoreBitcoinAccountBridge.js View on Github external
const checkValidTransaction = async (a, t) =>
  !t.feePerByte
    ? Promise.reject(new FeeNotLoaded())
    : !t.amount
    ? Promise.resolve(null)
    : getFees(a, t).then(() => null);
github LedgerHQ / ledger-live-common / src / families / bitcoin / bridge / libcore.js View on Github external
let { recipientError, recipientWarning } = await validateRecipient(
    a.currency,
    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;
        }
      }
    );
  }
github LedgerHQ / ledger-live-desktop / src / bridge / RippleJSBridge.js View on Github external
async function signAndBroadcast({ a, t, deviceId, isCancelled, onSigned, onOperationBroadcasted }) {
  const api = apiForEndpointConfig(RippleAPI, a.endpointConfig)
  const { fee } = t
  if (!fee) throw new FeeNotLoaded()
  try {
    await api.connect()
    const amount = formatAPICurrencyXRP(t.amount)
    const payment = {
      source: {
        address: a.freshAddress,
        amount,
      },
      destination: {
        address: t.recipient,
        minAmount: amount,
        tag: t.tag,
      },
    }
    const instruction = {
      fee: formatAPICurrencyXRP(fee).value,
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-common / src / families / bitcoin / libcore-buildTransaction.js View on Github external
isPartial: boolean,
  isCancelled: () => boolean
}): Promise {
  const bitcoinLikeAccount = await coreAccount.asBitcoinLikeAccount();

  const isValid = await isValidRecipient({
    currency: account.currency,
    recipient: transaction.recipient
  });

  if (isValid !== null) {
    throw new InvalidAddress("", { currencyName: account.currency.name });
  }

  const { feePerByte } = transaction;
  if (!feePerByte) throw new FeeNotLoaded();

  const fees = await bigNumberToLibcoreAmount(
    core,
    coreCurrency,
    BigNumber(feePerByte)
  );
  if (isCancelled()) return;
  const transactionBuilder = await bitcoinLikeAccount.buildTransaction(
    isPartial
  );
  if (isCancelled()) return;

  if (transaction.useAllAmount) {
    await transactionBuilder.wipeToAddress(transaction.recipient);
    if (isCancelled()) return;
  } else {
github LedgerHQ / ledger-live-common / src / families / tezos / libcore-buildTransaction.js View on Github external
tezosAccount = a;
        break;
      }
    }
    invariant(tezosAccount, "sub account not found " + subAccount.id);
  } else {
    tezosAccount = tezosLikeAccount;
  }

  if (transaction.mode !== "undelegate") {
    await isValidRecipient({ currency, recipient });
    if (isCancelled()) return;
  }

  if (!fees || !gasLimit || !storageLimit) {
    throw new FeeNotLoaded();
  }

  const feesAmount = await bigNumberToLibcoreAmount(core, coreCurrency, fees);
  if (isCancelled()) return;

  let gasLimitRounded = gasLimit;

  if (["delegate", "undelegate"].includes(transaction.mode)) {
    gasLimitRounded = upperModulo(gasLimit, BigNumber(136), BigNumber(1000));
  }

  const gasLimitAmount = await bigNumberToLibcoreAmount(
    core,
    coreCurrency,
    gasLimitRounded
  );
github LedgerHQ / ledger-live-desktop / src / bridge / LibcoreBridge.js View on Github external
const checkValidTransaction = async (a, t) =>
  !feesLoaded(a, t)
    ? Promise.reject(new FeeNotLoaded())
    : !t.amount
    ? Promise.resolve(null)
    : getFees(a, t).then(() => null)