Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] improve not enough funds/fee err msg - 1 #1493

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"Server response could not be verified": "Server response could not be verified",
"Could not build transaction": "Could not build transaction",
"You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.": "You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.",
"You are trying to send more funds than you have available.\n\nTrying to send:\nAvailable to send:": "You are trying to send more funds than you have available.\n\nTrying to send: {{formatRequiredAmount}}\nAvailable to send: {{formatAvailableAmount}}",
"You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.\n\nTrying to send:\nAvailable to send:": "You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.\n\nTrying to send: {{formatRequiredAmount}}\nAvailable to send: {{formatAvailableAmount}}",
"Bitcore Wallet Service is under maintenance. Please check https://status.bitpay.com/.": "Bitcore Wallet Service is under maintenance. Please check https://status.bitpay.com/.",
"Network error": "Network error",
"Wallet service not found": "Wallet service not found",
Expand Down Expand Up @@ -1598,7 +1600,7 @@
"Insufficient confirmed funds": "Insufficient confirmed funds",
"You do not have enough confirmed funds to make this payment. Wait for your pending transactions to confirm or enable \"Use unconfirmed funds\" in Advanced Settings.": "You do not have enough confirmed funds to make this payment. Wait for your pending transactions to confirm or enable \"Use unconfirmed funds\" in Advanced Settings.",
"Insufficient funds": "Insufficient funds",
"Insufficient funds in your linked wallet to cover the transaction fee.": "Insufficient funds in your linked {{linkedWalletAbbreviation}} wallet to cover the transaction fee.",
"Insufficient funds in your linked wallet to cover the transaction fee.\n\nRequired Gas:\nLinked Wallet Balance:": "Insufficient funds in your linked wallet {{linkedWalletAbbreviation}} to cover the transaction fee.\n\nRequired Gas: {{formatRequiredAmount}}\nLinked Wallet Balance: {{formatAvailableAmount}}",
"No compatible wallets": "No compatible wallets",
"You currently don't have any wallets capable of sending this payment. Would you like to import one?": "You currently don't have any wallets capable of sending this payment. Would you like to import one?",
"Maybe Later": "Maybe Later",
Expand Down
57 changes: 43 additions & 14 deletions src/store/wallet/effects/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ const formatAmounts = (
dispatch: any,
wallet: any,
amount: number,
): {formatAvailableAmount: string; formatSendingAmount: string} => {
): {formatAvailableAmount: string; formatRequiredAmount: string} => {
const _formatAvailableAmount = dispatch(
FormatAmountStr(
wallet.currencyAbbreviation,
Expand All @@ -1892,11 +1892,19 @@ const formatAmounts = (
),
);

const _formatRequiredAmount = dispatch(
FormatAmountStr(
wallet.currencyAbbreviation,
wallet.chain,
wallet.tokenAddress,
amount,
false,
),
);

const formatAvailableAmount = `~${_formatAvailableAmount}`;
const formatSendingAmount = `~${amount.toFixed(
2,
)} ${formatCurrencyAbbreviation(wallet.currencyAbbreviation)}`;
return {formatAvailableAmount, formatSendingAmount};
const formatRequiredAmount = `~${_formatRequiredAmount}`;
return {formatAvailableAmount, formatRequiredAmount};
};

const generateInsufficientFundsError = (
Expand All @@ -1905,23 +1913,23 @@ const generateInsufficientFundsError = (
amount: number,
onDismiss?: () => void,
) => {
const {formatAvailableAmount, formatSendingAmount} = formatAmounts(
const {formatAvailableAmount, formatRequiredAmount} = formatAmounts(
dispatch,
wallet,
amount,
);
let errMsg = IsEVMChain(wallet.chain)
? t(
'You are trying to send more funds than you have available.\n\nTrying to send: {{formatSendingAmount}}\nAvailable to send: {{formatAvailableAmount}}',
'You are trying to send more funds than you have available.\n\nTrying to send:\nAvailable to send:',
{
formatSendingAmount,
formatRequiredAmount,
formatAvailableAmount,
},
)
: t(
'You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.\n\nTrying to send: {{formatSendingAmount}}\nAvailable to send: {{formatAvailableAmount}}',
'You are trying to send more funds than you have available. Make sure you do not have funds locked by pending transaction proposals.\n\nTrying to send:\nAvailable to send:',
{
formatSendingAmount,
formatRequiredAmount,
formatAvailableAmount,
},
);
Expand Down Expand Up @@ -1999,7 +2007,12 @@ const processInsufficientFunds = async (
if (useConfirmedFunds && wallet.balance.sat >= amountSat + feeRatePerKb) {
return generateInsufficientConfirmedFundsError(onDismiss);
} else {
return generateInsufficientFundsError(dispatch, wallet, amount, onDismiss);
return generateInsufficientFundsError(
dispatch,
wallet,
amountSat,
onDismiss,
);
}
};

Expand All @@ -2016,17 +2029,33 @@ const handleDefaultError = (

const keys = getState().WALLET.keys;
const {wallet, amount} = tx;
const {feeLevel} = txp;
let toShowAmount = amount;
let linkedWallet: Wallet | undefined;
if (IsERCToken(wallet.currencyAbbreviation, wallet.chain) && err.message) {
const match = err.message.match(/RequiredFee:\s*([0-9]+)/);
if (match && match[1]) {
toShowAmount = Number(match[1]);
linkedWallet = getFullLinkedWallet(keys[wallet.keyId], wallet);
}
}

const {formatAvailableAmount, formatRequiredAmount} = formatAmounts(
dispatch,
linkedWallet ? linkedWallet : wallet,
toShowAmount,
);

const title = IsEVMChain(wallet.chain)
? t('Not enough gas for transaction')
: t('Insufficient funds for fee.');
const body = IsERCToken(wallet.currencyAbbreviation, wallet.chain)
? t(
'Insufficient funds in your linked wallet to cover the transaction fee.',
'Insufficient funds in your linked wallet to cover the transaction fee.\n\nRequired Gas:\nLinked Wallet Balance:',
{
linkedWalletAbbreviation:
wallet.chain === 'matic' ? 'POL' : wallet.chain.toUpperCase(),
formatRequiredAmount,
formatAvailableAmount,
},
)
: t(
Expand All @@ -2048,7 +2077,7 @@ const handleDefaultError = (
navigationRef.navigate('BuyCryptoRoot', {
amount: 100,
fromWallet: IsERCToken(wallet.currencyAbbreviation, wallet.chain)
? getFullLinkedWallet(keys[wallet.keyId], wallet)
? linkedWallet
: wallet,
});
},
Expand Down