Skip to content

Commit 1243346

Browse files
author
dschlabach
committed
Merge branch 'dms/playground-wallet-refactor' into dms/linking
2 parents 3e0dcb9 + d9c2747 commit 1243346

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

playground/nextjs-app-router/components/form/wallet-type.tsx

+21-17
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export enum WalletPreference {
1010
EOA = 'eoaOnly',
1111
}
1212

13-
function getConnector(
13+
const getConnector = (
1414
walletType: WalletPreference,
1515
connectors: GetConnectorsReturnType,
16-
) {
16+
) => {
1717
if (walletType === WalletPreference.SMART_WALLET) {
1818
return connectors[0];
1919
}
2020
return connectors[1];
21-
}
21+
};
2222

2323
export function WalletType() {
2424
const { disconnectAsync } = useDisconnect();
@@ -28,21 +28,30 @@ export function WalletType() {
2828

2929
const [walletType, setWalletType] = useState<WalletPreference>();
3030

31-
// Set localStorage ONLY when user has connected
32-
// otherwise, could result in walletType being set to smart wallet when user intended to connect eoa wallet
33-
useEffect(() => {
34-
if (walletType && account.address) {
35-
localStorage.setItem('walletType', walletType);
36-
}
37-
}, [walletType, account.address]);
38-
3931
useEffect(() => {
4032
const storedWalletType = localStorage.getItem('walletType');
4133
if (storedWalletType) {
4234
setWalletType(storedWalletType as WalletPreference);
4335
}
4436
}, []);
4537

38+
async function handleConnect(value: WalletPreference) {
39+
console.log('value:', value);
40+
setWalletType(value);
41+
connect(
42+
{
43+
connector: getConnector(value as WalletPreference, connectors),
44+
},
45+
{
46+
// Set localStorage ONLY when user has connected
47+
// otherwise, could result in walletType being set to smart wallet when user intended to connect eoa wallet
48+
onSuccess: () => {
49+
localStorage.setItem('walletType', value);
50+
},
51+
},
52+
);
53+
}
54+
4655
async function clearWalletType() {
4756
localStorage.removeItem('walletType');
4857
setWalletType(undefined);
@@ -61,12 +70,7 @@ export function WalletType() {
6170
id="wallet-type"
6271
value={walletType}
6372
className="flex items-center justify-between"
64-
onValueChange={(value) => {
65-
setWalletType(value as WalletPreference);
66-
connect({
67-
connector: getConnector(value as WalletPreference, connectors),
68-
});
69-
}}
73+
onValueChange={handleConnect}
7074
>
7175
<div className="flex items-center gap-2">
7276
<Label

0 commit comments

Comments
 (0)