Skip to content

Commit f34a14c

Browse files
author
ignaciosantise
committed
feat: migrated walletconnect connector to wagmi v2
1 parent 6d14d9c commit f34a14c

File tree

20 files changed

+1394
-1509
lines changed

20 files changed

+1394
-1509
lines changed

apps/native-cli/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"react-native-get-random-values": "~1.9.0",
2222
"react-native-modal": "13.0.1",
2323
"react-native-svg": "13.9.0",
24-
"viem": "1.19.3",
25-
"wagmi": "1.4.7"
24+
"viem": "2.11.1",
25+
"wagmi": "2.9.3"
2626
},
2727
"devDependencies": {
2828
"@babel/core": "^7.20.0",

apps/native/App.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { StyleSheet, View, useColorScheme } from 'react-native';
22
import { StatusBar } from 'expo-status-bar';
33
import * as Clipboard from 'expo-clipboard';
44
import '@walletconnect/react-native-compat';
5-
import { WagmiConfig } from 'wagmi';
5+
6+
import { CreateConfigParameters, WagmiProvider } from 'wagmi';
7+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
68

79
import {
810
Web3Modal,
@@ -11,7 +13,8 @@ import {
1113
createWeb3Modal,
1214
defaultWagmiConfig
1315
} from '@web3modal/wagmi-react-native';
14-
import { EmailConnector } from '@web3modal/email-wagmi-react-native';
16+
17+
// import { EmailConnector } from '@web3modal/email-wagmi-react-native';
1518

1619
import {
1720
arbitrum,
@@ -26,14 +29,14 @@ import {
2629
base,
2730
celo,
2831
aurora
29-
} from 'wagmi/chains';
32+
} from '@wagmi/core/chains';
3033
import { AccountView } from './src/views/AccountView';
3134
import { ActionsView } from './src/views/ActionsView';
3235
import { getCustomWallets } from './src/utils/misc';
3336

3437
const projectId = process.env.EXPO_PUBLIC_PROJECT_ID ?? '';
3538

36-
const chains = [
39+
const chains: CreateConfigParameters['chains'] = [
3740
mainnet,
3841
polygon,
3942
arbitrum,
@@ -49,8 +52,8 @@ const chains = [
4952
];
5053

5154
const metadata = {
52-
name: 'Web3Modal v3',
53-
description: 'Web3Modal v3 by WalletConnect',
55+
name: 'Web3Modal RN',
56+
description: 'Web3Modal RN by WalletConnect',
5457
url: 'https://walletconnect.com/',
5558
icons: ['https://avatars.githubusercontent.com/u/37784886'],
5659
redirect: {
@@ -64,20 +67,21 @@ const clipboardClient = {
6467
}
6568
};
6669

67-
const emailConnector = new EmailConnector({ chains, options: { projectId, metadata } });
70+
// const emailConnector = new EmailConnector({ chains, options: { projectId, metadata } });
6871

6972
const wagmiConfig = defaultWagmiConfig({
7073
chains,
7174
projectId,
72-
metadata,
73-
extraConnectors: [emailConnector]
75+
metadata
76+
// extraConnectors: [emailConnector]
7477
});
7578

79+
const queryClient = new QueryClient();
80+
7681
const customWallets = getCustomWallets();
7782

7883
createWeb3Modal({
7984
projectId,
80-
chains,
8185
wagmiConfig,
8286
clipboardClient,
8387
customWallets,
@@ -89,22 +93,24 @@ export default function Native() {
8993
const isDarkMode = useColorScheme() === 'dark';
9094

9195
return (
92-
<WagmiConfig config={wagmiConfig}>
93-
<View style={[styles.container, isDarkMode && styles.dark]}>
94-
<StatusBar style="auto" />
95-
<W3mButton
96-
connectStyle={styles.button}
97-
accountStyle={styles.button}
98-
label="Connect"
99-
loadingLabel="Connecting..."
100-
balance="show"
101-
/>
102-
<W3mNetworkButton />
103-
<AccountView />
104-
<ActionsView />
105-
<Web3Modal />
106-
</View>
107-
</WagmiConfig>
96+
<WagmiProvider config={wagmiConfig}>
97+
<QueryClientProvider client={queryClient}>
98+
<View style={[styles.container, isDarkMode && styles.dark]}>
99+
<StatusBar style="auto" />
100+
<W3mButton
101+
connectStyle={styles.button}
102+
accountStyle={styles.button}
103+
label="Connect"
104+
loadingLabel="Connecting..."
105+
balance="show"
106+
/>
107+
<W3mNetworkButton />
108+
<AccountView />
109+
<ActionsView />
110+
<Web3Modal />
111+
</View>
112+
</QueryClientProvider>
113+
</WagmiProvider>
108114
);
109115
}
110116

apps/native/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"dependencies": {
1818
"@react-native-async-storage/async-storage": "1.21.0",
1919
"@react-native-community/netinfo": "11.1.0",
20+
"@tanstack/react-query": "5.37.1",
2021
"@walletconnect/react-native-compat": "2.10.5",
21-
"@web3modal/email-wagmi-react-native": "1.4.0-email-beta.5",
2222
"@web3modal/wagmi-react-native": "1.4.0-email-beta.5",
2323
"expo": "^50.0.14",
2424
"expo-application": "~5.8.3",
@@ -34,8 +34,8 @@
3434
"react-native-web": "~0.19.6",
3535
"react-native-webview": "13.6.4",
3636
"uuid": "3.4.0",
37-
"viem": "1.19.3",
38-
"wagmi": "1.4.7"
37+
"viem": "2.11.0",
38+
"wagmi": "2.9.2"
3939
},
4040
"devDependencies": {
4141
"@babel/core": "^7.20.0",

apps/native/src/views/ActionsView.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@ import { parseEther } from 'viem';
55

66
export function ActionsView() {
77
const { isConnected } = useAccount();
8-
const { data, isError, isLoading, isSuccess, signMessage } = useSignMessage({
9-
message: 'Hello Web3Modal!'
10-
});
8+
const { data, isError, isPending, isSuccess, signMessage } = useSignMessage();
119

1210
const {
1311
data: sendData,
14-
isLoading: isSending,
12+
isPending: isSending,
1513
isSuccess: isSendSuccess,
1614
sendTransaction
17-
} = useSendTransaction({
18-
to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', //vitalik.etch
19-
value: parseEther('0.01'),
20-
data: '0x'
21-
});
15+
} = useSendTransaction();
2216

2317
return isConnected ? (
2418
<View>
2519
<Text variant="large-600">Wagmi Actions</Text>
26-
<Button disabled={isLoading} onPress={() => signMessage()}>
20+
<Button disabled={isPending} onPress={() => signMessage({ message: 'Hello Web3Modal!' })}>
2721
Sign
2822
</Button>
2923
{isSuccess && <Text>Signature: {data}</Text>}
3024
{isError && <Text>Error signing message</Text>}
31-
<Button disabled={isSending} onPress={() => sendTransaction()}>
25+
<Button
26+
disabled={isSending}
27+
onPress={() =>
28+
sendTransaction({
29+
to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', //vitalik.etch
30+
value: parseEther('0.01'),
31+
data: '0x'
32+
})
33+
}
34+
>
3235
Send
3336
</Button>
3437
{isSending && <Text>Check Wallet</Text>}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
"packages/scaffold-utils",
88
"packages/scaffold",
99
"packages/wagmi",
10-
"packages/coinbase-wagmi",
11-
"packages/email-wagmi",
1210
"packages/email-ethers",
1311
"packages/coinbase-ethers",
1412
"packages/ethers5",
@@ -34,6 +32,7 @@
3432
"@coinbase/wallet-mobile-sdk": "1.0.10",
3533
"@react-native-async-storage/async-storage": "1.18.2",
3634
"@react-native/eslint-config": "0.72.2",
35+
"@tanstack/react-query": "^5.37.1",
3736
"@testing-library/jest-native": "5.4.2",
3837
"@testing-library/react-native": "12.2.0",
3938
"@types/jest": "29.5.7",
@@ -59,8 +58,8 @@
5958
"tsconfig": "*",
6059
"turbo": "1.10.15",
6160
"typescript": "5.2.2",
62-
"viem": "1.19.3",
63-
"wagmi": "1.4.7"
61+
"viem": "2.11.0",
62+
"wagmi": "2.9.2"
6463
},
6564
"packageManager": "yarn@4.0.2"
6665
}

packages/coinbase-wagmi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"peerDependencies": {
4040
"@coinbase/wallet-mobile-sdk": ">=1.0.10",
41-
"wagmi": ">=1 <2"
41+
"wagmi": ">=2"
4242
},
4343
"react-native": "src/index.ts",
4444
"react-native-builder-bob": {

packages/core/src/controllers/AccountController.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { proxy } from 'valtio';
22
import { subscribeKey as subKey } from 'valtio/utils';
3+
34
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
4-
import type { CaipAddress } from '../utils/TypeUtil';
5+
import type { CaipAddress, ConnectedWalletInfo } from '../utils/TypeUtil';
56

67
// -- Types --------------------------------------------- //
78
export interface AccountControllerState {
@@ -13,8 +14,11 @@ export interface AccountControllerState {
1314
profileName?: string;
1415
profileImage?: string;
1516
addressExplorerUrl?: string;
17+
connectedWalletInfo?: ConnectedWalletInfo;
1618
}
1719

20+
type StateKey = keyof AccountControllerState;
21+
1822
// -- State --------------------------------------------- //
1923
const state = proxy<AccountControllerState>({
2024
isConnected: false
@@ -24,8 +28,8 @@ const state = proxy<AccountControllerState>({
2428
export const AccountController = {
2529
state,
2630

27-
subscribeConnection(callback: (value: AccountControllerState['isConnected']) => void) {
28-
return subKey(state, 'isConnected', callback);
31+
subscribeKey<K extends StateKey>(key: K, callback: (value: AccountControllerState[K]) => void) {
32+
return subKey(state, key, callback);
2933
},
3034

3135
setIsConnected(isConnected: AccountControllerState['isConnected']) {
@@ -54,6 +58,10 @@ export const AccountController = {
5458
state.profileImage = profileImage;
5559
},
5660

61+
setConnectedWalletInfo(connectedWalletInfo: AccountControllerState['connectedWalletInfo']) {
62+
state.connectedWalletInfo = connectedWalletInfo;
63+
},
64+
5765
setAddressExplorerUrl(explorerUrl: AccountControllerState['addressExplorerUrl']) {
5866
state.addressExplorerUrl = explorerUrl;
5967
},

packages/core/src/controllers/BlockchainApiController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ const api = new FetchUtil({ baseUrl: 'https://rpc.walletconnect.com' });
1010

1111
// -- Controller ---------------------------------------- //
1212
export const BlockchainApiController = {
13-
fetchIdentity({ caipChainId, address }: BlockchainApiIdentityRequest) {
13+
fetchIdentity({ address }: BlockchainApiIdentityRequest) {
1414
return api.get<BlockchainApiIdentityResponse>({
1515
path: `/v1/identity/${address}`,
1616
params: {
17-
chainId: caipChainId,
1817
projectId: OptionsController.state.projectId
1918
}
2019
});

packages/core/src/utils/TypeUtil.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export interface CaipNetwork {
99
imageUrl?: string;
1010
}
1111

12+
export type ConnectedWalletInfo =
13+
| {
14+
name?: string;
15+
icon?: string;
16+
[key: string]: unknown;
17+
}
18+
| undefined;
19+
1220
export interface LinkingRecord {
1321
redirect: string;
1422
href: string;
@@ -97,7 +105,6 @@ export interface ThemeVariables {
97105

98106
// -- BlockchainApiController Types ---------------------------------------------
99107
export interface BlockchainApiIdentityRequest {
100-
caipChainId: CaipNetworkId;
101108
address: string;
102109
}
103110

packages/ethers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@walletconnect/ethereum-provider": "2.11.1",
41+
"@walletconnect/ethereum-provider": "2.13.0",
4242
"@web3modal/scaffold-react-native": "1.4.0-email-beta.5",
4343
"@web3modal/scaffold-utils-react-native": "1.4.0-email-beta.5"
4444
},

packages/ethers5/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@walletconnect/ethereum-provider": "2.11.1",
41+
"@walletconnect/ethereum-provider": "2.13.0",
4242
"@web3modal/scaffold-react-native": "1.4.0-email-beta.5",
4343
"@web3modal/scaffold-utils-react-native": "1.4.0-email-beta.5"
4444
},

packages/scaffold/src/client.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import type {
1212
ThemeControllerState,
1313
ThemeMode,
1414
ThemeVariables,
15-
Connector
15+
Connector,
16+
ConnectedWalletInfo
1617
} from '@web3modal/core-react-native';
1718
import {
1819
AccountController,
@@ -89,6 +90,14 @@ export class Web3ModalScaffold {
8990
return ThemeController.subscribe(callback);
9091
}
9192

93+
public getWalletInfo() {
94+
return AccountController.state.connectedWalletInfo;
95+
}
96+
97+
public subscribeWalletInfo(callback: (newState: ConnectedWalletInfo) => void) {
98+
return AccountController.subscribeKey('connectedWalletInfo', callback);
99+
}
100+
92101
public getState() {
93102
return { ...PublicStateController.state };
94103
}
@@ -107,7 +116,7 @@ export class Web3ModalScaffold {
107116
public subscribeConnection(
108117
callback: (isConnected: AccountControllerState['isConnected']) => void
109118
) {
110-
return AccountController.subscribeConnection(callback);
119+
return AccountController.subscribeKey('isConnected', callback);
111120
}
112121

113122
public setLoading(loading: ModalControllerState['loading']) {
@@ -190,6 +199,11 @@ export class Web3ModalScaffold {
190199
AccountController.setAddressExplorerUrl(addressExplorerUrl);
191200
};
192201

202+
protected setConnectedWalletInfo: (typeof AccountController)['setConnectedWalletInfo'] =
203+
connectedWalletInfo => {
204+
AccountController.setConnectedWalletInfo(connectedWalletInfo);
205+
};
206+
193207
// -- Private ------------------------------------------------------------------
194208
private initControllers(options: ScaffoldOptions) {
195209
this.initAsyncValues(options);

packages/wagmi/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"react": ">=17",
4848
"react-native": ">=0.68.5",
4949
"react-native-get-random-values": "*",
50-
"viem": ">=1",
51-
"wagmi": ">=1"
50+
"viem": ">=2",
51+
"wagmi": ">=2"
5252
},
5353
"react-native": "src/index.tsx",
5454
"react-native-builder-bob": {

0 commit comments

Comments
 (0)