Skip to content

Commit d36c97e

Browse files
authored
Merge pull request #44 from davisshaver/chore-update-rainbowkit-wagmi
⬆️ Update RainbowKit and WAGMI
2 parents bc0ccf7 + b1ae100 commit d36c97e

File tree

4 files changed

+748
-740
lines changed

4 files changed

+748
-740
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
"url": "https://github.com/davisshaver/wp-rainbow/issues"
2222
},
2323
"dependencies": {
24-
"@rainbow-me/rainbowkit": "^0.1.0",
25-
"@wordpress/block-editor": "^8.6.0",
26-
"@wordpress/blocks": "^11.6.0",
27-
"@wordpress/components": "^19.9.0",
28-
"@wordpress/i18n": "^4.7.0",
24+
"@rainbow-me/rainbowkit": "^0.2.4",
25+
"@wordpress/block-editor": "^9.2.0",
26+
"@wordpress/blocks": "^11.9.0",
27+
"@wordpress/components": "^19.12.0",
28+
"@wordpress/i18n": "^4.10.0",
2929
"classnames": "^2.3.1",
30-
"ethers": "^5.6.4",
30+
"ethers": "^5.6.8",
3131
"process": "^0.11.10",
3232
"prop-types": "^15.8.1",
3333
"react-style-proptype": "^3.2.2",
3434
"siwe": "^1.1.6",
3535
"util": "^0.12.4",
36-
"wagmi": "^0.3.2"
36+
"wagmi": "^0.4.11"
3737
},
3838
"devDependencies": {
3939
"@wordpress/scripts": "^22.5.0",

src/connect.jsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { ConnectButton } from '@rainbow-me/rainbowkit';
22
import { __ } from '@wordpress/i18n';
3-
import { useAccount, useEnsName, useNetwork, useSignMessage } from 'wagmi';
3+
import {
4+
useAccount,
5+
useConnect,
6+
useDisconnect,
7+
useEnsName,
8+
useNetwork,
9+
useSignMessage,
10+
} from 'wagmi';
411
import stylePropType from 'react-style-proptype';
512
import { SiweMessage } from 'siwe';
613
import PropTypes from 'prop-types';
@@ -56,6 +63,8 @@ export function WPRainbowConnect( {
5663
const { data: ensName, isSuccess: isENSSuccess } = useEnsName( {
5764
address: accountData?.address,
5865
} );
66+
const { activeConnector } = useConnect();
67+
const { disconnectAsync } = useDisconnect();
5968

6069
const signIn = React.useCallback( async () => {
6170
try {
@@ -67,7 +76,7 @@ export function WPRainbowConnect( {
6776
setState( ( x ) => ( { ...x, address, loading: false } ) );
6877
return;
6978
}
70-
if ( window.signingIn.length > 1 ) {
79+
if ( window?.signingIn.length > 1 ) {
7180
return;
7281
}
7382
setState( ( x ) => ( { ...x, error: undefined, loading: true } ) );
@@ -124,7 +133,12 @@ export function WPRainbowConnect( {
124133

125134
const [ triggeredLogin, setTriggeredLogin ] = React.useState( false );
126135
React.useEffect( () => {
127-
if ( accountData && isENSSuccess && ! triggeredLogin ) {
136+
if (
137+
activeConnector &&
138+
accountData &&
139+
isENSSuccess &&
140+
! triggeredLogin
141+
) {
128142
window.signingIn = ! window.signingIn
129143
? [ true ]
130144
: [ true, ...window.signingIn ];
@@ -165,7 +179,7 @@ export function WPRainbowConnect( {
165179
) }
166180
</div>
167181
);
168-
} else if ( account ) {
182+
} else if ( activeConnector && account ) {
169183
let loginButtonText = __( 'Continue Log In with Ethereum' );
170184
if ( state.address ) {
171185
loginButtonText = `${ __( 'Logged In as ' ) } ${
@@ -204,7 +218,9 @@ export function WPRainbowConnect( {
204218
// Make sure we don't have an active signing attempt.
205219
setState( {} );
206220
setTriggeredLogin( false );
207-
openConnectModal();
221+
// This is a little weird, but since RainbowKit autoconnects,
222+
// we need to make sure we're disconnected before logging in.
223+
disconnectAsync().then( openConnectModal );
208224
};
209225
button = (
210226
<div

src/provider.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
apiProvider,
3-
configureChains,
4-
getDefaultWallets,
5-
RainbowKitProvider,
6-
} from '@rainbow-me/rainbowkit';
7-
import { chain, createClient, WagmiProvider } from 'wagmi';
1+
import { getDefaultWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit';
2+
import { chain, createClient, configureChains, WagmiConfig } from 'wagmi';
3+
import { infuraProvider } from 'wagmi/providers/infura';
84
import stylePropType from 'react-style-proptype';
95

106
import PropTypes from 'prop-types';
@@ -14,7 +10,7 @@ const { INFURA_ID, LOGGED_IN, SITE_TITLE } = wpRainbowData;
1410

1511
const { chains, provider } = configureChains(
1612
[ chain.mainnet ],
17-
[ apiProvider.infura( INFURA_ID ), apiProvider.fallback() ]
13+
[ infuraProvider( { infuraId: INFURA_ID } ) ]
1814
);
1915

2016
const { connectors } = getDefaultWallets( {
@@ -64,7 +60,7 @@ function WPRainbow( {
6460
style,
6561
} ) {
6662
return (
67-
<WagmiProvider client={ wagmiClient }>
63+
<WagmiConfig client={ wagmiClient }>
6864
<RainbowKitProvider chains={ chains }>
6965
<WPRainbowConnect
7066
buttonClassName={ buttonClassName }
@@ -83,7 +79,7 @@ function WPRainbow( {
8379
style={ style }
8480
/>
8581
</RainbowKitProvider>
86-
</WagmiProvider>
82+
</WagmiConfig>
8783
);
8884
}
8985

0 commit comments

Comments
 (0)