Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const amount = useAllAmount
? a.balance.minus(estimatedFees)
: BigNumber(t.amount);
if (amount.gt(0) && estimatedFees.times(10).gt(amount)) {
warnings.feeTooHigh = new FeeTooHigh();
}
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) {
{
name: "not enough spendable balance with base reserve",
transaction: fromTransactionRaw({
family: "ripple",
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
amount: "15000000",
tag: null,
fee: "1",
feeCustomUnit: null,
networkInfo: null
}),
expectedStatus: {
amount: BigNumber("15000000"),
estimatedFees: BigNumber("1"),
errors: {
amount: new NotEnoughSpendableBalance()
},
warnings: {},
totalSpent: BigNumber("15000001")
}
}
],
raw: {
id:
"libcore:1:ripple:xpub6BemYiVNp19a2SqH5MuUUuMUsiMU4ZLcXQgfoFxbRSRjPEuzcwcjx5SXezUhwcmgCTKGzuGAqHxRFSCn6YLAqydEdq11LVYENwxNC6ctwrv:",
seedIdentifier:
"02b96ea039567968d11d12e3195e4b6194a016c18511e51814e5cca03fcd800a29",
name: "XRP 1",
derivationMode: "",
index: 0,
freshAddress: "rJfzRJHcM9qGuMdULGM7mU4RikqRY47FxR",
freshAddressPath: "44'/144'/0'/0/0",
? t.amount.plus(estimatedFees)
: a.balance.minus(baseReserve);
const amount = t.useAllAmount ? a.balance.minus(estimatedFees) : t.amount;
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) {
const estimatedFees = BigNumber(t.fee || 0);
const totalSpent = BigNumber(t.amount).plus(estimatedFees);
const amount = BigNumber(t.amount);
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();
} 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 {