From aea54ae666c0a6ce8134b86bb48c9f213af1e404 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Tue, 7 Nov 2023 09:44:30 +0100 Subject: [PATCH 1/5] Fix: redirect /wc URL --- .../walletconnect/WcInput/index.tsx | 2 ++ src/config/routes.ts | 3 ++- src/pages/wc.tsx | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/pages/wc.tsx diff --git a/src/components/walletconnect/WcInput/index.tsx b/src/components/walletconnect/WcInput/index.tsx index fcfa32a919..125695708d 100644 --- a/src/components/walletconnect/WcInput/index.tsx +++ b/src/components/walletconnect/WcInput/index.tsx @@ -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 : ( diff --git a/src/config/routes.ts b/src/config/routes.ts index 6090dbb7ad..27402a440f 100644 --- a/src/config/routes.ts +++ b/src/config/routes.ts @@ -1,7 +1,7 @@ export const AppRoutes = { '404': '/404', - _offline: '/_offline', welcome: '/welcome', + wc: '/wc', terms: '/terms', privacy: '/privacy', licenses: '/licenses', @@ -11,6 +11,7 @@ export const AppRoutes = { cookie: '/cookie', addressBook: '/address-book', addOwner: '/addOwner', + _offline: '/_offline', apps: { open: '/apps/open', index: '/apps', diff --git a/src/pages/wc.tsx b/src/pages/wc.tsx new file mode 100644 index 0000000000..46a56a0c15 --- /dev/null +++ b/src/pages/wc.tsx @@ -0,0 +1,22 @@ +import { useEffect } from 'react' +import type { NextPage } from 'next' +import { useRouter } from 'next/router' +import useLastSafe from '@/hooks/useLastSafe' +import { AppRoutes } from '@/config/routes' + +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 ? `${AppRoutes.home}?safe=${lastSafe}&wc=${uri}` : `${AppRoutes.welcome}?wc=${uri}`) + }, [router, lastSafe]) + + return <> +} + +export default WcPage From 41d21d4335902cece2a22055d6fc993648099221 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Wed, 8 Nov 2023 12:48:50 +0100 Subject: [PATCH 2/5] Use raw URL query --- src/pages/wc.tsx | 23 +++++++++++++++++-- .../useWalletConnectSearchParamUri.ts | 18 +++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/pages/wc.tsx b/src/pages/wc.tsx index 46a56a0c15..5beaaea17b 100644 --- a/src/pages/wc.tsx +++ b/src/pages/wc.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react' import type { NextPage } from 'next' import { useRouter } from 'next/router' +import { parse } from 'querystring' import useLastSafe from '@/hooks/useLastSafe' import { AppRoutes } from '@/config/routes' @@ -12,8 +13,26 @@ const WcPage: NextPage = () => { if (!router.isReady || router.pathname !== AppRoutes.wc) { return } - const { uri = '' } = router.query - router.replace(lastSafe ? `${AppRoutes.home}?safe=${lastSafe}&wc=${uri}` : `${AppRoutes.welcome}?wc=${uri}`) + + // Don't use router.query because it cuts off internal paramters of the WC URI (e.g. symKey) + const { uri } = parse(window.location.search.slice(1)) + + router.replace( + lastSafe + ? { + pathname: AppRoutes.home, + query: { + safe: lastSafe, + wc: uri, + }, + } + : { + pathname: AppRoutes.welcome, + query: { + wc: uri, + }, + }, + ) }, [router, lastSafe]) return <> diff --git a/src/services/walletconnect/useWalletConnectSearchParamUri.ts b/src/services/walletconnect/useWalletConnectSearchParamUri.ts index d21a1bc14a..ab1151ec37 100644 --- a/src/services/walletconnect/useWalletConnectSearchParamUri.ts +++ b/src/services/walletconnect/useWalletConnectSearchParamUri.ts @@ -1,16 +1,20 @@ import { useRouter } from 'next/router' -import { useCallback } from 'react' - -import { isPairingUri } from './utils' +import { parse } from 'querystring' +import { useCallback, useEffect, useState } from 'react' const WC_URI_SEARCH_PARAM = 'wc' export function useWalletConnectSearchParamUri(): [string | null, (wcUri: string | null) => void] { const router = useRouter() + const wcQuery = router.query[WC_URI_SEARCH_PARAM] + const [rawUrlParam, setRawUrlParam] = useState('') - 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 + useEffect(() => { + // Don't use router.query because it cuts off internal paramters of the WC URI (e.g. symKey) + const query = parse(window.location.search.slice(1)) + const wcUri = query[WC_URI_SEARCH_PARAM] || '' + setRawUrlParam(wcUri.toString()) + }, [wcQuery]) const setWcUri = useCallback( (wcUri: string | null) => { @@ -30,5 +34,5 @@ export function useWalletConnectSearchParamUri(): [string | null, (wcUri: string [router], ) - return [wcUri, setWcUri] + return [rawUrlParam, setWcUri] } From ef608a57d8306cf3bfa486c773dac847cf0a7e9f Mon Sep 17 00:00:00 2001 From: katspaugh Date: Wed, 8 Nov 2023 14:43:47 +0100 Subject: [PATCH 3/5] Fix tests --- .../useWalletConnectSearchParamUri.test.ts | 24 +++++++++++++++++++ .../useWalletConnectSearchParamUri.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts b/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts index 584515b4cf..f9ca59c688 100644 --- a/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts +++ b/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts @@ -31,6 +31,14 @@ describe('useWalletConnectSearchParamUri', () => { it('should return the wc uri search param value when present', () => { mockRouter.query = { wc: 'wc:123' } + Object.defineProperty(window, 'location', { + writable: true, + value: { + pathname: window.location.pathname, + search: '?wc=wc:123', + }, + }) + const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri] = result.current @@ -41,6 +49,14 @@ describe('useWalletConnectSearchParamUri', () => { mockRouter.pathname = '/test' mockRouter.query = { test: 'example', wc: 'wc:123' } + Object.defineProperty(window, 'location', { + writable: true, + value: { + pathname: window.location.pathname, + search: '?wc=wc:123&test=example', + }, + }) + const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri, setWcUri] = result.current @@ -61,6 +77,14 @@ describe('useWalletConnectSearchParamUri', () => { mockRouter.pathname = '/test' mockRouter.query = { test: 'example', wc: 'wc:123' } + Object.defineProperty(window, 'location', { + writable: true, + value: { + pathname: window.location.pathname, + search: '?wc=wc:123&test=example', + }, + }) + const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri, setWcUri] = result.current diff --git a/src/services/walletconnect/useWalletConnectSearchParamUri.ts b/src/services/walletconnect/useWalletConnectSearchParamUri.ts index ab1151ec37..555502ca87 100644 --- a/src/services/walletconnect/useWalletConnectSearchParamUri.ts +++ b/src/services/walletconnect/useWalletConnectSearchParamUri.ts @@ -34,5 +34,5 @@ export function useWalletConnectSearchParamUri(): [string | null, (wcUri: string [router], ) - return [rawUrlParam, setWcUri] + return [rawUrlParam || null, setWcUri] } From 18735040b820aebbacd0e141b50ceafb3224e641 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Wed, 8 Nov 2023 15:28:25 +0100 Subject: [PATCH 4/5] Rm raw query parsing --- src/pages/wc.tsx | 9 ++++--- .../useWalletConnectSearchParamUri.test.ts | 24 ------------------- .../useWalletConnectSearchParamUri.ts | 17 ++++--------- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/pages/wc.tsx b/src/pages/wc.tsx index 5beaaea17b..02c41159db 100644 --- a/src/pages/wc.tsx +++ b/src/pages/wc.tsx @@ -1,9 +1,9 @@ import { useEffect } from 'react' import type { NextPage } from 'next' import { useRouter } from 'next/router' -import { parse } from 'querystring' 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() @@ -14,8 +14,7 @@ const WcPage: NextPage = () => { return } - // Don't use router.query because it cuts off internal paramters of the WC URI (e.g. symKey) - const { uri } = parse(window.location.search.slice(1)) + const { uri } = router.query router.replace( lastSafe @@ -23,13 +22,13 @@ const WcPage: NextPage = () => { pathname: AppRoutes.home, query: { safe: lastSafe, - wc: uri, + [WC_URI_SEARCH_PARAM]: uri, }, } : { pathname: AppRoutes.welcome, query: { - wc: uri, + [WC_URI_SEARCH_PARAM]: uri, }, }, ) diff --git a/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts b/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts index f9ca59c688..584515b4cf 100644 --- a/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts +++ b/src/services/walletconnect/__tests__/useWalletConnectSearchParamUri.test.ts @@ -31,14 +31,6 @@ describe('useWalletConnectSearchParamUri', () => { it('should return the wc uri search param value when present', () => { mockRouter.query = { wc: 'wc:123' } - Object.defineProperty(window, 'location', { - writable: true, - value: { - pathname: window.location.pathname, - search: '?wc=wc:123', - }, - }) - const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri] = result.current @@ -49,14 +41,6 @@ describe('useWalletConnectSearchParamUri', () => { mockRouter.pathname = '/test' mockRouter.query = { test: 'example', wc: 'wc:123' } - Object.defineProperty(window, 'location', { - writable: true, - value: { - pathname: window.location.pathname, - search: '?wc=wc:123&test=example', - }, - }) - const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri, setWcUri] = result.current @@ -77,14 +61,6 @@ describe('useWalletConnectSearchParamUri', () => { mockRouter.pathname = '/test' mockRouter.query = { test: 'example', wc: 'wc:123' } - Object.defineProperty(window, 'location', { - writable: true, - value: { - pathname: window.location.pathname, - search: '?wc=wc:123&test=example', - }, - }) - const { result } = renderHook(() => useWalletConnectSearchParamUri()) const [wcUri, setWcUri] = result.current diff --git a/src/services/walletconnect/useWalletConnectSearchParamUri.ts b/src/services/walletconnect/useWalletConnectSearchParamUri.ts index 555502ca87..41ed350120 100644 --- a/src/services/walletconnect/useWalletConnectSearchParamUri.ts +++ b/src/services/walletconnect/useWalletConnectSearchParamUri.ts @@ -1,20 +1,11 @@ import { useRouter } from 'next/router' -import { parse } from 'querystring' -import { useCallback, useEffect, useState } from 'react' +import { useCallback } from 'react' -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 wcQuery = router.query[WC_URI_SEARCH_PARAM] - const [rawUrlParam, setRawUrlParam] = useState('') - - useEffect(() => { - // Don't use router.query because it cuts off internal paramters of the WC URI (e.g. symKey) - const query = parse(window.location.search.slice(1)) - const wcUri = query[WC_URI_SEARCH_PARAM] || '' - setRawUrlParam(wcUri.toString()) - }, [wcQuery]) + const wcUri = (router.query[WC_URI_SEARCH_PARAM] || '').toString() || null const setWcUri = useCallback( (wcUri: string | null) => { @@ -34,5 +25,5 @@ export function useWalletConnectSearchParamUri(): [string | null, (wcUri: string [router], ) - return [rawUrlParam || null, setWcUri] + return [wcUri, setWcUri] } From 3042f96c5f92b733bfb8ac2f8c41f18879cbf98a Mon Sep 17 00:00:00 2001 From: katspaugh Date: Thu, 9 Nov 2023 11:27:57 +0100 Subject: [PATCH 5/5] Fix: unblock Base and Arbitrum bridges in WC --- src/services/walletconnect/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/walletconnect/constants.ts b/src/services/walletconnect/constants.ts index 435b964832..2206a0069c 100644 --- a/src/services/walletconnect/constants.ts +++ b/src/services/walletconnect/constants.ts @@ -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', @@ -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',