Skip to content

Commit 869808a

Browse files
authored
Merge pull request #53 from davisshaver/update-to-walletconnect-v2
💥 Update to WalletConnect v2
2 parents 05aa2fe + 01b6b5c commit 869808a

12 files changed

+6183
-5642
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ Thumbs.db
2323
# IDE files
2424
*.code-workspace
2525
.idea
26-
.vscode
26+
.vscode
27+
28+
# Webpack Stats
29+
stats.json

inc/class-wp-rainbow-settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public function action_rest_api_init() {
166166
'goerli',
167167
],
168168
],
169+
'wp_rainbow_field_walletconnect_project_id' => [
170+
'required' => true,
171+
'type' => 'string',
172+
'description' => 'WalletConnect Project ID',
173+
],
169174
'wp_rainbow_field_redirect_url' => [
170175
'required' => true,
171176
'type' => 'string',

inc/class-wp-rainbow.php

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ public function get_infura_id_filtered() {
9292
return apply_filters( 'wp_rainbow_infura_id', $options['wp_rainbow_field_infura_id'] );
9393
}
9494

95+
/**
96+
* Provide filter for WalletConnect Project ID. Defaults to RainbowKit Login global value.
97+
*
98+
* @return mixed|void Filtered WalletConnect Project ID network.
99+
*/
100+
public function get_walletconnect_project_id_filtered() {
101+
$options = get_option( 'wp_rainbow_options', [ 'wp_rainbow_field_walletconnect_project_id' => '' ] );
102+
$default = ! empty( $options['wp_rainbow_field_walletconnect_project_id'] ) ? $options['wp_rainbow_field_walletconnect_project_id'] : 'fd1a095387aaa4bfc4cc1437ec3caac3';
103+
104+
/**
105+
* Filter the WalletConnect Project ID used for WP Rainbow integration.
106+
*
107+
* @param string $default WalletConnect Project ID as set in WP Rainbow options.
108+
*/
109+
return apply_filters( 'wp_rainbow_walletconnect_project_id', $default );
110+
}
111+
95112
/**
96113
* Provide filter for Infura network. Defaults to settings page value.
97114
*
@@ -217,36 +234,38 @@ public function action_init() {
217234
'login-block',
218235
'wpRainbowData',
219236
[
220-
'ADMIN_URL' => get_admin_url(),
221-
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
222-
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
223-
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
224-
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
225-
'SITE_TITLE' => get_bloginfo( 'name' ),
226-
'COOL_MODE' => $this->get_cool_mode_filtered(),
227-
'THEME' => $this->get_theme_filtered(),
228-
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
229-
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
230-
'ATTRIBUTES' => $this->get_frontend_attributes(),
237+
'ADMIN_URL' => get_admin_url(),
238+
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
239+
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
240+
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
241+
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
242+
'SITE_TITLE' => get_bloginfo( 'name' ),
243+
'COOL_MODE' => $this->get_cool_mode_filtered(),
244+
'THEME' => $this->get_theme_filtered(),
245+
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
246+
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
247+
'ATTRIBUTES' => $this->get_frontend_attributes(),
248+
'WALLETCONNECT_PROJECT_ID' => esc_textarea( $this->get_walletconnect_project_id_filtered() ),
231249
]
232250
);
233251
wp_localize_script(
234252
'login-block-frontend',
235253
'wpRainbowData',
236254
[
237-
'ADMIN_URL' => get_admin_url(),
238-
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
239-
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
240-
'LOGGED_IN' => is_user_logged_in(),
241-
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
242-
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
243-
'SITE_TITLE' => get_bloginfo( 'name' ),
244-
'LOGOUT_URL' => wp_logout_url(),
245-
'COOL_MODE' => $this->get_cool_mode_filtered(),
246-
'THEME' => $this->get_theme_filtered(),
247-
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
248-
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
249-
'ATTRIBUTES' => $this->get_frontend_attributes(),
255+
'ADMIN_URL' => get_admin_url(),
256+
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
257+
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
258+
'LOGGED_IN' => is_user_logged_in(),
259+
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
260+
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
261+
'SITE_TITLE' => get_bloginfo( 'name' ),
262+
'LOGOUT_URL' => wp_logout_url(),
263+
'COOL_MODE' => $this->get_cool_mode_filtered(),
264+
'THEME' => $this->get_theme_filtered(),
265+
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
266+
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
267+
'ATTRIBUTES' => $this->get_frontend_attributes(),
268+
'WALLETCONNECT_PROJECT_ID' => esc_textarea( $this->get_walletconnect_project_id_filtered() ),
250269
]
251270
);
252271
}
@@ -333,17 +352,18 @@ public function action_login_enqueue_scripts() {
333352
'wp-rainbow-login',
334353
'wpRainbowData',
335354
[
336-
'ADMIN_URL' => get_admin_url(),
337-
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
338-
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
339-
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
340-
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
341-
'SITE_TITLE' => get_bloginfo( 'name' ),
342-
'COOL_MODE' => $this->get_cool_mode_filtered(),
343-
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
344-
'ATTRIBUTES' => $this->get_frontend_attributes(),
345-
'THEME' => $this->get_theme_filtered(),
346-
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
355+
'ADMIN_URL' => get_admin_url(),
356+
'INFURA_ID' => esc_textarea( $this->get_infura_id_filtered() ),
357+
'LOGIN_API' => get_rest_url( null, 'wp-rainbow/v1/login' ),
358+
'NONCE_API' => get_rest_url( null, 'wp-rainbow/v1/nonce' ),
359+
'REDIRECT_URL' => esc_url( $this->get_redirect_url_filtered() ),
360+
'SITE_TITLE' => get_bloginfo( 'name' ),
361+
'COOL_MODE' => $this->get_cool_mode_filtered(),
362+
'NETWORK' => esc_textarea( $this->get_infura_network_filtered() ),
363+
'ATTRIBUTES' => $this->get_frontend_attributes(),
364+
'THEME' => $this->get_theme_filtered(),
365+
'COMPACT_MODAL' => $this->get_compact_modal_filtered(),
366+
'WALLETCONNECT_PROJECT_ID' => esc_textarea( $this->get_walletconnect_project_id_filtered() ),
347367
]
348368
);
349369
}

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wp-rainbow",
3-
"version": "0.3.4",
3+
"version": "0.4.0",
44
"description": "RainbowKit Login (Web3 Integration for Sign-In With Ethereum)",
55
"author": "Davis Shaver",
66
"license": "GPL-2.0-or-later",
@@ -21,29 +21,29 @@
2121
"url": "https://github.com/davisshaver/wp-rainbow/issues"
2222
},
2323
"dependencies": {
24-
"@rainbow-me/rainbowkit": "^0.8.1",
25-
"@wordpress/block-editor": "^11.0.0",
26-
"@wordpress/blocks": "^12.0.0",
27-
"@wordpress/components": "^23.0.0",
28-
"@wordpress/i18n": "^4.23.0",
29-
"@xmtp/xmtp-js": "^7.7.2",
24+
"@rainbow-me/rainbowkit": "^1.0.2",
25+
"@wordpress/block-editor": "^12.3.0",
26+
"@wordpress/blocks": "^12.12.0",
27+
"@wordpress/components": "^25.1.0",
28+
"@wordpress/i18n": "^4.35.0",
3029
"classnames": "^2.3.2",
31-
"ethers": "^5.7.2",
3230
"process": "^0.11.10",
3331
"prop-types": "^15.8.1",
34-
"react-hook-form": "^7.41.1",
32+
"react-hook-form": "^7.44.3",
3533
"react-style-proptype": "^3.2.2",
36-
"siwe": "^1.1.6",
34+
"siwe": "^2.1.4",
3735
"util": "^0.12.5",
38-
"wagmi": "^0.9.5"
36+
"viem": "^1.0.7",
37+
"wagmi": "^1.2.0"
3938
},
4039
"devDependencies": {
41-
"@wordpress/scripts": "^25.0.0",
42-
"css-loader": "^6.7.3",
40+
"@wordpress/scripts": "^26.6.0",
41+
"css-loader": "^6.8.1",
4342
"eslint-config-airbnb": "^19.0.4",
44-
"style-loader": "^3.3.1",
45-
"webpack": "^5.75.0",
46-
"webpack-cli": "^4.10.0"
43+
"style-loader": "^3.3.3",
44+
"webpack": "^5.87.0",
45+
"webpack-bundle-analyzer": "^4.9.0",
46+
"webpack-cli": "^5.1.4"
4747
},
4848
"scripts": {
4949
"build": "wp-scripts build",
@@ -55,6 +55,7 @@
5555
"lint:md-docs": "wp-scripts lint-md-docs",
5656
"lint:pkg-json": "wp-scripts lint-pkg-json",
5757
"packages-update": "wp-scripts packages-update",
58-
"start": "wp-scripts start"
58+
"start": "wp-scripts start",
59+
"analyze": "webpack --json > stats.json && yarn webpack-bundle-analyzer stats.json"
5960
}
6061
}

readme.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ _Want to try it out? [Head here.](https://wp-rainbow.davisshaver.com/wp-login.ph
3232

3333
Using an Infura ID/API key is required to use most features in this plugin, including token-gating and role mapping. You can [sign up for a free account here](https://infura.io/). The free tier is sufficient for most use cases. If you're using this plugin for a production site, you'll want to [sign up for a paid account](https://infura.io/pricing) to avoid rate limiting.
3434

35+
Supplying your own WalletConnect Project ID is also highly recommended. You can [sign up for a free project ID from WallectConnect Cloud](https://cloud.walletconnect.com/).
36+
3537
== Frequently Asked Questions ==
3638

3739
= What filters are included? =
@@ -46,6 +48,8 @@ Find reference implementations of all filters in [example plugin here](https://g
4648

4749
**`wp_rainbow_infura_id`** - Filter Infura ID/API key to override settings value.
4850

51+
**`wp_rainbow_walletconnect_project_id`** - Filter WalletConnect project ID to override settings value.
52+
4953
**`wp_rainbow_infura_network`** - Filter Infura network to override settings value.
5054

5155
**`wp_rainbow_redirect_url`** - Filter login redirect URL.
@@ -66,6 +70,9 @@ Find reference implementations of all filters in [example plugin here](https://g
6670

6771
== Changelog ==
6872

73+
= 0.4.0 =
74+
* Update WAGMI, RainbowKit, and web3 dependencies
75+
6976
= 0.3.4 =
7077
* Use patched version of web3 library to fix BigNumber issue
7178

src/connect.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
useAccount,
55
useDisconnect,
66
useEnsName,
7-
useProvider,
7+
usePublicClient,
88
useNetwork,
99
useSignMessage,
1010
} from 'wagmi';
@@ -66,7 +66,9 @@ export function WPRainbowConnect( {
6666
chainId: 1,
6767
} );
6868

69-
const provider = useProvider( { chainId: 1 } );
69+
const provider = usePublicClient( {
70+
chainId: 1,
71+
} );
7072

7173
const { disconnectAsync } = useDisconnect();
7274

@@ -99,11 +101,11 @@ export function WPRainbowConnect( {
99101
const attributes = {};
100102
if ( ensName ) {
101103
try {
102-
const ensProvider = await provider.getResolver( ensName );
103104
await ATTRIBUTES.forEach( async ( attributeKey ) => {
104-
const attributeValue = await ensProvider.getText(
105-
attributeKey
106-
);
105+
const attributeValue = await provider.getEnsText( {
106+
name: ensName,
107+
key: attributeKey,
108+
} );
107109
attributes[ attributeKey ] = attributeValue;
108110
} );
109111
} catch ( error ) {
@@ -118,6 +120,7 @@ export function WPRainbowConnect( {
118120
setState( ( x ) => ( { ...x, address, loading: false } ) );
119121
return;
120122
}
123+
121124
const verifyRes = await fetch( LOGIN_API, {
122125
method: 'POST',
123126
headers: {

src/login.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { __ } from '@wordpress/i18n';
2+
import { createRoot } from '@wordpress/element';
23
import WPRainbow from './provider';
34
import { addErrorMessage } from './utilities/addErrorMessage';
45

@@ -26,5 +27,6 @@ const LoginPageElement = (
2627
const wpRainbowButton = document.getElementById( 'wp-rainbow-button' );
2728

2829
if ( wpRainbowButton ) {
29-
ReactDOM.render( LoginPageElement, wpRainbowButton );
30+
const root = createRoot( wpRainbowButton );
31+
root.render( LoginPageElement );
3032
}

src/provider.jsx

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import {
2-
getDefaultWallets,
32
RainbowKitProvider,
43
lightTheme,
54
darkTheme,
65
midnightTheme,
6+
connectorsForWallets,
77
} from '@rainbow-me/rainbowkit';
8-
import { createClient, configureChains, WagmiConfig } from 'wagmi';
9-
import * as allChains from 'wagmi/chains';
8+
import {
9+
metaMaskWallet,
10+
rainbowWallet,
11+
walletConnectWallet,
12+
injectedWallet,
13+
coinbaseWallet,
14+
} from '@rainbow-me/rainbowkit/wallets';
15+
import { createConfig, configureChains, WagmiConfig } from 'wagmi';
16+
import {
17+
mainnet,
18+
optimism,
19+
arbitrum,
20+
goerli,
21+
polygon,
22+
optimismGoerli,
23+
baseGoerli,
24+
foundry,
25+
zoraTestnet,
26+
} from 'wagmi/chains';
1027
import { infuraProvider } from 'wagmi/providers/infura';
1128
import stylePropType from 'react-style-proptype';
29+
import { publicProvider } from 'wagmi/providers/public';
1230

1331
import PropTypes from 'prop-types';
1432
import { WPRainbowConnect } from './connect';
@@ -21,30 +39,57 @@ const {
2139
NETWORK,
2240
SITE_TITLE,
2341
THEME,
42+
WALLETCONNECT_PROJECT_ID,
2443
} = wpRainbowData;
2544

2645
const themes = {
2746
lightTheme,
2847
darkTheme,
2948
midnightTheme,
3049
};
31-
const { chains, provider } = configureChains(
50+
51+
const allChains = {
52+
mainnet,
53+
optimism,
54+
arbitrum,
55+
goerli,
56+
polygon,
57+
optimismGoerli,
58+
baseGoerli,
59+
foundry,
60+
zoraTestnet,
61+
};
62+
63+
const { chains, publicClient } = configureChains(
3264
[
3365
...( NETWORK && allChains[ NETWORK ] ? [ allChains[ NETWORK ] ] : [] ),
3466
allChains.mainnet,
3567
],
36-
[ infuraProvider( { infuraId: INFURA_ID } ) ]
68+
[ infuraProvider( { apiKey: INFURA_ID } ), publicProvider() ]
3769
);
3870

39-
const { connectors } = getDefaultWallets( {
40-
appName: SITE_TITLE,
41-
chains,
42-
} );
71+
const wallets = [
72+
{
73+
groupName: 'Popular',
74+
wallets: [
75+
injectedWallet( { chains } ),
76+
rainbowWallet( { chains, projectId: WALLETCONNECT_PROJECT_ID } ),
77+
coinbaseWallet( { appName: SITE_TITLE, chains } ),
78+
metaMaskWallet( { chains, projectId: WALLETCONNECT_PROJECT_ID } ),
79+
walletConnectWallet( {
80+
chains,
81+
projectId: WALLETCONNECT_PROJECT_ID,
82+
} ),
83+
],
84+
},
85+
];
86+
87+
const connectors = connectorsForWallets( wallets );
4388

44-
const wagmiClient = createClient( {
89+
const wagmiConfig = createConfig( {
4590
autoConnect: LOGGED_IN === '1',
4691
connectors,
47-
provider,
92+
publicClient,
4893
} );
4994

5095
/**
@@ -83,7 +128,7 @@ function WPRainbow( {
83128
style,
84129
} ) {
85130
return (
86-
<WagmiConfig client={ wagmiClient }>
131+
<WagmiConfig config={ wagmiConfig }>
87132
<RainbowKitProvider
88133
chains={ chains }
89134
coolMode={ COOL_MODE === 'on' }

0 commit comments

Comments
 (0)