Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: redirect /wc URL #2747

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
usame-algan marked this conversation as resolved.
Show resolved Hide resolved
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
Loading