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
? 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
});
};
? 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
});
};
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
});
};
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());
});
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
});
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 })
);
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
};
}
},
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();
}