@dynamic-labs/wagmi-connector 0.19.0-alpha.2 → 0.19.0-alpha.21
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 +293 -0
- package/package.json +7 -9
- package/src/index.d.ts +1 -1
- package/src/lib/Connector.d.ts +46 -39
- package/src/lib/Connector.js +129 -121
- package/src/lib/DynamicWagmiConnector.d.ts +8 -8
- package/src/lib/DynamicWagmiConnector.js +52 -34
- package/src/lib/SyncDynamicWagmi.d.ts +10 -8
- package/src/lib/SyncDynamicWagmi.js +47 -36
- package/src/lib/getConnector.d.ts +3 -3
- package/src/lib/getConnector.js +6 -6
- package/src/lib/getWagmiChainsFromDynamicChains.d.ts +3 -3
- package/src/lib/getWagmiChainsFromDynamicChains.js +4 -4
- package/src/lib/getWagmiProvidersFromDynamicChains.d.ts +3 -4
- package/src/lib/getWagmiProvidersFromDynamicChains.js +31 -37
- package/src/lib/mappers/chain.d.ts +4 -3
- package/src/lib/mappers/chain.js +46 -39
- package/src/lib/types.d.ts +28 -25
- package/src/lib/utils/index.d.ts +1 -1
- package/src/lib/utils/resolveRpcUrlFromEvmNetworks/index.d.ts +1 -1
- package/src/lib/utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.d.ts +2 -2
- package/src/lib/utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.js +6 -6
package/src/lib/Connector.js
CHANGED
|
@@ -1,127 +1,135 @@
|
|
|
1
1
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
2
|
import { Connector as Connector$1 } from 'wagmi';
|
|
3
|
-
import { getAddress,
|
|
3
|
+
import { getAddress, createWalletClient, custom, toHex } from 'viem';
|
|
4
4
|
|
|
5
|
-
class Connector extends Connector$1 {
|
|
6
|
-
constructor({ chains, handleLogOut, walletConnector, }) {
|
|
7
|
-
super({ chains, options: undefined });
|
|
8
|
-
// wagmi properties
|
|
9
|
-
this.id = 'dynamic';
|
|
10
|
-
this.name = 'Dynamic';
|
|
11
|
-
// also a wagmi prop, but is only used for auto-connect
|
|
12
|
-
// which we have implemented ourselves, so this value
|
|
13
|
-
// doesn't matter
|
|
14
|
-
this.ready = false;
|
|
15
|
-
this.onAccountsChanged = (accounts) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
this.emit('change', {
|
|
17
|
-
account: getAddress(accounts[0]),
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
this.onChainChanged = (chain) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
this.emit('change', {
|
|
22
|
-
chain: { id: Number(chain), unsupported: false },
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
this.onDisconnect = () => __awaiter(this, void 0, void 0, function* () { });
|
|
26
|
-
this.handleLogOut = handleLogOut;
|
|
27
|
-
this.walletConnector = walletConnector;
|
|
28
|
-
this.id = `dynamic-${walletConnector.key}`;
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
yield ((
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
5
|
+
class Connector extends Connector$1 {
|
|
6
|
+
constructor({ chains, handleLogOut, walletConnector, }) {
|
|
7
|
+
super({ chains, options: undefined });
|
|
8
|
+
// wagmi properties
|
|
9
|
+
this.id = 'dynamic';
|
|
10
|
+
this.name = 'Dynamic';
|
|
11
|
+
// also a wagmi prop, but is only used for auto-connect
|
|
12
|
+
// which we have implemented ourselves, so this value
|
|
13
|
+
// doesn't matter
|
|
14
|
+
this.ready = false;
|
|
15
|
+
this.onAccountsChanged = (accounts) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
this.emit('change', {
|
|
17
|
+
account: getAddress(accounts[0]),
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
this.onChainChanged = (chain) => __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
this.emit('change', {
|
|
22
|
+
chain: { id: Number(chain), unsupported: false },
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
this.onDisconnect = () => __awaiter(this, void 0, void 0, function* () { });
|
|
26
|
+
this.handleLogOut = handleLogOut;
|
|
27
|
+
this.walletConnector = walletConnector;
|
|
28
|
+
this.id = `dynamic-${walletConnector.key}`;
|
|
29
|
+
}
|
|
30
|
+
_onAccountsChanged({ accounts }) {
|
|
31
|
+
this.onAccountsChanged(accounts);
|
|
32
|
+
}
|
|
33
|
+
_onChainChanged({ chain }) {
|
|
34
|
+
this.onChainChanged(chain);
|
|
35
|
+
}
|
|
36
|
+
_onDisconnect() {
|
|
37
|
+
this.onDisconnect();
|
|
38
|
+
}
|
|
39
|
+
setupEventListeners() {
|
|
40
|
+
this.walletConnector.on('accountChange', this._onAccountsChanged, this);
|
|
41
|
+
this.walletConnector.on('chainChange', this._onChainChanged, this);
|
|
42
|
+
this.walletConnector.on('disconnect', this._onDisconnect, this);
|
|
43
|
+
}
|
|
44
|
+
connect(config) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (!this.walletConnector) {
|
|
47
|
+
throw new Error('WalletConnector is not defined');
|
|
48
|
+
}
|
|
49
|
+
const account = yield this.getAccount();
|
|
50
|
+
this.setupEventListeners();
|
|
51
|
+
this.emit('message', { type: 'connecting' });
|
|
52
|
+
return {
|
|
53
|
+
account,
|
|
54
|
+
chain: { id: yield this.getChainId(), unsupported: false },
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
disconnect() {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
this.walletConnector.removeListener('accountChange', this._onAccountsChanged, this);
|
|
62
|
+
this.walletConnector.removeListener('chainChange', this._onChainChanged, this);
|
|
63
|
+
this.walletConnector.removeListener('disconnect', this._onDisconnect, this);
|
|
64
|
+
yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.endSession());
|
|
65
|
+
yield ((_b = this.handleLogOut) === null || _b === void 0 ? void 0 : _b.call(this));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
getAccount() {
|
|
69
|
+
var _a;
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const address = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress());
|
|
72
|
+
if (!address) {
|
|
73
|
+
throw new Error('Not connected');
|
|
74
|
+
}
|
|
75
|
+
return getAddress(address);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getChainId() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (!this.walletConnector) {
|
|
81
|
+
throw new Error('WalletConnector is not defined');
|
|
82
|
+
}
|
|
83
|
+
const network = yield this.walletConnector.getNetwork();
|
|
84
|
+
if (!network) {
|
|
85
|
+
throw new Error('Network is not defined');
|
|
86
|
+
}
|
|
87
|
+
return Number(network);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getProvider(config) {
|
|
91
|
+
var _a;
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWalletClient();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
getWalletClient(config) {
|
|
97
|
+
var _a;
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const signer = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getSigner());
|
|
100
|
+
if (signer === null || signer === void 0 ? void 0 : signer.account) {
|
|
101
|
+
return signer;
|
|
102
|
+
}
|
|
103
|
+
return createWalletClient({
|
|
104
|
+
account: yield this.getAccount(),
|
|
105
|
+
transport: custom(signer),
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
isAuthorized() {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const accounts = (_b = (yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()))) !== null && _b !== void 0 ? _b : [];
|
|
113
|
+
return accounts.length > 0;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
switchChain(chainId) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.switchNetwork({ networkChainId: chainId }));
|
|
120
|
+
const id = toHex(chainId);
|
|
121
|
+
return ((_b = this.chains.find((x) => x.id === chainId)) !== null && _b !== void 0 ? _b : {
|
|
122
|
+
id: chainId,
|
|
123
|
+
name: `Chain ${id}`,
|
|
124
|
+
nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' },
|
|
125
|
+
network: `${id}`,
|
|
126
|
+
rpcUrls: { default: { http: [''] }, public: { http: [''] } },
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
watchAsset(asset) {
|
|
131
|
+
throw new Error('Method not implemented.');
|
|
132
|
+
}
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
export { Connector };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { WagmiEvmNetworks } from './types';
|
|
3
|
-
type DynamicWagmiConnectorProps = {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
evmNetworks?: WagmiEvmNetworks[];
|
|
6
|
-
};
|
|
7
|
-
export declare const DynamicWagmiConnector: ({ evmNetworks: customerSuppliedEvmNetworks, children, }: DynamicWagmiConnectorProps) => React.FunctionComponentElement<React.PropsWithChildren<import("wagmi").WagmiConfigProps<import("@wagmi/core/dist/index-
|
|
8
|
-
export {};
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { WagmiEvmNetworks } from './types';
|
|
3
|
+
type DynamicWagmiConnectorProps = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
evmNetworks?: WagmiEvmNetworks[];
|
|
6
|
+
};
|
|
7
|
+
export declare const DynamicWagmiConnector: ({ evmNetworks: customerSuppliedEvmNetworks, children, }: DynamicWagmiConnectorProps) => React.FunctionComponentElement<React.PropsWithChildren<import("wagmi").WagmiConfigProps<import("@wagmi/core/dist/index-e744bbc2").P, import("@wagmi/core/dist/index-e744bbc2").W>>>;
|
|
8
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { configureChains, mainnet,
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
|
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';
|
|
@@ -8,38 +8,56 @@ import { getWagmiChainsFromDynamicChains } from './getWagmiChainsFromDynamicChai
|
|
|
8
8
|
import { getWagmiProvidersFromDynamicChains } from './getWagmiProvidersFromDynamicChains.js';
|
|
9
9
|
import { getConnector } from './getConnector.js';
|
|
10
10
|
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const wallets = authMode === 'connect-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
11
|
+
const { publicClient } = configureChains([mainnet], [publicProvider()]);
|
|
12
|
+
const config = createConfig({
|
|
13
|
+
autoConnect: true,
|
|
14
|
+
publicClient,
|
|
15
|
+
});
|
|
16
|
+
const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
|
|
17
|
+
const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
|
|
18
|
+
/**
|
|
19
|
+
* Linked wallets are only available on connect-and-sign mode and the connected wallets
|
|
20
|
+
* are only available on connect-only mode, the wallet const represents the current available
|
|
21
|
+
* wallets to be used when creating an wagmi connector
|
|
22
|
+
*/
|
|
23
|
+
const wallets = authMode === 'connect-and-sign' ? linkedWallets : connectedWallets;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
// only send wagmi settings once, when the first time DynamicWagmiConnector renders
|
|
26
|
+
sendWagmiSettings({
|
|
27
|
+
dynamicWagmiSettings: customerSuppliedEvmNetworks,
|
|
28
|
+
});
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, []);
|
|
31
|
+
const { chains, publicClient, webSocketPublicClient } = useMemo(() => {
|
|
32
|
+
var _a;
|
|
33
|
+
const evmNetworks = ((_a = customerSuppliedEvmNetworks !== null && customerSuppliedEvmNetworks !== void 0 ? customerSuppliedEvmNetworks : networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) !== null && _a !== void 0 ? _a : []).map((network) => {
|
|
34
|
+
network.chainId = parseInt(network.chainId.toString());
|
|
35
|
+
return network;
|
|
36
|
+
});
|
|
37
|
+
const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
|
|
38
|
+
const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
|
|
39
|
+
return configureChains(mappedChains, mappedProviders);
|
|
40
|
+
}, [customerSuppliedEvmNetworks, networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm]);
|
|
41
|
+
const connector = useMemo(() => getConnector(wallets, (wallet) => new Connector({
|
|
42
|
+
chains,
|
|
43
|
+
handleLogOut,
|
|
44
|
+
walletConnector: wallet.connector,
|
|
45
|
+
})), [wallets, chains, handleLogOut]);
|
|
46
|
+
/**
|
|
47
|
+
* Updating the wagmi config must be done in a useEffect because
|
|
48
|
+
* when setting the public client and connectors, wagmi will fire
|
|
49
|
+
* an rerender.
|
|
50
|
+
* Keeping the update in a useEffect will prevent an state update
|
|
51
|
+
* while react is in the middle of rendering.
|
|
52
|
+
*/
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
config.setPublicClient(publicClient);
|
|
55
|
+
config.setWebSocketPublicClient(webSocketPublicClient);
|
|
56
|
+
config.setConnectors(connector ? [connector] : []);
|
|
57
|
+
}, [connector, publicClient, webSocketPublicClient]);
|
|
58
|
+
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
59
|
+
// which is not compatible when bundling apps using React 17
|
|
60
|
+
return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector, wallets }, children));
|
|
43
61
|
};
|
|
44
62
|
|
|
45
63
|
export { DynamicWagmiConnector };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
3
|
+
import { Connector } from './Connector';
|
|
4
|
+
export type SyncDynamicWagmiProps = React.PropsWithChildren<{
|
|
5
|
+
connector: Connector | undefined;
|
|
6
|
+
wallets: Wallet[];
|
|
7
|
+
}>;
|
|
8
|
+
export declare const SyncDynamicWagmi: ({ children, connector, wallets, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}>;
|
|
@@ -1,42 +1,53 @@
|
|
|
1
1
|
import React, { useRef, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useConfig, useConnect, useDisconnect } from 'wagmi';
|
|
3
3
|
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
|
|
4
4
|
|
|
5
|
-
const SyncDynamicWagmi = ({ children, connector, }) => {
|
|
6
|
-
const { status: clientStatus } =
|
|
7
|
-
const { connect } = useConnect();
|
|
8
|
-
const { disconnect } = useDisconnect();
|
|
9
|
-
const {
|
|
10
|
-
const lastConnectedConnectorId = useRef(undefined);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
5
|
+
const SyncDynamicWagmi = ({ children, connector, wallets, }) => {
|
|
6
|
+
const { status: clientStatus } = useConfig();
|
|
7
|
+
const { connect } = useConnect();
|
|
8
|
+
const { disconnect } = useDisconnect();
|
|
9
|
+
const { walletConnector } = useDynamicContext();
|
|
10
|
+
const lastConnectedConnectorId = useRef(undefined);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const isConnected = Boolean(lastConnectedConnectorId.current);
|
|
13
|
+
/**
|
|
14
|
+
* Disconnects from Wagmi when no more wallets are available
|
|
15
|
+
* and returns early to prevent re-connecting to the same connector
|
|
16
|
+
*/
|
|
17
|
+
if (!wallets.length) {
|
|
18
|
+
/**
|
|
19
|
+
* Check if the connector is already disconnected to prevent
|
|
20
|
+
* disconnecting in a page transition on NextJS with multiple
|
|
21
|
+
* layouts
|
|
22
|
+
*/
|
|
23
|
+
if (isConnected) {
|
|
24
|
+
disconnect();
|
|
25
|
+
lastConnectedConnectorId.current = undefined;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Connects to Wagmi when a connector is available and
|
|
31
|
+
* the connector has changed since the last connection
|
|
32
|
+
*/
|
|
33
|
+
if (walletConnector &&
|
|
34
|
+
connector &&
|
|
35
|
+
(connector === null || connector === void 0 ? void 0 : connector.id) !== lastConnectedConnectorId.current) {
|
|
36
|
+
lastConnectedConnectorId.current = connector.id;
|
|
37
|
+
connect({ connector });
|
|
38
|
+
}
|
|
39
|
+
}, [
|
|
40
|
+
clientStatus,
|
|
41
|
+
connect,
|
|
42
|
+
connector,
|
|
43
|
+
disconnect,
|
|
44
|
+
lastConnectedConnectorId,
|
|
45
|
+
walletConnector,
|
|
46
|
+
wallets,
|
|
47
|
+
]);
|
|
48
|
+
// use React.createElement to prevent bunding react/jsx-runtime,
|
|
49
|
+
// which is not compatible when bundling apps using React 17
|
|
50
|
+
return React.createElement(React.Fragment, null, children);
|
|
40
51
|
};
|
|
41
52
|
|
|
42
53
|
export { SyncDynamicWagmi };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
2
|
-
import { Connector } from './Connector';
|
|
3
|
-
export declare const getConnector: (wallets: Wallet[], createConnector: (wallet: Wallet) => Connector) => Connector | undefined;
|
|
1
|
+
import { Wallet } from '@dynamic-labs/sdk-react-core';
|
|
2
|
+
import { Connector } from './Connector';
|
|
3
|
+
export declare const getConnector: (wallets: Wallet[], createConnector: (wallet: Wallet) => Connector) => Connector | undefined;
|
package/src/lib/getConnector.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const getConnector = (wallets, createConnector) => {
|
|
2
|
-
for (const wallet of wallets) {
|
|
3
|
-
if (wallet.connected && wallet.connector.connectedChain === 'EVM') {
|
|
4
|
-
return createConnector(wallet);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
const getConnector = (wallets, createConnector) => {
|
|
2
|
+
for (const wallet of wallets) {
|
|
3
|
+
if (wallet.connected && wallet.connector.connectedChain === 'EVM') {
|
|
4
|
+
return createConnector(wallet);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { getConnector };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Chain } from '
|
|
2
|
-
import { WagmiEvmNetworks } from './types';
|
|
3
|
-
export declare const getWagmiChainsFromDynamicChains: (dynamicChains: WagmiEvmNetworks[]) => Chain[];
|
|
1
|
+
import { Chain } from 'viem/chains';
|
|
2
|
+
import { WagmiEvmNetworks } from './types';
|
|
3
|
+
export declare const getWagmiChainsFromDynamicChains: (dynamicChains: WagmiEvmNetworks[]) => Chain[];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { mainnet } from '
|
|
1
|
+
import { mainnet } from 'viem/chains';
|
|
2
2
|
import { mapDynamicChainToWagmi } from './mappers/chain.js';
|
|
3
3
|
|
|
4
|
-
const getWagmiChainsFromDynamicChains = (dynamicChains) => {
|
|
5
|
-
const mappedChains = dynamicChains.map(mapDynamicChainToWagmi);
|
|
6
|
-
return mappedChains.length > 0 ? mappedChains : [mainnet];
|
|
4
|
+
const getWagmiChainsFromDynamicChains = (dynamicChains) => {
|
|
5
|
+
const mappedChains = dynamicChains.map(mapDynamicChainToWagmi);
|
|
6
|
+
return mappedChains.length > 0 ? mappedChains : [mainnet];
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { getWagmiChainsFromDynamicChains };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare const getWagmiProvidersFromDynamicChains: (dynamicChains: WagmiEvmNetworks[]) => ChainProviderFn<Chain, providers.JsonRpcProvider, providers.WebSocketProvider>[];
|
|
1
|
+
import { Chain, ChainProviderFn } from 'wagmi';
|
|
2
|
+
import { WagmiEvmNetworks } from './types';
|
|
3
|
+
export declare const getWagmiProvidersFromDynamicChains: (dynamicChains: WagmiEvmNetworks[]) => ChainProviderFn<Chain>[];
|
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import { publicProvider } from 'wagmi/providers/public';
|
|
2
2
|
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc';
|
|
3
3
|
|
|
4
|
-
/* eslint-disable prefer-destructuring */
|
|
5
|
-
const getProvider = (dynamicChain, rpcUrl) => {
|
|
6
|
-
let http;
|
|
7
|
-
let webSocket;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var _a;
|
|
36
|
-
((_a = dynamicChain.privateCustomerRpcUrls) !== null && _a !== void 0 ? _a : []).forEach((rpcUrl) => {
|
|
37
|
-
wagmiProviders.push(getProvider(dynamicChain, rpcUrl));
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
return [...wagmiProviders, publicProvider()];
|
|
4
|
+
/* eslint-disable prefer-destructuring */
|
|
5
|
+
const getProvider = (dynamicChain, rpcUrl) => {
|
|
6
|
+
let http;
|
|
7
|
+
let webSocket;
|
|
8
|
+
if (typeof rpcUrl !== 'string') {
|
|
9
|
+
http = rpcUrl.http;
|
|
10
|
+
webSocket = rpcUrl.webSocket;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
http = rpcUrl;
|
|
14
|
+
}
|
|
15
|
+
return (chain) => {
|
|
16
|
+
if (chain.id !== dynamicChain.chainId)
|
|
17
|
+
return null;
|
|
18
|
+
return jsonRpcProvider({
|
|
19
|
+
rpc: () => ({
|
|
20
|
+
http,
|
|
21
|
+
webSocket,
|
|
22
|
+
}),
|
|
23
|
+
})(chain);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const getWagmiProvidersFromDynamicChains = (dynamicChains) => {
|
|
27
|
+
const wagmiProviders = [];
|
|
28
|
+
dynamicChains.forEach((dynamicChain) => {
|
|
29
|
+
var _a;
|
|
30
|
+
((_a = dynamicChain.privateCustomerRpcUrls) !== null && _a !== void 0 ? _a : []).forEach((rpcUrl) => {
|
|
31
|
+
wagmiProviders.push(getProvider(dynamicChain, rpcUrl));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
return [...wagmiProviders, publicProvider()];
|
|
41
35
|
};
|
|
42
36
|
|
|
43
37
|
export { getWagmiProvidersFromDynamicChains };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { Chain } from 'wagmi';
|
|
2
|
-
import { WagmiEvmNetworks } from '../types';
|
|
3
|
-
export declare const mapDynamicChainToWagmi: (dynamicChain: WagmiEvmNetworks) => Chain;
|
|
1
|
+
import { Chain } from 'wagmi';
|
|
2
|
+
import { WagmiEvmNetworks } from '../types';
|
|
3
|
+
export declare const mapDynamicChainToWagmi: (dynamicChain: WagmiEvmNetworks) => Chain;
|
|
4
|
+
export declare const overrideWagmiChainWithDynamicSettings: (wagmiChain: Chain, dynamicChain: WagmiEvmNetworks) => Chain;
|