How to use the @ledgerhq/errors.NotEnoughBalanceBecauseDestinationNotCreated 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 / ripple / bridge / mock.js View on Github external
}

  if (totalSpent.gt(a.balance)) {
    errors.amount = new NotEnoughSpendableBalance();
  } else if (
    minimalBaseAmount &&
    a.balance.minus(totalSpent).lt(minimalBaseAmount)
  ) {
    errors.amount = new NotEnoughSpendableBalance();
  } else if (
    minimalBaseAmount &&
    t.recipient.includes("new") &&
    amount.lt(minimalBaseAmount)
  ) {
    // mimic XRP base minimal for new addresses
    errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated(null, {
      minimalAmount: `XRP Minimum reserve`
    });
  }

  if (!t.recipient) {
    errors.recipient = new RecipientRequired("");
  } else if (isInvalidRecipient(t.recipient)) {
    errors.recipient = new InvalidAddress("");
  } else if (a.freshAddress === t.recipient) {
    errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
  }

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / libcore.js View on Github external
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
    );

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

    if (recipientWarning) {
      warnings.recipient = recipientWarning;
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / js.js View on Github external
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) {
    errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
  } else {
    try {
      bs58check.decode(t.recipient);
    } catch (e) {
      errors.recipient = new InvalidAddress("", {
        currencyName: a.currency.name
      });
    }
github LedgerHQ / ledger-live-desktop / src / bridge / RippleJSBridge.js View on Github external
checkValidTransaction: async (a, t) => {
    if (!t.fee) throw new FeeNotLoaded()
    const r = await getServerInfo(a.endpointConfig)
    const reserveBaseXRP = parseAPIValue(r.validatedLedger.reserveBaseXRP)
    if (t.recipient) {
      if (await cachedRecipientIsNew(a.endpointConfig, t.recipient)) {
        if (t.amount.lt(reserveBaseXRP)) {
          const f = formatAPICurrencyXRP(reserveBaseXRP)
          throw new NotEnoughBalanceBecauseDestinationNotCreated('', {
            minimalAmount: `${f.currency} ${BigNumber(f.value).toFixed()}`,
          })
        }
      }
    }
    if (
      t.amount
        .plus(t.fee || 0)
        .plus(reserveBaseXRP)
        .isLessThanOrEqualTo(a.balance)
    ) {
      return null
    }
    throw new NotEnoughBalance()
  },
github LedgerHQ / ledger-live-common / src / bridge / makeMockBridge.js View on Github external
const checkValidRecipient = (account, recipient) => {
    if (account.freshAddress === recipient) {
      switch (account.currency.family) {
        case "ethereum":
        case "ripple":
          throw new InvalidAddressBecauseDestinationIsAlsoSource();
      }
    }

    if (account.currency.family === "ripple" && recipient.includes("new")) {
      throw new NotEnoughBalanceBecauseDestinationNotCreated("", {
        minimalAmount: `XRP Minimum reserve`
      });
    }

    if (recipient.length <= 3) throw new Error("invalid recipient");
    return Promise.resolve(null);
  };