How to use the @ledgerhq/errors.RecipientRequired 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 / bridge / mock.js View on Github external
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 / bridge / mock.js View on Github external
? 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 / ripple / bridge / mock.js View on Github external
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,
    amount,
    totalSpent
  });
};
github LedgerHQ / ledger-live-common / cli / src / __tests__ / bridges.js View on Github external
test("Default empty recipient have a recipientError", async () => {
          const account = await getSynced();
          let t = {
            ...bridge.createTransaction(account)
          };
          let status = await bridge.getTransactionStatus(account, t);
          expect(status.errors.recipient).toEqual(new RecipientRequired());
        });
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / js.js View on Github external
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
    });
  }
  if (!errors.amount && amount.eq(0)) {
    errors.amount = new AmountRequired();
  }

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
  });
github LedgerHQ / ledger-live-common / src / libcore / isValidRecipient.js View on Github external
export const isValidRecipient: F = withLibcoreF(core => async arg => {
  const { currency, recipient } = arg;
  if (!recipient) {
    return Promise.reject(new RecipientRequired(""));
  }
  const custom = customAddressValidationByFamily[arg.currency.family];
  if (custom) {
    const res = await custom(core, arg);
    return res;
  }
  const poolInstance = core.getPoolInstance();
  const currencyCore = await poolInstance.getCurrency(currency.id);
  const value = await core.Address.isValid(recipient, currencyCore);
  if (value) {
    return Promise.resolve(null);
  }

  return Promise.reject(
    new InvalidAddress(null, { currencyName: currency.name })
  );
github LedgerHQ / ledger-live-common / src / bridge / shared.js View on Github external
async (currency, recipient) => {
    if (!recipient) {
      return {
        recipientError: new RecipientRequired(""),
        recipientWarning: null
      };
    }
    try {
      const recipientWarning = await isValidRecipient({ currency, recipient });
      return {
        recipientError: null,
        recipientWarning
      };
    } catch (recipientError) {
      return {
        recipientError,
        recipientWarning: null
      };
    }
  },
github LedgerHQ / ledger-live-common / src / families / ripple / bridge / js.js View on Github external
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
      });
    }
  }

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