How to use the @ledgerhq/errors.AmountRequired 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 / libcore.js View on Github external
}

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

  // FIXME libcore have a bug that don't detect some cases like when doing send max!
  if (!errors.amount && useAllAmount && !amount.gt(0)) {
    errors.amount = new NotEnoughBalance();
  }

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

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

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

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

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
  });
};
github LedgerHQ / ledger-live-common / src / families / tezos / bridge / libcore.js View on Github external
? t.amount.plus(estimatedFees)
    : account.balance;

  if (
    !errors.recipient &&
    !errors.amount &&
    (amount.lt(0) || totalSpent.gt(account.balance))
  ) {
    errors.amount = new NotEnoughBalance();
    totalSpent = BigNumber(0);
    amount = BigNumber(0);
  }

  if (t.mode === "send") {
    if (!errors.amount && amount.eq(0)) {
      errors.amount = new AmountRequired();
    } else if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
      warnings.feeTooHigh = new FeeTooHigh();
    }

    const thresholdWarning = 0.5 * 10 ** a.currency.units[0].magnitude;

    if (
      !subAcc &&
      !errors.amount &&
      account.balance.minus(totalSpent).lt(thresholdWarning)
    ) {
      if (isAccountDelegating(account)) {
        warnings.amount = new RecommendUndelegation();
      } else if ((a.subAccounts || []).some(isAccountBalanceSignificant)) {
        warnings.amount = new RecommendSubAccountsToEmpty();
      }
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / libcore.js View on Github external
: tokenAccount
    ? BigNumber(t.amount || 0)
    : BigNumber(t.amount || 0).plus(estimatedFees);

  const amount = useAllAmount
    ? tokenAccount
      ? tokenAccount.balance
      : account.balance.minus(estimatedFees)
    : BigNumber(t.amount || 0);

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

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

  return Promise.resolve({
    errors,
    warnings,
    estimatedFees,
    amount,
    totalSpent
  });
};
github LedgerHQ / ledger-live-common / src / families / ethereum / bridge / js.js View on Github external
}

  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
  });
};