From fb3550c2c380ceb23bdf2ae2c1c535be00e7ecfa Mon Sep 17 00:00:00 2001
From: Hau Nguyen Van <nguyenvanhauit1997@gmail.com>
Date: Thu, 2 Jan 2025 20:45:54 +0700
Subject: [PATCH] fix crash

---
 package.json                                  |  5 +-
 src/pages/Balance/index.tsx                   | 43 ++---------
 .../Swap/components/AddressBook/index.tsx     |  4 +-
 .../Swap/components/AddressForm/index.tsx     |  4 +-
 src/pages/UniversalSwap/helpers.ts            |  2 +-
 yarn.lock                                     | 74 +++++--------------
 6 files changed, 32 insertions(+), 100 deletions(-)

diff --git a/package.json b/package.json
index fb1e3ad8d..9897777c4 100644
--- a/package.json
+++ b/package.json
@@ -25,11 +25,10 @@
     "@oraichain/ethereum-multicall": "^1.0.2",
     "@oraichain/kawaiiverse-txs": "^0.0.3",
     "@oraichain/orai-bitcoin": "2.0.0",
-    "@oraichain/oraidex-common": "2.0.6",
     "@oraichain/orai-token-inspector": "^0.1.24",
     "@oraichain/oraidex-common-ui": "1.0.11",
     "@oraichain/oraidex-contracts-sdk": "1.0.55",
-    "@oraichain/oraidex-universal-swap": "1.2.0-beta28",
+    "@oraichain/oraidex-universal-swap": "1.3.1",
     "@oraichain/oraiswap-v3": "1.2.0-beta26",
     "@oraichain/ton-bridge-contracts": "^0.15.8",
     "@oraichain/tonbridge-contracts-sdk": "^1.3.1",
@@ -170,7 +169,7 @@
     "axios": "0.26.1",
     "@sentry/react": "7.99.0",
     "@cosmjs/amino": "0.32.4",
