Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
});
};
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),
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,
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 }))
}
}
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;
}
}
}
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)) {