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