-    "@oraichain/oraidex-common": "2.0.6"
+    "@oraichain/oraidex-common": "2.0.8"
   },
   "overrides": {
     "cosmjs-types@>0.7.0 <0.8.0": "0.7.1",
diff --git a/src/pages/Balance/index.tsx b/src/pages/Balance/index.tsx
index 219d1e2f2..8c5029f81 100644
--- a/src/pages/Balance/index.tsx
+++ b/src/pages/Balance/index.tsx
@@ -614,47 +614,23 @@ const Balance: React.FC<BalanceProps> = () => {
       const fromBalance = from && initFromBalance ? subAmount + BigInt(initFromBalance) : BigInt(0);
       const condition = fromAmount > 0 && toAmount(fromAmount, from.decimals) <= fromBalance;
       assert(condition, 'Your balance is insufficient to make this transfer');
-
       displayToast(TToastType.TX_BROADCASTING);
       let result: DeliverTxResponse | string | any;
-
       let newToToken = to;
       if (toNetworkChainId) {
-        // ORAICHAIN -> EVM (BSC/ETH/TRON) ( TO: TOKEN ORAIBRIDGE)
         newToToken = [...otherChainTokens, ...oraichainTokens].find(
           (flat) => flat.chainId === toNetworkChainId && flat.coinGeckoId === from.coinGeckoId
         );
-
-        // TODO: vuonghuuhung support dynamic bridge orai <-> solana
-        // if (from.chainId === SolanaNetworkConfig.chainId) {
-        //   newToToken = [...allOraichainTokens, ...allOtherChainTokens].find(
-        //     (flat) =>
-        //       flat.chainId === toNetworkChainId &&
-        //       flat.coinGeckoId === from.coinGeckoId &&
-        //       flat.denom.includes(from.denom)
-        //   );
-        // }
-
-        // if (toNetworkChainId === SolanaNetworkConfig.chainId) {
-        //   console.log('🚀 ~ onClickTransfer ~ toNetworkChainId', toNetworkChainId);
-        //   const subDenom = from.denom.split('/')[2];
-        //   const targetTokenInfo = onChainTokenToTokenItem(
-        //     await tokenInspector.inspectTokenFromSpecifiedChain({
-        //       tokenId: subDenom,
-        //       chainId: toNetworkChainId
-        //     })
-        //   );
-        //   newToToken = targetTokenInfo;
-        // }
-
-        // console.log('🚀 ~ onClickTransfer ~ newToToken', newToToken);
         assert(newToToken, 'Cannot find newToToken token that matches from token to bridge!');
       }
 
+      assert(
+        newToToken.coinGeckoId === from.coinGeckoId,
+        `From token ${from.coinGeckoId} is different from to token ${newToToken.coinGeckoId}`
+      );
+
       // check transfer TON <=> ORAICHAIN,Osmosis
       const { isFromTonToCosmos, isFromCosmosToTON, isFromCosmosToCosmos } = await checkTransferTon(toNetworkChainId);
-      console.log({ isFromTonToCosmos, isFromCosmosToTON, isFromCosmosToCosmos });
-
       if (isFromCosmosToCosmos || isFromTonToCosmos || isFromCosmosToTON) {
         return await handleTransferTon({
           isTonToCosmos: isFromTonToCosmos,
@@ -664,12 +640,7 @@ const Balance: React.FC<BalanceProps> = () => {
         });
       }
 
-      assert(
-        newToToken.coinGeckoId === from.coinGeckoId,
-        `From token ${from.coinGeckoId} is different from to token ${newToToken.coinGeckoId}`
-      );
-
-      let [isSolToOraichain, isOraichainToSol, isBTCToOraichain, isBtcBridge] = checkTransfer(
+      const [isSolToOraichain, isOraichainToSol, isBTCToOraichain, isBtcBridge] = checkTransfer(
         from.chainId,
         newToToken.chainId
       );
@@ -682,7 +653,6 @@ const Balance: React.FC<BalanceProps> = () => {
           transferAmount: fromAmount
         });
       }
-
       if (isSolToOraichain || isOraichainToSol) {
         if (isOraichainToSol) {
           return handleTransferOraichainToSol({ fromToken: from, toToken: newToToken, transferAmount: fromAmount });
@@ -725,6 +695,7 @@ const Balance: React.FC<BalanceProps> = () => {
       if (newToToken.chainId === 'injective-1' && newToToken.coinGeckoId === 'injective-protocol') {
         simulateAmount = toAmount(fromAmount, newToToken.decimals).toString();
       }
+      alert(1);
 
       let relayerFee = {
         relayerAmount: DEFAULT_RELAYER_FEE,
diff --git a/src/pages/UniversalSwap/Swap/components/AddressBook/index.tsx b/src/pages/UniversalSwap/Swap/components/AddressBook/index.tsx
index 799e4753c..12fbfa144 100644
--- a/src/pages/UniversalSwap/Swap/components/AddressBook/index.tsx
+++ b/src/pages/UniversalSwap/Swap/components/AddressBook/index.tsx
@@ -103,7 +103,7 @@ const AddressBook = ({ tokenTo, onSelected }: { tokenTo: TokenItemType; onSelect
                       >
                         {IconToken ? (
                           <div className={styles.tokenIcon}>
-                            <IconToken />
+                            <img src={IconToken} width={30} height={30} />
                           </div>
                         ) : (
                           <div className={styles.selectTokenIcon}>
@@ -155,7 +155,7 @@ const AddressBook = ({ tokenTo, onSelected }: { tokenTo: TokenItemType; onSelect
                       <div className={styles.content}>
                         {IconToken ? (
                           <div className={styles.tokenIcon}>
-                            <IconToken />
+                            <img src={IconToken} width={30} height={30} />
                           </div>
                         ) : (
                           <div className={styles.selectTokenIcon}>
diff --git a/src/pages/UniversalSwap/Swap/components/AddressForm/index.tsx b/src/pages/UniversalSwap/Swap/components/AddressForm/index.tsx
index 854a14b38..5ced0386b 100644
--- a/src/pages/UniversalSwap/Swap/components/AddressForm/index.tsx
+++ b/src/pages/UniversalSwap/Swap/components/AddressForm/index.tsx
@@ -71,7 +71,7 @@ const AddressBookForm = ({ tokenTo }: { tokenTo: TokenItemType }) => {
 
       return (
         <div className={styles.label}>
-          <div>{Icon ? <Icon /> : <DefaultIcon />}</div>
+          <div>{Icon ? <img src={Icon} width={30} height={30} /> : <DefaultIcon />}</div>
           <span>{token?.name}</span>
         </div>
       );
@@ -165,7 +165,7 @@ const AddressBookForm = ({ tokenTo }: { tokenTo: TokenItemType }) => {
             prefix={
               CurrentTokenIcon ? (
                 <div className={styles.tokenIcon}>
-                  <CurrentTokenIcon />
+                  <img src={CurrentTokenIcon} width={30} height={30} />
                 </div>
               ) : (
                 <div className={styles.selectTokenIcon}>
diff --git a/src/pages/UniversalSwap/helpers.ts b/src/pages/UniversalSwap/helpers.ts
index 8fbb63a78..2e5fbb2d2 100644
--- a/src/pages/UniversalSwap/helpers.ts
+++ b/src/pages/UniversalSwap/helpers.ts
@@ -260,7 +260,7 @@ export const getTokenIcon = (token: TokenItemType, theme: string) => {
   const tokenInfo = oraichainTokensWithIcon.find((e) => e.coinGeckoId === token?.coinGeckoId);
 
   if (tokenInfo && Object.keys(tokenInfo.IconLight || tokenInfo.Icon || {}).length > 0) {
-    tokenIcon = theme === 'light' ? tokenInfo?.IconLight || tokenInfo?.Icon : tokenInfo?.Icon;
+    tokenIcon = theme === 'light' ? tokenInfo?.iconLight : tokenInfo?.icon;
   }
   return tokenIcon;
 };
diff --git a/yarn.lock b/yarn.lock
index c5fccfc9e..4ba64cc07 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3818,23 +3818,10 @@
     ethers "^5.5.1"
     lodash "^4.17.21"
 
-"@oraichain/common@1.2.6":
-  version "1.2.6"
-  resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.6.tgz#7b2f4bed1a7a93e54190a8409e289f6ebab7ba06"
-  integrity sha512-Ten4zmHnunmXtE4zBPO2e4zENvr/Iv1nOzDpZcdCoFJHd7Xe4JuKMWuDBfDy9FWW9AlMbnkcKB7jqaLq4uyP3A==
-  dependencies:
-    "@keplr-wallet/types" "0.12.141"
-    axios "0.21.4"
-    axios-extensions "3.1.6"
-    bech32 "^1.1.4"
-    cosmjs-types "^0.9.0"
-    ethers "^5.5.1"
-    lodash "^4.17.21"
-
-"@oraichain/common@1.2.7":
-  version "1.2.7"
-  resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.7.tgz#5063b20967eac14b5fc94e75f02afa6685565507"
-  integrity sha512-yOaEpjxtYwGkOxzSiqYwULfK0KSGdBj0ziQLZjQhM6yhW3MzTK70nAORW64ATKomSlBQFy9I/6MFsGkQBHiv3w==
+"@oraichain/common@1.2.8":
+  version "1.2.8"
+  resolved "https://registry.yarnpkg.com/@oraichain/common/-/common-1.2.8.tgz#af1e5766d78a4c8b080b7b0544eaceecf852996e"
+  integrity sha512-g01foLXdpdAPR6bFzos96P3juGf5EGCiKMx5/Ld6RcY2m6ibyVZK5tIpXdn+G67da5w9vhdqHOspL38La1l+yA==
   dependencies:
     "@keplr-wallet/types" "0.12.141"
     axios "0.21.4"
@@ -3990,10 +3977,10 @@
     react-use "^17.4.0"
     react-use-websocket "^4.5.0"
 
-"@oraichain/oraidex-common@2.0.5", "@oraichain/oraidex-common@2.0.6", "@oraichain/oraidex-common@^1.1.6":
-  version "2.0.6"
-  resolved "https://registry.yarnpkg.com/@oraichain/oraidex-common/-/oraidex-common-2.0.6.tgz#948acc4f93fd51365f2015be55a2d8a9dedb6309"
-  integrity sha512-S8Qtu6ajmrGQemPjcO2BzUx1zs0eqRKcxG17pnZXpZOX4mbI4GefwCTSUyBliSOms7ltMmZp9Xes/su7nVkhPg==
+"@oraichain/oraidex-common@2.0.5", "@oraichain/oraidex-common@2.0.8", "@oraichain/oraidex-common@^1.1.6":
+  version "2.0.8"
+  resolved "https://registry.yarnpkg.com/@oraichain/oraidex-common/-/oraidex-common-2.0.8.tgz#4e2682bc03d909e4e02e6a83fe348f90b78b7ee0"
+  integrity sha512-6LKwgkwsaN5KxwlTngNyVqeGWqO5xc2H0FuebLr3hA1O72gICMmmqD3/pCB2c7nITQucuu59aX07frnHamgkAQ==
   dependencies:
     "@cosmjs/amino" "^0.32.4"
     "@cosmjs/cosmwasm-stargate" "^0.32.4"
@@ -4004,7 +3991,7 @@
     "@ethersproject/providers" "^5.0.10"
     "@injectivelabs/sdk-ts" "1.12.1"
     "@keplr-wallet/types" "^0.11.38"
-    "@oraichain/common" "1.2.7"
+    "@oraichain/common" "1.2.8"
     "@oraichain/oraidex-contracts-sdk" latest
     "@ton/core" "0.56.3"
     "@ton/crypto" "3.3.0"
@@ -4035,13 +4022,13 @@
   resolved "https://registry.yarnpkg.com/@oraichain/oraidex-contracts-sdk/-/oraidex-contracts-sdk-1.0.45.tgz#42dae0fdd9e005f920ba305b987009f791acc365"
   integrity sha512-/nYztdxEX5LQM4DMJQmi9HvZrBVoY3nLAmYqSKZGZ0U1h1SxU7O/o22R3/pQwB+sAJdcibaI8ygC0ov7jC8paA==
 
-"@oraichain/oraidex-universal-swap@1.2.0-beta28":
-  version "1.2.0-beta28"
-  resolved "https://registry.yarnpkg.com/@oraichain/oraidex-universal-swap/-/oraidex-universal-swap-1.2.0-beta28.tgz#3014aa77279c646a8c116846c16d90da22134ff3"
-  integrity sha512-GiY7v1lFuAkt/TKt8fQJQSTEpRJtggDKD892hqdfFY5mN9Cjb+E6wdJEFfE56vXmin2EzHVWjfO/PqVteq4hHg==
+"@oraichain/oraidex-universal-swap@1.3.1":
+  version "1.3.1"
+  resolved "https://registry.yarnpkg.com/@oraichain/oraidex-universal-swap/-/oraidex-universal-swap-1.3.1.tgz#d5f952d9a117d78d9281547493c716915b8ef160"
+  integrity sha512-HiYISG6oZWBYVJrXS6enYVBFOSdgQu2hUT1kBDeLACu/86LJjSPPs/3ztBhMTDuEP6yKfR1ZnTBVz5U9XwsUzA==
   dependencies:
-    "@oraichain/common" "1.2.6"
-    "@oraichain/oraidex-common" "2.0.5"
+    "@oraichain/common" "1.2.8"
+    "@oraichain/oraidex-common" "2.0.8"
     "@oraichain/oraidex-contracts-sdk" "^1.0.49"
     "@oraichain/osor-api-contracts-sdk" "^1.0.2"
     bech32 "1.1.4"
@@ -16830,7 +16817,7 @@ string-env-interpolation@^1.0.1:
   resolved "https://registry.yarnpkg.com/string-env-interpolation/-/string-env-interpolation-1.0.1.tgz#ad4397ae4ac53fe6c91d1402ad6f6a52862c7152"
   integrity sha512-78lwMoCcn0nNu8LszbP1UA7g55OeE4v7rCeWnM5B453rnNr4aq+5it3FEYtZrSEiMvHZOZ9Jlqb0OD0M2VInqg==
 
-"string-width-cjs@npm:string-width@^4.2.0":
+"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
   version "4.2.3"
   resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
   integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -16848,15 +16835,6 @@ string-width@^3.0.0, string-width@^3.1.0:
     is-fullwidth-code-point "^2.0.0"
     strip-ansi "^5.1.0"
 
-string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.2, string-width@^4.2.3:
-  version "4.2.3"
-  resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
-  integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
-  dependencies:
-    emoji-regex "^8.0.0"
-    is-fullwidth-code-point "^3.0.0"
-    strip-ansi "^6.0.1"
-
 string-width@^5.0.1, string-width@^5.1.2:
   version "5.1.2"
   resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
@@ -16885,7 +16863,7 @@ string_decoder@~1.1.1:
   dependencies:
     safe-buffer "~5.1.0"
 
-"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
+"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
   version "6.0.1"
   resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
   integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -16906,13 +16884,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
   dependencies:
     ansi-regex "^4.1.0"
 
-strip-ansi@^6.0.0, strip-ansi@^6.0.1:
-  version "6.0.1"
-  resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
-  integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
-  dependencies:
-    ansi-regex "^5.0.1"
-
 strip-ansi@^7.0.1:
   version "7.1.0"
   resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -18316,7 +18287,7 @@ wordwrapjs@^5.1.0:
   resolved "https://registry.yarnpkg.com/wordwrapjs/-/wordwrapjs-5.1.0.tgz#4c4d20446dcc670b14fa115ef4f8fd9947af2b3a"
   integrity sha512-JNjcULU2e4KJwUNv6CHgI46UvDGitb6dGryHajXTDiLgg1/RiGoPSDw4kZfYnwGtEXf2ZMeIewDQgFGzkCB2Sg==
 
-"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
+"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
   version "7.0.0"
   resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
   integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -18343,15 +18314,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
     string-width "^4.1.0"
     strip-ansi "^6.0.0"
 
-wrap-ansi@^7.0.0:
-  version "7.0.0"
-  resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
-  integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
-  dependencies:
-    ansi-styles "^4.0.0"
-    string-width "^4.1.0"
-    strip-ansi "^6.0.0"
-
 wrap-ansi@^8.1.0:
   version "8.1.0"
   resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"