@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.
@@ -1,127 +1,135 @@
1
1
  import { __awaiter } from '../../_virtual/_tslib.js';
2
2
  import { Connector as Connector$1 } from 'wagmi';
3
- import { getAddress, hexValue } from 'ethers/lib/utils.js';
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
- this.setupEventListeners();
30
- }
31
- setupEventListeners() {
32
- this.walletConnector.setupEventListeners({
33
- onAccountChange: this.onAccountsChanged,
34
- onChainChange: this.onChainChanged,
35
- onDisconnect: this.onDisconnect,
36
- });
37
- }
38
- connect(config) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- if (!this.walletConnector) {
41
- throw new Error('WalletConnector is not defined');
42
- }
43
- const account = yield this.getAccount();
44
- this.setupEventListeners();
45
- this.emit('message', { type: 'connecting' });
46
- const web3Provider = yield this.getProvider();
47
- const { provider } = web3Provider;
48
- return {
49
- account,
50
- chain: { id: yield this.getChainId(), unsupported: false },
51
- provider,
52
- };
53
- });
54
- }
55
- disconnect() {
56
- var _a, _b;
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const web3Provider = yield this.getProvider();
59
- const { provider } = web3Provider;
60
- provider.removeListener('accountsChanged', this.onAccountsChanged);
61
- provider.removeListener('chainChanged', this.onChainChanged);
62
- provider.removeListener('disconnect', this.onDisconnect);
63
- yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.endSession());
64
- yield ((_b = this.handleLogOut) === null || _b === void 0 ? void 0 : _b.call(this));
65
- });
66
- }
67
- getAccount() {
68
- var _a;
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const address = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress());
71
- if (!address) {
72
- throw new Error('Not connected');
73
- }
74
- return getAddress(address);
75
- });
76
- }
77
- getChainId() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- if (!this.walletConnector) {
80
- throw new Error('WalletConnector is not defined');
81
- }
82
- const network = yield this.walletConnector.getNetwork();
83
- if (!network) {
84
- throw new Error('Network is not defined');
85
- }
86
- return Number(network);
87
- });
88
- }
89
- getProvider(config) {
90
- var _a;
91
- return __awaiter(this, void 0, void 0, function* () {
92
- return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWeb3Provider();
93
- });
94
- }
95
- getSigner(config) {
96
- var _a;
97
- return __awaiter(this, void 0, void 0, function* () {
98
- return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getSigner();
99
- });
100
- }
101
- isAuthorized() {
102
- var _a, _b;
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const accounts = (_b = (yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()))) !== null && _b !== void 0 ? _b : [];
105
- return accounts.length > 0;
106
- });
107
- }
108
- switchChain(chainId) {
109
- var _a, _b;
110
- return __awaiter(this, void 0, void 0, function* () {
111
- yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.switchNetwork({ networkChainId: chainId }));
112
- const id = hexValue(chainId);
113
- return ((_b = this.chains.find((x) => x.id === chainId)) !== null && _b !== void 0 ? _b : {
114
- id: chainId,
115
- name: `Chain ${id}`,
116
- nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' },
117
- network: `${id}`,
118
- rpcUrls: { default: { http: [''] }, public: { http: [''] } },
119
- });
120
- });
121
- }
122
- watchAsset(asset) {
123
- throw new Error('Method not implemented.');
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-35b6525c").P, import("@wagmi/core/dist/index-35b6525c").W>>>;
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, createClient, WagmiConfig } from 'wagmi';
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 { provider } = configureChains([mainnet], [publicProvider()]);
12
- const client = createClient({
13
- provider,
14
- });
15
- /**
16
- * we create a "default" (static chain and provider) client to use in the WagmiConfig
17
- * until we've loaded the dynamic chains and providers, at which point we update the client
18
- */
19
- let connector = undefined;
20
- const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
21
- var _a;
22
- const { networkConfigurations, handleLogOut, connectedWallets, linkedWallets, authMode, sendWagmiSettings, } = useDynamicContext();
23
- const wallets = authMode === 'connect-only' ? connectedWallets : linkedWallets;
24
- sendWagmiSettings({
25
- dynamicWagmiSettings: customerSuppliedEvmNetworks,
26
- });
27
- 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) => {
28
- network.chainId = parseInt(network.chainId.toString());
29
- return network;
30
- });
31
- const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
32
- const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
33
- const { chains, provider } = configureChains(mappedChains, mappedProviders);
34
- connector = getConnector(wallets, (wallet) => new Connector({
35
- chains,
36
- handleLogOut,
37
- walletConnector: wallet.connector,
38
- }));
39
- client.config = Object.assign(Object.assign({}, client.config), { autoConnect: true, connectors: connector ? [connector] : [], provider: provider });
40
- // use React.createElement to prevent bunding react/jsx-runtime,
41
- // which is not compatible when bundling apps using React 17
42
- return React.createElement(WagmiConfig, { client: client }, React.createElement(SyncDynamicWagmi, { connector }, children));
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 { Connector } from './Connector';
3
- export type SyncDynamicWagmiProps = React.PropsWithChildren<{
4
- connector: Connector | undefined;
5
- }>;
6
- export declare const SyncDynamicWagmi: ({ children, connector, }: SyncDynamicWagmiProps) => React.FunctionComponentElement<{
7
- children?: React.ReactNode;
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 { useClient, useConnect, useDisconnect } from 'wagmi';
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 } = useClient();
7
- const { connect } = useConnect();
8
- const { disconnect } = useDisconnect();
9
- const { internalEvents, walletConnector } = useDynamicContext();
10
- const lastConnectedConnectorId = useRef(undefined);
11
- useEffect(() => {
12
- const events = internalEvents.current;
13
- const handleDisconnect = () => {
14
- lastConnectedConnectorId.current = undefined;
15
- disconnect();
16
- };
17
- events.on('clearPrimaryWallet', handleDisconnect);
18
- return () => {
19
- events.off('clearPrimaryWallet', handleDisconnect);
20
- };
21
- }, [disconnect, internalEvents]);
22
- useEffect(() => {
23
- if (walletConnector &&
24
- connector &&
25
- (connector === null || connector === void 0 ? void 0 : connector.id) !== lastConnectedConnectorId.current) {
26
- lastConnectedConnectorId.current = connector.id;
27
- connect({ connector });
28
- }
29
- }, [
30
- clientStatus,
31
- connect,
32
- connector,
33
- disconnect,
34
- lastConnectedConnectorId,
35
- walletConnector,
36
- ]);
37
- // use React.createElement to prevent bunding react/jsx-runtime,
38
- // which is not compatible when bundling apps using React 17
39
- return React.createElement(React.Fragment, null, children);
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;
@@ -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 'wagmi';
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 'wagmi';
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 { providers } from 'ethers';
2
- import { Chain, ChainProviderFn } from 'wagmi';
3
- import { WagmiEvmNetworks } from './types';
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
- let priority;
9
- let stallTimeout;
10
- if (typeof rpcUrl !== 'string') {
11
- http = rpcUrl.http;
12
- webSocket = rpcUrl.webSocket;
13
- priority = rpcUrl.priority;
14
- stallTimeout = rpcUrl.stallTimeout;
15
- }
16
- else {
17
- http = rpcUrl;
18
- }
19
- return (chain) => {
20
- if (chain.id !== dynamicChain.chainId)
21
- return null;
22
- return jsonRpcProvider({
23
- priority,
24
- rpc: () => ({
25
- http,
26
- webSocket,
27
- }),
28
- stallTimeout,
29
- })(chain);
30
- };
31
- };
32
- const getWagmiProvidersFromDynamicChains = (dynamicChains) => {
33
- const wagmiProviders = [];
34
- dynamicChains.forEach((dynamicChain) => {
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;