Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
5640c115
Unverified
Commit
5640c115
authored
Jul 03, 2023
by
eddie
Committed by
GitHub
Jul 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove error popup when switching chains from URL param (#6866)
parent
7b8114b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
20 deletions
+14
-20
switch-network.test.ts
cypress/e2e/wallet-connection/switch-network.test.ts
+9
-0
useSelectChain.ts
src/hooks/useSelectChain.ts
+1
-1
useSyncChainQuery.ts
src/hooks/useSyncChainQuery.ts
+4
-19
No files found.
cypress/e2e/wallet-connection/switch-network.test.ts
View file @
5640c115
...
@@ -119,3 +119,12 @@ describe('network switching', () => {
...
@@ -119,3 +119,12 @@ describe('network switching', () => {
cy
.
get
(
`#swap-currency-output .token-symbol-container`
).
should
(
'
contain.text
'
,
'
Select token
'
)
cy
.
get
(
`#swap-currency-output .token-symbol-container`
).
should
(
'
contain.text
'
,
'
Select token
'
)
})
})
})
})
describe
(
'
network switching from URL param
'
,
()
=>
{
it
(
'
should switch network from URL param
'
,
()
=>
{
cy
.
visit
(
'
/swap?chain=polygon
'
,
{
ethereum
:
'
hardhat
'
})
cy
.
get
(
getTestSelector
(
'
web3-status-connected
'
))
cy
.
wait
(
'
@wallet_switchEthereumChain
'
)
waitsForActiveChain
(
'
Polygon
'
)
})
})
src/hooks/useSelectChain.ts
View file @
5640c115
...
@@ -22,7 +22,7 @@ export default function useSelectChain() {
...
@@ -22,7 +22,7 @@ export default function useSelectChain() {
try
{
try
{
await
switchChain
(
connector
,
targetChain
)
await
switchChain
(
connector
,
targetChain
)
}
catch
(
error
)
{
}
catch
(
error
)
{
if
(
!
didUserReject
(
connection
,
error
))
{
if
(
!
didUserReject
(
connection
,
error
)
&&
error
.
code
!==
-
32002
/* request already pending */
)
{
console
.
error
(
'
Failed to switch networks
'
,
error
)
console
.
error
(
'
Failed to switch networks
'
,
error
)
dispatch
(
addPopup
({
content
:
{
failedSwitchNetwork
:
targetChain
},
key
:
'
failed-network-switch
'
}))
dispatch
(
addPopup
({
content
:
{
failedSwitchNetwork
:
targetChain
},
key
:
'
failed-network-switch
'
}))
}
}
...
...
src/hooks/useSyncChainQuery.ts
View file @
5640c115
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
useWeb3React
}
from
'
@web3-react/core
'
import
{
CHAIN_IDS_TO_NAMES
}
from
'
constants/chains
'
import
{
CHAIN_IDS_TO_NAMES
}
from
'
constants/chains
'
import
{
ParsedQs
}
from
'
qs
'
import
{
ParsedQs
}
from
'
qs
'
import
{
useEffect
,
useState
}
from
'
react
'
import
{
useEffect
}
from
'
react
'
import
{
useSearchParams
}
from
'
react-router-dom
'
import
{
useSearchParams
}
from
'
react-router-dom
'
import
useParsedQueryString
from
'
./useParsedQueryString
'
import
useParsedQueryString
from
'
./useParsedQueryString
'
import
usePrevious
from
'
./usePrevious
'
import
useSelectChain
from
'
./useSelectChain
'
import
useSelectChain
from
'
./useSelectChain
'
function
getChainIdFromName
(
name
:
string
)
{
function
getChainIdFromName
(
name
:
string
)
{
...
@@ -26,28 +25,14 @@ export default function useSyncChainQuery() {
...
@@ -26,28 +25,14 @@ export default function useSyncChainQuery() {
const
parsedQs
=
useParsedQueryString
()
const
parsedQs
=
useParsedQueryString
()
const
urlChainId
=
getParsedChainId
(
parsedQs
)
const
urlChainId
=
getParsedChainId
(
parsedQs
)
const
previousUrlChainId
=
usePrevious
(
urlChainId
)
const
selectChain
=
useSelectChain
()
const
selectChain
=
useSelectChain
()
// Can't use `usePrevious` because `chainId` can be undefined while activating.
const
[
previousChainId
,
setPreviousChainId
]
=
useState
<
number
|
undefined
>
(
undefined
)
useEffect
(()
=>
{
if
(
chainId
&&
chainId
!==
previousChainId
)
{
setPreviousChainId
(
chainId
)
}
},
[
chainId
,
previousChainId
])
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
()
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
()
const
chainQueryManuallyUpdated
=
urlChainId
&&
urlChainId
!==
previousUrlChainId
&&
isActive
useEffect
(()
=>
{
if
(
isActive
&&
urlChainId
&&
chainId
!==
urlChainId
)
{
return
useEffect
(()
=>
{
if
(
chainQueryManuallyUpdated
)
{
// If the query param changed, and the chain didn't change, then activate the new chain
selectChain
(
urlChainId
)
selectChain
(
urlChainId
)
searchParams
.
delete
(
'
chain
'
)
setSearchParams
(
searchParams
)
}
}
},
[
chainQueryManuallyUpdated
,
urlChainId
,
selectChain
,
searchParams
,
setSearchParams
])
},
[
urlChainId
,
selectChain
,
searchParams
,
setSearchParams
,
isActive
,
chainId
])
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment