How to use the @ledgerhq/errors.InvalidAddressBecauseDestinationIsAlsoSource 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
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,
    amount,
    totalSpent
  });
};
github LedgerHQ / ledger-live-common / src / families / tezos / test-dataset.js View on Github external
estimatedFees: fees,
                  amount: account.balance.minus(fees),
                  totalSpent: account.balance
                }
              )
            },
            {
              name: "self tx forbidden",
              transaction: t => ({
                ...t,
                recipient: addressAccountTZrevealedDelegating,
                amount: BigNumber(0.1)
              }),
              expectedStatus: {
                errors: {
                  recipient: new InvalidAddressBecauseDestinationIsAlsoSource()
                },
                warnings: {}
              }
            },
            {
              name: "undelegate",
              transaction: t => ({
                ...t,
                mode: "undelegate"
              }),
              expectedStatus: (account, { fees }) => (
                invariant(fees, "fees are required"),
                {
                  errors: {},
                  warnings: {},
                  amount: BigNumber(0),
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / js.js View on Github external
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
      });
    }
  }

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

  return Promise.resolve({
    errors,
github LedgerHQ / ledger-live-desktop / src / bridge / RippleJSBridge.js View on Github external
function checkValidRecipient(account, recipient) {
  if (account.freshAddress === recipient) {
    return Promise.reject(new InvalidAddressBecauseDestinationIsAlsoSource())
  }

  try {
    bs58check.decode(recipient)
    return Promise.resolve(null)
  } catch (e) {
    return Promise.reject(new InvalidAddress('', { currencyName: account.currency.name }))
  }
}
github LedgerHQ / ledger-live-common / src / families / tezos / bridge / libcore.js View on Github external
const errors = {};
  const warnings = {};
  const subAcc = !t.subAccountId
    ? null
    : a.subAccounts && a.subAccounts.find(ta => ta.id === t.subAccountId);

  invariant(
    t.mode === "send" || !subAcc,
    "delegation features not supported for sub accounts"
  );

  const account = subAcc || a;

  if (t.mode !== "undelegate") {
    if (account.freshAddress === t.recipient) {
      errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
    } else {
      const { 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 / libcore.js View on Github external
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;
    }
  }

  if (!errors.amount && amount.eq(0)) {