Skip to content

Commit

Permalink
fix: CR-537 KEP-1461 (#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv authored Aug 7, 2023
1 parent f66b0d0 commit c52ebcd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/components/TradeRouting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ const RouteRow = ({ route, chainId, backgroundColor }: RouteRowProps) => {
{Array.isArray(subRoute)
? subRoute.map(pool => {
const dex = getDexInfoByPool(pool, allDexes)
const poolId = pool.id.split('-')?.[0]
const link = (i => {
// TODO: Dungz remove condition
return isAddress(chainId, pool.id) && !['1inch', 'paraswap', '0x'].includes(pool.exchange) ? (
return isAddress(chainId, poolId) && !['1inch', 'paraswap', '0x'].includes(pool.exchange) ? (
<StyledExchange
key={`${i}-${pool.id}`}
href={getEtherscanLink(chainId, pool.id, 'address')}
href={getEtherscanLink(chainId, poolId, 'address')}
target="_blank"
>
{i}
Expand Down
32 changes: 21 additions & 11 deletions src/hooks/web3/useChangeNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function useChangeNetwork() {
method: 'wallet_addEthereumChain',
params: [addChainParameter],
})
changeNetworkHandler(desiredChainId, wrappedSuccessCallback)
wrappedSuccessCallback()
} catch (error) {
console.error('Add new network failed', { addChainParameter, error })
failureCallback(connector, desiredChainId, error, customFailureCallback, customTexts)
Expand All @@ -160,7 +160,6 @@ export function useChangeNetwork() {
[
library?.provider,
chainId,
changeNetworkHandler,
connector,
failureCallback,
fetchKyberswapConfig,
Expand All @@ -175,6 +174,7 @@ export function useChangeNetwork() {
customSuccessCallback?: () => void,
customFailureCallback?: (connector: Connector, error: Error) => void,
waitUtilUpdatedChainId = false,
isAddNetworkIfPossible = true,
) => {
const wrappedSuccessCallback = () =>
successCallback(desiredChainId, waitUtilUpdatedChainId, customSuccessCallback)
Expand Down Expand Up @@ -207,15 +207,25 @@ export function useChangeNetwork() {
failureCallback(connector, desiredChainId, error, customFailureCallback)
return
}

addNewNetwork(
desiredChainId,
undefined,
undefined,
customSuccessCallback,
customFailureCallback,
waitUtilUpdatedChainId,
)
if (isAddNetworkIfPossible) {
addNewNetwork(
desiredChainId,
undefined,
undefined,
() =>
changeNetwork(
desiredChainId,
customSuccessCallback,
customFailureCallback,
waitUtilUpdatedChainId,
false,
),
customFailureCallback,
waitUtilUpdatedChainId,
)
} else {
failureCallback(connector, desiredChainId, error, customFailureCallback)
}
}
} else {
changeNetworkHandler(desiredChainId, wrappedSuccessCallback)
Expand Down

0 comments on commit c52ebcd

Please sign in to comment.