Skip to content

Commit

Permalink
Fix: redirect /wc URL (#2747)
Browse files Browse the repository at this point in the history
* Fix: redirect /wc URL

* Use raw URL query

* Fix tests

* Rm raw query parsing

* Fix: unblock Base and Arbitrum bridges in WC
  • Loading branch information
katspaugh authored Nov 9, 2023
1 parent e72f222 commit b2ba82d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/components/walletconnect/WcInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const WcInput = ({ uri }: { uri: string }) => {
error={!!error}
label={error ? error.message : 'Pairing code'}
placeholder="wc:"
spellCheck={false}
InputProps={{
autoComplete: 'off',
endAdornment: isClipboardSupported() ? undefined : (
<InputAdornment position="end">
<Track {...WALLETCONNECT_EVENTS.PASTE_CLICK}>
Expand Down
3 changes: 2 additions & 1 deletion src/config/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const AppRoutes = {
'404': '/404',
_offline: '/_offline',
welcome: '/welcome',
wc: '/wc',
terms: '/terms',
privacy: '/privacy',
licenses: '/licenses',
Expand All @@ -11,6 +11,7 @@ export const AppRoutes = {
cookie: '/cookie',
addressBook: '/address-book',
addOwner: '/addOwner',
_offline: '/_offline',
apps: {
open: '/apps/open',
index: '/apps',
Expand Down
40 changes: 40 additions & 0 deletions src/pages/wc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useEffect } from 'react'
import type { NextPage } from 'next'
import { useRouter } from 'next/router'
import useLastSafe from '@/hooks/useLastSafe'
import { AppRoutes } from '@/config/routes'
import { WC_URI_SEARCH_PARAM } from '@/services/walletconnect/useWalletConnectSearchParamUri'

const WcPage: NextPage = () => {
const router = useRouter()
const lastSafe = useLastSafe()

useEffect(() => {
if (!router.isReady || router.pathname !== AppRoutes.wc) {
return
}

const { uri } = router.query

router.replace(
lastSafe
? {
pathname: AppRoutes.home,
query: {
safe: lastSafe,
[WC_URI_SEARCH_PARAM]: uri,
},
}
: {
pathname: AppRoutes.welcome,
query: {
[WC_URI_SEARCH_PARAM]: uri,
},
},
)
}, [router, lastSafe])

return <></>
}

export default WcPage
4 changes: 2 additions & 2 deletions src/services/walletconnect/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export const EIP155 = 'eip155' as const
// Bridges enforcing same address on destination chains
export const BlockedBridges = [
'app.chainport.io',
'bridge.arbitrum.io',
'bridge.base.org',
'cbridge.celer.network',
'www.orbiter.finance',
'zksync-era.l2scan.co',
Expand Down Expand Up @@ -66,6 +64,8 @@ export const BlockedBridges = [
export const WarnedBridges = [
'across.to', // doesn't send their URL in the session proposal
'app.allbridge.io',
'bridge.arbitrum.io',
'bridge.base.org',
'core.allbridge.io',
'bungee.exchange',
'www.carrier.so',
Expand Down
9 changes: 2 additions & 7 deletions src/services/walletconnect/useWalletConnectSearchParamUri.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { useRouter } from 'next/router'
import { useCallback } from 'react'

import { isPairingUri } from './utils'

const WC_URI_SEARCH_PARAM = 'wc'
export const WC_URI_SEARCH_PARAM = 'wc'

export function useWalletConnectSearchParamUri(): [string | null, (wcUri: string | null) => void] {
const router = useRouter()

const wcUriQuery = router.query[WC_URI_SEARCH_PARAM]
const value = wcUriQuery ? (Array.isArray(wcUriQuery) ? wcUriQuery[0] : wcUriQuery) : null
const wcUri = value && isPairingUri(value) ? value : null
const wcUri = (router.query[WC_URI_SEARCH_PARAM] || '').toString() || null

const setWcUri = useCallback(
(wcUri: string | null) => {
Expand Down

0 comments on commit b2ba82d

Please sign in to comment.