@dynamic-labs/wagmi-connector 1.0.0-alpha.5 → 1.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/package.json +5 -5
- package/src/lib/Connector.d.ts +17 -13
- package/src/lib/Connector.js +13 -4
- package/src/lib/DynamicWagmiConnector.js +11 -5
- package/src/lib/SyncDynamicWagmi.d.ts +3 -2
- package/src/lib/SyncDynamicWagmi.js +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.0.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2023-12-05)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for Turnkey HD wallets and backwards compatiblity for private key wallets ([#4011](https://github.com/dynamic-labs/DynamicAuth/issues/4011)) ([75c5258](https://github.com/dynamic-labs/DynamicAuth/commit/75c5258da494d5d4dfa8b96655303dd9645f2269))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* add close button to wallets list ([#4036](https://github.com/dynamic-labs/DynamicAuth/issues/4036)) ([a2b988b](https://github.com/dynamic-labs/DynamicAuth/commit/a2b988bdfc662af6f85d37a79ed6666c483aa447))
|
|
13
|
+
* add support for embedded wallets in connect-only ([#4041](https://github.com/dynamic-labs/DynamicAuth/issues/4041)) ([ceea635](https://github.com/dynamic-labs/DynamicAuth/commit/ceea635b69e2a0c2636b47fbd30639d69dba7a1c))
|
|
14
|
+
* embedded wallet invalid stored chain breaking network picker ([#4050](https://github.com/dynamic-labs/DynamicAuth/issues/4050)) ([2e2384b](https://github.com/dynamic-labs/DynamicAuth/commit/2e2384ba37407d9164cce47e23f5d5f469f7e062))
|
|
15
|
+
* handle insufficient funds from AA provider ([#4027](https://github.com/dynamic-labs/DynamicAuth/issues/4027)) ([6b9cc88](https://github.com/dynamic-labs/DynamicAuth/commit/6b9cc886f4f2590094bd50aba195c07a5532dfa4))
|
|
16
|
+
* prevent double logout caused by wagmi sync ([#4048](https://github.com/dynamic-labs/DynamicAuth/issues/4048)) ([c66c81c](https://github.com/dynamic-labs/DynamicAuth/commit/c66c81c80839aa9ce1cfae76f4afce12e34f3513))
|
|
17
|
+
* properly detect network switch for secondary wallets ([#4038](https://github.com/dynamic-labs/DynamicAuth/issues/4038)) ([f87174d](https://github.com/dynamic-labs/DynamicAuth/commit/f87174de0892dd057401eaf3c0bc68d974add0fc))
|
|
18
|
+
* **use-wallets-connected-state:** update state on wallet id change ([#4045](https://github.com/dynamic-labs/DynamicAuth/issues/4045)) ([ca3a835](https://github.com/dynamic-labs/DynamicAuth/commit/ca3a8359eae386bffa758ed646ac14af8360a7f8))
|
|
19
|
+
* user should be able to see the full passkey name on management view ([#4043](https://github.com/dynamic-labs/DynamicAuth/issues/4043)) ([7bc1b70](https://github.com/dynamic-labs/DynamicAuth/commit/7bc1b7043cbc9f0e21df78a57efc3e6938a99db2))
|
|
20
|
+
* users should be able to easily find passkey recovery ([#4058](https://github.com/dynamic-labs/DynamicAuth/issues/4058)) ([0202ae9](https://github.com/dynamic-labs/DynamicAuth/commit/0202ae98c96544dec5ac357dc77000996e32ad33))
|
|
21
|
+
|
|
22
|
+
## [1.0.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2023-11-29)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* transaction layout show alert ([#4024](https://github.com/dynamic-labs/DynamicAuth/issues/4024)) ([52057f5](https://github.com/dynamic-labs/DynamicAuth/commit/52057f54ebc32464b2486a2328cb6310caf85208)), closes [#4020](https://github.com/dynamic-labs/DynamicAuth/issues/4020)
|
|
28
|
+
|
|
2
29
|
## [1.0.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2023-11-29)
|
|
3
30
|
|
|
4
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/wagmi-connector",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"react": "^17.0.2 || ^18.0.0",
|
|
12
12
|
"viem": "^1.1.0",
|
|
13
13
|
"wagmi": "^1.2.0",
|
|
14
|
-
"@dynamic-labs/rpc-providers": "1.0.0-alpha.
|
|
15
|
-
"@dynamic-labs/sdk-react-core": "1.0.0-alpha.
|
|
16
|
-
"@dynamic-labs/types": "1.0.0-alpha.
|
|
17
|
-
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.
|
|
14
|
+
"@dynamic-labs/rpc-providers": "1.0.0-alpha.7",
|
|
15
|
+
"@dynamic-labs/sdk-react-core": "1.0.0-alpha.7",
|
|
16
|
+
"@dynamic-labs/types": "1.0.0-alpha.7",
|
|
17
|
+
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.7",
|
|
18
18
|
"eventemitter3": "5.0.1"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
package/src/lib/Connector.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
1
2
|
import { Address, Connector as BaseWagmiConnector, ConnectorData, Chain } from 'wagmi';
|
|
2
3
|
import { Account, Transport, WalletClient } from 'viem';
|
|
3
4
|
import { WalletConnector } from '@dynamic-labs/sdk-react-core';
|
|
@@ -7,10 +8,13 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
7
8
|
id: string;
|
|
8
9
|
name: string;
|
|
9
10
|
ready: boolean;
|
|
10
|
-
|
|
11
|
+
/** See this variable's reason in it's definition in DynamicContext */
|
|
12
|
+
preventWagmiSyncFromCallingLogout: MutableRefObject<boolean>;
|
|
13
|
+
constructor({ chains, handleLogOut, walletConnector, preventWagmiSyncFromCallingLogout, }: {
|
|
11
14
|
chains: Chain[];
|
|
12
15
|
handleLogOut: () => Promise<void>;
|
|
13
16
|
walletConnector: WalletConnector;
|
|
17
|
+
preventWagmiSyncFromCallingLogout: MutableRefObject<boolean>;
|
|
14
18
|
});
|
|
15
19
|
_onAccountsChanged({ accounts }: {
|
|
16
20
|
accounts: string[];
|
|
@@ -49,20 +53,20 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
49
53
|
type: string;
|
|
50
54
|
uid: string;
|
|
51
55
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
52
|
-
deployContract: <const TAbi extends import("viem").Abi | readonly unknown[], TChainOverride extends Chain | undefined>(args: import("viem").DeployContractParameters<TAbi, Chain, Account, TChainOverride>) => Promise<`0x${string}`>;
|
|
56
|
+
deployContract: <const TAbi extends import("viem").Abi | readonly unknown[], TChainOverride extends Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi, Chain, Account, TChainOverride>) => Promise<`0x${string}`>;
|
|
53
57
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
54
58
|
getChainId: () => Promise<number>;
|
|
55
59
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
56
|
-
prepareTransactionRequest: <TChainOverride_1 extends Chain | undefined>(args: import("viem").PrepareTransactionRequestParameters<Chain, Account, TChainOverride_1>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
60
|
+
prepareTransactionRequest: <TChainOverride_1 extends Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<Chain, Account, TChainOverride_1>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
57
61
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
58
62
|
requestPermissions: (args: {
|
|
59
63
|
[x: string]: Record<string, any>;
|
|
60
64
|
eth_accounts: Record<string, any>;
|
|
61
65
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
62
66
|
sendRawTransaction: (args: import("viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
63
|
-
sendTransaction: <TChainOverride_2 extends Chain | undefined>(args: import("viem").SendTransactionParameters<Chain, Account, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
67
|
+
sendTransaction: <TChainOverride_2 extends Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<Chain, Account, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
64
68
|
signMessage: (args: import("viem").SignMessageParameters<Account>) => Promise<`0x${string}`>;
|
|
65
|
-
signTransaction: <TChainOverride_3 extends Chain | undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<Chain, Account, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
69
|
+
signTransaction: <TChainOverride_3 extends Chain | undefined = undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<Chain, Account, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
66
70
|
signTypedData: <const TTypedData extends {
|
|
67
71
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
68
72
|
[x: `string[${string}]`]: undefined;
|
|
@@ -273,7 +277,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
273
277
|
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, Account>) => Promise<`0x${string}`>;
|
|
274
278
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
275
279
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
276
|
-
writeContract: <const TAbi_1 extends import("viem").Abi | readonly unknown[], TFunctionName extends string, TChainOverride_4 extends Chain | undefined>(args: import("viem").WriteContractParameters<TAbi_1, TFunctionName, Chain, Account, TChainOverride_4>) => Promise<`0x${string}`>;
|
|
280
|
+
writeContract: <const TAbi_1 extends import("viem").Abi | readonly unknown[], TFunctionName extends string, TChainOverride_4 extends Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_1, TFunctionName, Chain, Account, TChainOverride_4>) => Promise<`0x${string}`>;
|
|
277
281
|
extend: <const client extends {
|
|
278
282
|
[x: string]: unknown;
|
|
279
283
|
account?: undefined;
|
|
@@ -287,7 +291,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
287
291
|
transport?: undefined;
|
|
288
292
|
type?: undefined;
|
|
289
293
|
uid?: undefined;
|
|
290
|
-
}>(fn: (client: import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, import("viem").WalletActions<Chain, Account>>) => client) => import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<Chain, Account>>;
|
|
294
|
+
} & Partial<Pick<import("viem").PublicActions, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, import("viem").WalletActions<Chain, Account>>) => client) => import("viem").Client<Transport, Chain, Account, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<Chain, Account>>;
|
|
291
295
|
} | {
|
|
292
296
|
account: {
|
|
293
297
|
address: `0x${string}`;
|
|
@@ -309,14 +313,14 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
309
313
|
type: string;
|
|
310
314
|
uid: string;
|
|
311
315
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
312
|
-
deployContract: <const TAbi_2 extends import("viem").Abi | readonly unknown[], TChainOverride_5 extends Chain | undefined>(args: import("viem").DeployContractParameters<TAbi_2, Chain, {
|
|
316
|
+
deployContract: <const TAbi_2 extends import("viem").Abi | readonly unknown[], TChainOverride_5 extends Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi_2, Chain, {
|
|
313
317
|
address: `0x${string}`;
|
|
314
318
|
type: "json-rpc";
|
|
315
319
|
}, TChainOverride_5>) => Promise<`0x${string}`>;
|
|
316
320
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
317
321
|
getChainId: () => Promise<number>;
|
|
318
322
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
319
|
-
prepareTransactionRequest: <TChainOverride_6 extends Chain | undefined>(args: import("viem").PrepareTransactionRequestParameters<Chain, {
|
|
323
|
+
prepareTransactionRequest: <TChainOverride_6 extends Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<Chain, {
|
|
320
324
|
address: `0x${string}`;
|
|
321
325
|
type: "json-rpc";
|
|
322
326
|
}, TChainOverride_6>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
@@ -326,7 +330,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
326
330
|
eth_accounts: Record<string, any>;
|
|
327
331
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
328
332
|
sendRawTransaction: (args: import("viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
329
|
-
sendTransaction: <TChainOverride_7 extends Chain | undefined>(args: import("viem").SendTransactionParameters<Chain, {
|
|
333
|
+
sendTransaction: <TChainOverride_7 extends Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<Chain, {
|
|
330
334
|
address: `0x${string}`;
|
|
331
335
|
type: "json-rpc";
|
|
332
336
|
}, TChainOverride_7>) => Promise<`0x${string}`>;
|
|
@@ -334,7 +338,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
334
338
|
address: `0x${string}`;
|
|
335
339
|
type: "json-rpc";
|
|
336
340
|
}>) => Promise<`0x${string}`>;
|
|
337
|
-
signTransaction: <TChainOverride_8 extends Chain | undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<Chain, {
|
|
341
|
+
signTransaction: <TChainOverride_8 extends Chain | undefined = undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<Chain, {
|
|
338
342
|
address: `0x${string}`;
|
|
339
343
|
type: "json-rpc";
|
|
340
344
|
}, TChainOverride_8>) => Promise<`0x${string}`>;
|
|
@@ -551,7 +555,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
551
555
|
}>) => Promise<`0x${string}`>;
|
|
552
556
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
553
557
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
554
|
-
writeContract: <const TAbi_3 extends import("viem").Abi | readonly unknown[], TFunctionName_1 extends string, TChainOverride_9 extends Chain | undefined>(args: import("viem").WriteContractParameters<TAbi_3, TFunctionName_1, Chain, {
|
|
558
|
+
writeContract: <const TAbi_3 extends import("viem").Abi | readonly unknown[], TFunctionName_1 extends string, TChainOverride_9 extends Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_3, TFunctionName_1, Chain, {
|
|
555
559
|
address: `0x${string}`;
|
|
556
560
|
type: "json-rpc";
|
|
557
561
|
}, TChainOverride_9>) => Promise<`0x${string}`>;
|
|
@@ -568,7 +572,7 @@ export declare class Connector extends BaseWagmiConnector<WalletClient<Transport
|
|
|
568
572
|
transport?: undefined;
|
|
569
573
|
type?: undefined;
|
|
570
574
|
uid?: undefined;
|
|
571
|
-
}>(fn: (client: import("viem").Client<import("viem").CustomTransport, Chain, {
|
|
575
|
+
} & Partial<Pick<import("viem").PublicActions, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, Chain, {
|
|
572
576
|
address: `0x${string}`;
|
|
573
577
|
type: "json-rpc";
|
|
574
578
|
}, import("viem").WalletRpcSchema, import("viem").WalletActions<Chain, {
|
package/src/lib/Connector.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Connector as Connector$1 } from 'wagmi';
|
|
|
3
3
|
import { getAddress, createWalletClient, custom, toHex } from 'viem';
|
|
4
4
|
|
|
5
5
|
class Connector extends Connector$1 {
|
|
6
|
-
constructor({ chains, handleLogOut, walletConnector, }) {
|
|
6
|
+
constructor({ chains, handleLogOut, walletConnector, preventWagmiSyncFromCallingLogout, }) {
|
|
7
7
|
super({ chains, options: undefined });
|
|
8
8
|
// wagmi properties
|
|
9
9
|
this.id = 'dynamic';
|
|
@@ -26,6 +26,7 @@ class Connector extends Connector$1 {
|
|
|
26
26
|
this.handleLogOut = handleLogOut;
|
|
27
27
|
this.walletConnector = walletConnector;
|
|
28
28
|
this.id = `dynamic-${walletConnector.key}`;
|
|
29
|
+
this.preventWagmiSyncFromCallingLogout = preventWagmiSyncFromCallingLogout;
|
|
29
30
|
}
|
|
30
31
|
_onAccountsChanged({ accounts }) {
|
|
31
32
|
this.onAccountsChanged(accounts);
|
|
@@ -56,13 +57,21 @@ class Connector extends Connector$1 {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
disconnect() {
|
|
59
|
-
var _a, _b;
|
|
60
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
61
|
this.walletConnector.removeListener('accountChange', this._onAccountsChanged, this);
|
|
62
62
|
this.walletConnector.removeListener('chainChange', this._onChainChanged, this);
|
|
63
63
|
this.walletConnector.removeListener('disconnect', this._onDisconnect, this);
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (!this.preventWagmiSyncFromCallingLogout.current) {
|
|
65
|
+
yield this.walletConnector.endSession();
|
|
66
|
+
yield this.handleLogOut();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* In our own Dynamic Wagmi sync component, we will flip the flag to true before calling disconnect,
|
|
70
|
+
* and here it automatically flips back to false afterwards. This will prevent the Connector from
|
|
71
|
+
* calling handleLogOut when we are the ones calling disconnect, but will preserve the existing behavior
|
|
72
|
+
* for customers who use useDisconnect directly.
|
|
73
|
+
*/
|
|
74
|
+
this.preventWagmiSyncFromCallingLogout.current = false;
|
|
66
75
|
});
|
|
67
76
|
}
|
|
68
77
|
getAccount() {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { useEffect, useMemo } from 'react';
|
|
1
|
+
import React, { useRef, useEffect, useMemo } from 'react';
|
|
2
2
|
import { configureChains, mainnet, createConfig, WagmiConfig } from 'wagmi';
|
|
3
3
|
import { publicProvider } from 'wagmi/providers/public';
|
|
4
4
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
5
5
|
import { Connector } from './Connector.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConnector } from './getConnector.js';
|
|
7
7
|
import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChains.js';
|
|
8
8
|
import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.js';
|
|
9
|
-
import {
|
|
9
|
+
import { SyncDynamicWagmi } from './SyncDynamicWagmi.js';
|
|
10
10
|
|
|
11
11
|
const { publicClient } = configureChains([mainnet], [publicProvider()]);
|
|
12
12
|
const config = createConfig({
|
|
@@ -15,6 +15,11 @@ const config = createConfig({
|
|
|
15
15
|
});
|
|
16
16
|
const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
|
|
17
17
|
const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
|
|
18
|
+
/**
|
|
19
|
+
* This will prevent the wagmi Connector from calling handleLogOut when we are the ones calling disconnect
|
|
20
|
+
* as a result of a handleLogOut call (see SyncDynamicWagmi), but will preserve the existing behavior for customers.
|
|
21
|
+
*/
|
|
22
|
+
const preventWagmiSyncFromCallingLogout = useRef(false);
|
|
18
23
|
/**
|
|
19
24
|
* Linked wallets are only available on connect-and-sign mode and the connected wallets
|
|
20
25
|
* are only available on connect-only mode, the wallet const represents the current available
|
|
@@ -41,8 +46,9 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
|
|
|
41
46
|
const connector = useMemo(() => getConnector(wallets, (wallet) => new Connector({
|
|
42
47
|
chains,
|
|
43
48
|
handleLogOut,
|
|
49
|
+
preventWagmiSyncFromCallingLogout,
|
|
44
50
|
walletConnector: wallet.connector,
|
|
45
|
-
})), [wallets, chains, handleLogOut]);
|
|
51
|
+
})), [wallets, chains, handleLogOut, preventWagmiSyncFromCallingLogout]);
|
|
46
52
|
/**
|
|
47
53
|
* Updating the wagmi config must be done in a useEffect because
|
|
48
54
|
* when setting the public client and connectors, wagmi will fire
|
|
@@ -57,7 +63,7 @@ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, child
|
|
|
57
63
|
}, [connector, publicClient, webSocketPublicClient]);
|
|
58
64
|
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
59
65
|
// which is not compatible when bundling apps using React 17
|
|
60
|
-
return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector, wallets }, children));
|
|
66
|
+
return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector, preventWagmiSyncFromCallingLogout, wallets }, children));
|
|
61
67
|
};
|
|
62
68
|
|
|
63
69
|
export { DynamicWagmiConnector };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { MutableRefObject } from 'react';
|
|
2
2
|
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
3
3
|
import { Connector } from './Connector';
|
|
4
4
|
export type SyncDynamicWagmiProps = React.PropsWithChildren<{
|
|
5
5
|
connector: Connector | undefined;
|
|
6
6
|
wallets: Wallet[];
|
|
7
|
+
preventWagmiSyncFromCallingLogout: MutableRefObject<boolean>;
|
|
7
8
|
}>;
|
|
8
|
-
export declare const SyncDynamicWagmi: ({ children, connector, wallets, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
|
|
9
|
+
export declare const SyncDynamicWagmi: ({ children, connector, wallets, preventWagmiSyncFromCallingLogout, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
|
|
9
10
|
children?: React.ReactNode;
|
|
10
11
|
}>;
|
|
@@ -2,7 +2,7 @@ import React, { useRef, useEffect } from 'react';
|
|
|
2
2
|
import { useConfig, useConnect, useDisconnect } from 'wagmi';
|
|
3
3
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
|
|
5
|
-
const SyncDynamicWagmi = ({ children, connector, wallets, }) => {
|
|
5
|
+
const SyncDynamicWagmi = ({ children, connector, wallets, preventWagmiSyncFromCallingLogout, }) => {
|
|
6
6
|
const { status: clientStatus } = useConfig();
|
|
7
7
|
const { connect } = useConnect();
|
|
8
8
|
const { disconnect } = useDisconnect();
|
|
@@ -21,6 +21,11 @@ const SyncDynamicWagmi = ({ children, connector, wallets, }) => {
|
|
|
21
21
|
* layouts
|
|
22
22
|
*/
|
|
23
23
|
if (isConnected) {
|
|
24
|
+
/**
|
|
25
|
+
* This will prevent the Connector from calling handleLogOut when we are the ones calling disconnect,
|
|
26
|
+
* but will preserve the existing behavior for customers who use useDisconnect directly.
|
|
27
|
+
*/
|
|
28
|
+
preventWagmiSyncFromCallingLogout.current = true;
|
|
24
29
|
disconnect();
|
|
25
30
|
lastConnectedConnectorId.current = undefined;
|
|
26
31
|
}
|
|
@@ -42,6 +47,7 @@ const SyncDynamicWagmi = ({ children, connector, wallets, }) => {
|
|
|
42
47
|
connector,
|
|
43
48
|
disconnect,
|
|
44
49
|
lastConnectedConnectorId,
|
|
50
|
+
preventWagmiSyncFromCallingLogout,
|
|
45
51
|
walletConnector,
|
|
46
52
|
wallets,
|
|
47
53
|
]);
|