Skip to content

Commit 9223328

Browse files
authored
refactor:@reown/walletkit (#710)
* refactor: replaces `@walletconnect/web3wallet` with `@reown/walletkit` * refactor: package name
1 parent 05a010a commit 9223328

32 files changed

+157
-394
lines changed

advanced/wallets/react-wallet-v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@taquito/signer": "^15.1.0",
3434
"@taquito/taquito": "^15.1.0",
3535
"@types/semver": "^7.5.8",
36-
"@walletconnect/web3wallet": "1.15.1",
36+
"@reown/walletkit": "1.0.0",
3737
"@zerodev/ecdsa-validator": "5.3.0",
3838
"@zerodev/presets": "5.3.0",
3939
"@zerodev/sdk": "5.3.1",

advanced/wallets/react-wallet-v2/src/components/Modal.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SessionSendCallsModal from '@/views/SessionSendCallsModal'
1616
import { Modal as NextModal } from '@nextui-org/react'
1717
import { useSnapshot } from 'valtio'
1818
import { useCallback, useMemo } from 'react'
19-
import AuthRequestModal from '@/views/AuthRequestModal'
2019
import LoadingModal from '@/views/LoadingModal'
2120
import SessionAuthenticateModal from '@/views/SessionAuthenticateModal'
2221
import SessionGrantPermissionsModal from '@/views/SessionGrantPermissionsModal'
@@ -62,8 +61,6 @@ export default function Modal() {
6261
return <SessionSignTezosModal />
6362
case 'SessionSignKadenaModal':
6463
return <SessionSignKadenaModal />
65-
case 'AuthRequestModal':
66-
return <AuthRequestModal />
6764
case 'LoadingModal':
6865
return <LoadingModal />
6966
case 'SessionAuthenticateModal':

advanced/wallets/react-wallet-v2/src/components/MultibridgeRequestModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LoaderProps } from '@/components/ModalFooter'
22

33
import RequestMethodCard from '@/components/RequestMethodCard'
44
import { Avatar, Col, Container, Divider, Row, Text } from '@nextui-org/react'
5-
import { web3wallet } from '@/utils/WalletConnectUtil'
5+
import { walletkit } from '@/utils/WalletConnectUtil'
66
import RequestModal from './RequestModal'
77
import ModalStore from '@/store/ModalStore'
88
import { useCallback, useState } from 'react'
@@ -92,7 +92,7 @@ export default function MultibridgeRequestModal({
9292
} ms`
9393
)
9494

95-
await web3wallet.respondSessionRequest({
95+
await walletkit.respondSessionRequest({
9696
topic,
9797
response
9898
})

advanced/wallets/react-wallet-v2/src/hooks/useInitialization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createOrRestoreNearWallet } from '@/utils/NearWalletUtil'
77
import { createOrRestoreMultiversxWallet } from '@/utils/MultiversxWalletUtil'
88
import { createOrRestoreTronWallet } from '@/utils/TronWalletUtil'
99
import { createOrRestoreTezosWallet } from '@/utils/TezosWalletUtil'
10-
import { createWeb3Wallet, web3wallet } from '@/utils/WalletConnectUtil'
10+
import { createWalletKit, walletkit } from '@/utils/WalletConnectUtil'
1111
import { createOrRestoreKadenaWallet } from '@/utils/KadenaWalletUtil'
1212
import { useCallback, useEffect, useRef, useState } from 'react'
1313
import { useSnapshot } from 'valtio'
@@ -42,7 +42,7 @@ export default function useInitialization() {
4242
SettingsStore.setTronAddress(tronAddresses[0])
4343
SettingsStore.setTezosAddress(tezosAddresses[0])
4444
SettingsStore.setKadenaAddress(kadenaAddresses[0])
45-
await createWeb3Wallet(relayerRegionURL)
45+
await createWalletKit(relayerRegionURL)
4646
setInitialized(true)
4747
} catch (err: unknown) {
4848
console.error('Initialization failed', err)
@@ -54,7 +54,7 @@ export default function useInitialization() {
5454
// restart transport if relayer region changes
5555
const onRelayerRegionChange = useCallback(() => {
5656
try {
57-
web3wallet?.core?.relayer.restartTransport(relayerRegionURL)
57+
walletkit?.core?.relayer.restartTransport(relayerRegionURL)
5858
prevRelayerURLValue.current = relayerRegionURL
5959
} catch (err: unknown) {
6060
alert(err)

advanced/wallets/react-wallet-v2/src/hooks/useWalletConnectEventsManager.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Web3WalletTypes } from '@walletconnect/web3wallet'
21
import { COSMOS_SIGNING_METHODS } from '@/data/COSMOSData'
32
import { EIP155_SIGNING_METHODS } from '@/data/EIP155Data'
43
import { EIP5792_METHODS } from '@/data/EIP5792Data'
@@ -8,7 +7,7 @@ import { MULTIVERSX_SIGNING_METHODS } from '@/data/MultiversxData'
87
import { TRON_SIGNING_METHODS } from '@/data/TronData'
98
import ModalStore from '@/store/ModalStore'
109
import SettingsStore from '@/store/SettingsStore'
11-
import { web3wallet } from '@/utils/WalletConnectUtil'
10+
import { walletkit } from '@/utils/WalletConnectUtil'
1211
import { SignClientTypes } from '@walletconnect/types'
1312
import { useCallback, useEffect, useMemo } from 'react'
1413
import { NEAR_SIGNING_METHODS } from '@/data/NEARData'
@@ -35,12 +34,6 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
3534
},
3635
[]
3736
)
38-
/******************************************************************************
39-
* 2. Open Auth modal for confirmation / rejection
40-
*****************************************************************************/
41-
const onAuthRequest = useCallback((request: Web3WalletTypes.AuthRequest) => {
42-
ModalStore.open('AuthRequestModal', { request })
43-
}, [])
4437

4538
/******************************************************************************
4639
* 3. Open request handling modal based on method that was used
@@ -49,7 +42,7 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
4942
async (requestEvent: SignClientTypes.EventArguments['session_request']) => {
5043
const { topic, params, verifyContext, id } = requestEvent
5144
const { request } = params
52-
const requestSession = web3wallet.engine.signClient.session.get(topic)
45+
const requestSession = walletkit.engine.signClient.session.get(topic)
5346
// set the verify context so it can be displayed in the projectInfoCard
5447
SettingsStore.setCurrentRequestVerifyContext(verifyContext)
5548
switch (request.method) {
@@ -72,13 +65,13 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
7265

7366
case EIP5792_METHODS.WALLET_GET_CAPABILITIES:
7467
case EIP5792_METHODS.WALLET_GET_CALLS_STATUS:
75-
return await web3wallet.respondSessionRequest({
68+
return await walletkit.respondSessionRequest({
7669
topic,
7770
response: await approveEIP5792Request(requestEvent)
7871
})
7972

8073
case EIP5792_METHODS.WALLET_SHOW_CALLS_STATUS:
81-
return await web3wallet.respondSessionRequest({
74+
return await walletkit.respondSessionRequest({
8275
topic,
8376
response: formatJsonRpcError(id, "Wallet currently don't show call status.")
8477
})
@@ -91,7 +84,7 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
9184
* if EOA, we can submit call one by one, but need to have a data structure
9285
* to return bundle id, for all the calls,
9386
*/
94-
return await web3wallet.respondSessionRequest({
87+
return await walletkit.respondSessionRequest({
9588
topic,
9689
response: formatJsonRpcError(id, "Wallet currently don't support batch call for EOA")
9790
})
@@ -131,7 +124,7 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
131124
return ModalStore.open('SessionSignMultiversxModal', { requestEvent, requestSession })
132125

133126
case NEAR_SIGNING_METHODS.NEAR_GET_ACCOUNTS:
134-
return web3wallet.respondSessionRequest({
127+
return walletkit.respondSessionRequest({
135128
topic,
136129
response: await approveNearRequest(requestEvent)
137130
})
@@ -166,21 +159,19 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
166159
* Set up WalletConnect event listeners
167160
*****************************************************************************/
168161
useEffect(() => {
169-
if (initialized && web3wallet) {
162+
if (initialized && walletkit) {
170163
//sign
171-
web3wallet.on('session_proposal', onSessionProposal)
172-
web3wallet.on('session_request', onSessionRequest)
173-
// auth
174-
web3wallet.on('auth_request', onAuthRequest)
164+
walletkit.on('session_proposal', onSessionProposal)
165+
walletkit.on('session_request', onSessionRequest)
175166
// TODOs
176-
web3wallet.engine.signClient.events.on('session_ping', data => console.log('ping', data))
177-
web3wallet.on('session_delete', data => {
167+
walletkit.engine.signClient.events.on('session_ping', data => console.log('ping', data))
168+
walletkit.on('session_delete', data => {
178169
console.log('session_delete event received', data)
179170
refreshSessionsList()
180171
})
181-
web3wallet.on('session_authenticate', onSessionAuthenticate)
172+
walletkit.on('session_authenticate', onSessionAuthenticate)
182173
// load sessions on init
183174
refreshSessionsList()
184175
}
185-
}, [initialized, onAuthRequest, onSessionAuthenticate, onSessionProposal, onSessionRequest])
176+
}, [initialized, onSessionAuthenticate, onSessionProposal, onSessionRequest])
186177
}

advanced/wallets/react-wallet-v2/src/lib/NearLib.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'near-api-js'
88
import { AccessKeyView } from 'near-api-js/lib/providers/provider'
99

10-
import { web3wallet } from '@/utils/WalletConnectUtil'
10+
import { walletkit } from '@/utils/WalletConnectUtil'
1111
import { NEAR_TEST_CHAINS, TNearChain } from '@/data/NEARData'
1212
import { Schema, serialize } from 'borsh'
1313

@@ -184,7 +184,7 @@ export class NearWallet {
184184
}
185185

186186
private isAccountsValid(topic: string, accounts: Array<{ accountId: string }>) {
187-
const session = web3wallet.engine.signClient.session.get(topic)
187+
const session = walletkit.engine.signClient.session.get(topic)
188188
const validAccountIds = session.namespaces.near.accounts.map(accountId => {
189189
return accountId.split(':')[2]
190190
})
@@ -243,7 +243,7 @@ export class NearWallet {
243243
}
244244

245245
async getAccounts({ topic }: GetAccountsParams): Promise<Array<Account>> {
246-
const session = web3wallet.engine.signClient.session.get(topic)
246+
const session = walletkit.engine.signClient.session.get(topic)
247247
return Promise.all(
248248
session.namespaces.near.accounts.map(async account => {
249249
const accountId = account.split(':')[2]

advanced/wallets/react-wallet-v2/src/pages/_app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Layout from '@/components/Layout'
66
import Modal from '@/components/Modal'
77
import useInitialization from '@/hooks/useInitialization'
88
import useWalletConnectEventsManager from '@/hooks/useWalletConnectEventsManager'
9-
import { web3wallet } from '@/utils/WalletConnectUtil'
9+
import { walletkit } from '@/utils/WalletConnectUtil'
1010
import { RELAYER_EVENTS } from '@walletconnect/core'
1111
import { AppProps } from 'next/app'
1212
import '../../public/main.css'
@@ -20,11 +20,11 @@ export default function App({ Component, pageProps }: AppProps) {
2020
useWalletConnectEventsManager(initialized)
2121
useEffect(() => {
2222
if (!initialized) return
23-
web3wallet?.core.relayer.on(RELAYER_EVENTS.connect, () => {
23+
walletkit?.core.relayer.on(RELAYER_EVENTS.connect, () => {
2424
styledToast('Network connection is restored!', 'success')
2525
})
2626

27-
web3wallet?.core.relayer.on(RELAYER_EVENTS.disconnect, () => {
27+
walletkit?.core.relayer.on(RELAYER_EVENTS.disconnect, () => {
2828
styledToast('Network connection lost.', 'error')
2929
})
3030
}, [initialized])

advanced/wallets/react-wallet-v2/src/pages/pairings.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import PageHeader from '@/components/PageHeader'
22
import PairingCard from '@/components/PairingCard'
3-
import { web3wallet } from '@/utils/WalletConnectUtil'
3+
import { walletkit } from '@/utils/WalletConnectUtil'
44
import { Text } from '@nextui-org/react'
55
import { getSdkError } from '@walletconnect/utils'
66
import { Fragment, useState } from 'react'
77

88
export default function PairingsPage() {
9-
const [pairings, setPairings] = useState(web3wallet.core.pairing.getPairings())
9+
const [pairings, setPairings] = useState(walletkit.core.pairing.getPairings())
1010

1111
async function onDelete(topic: string) {
12-
await web3wallet.disconnectSession({ topic, reason: getSdkError('USER_DISCONNECTED') })
12+
await walletkit.disconnectSession({ topic, reason: getSdkError('USER_DISCONNECTED') })
1313
const newPairings = pairings.filter(pairing => pairing.topic !== topic)
1414
setPairings(newPairings)
1515
}

advanced/wallets/react-wallet-v2/src/pages/session.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PageHeader from '@/components/PageHeader'
33
import ProjectInfoCard from '@/components/ProjectInfoCard'
44
import SessionChainCard from '@/components/SessionChainCard'
55
import { styledToast } from '@/utils/HelperUtil'
6-
import { web3wallet } from '@/utils/WalletConnectUtil'
6+
import { walletkit } from '@/utils/WalletConnectUtil'
77
import { Button, Col, Divider, Loading, Row, Text } from '@nextui-org/react'
88
import { getSdkError } from '@walletconnect/utils'
99
import { useRouter } from 'next/router'
@@ -29,7 +29,7 @@ export default function SessionPage() {
2929
}, [query])
3030

3131
const session = useMemo(
32-
() => web3wallet.engine.signClient.session.values.find(s => s.topic === topic),
32+
() => walletkit.engine.signClient.session.values.find(s => s.topic === topic),
3333
[topic]
3434
)
3535
const namespaces = useMemo(() => session?.namespaces, [session])
@@ -38,7 +38,7 @@ export default function SessionPage() {
3838
const expiryDate = useMemo(() => new Date(session?.expiry! * 1000), [session])
3939
const getPendingRequests = useCallback(() => {
4040
if (!session) return
41-
const allPending = web3wallet.getPendingSessionRequests()
41+
const allPending = walletkit.getPendingSessionRequests()
4242
const requestsForSession = allPending?.filter(r => r.topic === session.topic)
4343
setPendingRequests(requestsForSession)
4444
}, [session])
@@ -55,7 +55,7 @@ export default function SessionPage() {
5555
const onDeleteSession = useCallback(async () => {
5656
setDeleteLoading(true)
5757
try {
58-
await web3wallet.disconnectSession({ topic, reason: getSdkError('USER_DISCONNECTED') })
58+
await walletkit.disconnectSession({ topic, reason: getSdkError('USER_DISCONNECTED') })
5959
replace('/sessions')
6060
} catch (e) {
6161
styledToast((e as Error).message, 'error')
@@ -65,7 +65,7 @@ export default function SessionPage() {
6565

6666
const onSessionPing = useCallback(async () => {
6767
setPingLoading(true)
68-
await web3wallet.engine.signClient.ping({ topic })
68+
await walletkit.engine.signClient.ping({ topic })
6969
setPingLoading(false)
7070
}, [topic])
7171

@@ -74,7 +74,7 @@ export default function SessionPage() {
7474
try {
7575
const namespace = Object.keys(session?.namespaces!)[0]
7676
const chainId = session?.namespaces[namespace].chains?.[0]
77-
await web3wallet.emitSessionEvent({
77+
await walletkit.emitSessionEvent({
7878
topic,
7979
event: { name: 'chainChanged', data: 'Hello World' },
8080
chainId: chainId! // chainId: 'eip155:1'
@@ -88,11 +88,11 @@ export default function SessionPage() {
8888
const onSessionUpdate = useCallback(async () => {
8989
setUpdateLoading(true)
9090
try {
91-
const session = web3wallet.engine.signClient.session.get(topic)
91+
const session = walletkit.engine.signClient.session.get(topic)
9292
const baseAddress = '0x70012948c348CBF00806A3C79E3c5DAdFaAa347'
9393
const namespaceKeyToUpdate = Object.keys(session?.namespaces)[0]
9494
const namespaceToUpdate = session?.namespaces[namespaceKeyToUpdate]
95-
await web3wallet.updateSession({
95+
await walletkit.updateSession({
9696
topic,
9797
namespaces: {
9898
...session?.namespaces,

advanced/wallets/react-wallet-v2/src/pages/settings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export default function SettingsPage() {
4040
Packages
4141
</Text>
4242
<Row justify="space-between" align="center">
43-
<Text color="$gray400">@walletconnect/web3wallet</Text>
44-
<Text color="$gray400">{packageJSON.dependencies['@walletconnect/web3wallet']}</Text>
43+
<Text color="$gray400">@reown/walletkit</Text>
44+
<Text color="$gray400">{packageJSON.dependencies['@reown/walletkit']}</Text>
4545
</Row>
4646

4747
<Divider y={2} />

advanced/wallets/react-wallet-v2/src/pages/walletconnect.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parseUri } from '@walletconnect/utils'
22
import PageHeader from '@/components/PageHeader'
33
import QrReader from '@/components/QrReader'
4-
import { web3wallet } from '@/utils/WalletConnectUtil'
4+
import { walletkit } from '@/utils/WalletConnectUtil'
55
import { Button, Input, Loading, Text } from '@nextui-org/react'
66
import { Fragment, useEffect, useState } from 'react'
77
import { styledToast } from '@/utils/HelperUtil'
@@ -19,16 +19,16 @@ export default function WalletConnectPage(params: { deepLink?: string }) {
1919
if (pairingTopic === topic) {
2020
styledToast('Pairing expired. Please try again with new Connection URI', 'error')
2121
ModalStore.close()
22-
web3wallet.core.pairing.events.removeListener('pairing_expire', pairingExpiredListener)
22+
walletkit.core.pairing.events.removeListener('pairing_expire', pairingExpiredListener)
2323
}
2424
}
25-
web3wallet.once('session_proposal', () => {
26-
web3wallet.core.pairing.events.removeListener('pairing_expire', pairingExpiredListener)
25+
walletkit.once('session_proposal', () => {
26+
walletkit.core.pairing.events.removeListener('pairing_expire', pairingExpiredListener)
2727
})
2828
try {
2929
setLoading(true)
30-
web3wallet.core.pairing.events.on('pairing_expire', pairingExpiredListener)
31-
await web3wallet.pair({ uri })
30+
walletkit.core.pairing.events.on('pairing_expire', pairingExpiredListener)
31+
await walletkit.pair({ uri })
3232
} catch (error) {
3333
styledToast((error as Error).message, 'error')
3434
ModalStore.close()

advanced/wallets/react-wallet-v2/src/pages/wc.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import WalletConnectPage from './walletconnect'
55
import ModalStore from '@/store/ModalStore'
66
import { useSnapshot } from 'valtio'
77
import SettingsStore from '@/store/SettingsStore'
8-
import { web3wallet } from '@/utils/WalletConnectUtil'
8+
import { walletkit } from '@/utils/WalletConnectUtil'
99

1010
export default function DeepLinkPairingPage() {
1111
const state = useSnapshot(ModalStore.state)
@@ -58,6 +58,6 @@ export default function DeepLinkPairingPage() {
5858
}
5959

6060
export function refreshSessionsList() {
61-
if (!web3wallet) return
62-
SettingsStore.setSessions(Object.values(web3wallet.getActiveSessions()))
61+
if (!walletkit) return
62+
SettingsStore.setSessions(Object.values(walletkit.getActiveSessions()))
6363
}

advanced/wallets/react-wallet-v2/src/store/ModalStore.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SessionTypes, SignClientTypes } from '@walletconnect/types'
2-
import { Web3WalletTypes } from '@walletconnect/web3wallet'
2+
import { WalletKitTypes } from '@reown/walletkit'
33
import { proxy } from 'valtio'
44

55
/**
@@ -9,7 +9,6 @@ interface ModalData {
99
proposal?: SignClientTypes.EventArguments['session_proposal']
1010
requestEvent?: SignClientTypes.EventArguments['session_request']
1111
requestSession?: SessionTypes.Struct
12-
request?: Web3WalletTypes.AuthRequest
1312
loadingMessage?: string
1413
authRequest?: SignClientTypes.EventArguments['session_authenticate']
1514
}
@@ -32,7 +31,6 @@ interface State {
3231
| 'SessionSignTronModal'
3332
| 'SessionSignTezosModal'
3433
| 'SessionSignKadenaModal'
35-
| 'AuthRequestModal'
3634
| 'SessionAuthenticateModal'
3735
| 'LoadingModal'
3836
data?: ModalData

0 commit comments

Comments
 (0)