placeholder={`If more than one XEC address, separate them by comma \ne.g. \necash:qpatql05s9jfavnu0tv6lkjjk25n6tmj9gkpyrlwu8,ecash:qzvydd4n3lm3xv62cx078nu9rg0e3srmqq0knykfed`}
// Only set txInfoFromUrl if you have valid legacy params or bip21
let validUrlParams =
(parseAllAsBip21 && 'bip21' in txInfo) ||
// Good if we have both address and value
('address' in txInfo && 'value' in txInfo) ||
// Good if we have address and no value
('address' in txInfo && !('value' in txInfo));
// If we 'value' key with no address, no good
// Note: because only the address and value keys are handled below,
// it's not an issue if we get all kinds of other garbage params
if (validUrlParams) {
// This is a tx request from the URL
// Save this flag in state var so it can be parsed in useEffect
txInfo.parseAllAsBip21 = parseAllAsBip21;
setTxInfoFromUrl(txInfo);
}
}, []);
useEffect(() => {
if (txInfoFromUrl === false) {
return;
}
if (txInfoFromUrl.parseAllAsBip21) {
handleAddressChange({
target: {
name: 'address',
value: txInfoFromUrl.bip21,
},
});
} else {
// Enter address into input field and trigger handleAddressChange for validation
handleAddressChange({
target: {
name: 'address',
value: txInfoFromUrl.address,
},
});
if (
'value' in txInfoFromUrl &&
!Number.isNaN(parseFloat(txInfoFromUrl.value))
) {
// Only update the amount field if txInfo.value is a good input
// Sometimes we want this field to be adjusted by the user, e.g. a donation amount
// Do not populate the field if the value param is not parseable as a number
// the strings 'undefined' and 'null', which PayButton passes to signify 'no amount', fail this test
// TODO deprecate this support once PayButton and cashtab-components do not require it
handleAmountChange({
target: {
name: 'amount',
value: txInfoFromUrl.value,
},
});
}
}
// We re-run this when balanceSats changes because validation of send amounts depends on balanceSats
}, [txInfoFromUrl, balanceSats]);
function handleSendXecError(errorObj) {
let message;
if (
errorObj.error &&
errorObj.error.includes(
'too-long-mempool-chain, too many unconfirmed ancestors [limit: 50] (code 64)',
)
) {
message = `The ${appConfig.ticker} you are trying to send has too many unconfirmed ancestors to send (limit 50). Sending will be possible after a block confirmation. Try again in about 10 minutes.`;