From 6991ee457771540e6da5a723d2bb7201842956b4 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Thu, 11 May 2023 17:49:12 +0700 Subject: [PATCH] fix: add insufficient funds error handling --- packages/wallet-management/package.json | 2 +- packages/widget-embedded/package.json | 2 +- packages/widget-playground/package.json | 2 +- packages/widget/package.json | 2 +- packages/widget/src/hooks/useProcessMessage.ts | 6 ++++++ packages/widget/src/i18n/en.json | 2 ++ yarn.lock | 16 ++++++++-------- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/wallet-management/package.json b/packages/wallet-management/package.json index e86fc75fd..83af86823 100644 --- a/packages/wallet-management/package.json +++ b/packages/wallet-management/package.json @@ -52,7 +52,7 @@ "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/experimental": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@lifi/sdk": "^2.0.0-beta.12", + "@lifi/sdk": "^2.0.0-beta.13", "@walletconnect/ethereum-provider": "^1.8.0", "@walletconnect/web3-provider": "^1.8.0", "events": "^3.3.0", diff --git a/packages/widget-embedded/package.json b/packages/widget-embedded/package.json index 651a09fd7..ac3036a2a 100644 --- a/packages/widget-embedded/package.json +++ b/packages/widget-embedded/package.json @@ -24,7 +24,7 @@ "author": "Eugene Chybisov ", "dependencies": { "@ethersproject/abstract-signer": "^5.7.0", - "@lifi/sdk": "^2.0.0-beta.12", + "@lifi/sdk": "^2.0.0-beta.13", "@lifi/wallet-management": "^2.0.0-beta.6", "@lifi/widget": "^2.0.0-beta.8", "@mui/icons-material": "^5.11.16", diff --git a/packages/widget-playground/package.json b/packages/widget-playground/package.json index 39b3c50f3..0154f56b9 100644 --- a/packages/widget-playground/package.json +++ b/packages/widget-playground/package.json @@ -23,7 +23,7 @@ }, "author": "Eugene Chybisov ", "dependencies": { - "@lifi/sdk": "^2.0.0-beta.12", + "@lifi/sdk": "^2.0.0-beta.13", "@lifi/wallet-management": "^2.0.0-beta.6", "@lifi/widget": "^2.0.0-beta.8", "@mui/icons-material": "^5.11.16", diff --git a/packages/widget/package.json b/packages/widget/package.json index 8011a345b..e00762967 100644 --- a/packages/widget/package.json +++ b/packages/widget/package.json @@ -53,7 +53,7 @@ "@ethersproject/address": "^5.7.0", "@ethersproject/experimental": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@lifi/sdk": "^2.0.0-beta.12", + "@lifi/sdk": "^2.0.0-beta.13", "@lifi/wallet-management": "^2.0.0-beta.6", "@mui/icons-material": "^5.11.16", "@mui/lab": "^5.0.0-alpha.129", diff --git a/packages/widget/src/hooks/useProcessMessage.ts b/packages/widget/src/hooks/useProcessMessage.ts index 4e0a7b2cc..c8a777460 100644 --- a/packages/widget/src/hooks/useProcessMessage.ts +++ b/packages/widget/src/hooks/useProcessMessage.ts @@ -135,6 +135,12 @@ export function getProcessMessage( title = t(`swap.error.title.gasLimitIsTooLow`); message = getTransactionNotSentMessage(); break; + case LifiErrorCode.InsufficientFunds: + title = t(`swap.error.title.insufficientFunds`); + message = `${t( + `swap.error.message.insufficientFunds`, + )} ${getTransactionNotSentMessage()}`; + break; case LifiErrorCode.SlippageError: title = t(`swap.error.title.slippageNotMet`); message = t(`swap.error.message.slippageThreshold`); diff --git a/packages/widget/src/i18n/en.json b/packages/widget/src/i18n/en.json index deccd7844..5104466fc 100644 --- a/packages/widget/src/i18n/en.json +++ b/packages/widget/src/i18n/en.json @@ -83,6 +83,7 @@ "error": { "message": { "allowanceRequired": "Transfer amount for {{tokenSymbol}} exceeds your current allowance. Please increase your allowance and try again.", + "insufficientFunds": "You don't have enough gas to cover the cost of the transaction.", "slippageThreshold": "The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.", "transactionFailed": "Please check the block explorer for more information.", "transactionNotSent": "Transaction was not sent. {{amount, number(maximumFractionDigits: 9)}} {{tokenSymbol}} on {{chainName}} remain in your wallet.", @@ -95,6 +96,7 @@ "chainSwitch": "Chain switch required", "failed": "Swap failed", "gasLimitIsTooLow": "The gas limit is too low", + "insufficientFunds": "Insufficient funds", "slippageNotMet": "Slippage conditions not met", "transactionCanceled": "Transaction canceled", "transactionFailed": "Transaction failed", diff --git a/yarn.lock b/yarn.lock index 353bda36b..a86557fd2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2627,9 +2627,9 @@ __metadata: languageName: node linkType: hard -"@lifi/sdk@npm:^2.0.0-beta.12": - version: 2.0.0-beta.12 - resolution: "@lifi/sdk@npm:2.0.0-beta.12" +"@lifi/sdk@npm:^2.0.0-beta.13": + version: 2.0.0-beta.13 + resolution: "@lifi/sdk@npm:2.0.0-beta.13" dependencies: "@ethersproject/abi": ^5.7.0 "@ethersproject/contracts": ^5.7.0 @@ -2637,7 +2637,7 @@ __metadata: bignumber.js: ^9.1.1 eth-rpc-errors: ^4.0.3 ethers: ^5.7.2 - checksum: 7240974c05f52b7fa8c95b602b4c8bf3ec0dc28d16d8f202884569d1c1917852422828da8cb371271d6ea3fbfd6236c4707277ebc11ccbeccccf43e85758711e + checksum: aba59d9ea9c95bf07c467781ad19f9b5e656c55a38ff4a148e2c2a45325ff92eef64cd47e87b151d249b07c1baabf00e115774b5fb935f7e8fccb419720b568f languageName: node linkType: hard @@ -2658,7 +2658,7 @@ __metadata: "@ethersproject/abstract-signer": ^5.7.0 "@ethersproject/experimental": ^5.7.0 "@ethersproject/providers": ^5.7.2 - "@lifi/sdk": ^2.0.0-beta.12 + "@lifi/sdk": ^2.0.0-beta.13 "@walletconnect/ethereum-provider": ^1.8.0 "@walletconnect/web3-provider": ^1.8.0 cpy-cli: ^4.2.0 @@ -2674,7 +2674,7 @@ __metadata: dependencies: "@esbuild-plugins/node-globals-polyfill": ^0.2.3 "@ethersproject/abstract-signer": ^5.7.0 - "@lifi/sdk": ^2.0.0-beta.12 + "@lifi/sdk": ^2.0.0-beta.13 "@lifi/wallet-management": ^2.0.0-beta.6 "@lifi/widget": ^2.0.0-beta.8 "@mui/icons-material": ^5.11.16 @@ -2705,7 +2705,7 @@ __metadata: resolution: "@lifi/widget-playground@workspace:packages/widget-playground" dependencies: "@esbuild-plugins/node-globals-polyfill": ^0.2.3 - "@lifi/sdk": ^2.0.0-beta.12 + "@lifi/sdk": ^2.0.0-beta.13 "@lifi/wallet-management": ^2.0.0-beta.6 "@lifi/widget": ^2.0.0-beta.8 "@mui/icons-material": ^5.11.16 @@ -2734,7 +2734,7 @@ __metadata: "@ethersproject/address": ^5.7.0 "@ethersproject/experimental": ^5.7.0 "@ethersproject/providers": ^5.7.2 - "@lifi/sdk": ^2.0.0-beta.12 + "@lifi/sdk": ^2.0.0-beta.13 "@lifi/wallet-management": ^2.0.0-beta.6 "@mui/icons-material": ^5.11.16 "@mui/lab": ^5.0.0-alpha.129