@dynamic-labs/wagmi-connector 0.18.0 → 0.18.100-viem.1

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +0 -24
  2. package/package.json +7 -7
  3. package/src/index.d.ts +1 -1
  4. package/src/lib/Connector.d.ts +39 -39
  5. package/src/lib/Connector.js +118 -121
  6. package/src/lib/DynamicWagmiConnector.d.ts +8 -8
  7. package/src/lib/DynamicWagmiConnector.js +38 -33
  8. package/src/lib/SyncDynamicWagmi.d.ts +8 -8
  9. package/src/lib/SyncDynamicWagmi.js +25 -25
  10. package/src/lib/getConnector.d.ts +3 -3
  11. package/src/lib/getConnector.js +6 -6
  12. package/src/lib/getWagmiChainsFromDynamicChains.d.ts +3 -3
  13. package/src/lib/getWagmiChainsFromDynamicChains.js +4 -4
  14. package/src/lib/getWagmiProvidersFromDynamicChains.d.ts +3 -4
  15. package/src/lib/getWagmiProvidersFromDynamicChains.js +31 -37
  16. package/src/lib/hooks/index.d.ts +2 -2
  17. package/src/lib/hooks/useSyncConnectState/index.d.ts +1 -1
  18. package/src/lib/hooks/useSyncConnectState/usePrevious.d.ts +19 -19
  19. package/src/lib/hooks/useSyncConnectState/usePrevious.js +24 -24
  20. package/src/lib/hooks/useSyncConnectState/useSyncConnectState.d.ts +11 -11
  21. package/src/lib/hooks/useSyncConnectState/useSyncConnectState.js +21 -21
  22. package/src/lib/hooks/useWalletConnectorEverPresent/index.d.ts +1 -1
  23. package/src/lib/hooks/useWalletConnectorEverPresent/useWalletConnectorEverPresent.d.ts +2 -2
  24. package/src/lib/hooks/useWalletConnectorEverPresent/useWalletConnectorEverPresent.js +8 -8
  25. package/src/lib/mappers/chain.d.ts +3 -3
  26. package/src/lib/mappers/chain.js +38 -38
  27. package/src/lib/types.d.ts +25 -25
  28. package/src/lib/utils/index.d.ts +1 -1
  29. package/src/lib/utils/resolveRpcUrlFromEvmNetworks/index.d.ts +1 -1
  30. package/src/lib/utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.d.ts +2 -2
  31. package/src/lib/utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.js +6 -6
package/CHANGELOG.md CHANGED
@@ -1,28 +1,4 @@
1
1
 
2
- ## [0.18.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.32...v0.18.0) (2023-08-13)
3
-
4
-
5
- ### Features
6
-
7
- * add in OKX wallet integration ([#2871](https://github.com/dynamic-labs/DynamicAuth/issues/2871)) ([#2927](https://github.com/dynamic-labs/DynamicAuth/issues/2927)) ([f6d06bc](https://github.com/dynamic-labs/DynamicAuth/commit/f6d06bc75ee0e53c9d972f5fab1f4de11818bd82))
8
- * update wallet locked view ([#2923](https://github.com/dynamic-labs/DynamicAuth/issues/2923)) ([3cc03ee](https://github.com/dynamic-labs/DynamicAuth/commit/3cc03ee5913434d99386fc89d4d26d5d3fb3ca19))
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * account already exist message not displaying automatically ([#2896](https://github.com/dynamic-labs/DynamicAuth/issues/2896)) ([#2906](https://github.com/dynamic-labs/DynamicAuth/issues/2906)) ([5e7478a](https://github.com/dynamic-labs/DynamicAuth/commit/5e7478acd864451a7cf7e8e62845cca7ef5439c6))
14
- * don't let user update email if it's tied to an embedded wallet ([#2903](https://github.com/dynamic-labs/DynamicAuth/issues/2903)) ([33c52b5](https://github.com/dynamic-labs/DynamicAuth/commit/33c52b50a880a34b4161a700b8b1805c9b01527d)), closes [#2883](https://github.com/dynamic-labs/DynamicAuth/issues/2883)
15
- * **GVTY-195:** issues with mergeUserAccountsView ([#2945](https://github.com/dynamic-labs/DynamicAuth/issues/2945)) ([2c6265e](https://github.com/dynamic-labs/DynamicAuth/commit/2c6265e3e709edb9ff1af6e6c139b85418e46d76))
16
- * **Magic:** improve gas estimate for transactions ([#2947](https://github.com/dynamic-labs/DynamicAuth/issues/2947)) ([ad35a72](https://github.com/dynamic-labs/DynamicAuth/commit/ad35a722df6abd54b98ea491661ff4ec3e602621))
17
- * missing enable isVerificationInProgress ([#2926](https://github.com/dynamic-labs/DynamicAuth/issues/2926)) ([98f54fd](https://github.com/dynamic-labs/DynamicAuth/commit/98f54fd1345713dfaf0ef837502dfaca3709d633))
18
- * **networks:** merge custom network after API networks ([#2949](https://github.com/dynamic-labs/DynamicAuth/issues/2949)) ([ab22303](https://github.com/dynamic-labs/DynamicAuth/commit/ab22303294123c2a914a65f0d2c15481740647bb))
19
- * onBeforeConnectSuccessConfirmation is being called multiple time ([#2965](https://github.com/dynamic-labs/DynamicAuth/issues/2965)) ([a276968](https://github.com/dynamic-labs/DynamicAuth/commit/a2769689bc82350dfb8123e1fe8a4e92a60b262c))
20
- * **QNTM-249:** broken email update when user is authenticated ([#2932](https://github.com/dynamic-labs/DynamicAuth/issues/2932)) ([db33ba1](https://github.com/dynamic-labs/DynamicAuth/commit/db33ba14c317469958ce314a3822b706e20b07d0))
21
- * reformat social sign-in text ([#2956](https://github.com/dynamic-labs/DynamicAuth/issues/2956)) ([#2961](https://github.com/dynamic-labs/DynamicAuth/issues/2961)) ([f8d2222](https://github.com/dynamic-labs/DynamicAuth/commit/f8d2222d102f5335f95ec917cbb63bf9b55eff0b))
22
- * **transaction:** improve gas estimate in transaction confirmation ([#2938](https://github.com/dynamic-labs/DynamicAuth/issues/2938)) ([02d0f46](https://github.com/dynamic-labs/DynamicAuth/commit/02d0f46127e94e83b4decbaaf6a45dbae135c89d))
23
- * useSyncPrimaryWallet overrides views with "wallet-locked-view" ([#2921](https://github.com/dynamic-labs/DynamicAuth/issues/2921)) ([aa8c369](https://github.com/dynamic-labs/DynamicAuth/commit/aa8c369d2a713eb57ecc99b16a6b62d465789370))
24
- * **wallet-list:** update key to distinguish wallet and wallet group ([#2922](https://github.com/dynamic-labs/DynamicAuth/issues/2922)) ([f40c07c](https://github.com/dynamic-labs/DynamicAuth/commit/f40c07c65915775e99a1dbb8d07bb23824a92915)), closes [#2909](https://github.com/dynamic-labs/DynamicAuth/issues/2909)
25
-
26
2
  ## [0.18.0-beta.32](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.31...v0.18.0-beta.32) (2023-08-09)
27
3
 
28
4
 
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@dynamic-labs/wagmi-connector",
3
- "version": "0.18.0",
3
+ "version": "0.18.100-viem.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
7
7
  "directory": "packages/wagmi-connector"
8
8
  },
9
9
  "peerDependencies": {
10
- "@wagmi/core": "~0.10.11",
10
+ "@wagmi/core": "^1.3.0",
11
11
  "react": "^17.0.2 || ^18.0.0",
12
- "ethers": "5.7.2",
13
- "wagmi": "~0.12.13",
14
- "@dynamic-labs/sdk-react-core": "0.18.0",
15
- "@dynamic-labs/types": "0.18.0",
16
- "@dynamic-labs/wallet-connector-core": "0.18.0"
12
+ "viem": "^1.1.0",
13
+ "wagmi": "^1.2.0",
14
+ "@dynamic-labs/sdk-react-core": "0.18.100-viem.1",
15
+ "@dynamic-labs/types": "0.18.100-viem.1",
16
+ "@dynamic-labs/wallet-connector-core": "0.18.100-viem.1"
17
17
  },
18
18
  "license": "MIT",
19
19
  "main": "./src/index.cjs",
package/src/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { DynamicWagmiConnector } from './lib/DynamicWagmiConnector';
1
+ export { DynamicWagmiConnector } from './lib/DynamicWagmiConnector';
@@ -1,39 +1,39 @@
1
- import { ethers } from 'ethers';
2
- import { Address, Connector as BaseWagmiConnector, ConnectorData, Chain } from 'wagmi';
3
- import { WalletConnector } from '@dynamic-labs/sdk-react-core';
4
- export declare class Connector extends BaseWagmiConnector<ethers.providers.Web3Provider, undefined, ethers.providers.JsonRpcSigner> {
5
- handleLogOut: () => Promise<void>;
6
- walletConnector: WalletConnector;
7
- id: string;
8
- name: string;
9
- ready: boolean;
10
- constructor({ chains, handleLogOut, walletConnector, }: {
11
- chains: Chain[];
12
- handleLogOut: () => Promise<void>;
13
- walletConnector: WalletConnector;
14
- });
15
- setupEventListeners(): void;
16
- connect(config?: {
17
- chainId?: number;
18
- }): Promise<Required<ConnectorData>>;
19
- disconnect(): Promise<void>;
20
- getAccount(): Promise<Address>;
21
- getChainId(): Promise<number>;
22
- getProvider(config?: {
23
- chainId?: number;
24
- } | undefined): Promise<ethers.providers.Web3Provider>;
25
- getSigner(config?: {
26
- chainId?: number;
27
- } | undefined): Promise<ethers.providers.JsonRpcSigner>;
28
- isAuthorized(): Promise<boolean>;
29
- switchChain?(chainId: number): Promise<Chain>;
30
- watchAsset?(asset: {
31
- address: string;
32
- decimals?: number;
33
- image?: string;
34
- symbol: string;
35
- }): Promise<boolean>;
36
- protected onAccountsChanged: (accounts: string[]) => Promise<void>;
37
- protected onChainChanged: (chain: number | string) => Promise<void>;
38
- protected onDisconnect: () => Promise<void>;
39
- }
1
+ import { Address, Connector as BaseWagmiConnector, ConnectorData, Chain } from 'wagmi';
2
+ import { WalletClient } from 'viem';
3
+ import { WalletConnector } from '@dynamic-labs/sdk-react-core';
4
+ export declare class Connector extends BaseWagmiConnector<WalletClient, undefined> {
5
+ handleLogOut: () => Promise<void>;
6
+ walletConnector: WalletConnector;
7
+ id: string;
8
+ name: string;
9
+ ready: boolean;
10
+ constructor({ chains, handleLogOut, walletConnector, }: {
11
+ chains: Chain[];
12
+ handleLogOut: () => Promise<void>;
13
+ walletConnector: WalletConnector;
14
+ });
15
+ setupEventListeners(): void;
16
+ connect(config?: {
17
+ chainId?: number;
18
+ }): Promise<Required<ConnectorData>>;
19
+ disconnect(): Promise<void>;
20
+ getAccount(): Promise<Address>;
21
+ getChainId(): Promise<number>;
22
+ getProvider(config?: {
23
+ chainId?: number;
24
+ } | undefined): Promise<WalletClient>;
25
+ getWalletClient(config?: {
26
+ chainId?: number;
27
+ } | undefined): Promise<any>;
28
+ isAuthorized(): Promise<boolean>;
29
+ switchChain?(chainId: number): Promise<Chain>;
30
+ watchAsset?(asset: {
31
+ address: string;
32
+ decimals?: number;
33
+ image?: string;
34
+ symbol: string;
35
+ }): Promise<boolean>;
36
+ protected onAccountsChanged: (accounts: string[]) => Promise<void>;
37
+ protected onChainChanged: (chain: number | string) => Promise<void>;
38
+ protected onDisconnect: () => Promise<void>;
39
+ }
@@ -1,127 +1,124 @@
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
+ 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
+ return {
47
+ account,
48
+ chain: { id: yield this.getChainId(), unsupported: false },
49
+ };
50
+ });
51
+ }
52
+ disconnect() {
53
+ var _a, _b;
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ this.walletConnector.teardownEventListeners();
56
+ yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.endSession());
57
+ yield ((_b = this.handleLogOut) === null || _b === void 0 ? void 0 : _b.call(this));
58
+ });
59
+ }
60
+ getAccount() {
61
+ var _a;
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const address = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress());
64
+ if (!address) {
65
+ throw new Error('Not connected');
66
+ }
67
+ return getAddress(address);
68
+ });
69
+ }
70
+ getChainId() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ if (!this.walletConnector) {
73
+ throw new Error('WalletConnector is not defined');
74
+ }
75
+ const network = yield this.walletConnector.getNetwork();
76
+ if (!network) {
77
+ throw new Error('Network is not defined');
78
+ }
79
+ return Number(network);
80
+ });
81
+ }
82
+ getProvider(config) {
83
+ var _a;
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ return (_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getWeb3Provider();
86
+ });
87
+ }
88
+ getWalletClient(config) {
89
+ var _a;
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const signer = yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getSigner());
92
+ return createWalletClient({
93
+ account: yield this.getAccount(),
94
+ transport: custom(signer),
95
+ });
96
+ });
97
+ }
98
+ isAuthorized() {
99
+ var _a, _b;
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const accounts = (_b = (yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.getConnectedAccounts()))) !== null && _b !== void 0 ? _b : [];
102
+ return accounts.length > 0;
103
+ });
104
+ }
105
+ switchChain(chainId) {
106
+ var _a, _b;
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ yield ((_a = this.walletConnector) === null || _a === void 0 ? void 0 : _a.switchNetwork({ networkChainId: chainId }));
109
+ const id = toHex(chainId);
110
+ return ((_b = this.chains.find((x) => x.id === chainId)) !== null && _b !== void 0 ? _b : {
111
+ id: chainId,
112
+ name: `Chain ${id}`,
113
+ nativeCurrency: { decimals: 18, name: 'Ether', symbol: 'ETH' },
114
+ network: `${id}`,
115
+ rpcUrls: { default: { http: [''] }, public: { http: [''] } },
116
+ });
117
+ });
118
+ }
119
+ watchAsset(asset) {
120
+ throw new Error('Method not implemented.');
121
+ }
125
122
  }
126
123
 
127
124
  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-fc9ab085").P, import("@wagmi/core/dist/index-fc9ab085").W>>>;
8
+ export {};
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { configureChains, mainnet, createClient, WagmiConfig } from 'wagmi';
1
+ import React, { 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,37 +8,42 @@ 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, linkedWallets, sendWagmiSettings, } = useDynamicContext();
23
- sendWagmiSettings({
24
- dynamicWagmiSettings: customerSuppliedEvmNetworks,
25
- });
26
- 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) => {
27
- network.chainId = parseInt(network.chainId.toString());
28
- return network;
29
- });
30
- const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
31
- const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
32
- const { chains, provider } = configureChains(mappedChains, mappedProviders);
33
- connector = getConnector(linkedWallets, (wallet) => new Connector({
34
- chains,
35
- handleLogOut,
36
- walletConnector: wallet.connector,
37
- }));
38
- client.config = Object.assign(Object.assign({}, client.config), { autoConnect: true, connectors: connector ? [connector] : [], provider: provider });
39
- // use React.createElement to prevent bunding react/jsx-runtime,
40
- // which is not compatible when bundling apps using React 17
41
- return React.createElement(WagmiConfig, { client: client }, React.createElement(SyncDynamicWagmi, { connector }, children));
11
+ /**
12
+ * we create a "default" (static chain and provider) client to use in the WagmiConfig
13
+ * until we've loaded the dynamic chains and providers, at which point we update the client
14
+ */
15
+ let connector = undefined;
16
+ const { publicClient } = configureChains([mainnet], [publicProvider()]);
17
+ const config = createConfig({
18
+ autoConnect: true,
19
+ publicClient,
20
+ });
21
+ const DynamicWagmiConnector = ({ evmNetworks: customerSuppliedEvmNetworks, children, }) => {
22
+ const { networkConfigurations, handleLogOut, linkedWallets, sendWagmiSettings, } = useDynamicContext();
23
+ sendWagmiSettings({
24
+ dynamicWagmiSettings: customerSuppliedEvmNetworks,
25
+ });
26
+ const chains = useMemo(() => {
27
+ var _a;
28
+ 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) => {
29
+ network.chainId = parseInt(network.chainId.toString());
30
+ return network;
31
+ });
32
+ const mappedChains = getWagmiChainsFromDynamicChains(evmNetworks);
33
+ const mappedProviders = getWagmiProvidersFromDynamicChains(evmNetworks);
34
+ const { chains, publicClient } = configureChains(mappedChains, mappedProviders);
35
+ config.setPublicClient(publicClient);
36
+ return chains;
37
+ }, [customerSuppliedEvmNetworks, networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm]);
38
+ connector = getConnector(linkedWallets, (wallet) => new Connector({
39
+ chains,
40
+ handleLogOut,
41
+ walletConnector: wallet.connector,
42
+ }));
43
+ config.setConnectors(connector ? [connector] : []);
44
+ // use React.createElement to prevent bunding react/jsx-runtime,
45
+ // which is not compatible when bundling apps using React 17
46
+ return React.createElement(WagmiConfig, { config: config }, React.createElement(SyncDynamicWagmi, { connector }, children));
42
47
  };
43
48
 
44
49
  export { DynamicWagmiConnector };
@@ -1,8 +1,8 @@
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 { 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,32 +1,32 @@
1
1
  import React 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
  import { useSyncConnectState } from './hooks/useSyncConnectState/useSyncConnectState.js';
5
5
 
6
- const SyncDynamicWagmi = ({ children, connector, }) => {
7
- const { status: clientStatus } = useClient();
8
- const { walletConnector } = useDynamicContext();
9
- const { connect, status } = useConnect();
10
- const { disconnect } = useDisconnect();
11
- if (walletConnector) {
12
- // after connection is successful, re-setup event listeners after a short delay
13
- // so that they are not cleared by the teardown in useWalletEventListeners
14
- if (status === 'success') {
15
- setTimeout(() => {
16
- connector === null || connector === void 0 ? void 0 : connector.setupEventListeners();
17
- }, 100);
18
- }
19
- }
20
- useSyncConnectState({
21
- clientStatus,
22
- connect,
23
- connector,
24
- disconnect,
25
- walletConnector,
26
- });
27
- // use React.createElement to prevent bunding react/jsx-runtime,
28
- // which is not compatible when bundling apps using React 17
29
- return React.createElement(React.Fragment, null, children);
6
+ const SyncDynamicWagmi = ({ children, connector, }) => {
7
+ const { status: clientStatus } = useConfig();
8
+ const { walletConnector } = useDynamicContext();
9
+ const { connect, status } = useConnect();
10
+ const { disconnect } = useDisconnect();
11
+ if (walletConnector) {
12
+ // after connection is successful, re-setup event listeners after a short delay
13
+ // so that they are not cleared by the teardown in useWalletEventListeners
14
+ if (status === 'success') {
15
+ setTimeout(() => {
16
+ connector === null || connector === void 0 ? void 0 : connector.setupEventListeners();
17
+ }, 100);
18
+ }
19
+ }
20
+ useSyncConnectState({
21
+ clientStatus,
22
+ connect,
23
+ connector,
24
+ disconnect,
25
+ walletConnector,
26
+ });
27
+ // use React.createElement to prevent bunding react/jsx-runtime,
28
+ // which is not compatible when bundling apps using React 17
29
+ return React.createElement(React.Fragment, null, children);
30
30
  };
31
31
 
32
32
  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,2 +1,2 @@
1
- export * from './useWalletConnectorEverPresent';
2
- export * from './useSyncConnectState';
1
+ export * from './useWalletConnectorEverPresent';
2
+ export * from './useSyncConnectState';
@@ -1 +1 @@
1
- export { useSyncConnectState } from './useSyncConnectState';
1
+ export { useSyncConnectState } from './useSyncConnectState';
@@ -1,19 +1,19 @@
1
- /**
2
- * This is used to track a previous value of a variable.
3
- *
4
- * Example:
5
- * const someHook = ({ value }) => {
6
- * const previousValue = usePrevious(value);
7
- * useEffect(() => {
8
- * if (previousValue !== value) {
9
- * // do something
10
- * }
11
- * }, [value, previousValue]);
12
- * }
13
- *
14
- * When someHook is rendered for the first time with value = true, previousValue will be undefined
15
- * so the condition will be true and the effect will run. When someHook is rendered again with
16
- * value = true, previousValue will have been set to true so the condition will be false and the
17
- * effect will not run.
18
- */
19
- export declare const usePrevious: <T>(value: T) => T | undefined;
1
+ /**
2
+ * This is used to track a previous value of a variable.
3
+ *
4
+ * Example:
5
+ * const someHook = ({ value }) => {
6
+ * const previousValue = usePrevious(value);
7
+ * useEffect(() => {
8
+ * if (previousValue !== value) {
9
+ * // do something
10
+ * }
11
+ * }, [value, previousValue]);
12
+ * }
13
+ *
14
+ * When someHook is rendered for the first time with value = true, previousValue will be undefined
15
+ * so the condition will be true and the effect will run. When someHook is rendered again with
16
+ * value = true, previousValue will have been set to true so the condition will be false and the
17
+ * effect will not run.
18
+ */
19
+ export declare const usePrevious: <T>(value: T) => T | undefined;
@@ -1,29 +1,29 @@
1
1
  import { useRef, useEffect } from 'react';
2
2
 
3
- /**
4
- * This is used to track a previous value of a variable.
5
- *
6
- * Example:
7
- * const someHook = ({ value }) => {
8
- * const previousValue = usePrevious(value);
9
- * useEffect(() => {
10
- * if (previousValue !== value) {
11
- * // do something
12
- * }
13
- * }, [value, previousValue]);
14
- * }
15
- *
16
- * When someHook is rendered for the first time with value = true, previousValue will be undefined
17
- * so the condition will be true and the effect will run. When someHook is rendered again with
18
- * value = true, previousValue will have been set to true so the condition will be false and the
19
- * effect will not run.
20
- */
21
- const usePrevious = (value) => {
22
- const ref = useRef();
23
- useEffect(() => {
24
- ref.current = value;
25
- }, [value]);
26
- return ref.current;
3
+ /**
4
+ * This is used to track a previous value of a variable.
5
+ *
6
+ * Example:
7
+ * const someHook = ({ value }) => {
8
+ * const previousValue = usePrevious(value);
9
+ * useEffect(() => {
10
+ * if (previousValue !== value) {
11
+ * // do something
12
+ * }
13
+ * }, [value, previousValue]);
14
+ * }
15
+ *
16
+ * When someHook is rendered for the first time with value = true, previousValue will be undefined
17
+ * so the condition will be true and the effect will run. When someHook is rendered again with
18
+ * value = true, previousValue will have been set to true so the condition will be false and the
19
+ * effect will not run.
20
+ */
21
+ const usePrevious = (value) => {
22
+ const ref = useRef();
23
+ useEffect(() => {
24
+ ref.current = value;
25
+ }, [value]);
26
+ return ref.current;
27
27
  };
28
28
 
29
29
  export { usePrevious };
@@ -1,11 +1,11 @@
1
- import { Connector } from 'wagmi';
2
- import { ConnectArgs } from '@wagmi/core';
3
- import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
- export type SyncConnectStateHookProps = {
5
- clientStatus: 'connected' | 'connecting' | 'reconnecting' | 'disconnected';
6
- connect: (args?: Partial<ConnectArgs> | undefined) => void;
7
- connector: Connector | undefined;
8
- disconnect: () => void;
9
- walletConnector: WalletConnector | null;
10
- };
11
- export declare const useSyncConnectState: ({ walletConnector, disconnect, clientStatus, connect, connector, }: SyncConnectStateHookProps) => void;
1
+ import { Connector } from 'wagmi';
2
+ import { ConnectArgs } from '@wagmi/core';
3
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
+ export type SyncConnectStateHookProps = {
5
+ clientStatus: 'connected' | 'connecting' | 'reconnecting' | 'disconnected';
6
+ connect: (args?: Partial<ConnectArgs> | undefined) => void;
7
+ connector: Connector | undefined;
8
+ disconnect: () => void;
9
+ walletConnector: WalletConnector | null;
10
+ };
11
+ export declare const useSyncConnectState: ({ walletConnector, disconnect, clientStatus, connect, connector, }: SyncConnectStateHookProps) => void;
@@ -2,27 +2,27 @@ import { useEffect } from 'react';
2
2
  import { useWalletConnectorEverPresent } from '../useWalletConnectorEverPresent/useWalletConnectorEverPresent.js';
3
3
  import { usePrevious } from './usePrevious.js';
4
4
 
5
- const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connect, connector, }) => {
6
- const wasWalletConnectEverPresent = useWalletConnectorEverPresent(walletConnector);
7
- const prevConnectorId = usePrevious(connector === null || connector === void 0 ? void 0 : connector.id);
8
- useEffect(() => {
9
- if (!walletConnector) {
10
- if (wasWalletConnectEverPresent) {
11
- disconnect();
12
- }
13
- }
14
- else if ((connector === null || connector === void 0 ? void 0 : connector.id) !== prevConnectorId) {
15
- connect({ connector });
16
- }
17
- }, [
18
- clientStatus,
19
- connect,
20
- connector,
21
- disconnect,
22
- prevConnectorId,
23
- walletConnector,
24
- wasWalletConnectEverPresent,
25
- ]);
5
+ const useSyncConnectState = ({ walletConnector, disconnect, clientStatus, connect, connector, }) => {
6
+ const wasWalletConnectEverPresent = useWalletConnectorEverPresent(walletConnector);
7
+ const prevConnectorId = usePrevious(connector === null || connector === void 0 ? void 0 : connector.id);
8
+ useEffect(() => {
9
+ if (!walletConnector) {
10
+ if (wasWalletConnectEverPresent) {
11
+ disconnect();
12
+ }
13
+ }
14
+ else if ((connector === null || connector === void 0 ? void 0 : connector.id) !== prevConnectorId) {
15
+ connect({ connector });
16
+ }
17
+ }, [
18
+ clientStatus,
19
+ connect,
20
+ connector,
21
+ disconnect,
22
+ prevConnectorId,
23
+ walletConnector,
24
+ wasWalletConnectEverPresent,
25
+ ]);
26
26
  };
27
27
 
28
28
  export { useSyncConnectState };
@@ -1 +1 @@
1
- export { useWalletConnectorEverPresent } from './useWalletConnectorEverPresent';
1
+ export { useWalletConnectorEverPresent } from './useWalletConnectorEverPresent';
@@ -1,2 +1,2 @@
1
- import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
- export declare const useWalletConnectorEverPresent: (walletConnector: WalletConnector | null) => boolean;
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ export declare const useWalletConnectorEverPresent: (walletConnector: WalletConnector | null) => boolean;
@@ -1,13 +1,13 @@
1
1
  import { useState, useEffect } from 'react';
2
2
 
3
- const useWalletConnectorEverPresent = (walletConnector) => {
4
- const [present, setPresent] = useState(false);
5
- useEffect(() => {
6
- if (walletConnector) {
7
- setPresent(true);
8
- }
9
- }, [walletConnector]);
10
- return present;
3
+ const useWalletConnectorEverPresent = (walletConnector) => {
4
+ const [present, setPresent] = useState(false);
5
+ useEffect(() => {
6
+ if (walletConnector) {
7
+ setPresent(true);
8
+ }
9
+ }, [walletConnector]);
10
+ return present;
11
11
  };
12
12
 
13
13
  export { useWalletConnectorEverPresent };
@@ -1,3 +1,3 @@
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;
@@ -1,44 +1,44 @@
1
1
  import * as allChains from 'wagmi/chains';
2
2
  import { resolveRpcUrlFromEvmNetworks } from '../utils/resolveRpcUrlFromEvmNetworks/resolveRpcUrlFromEvmNetworks.js';
3
3
 
4
- // eslint-disable-next-line import/no-namespace
5
- const findRpcProvider = (rpcUrls, privateCustomerRpcUrls, name) => {
6
- const findRpcUrl = privateCustomerRpcUrls === null || privateCustomerRpcUrls === void 0 ? void 0 : privateCustomerRpcUrls.find((rpcUrl) => {
7
- if (typeof rpcUrl === 'string') {
8
- return rpcUrl.includes(name);
9
- }
10
- else if (typeof rpcUrl.http === 'string') {
11
- return rpcUrl.http.includes(name);
12
- }
13
- else {
14
- return false;
15
- }
16
- });
17
- if (typeof findRpcUrl === 'string') {
18
- rpcUrls[name] = { http: [findRpcUrl] };
19
- }
20
- else if (typeof (findRpcUrl === null || findRpcUrl === void 0 ? void 0 : findRpcUrl.http) === 'string') {
21
- rpcUrls[name] = { http: [findRpcUrl.http] };
22
- }
23
- };
24
- const mapDynamicChainToWagmi = (dynamicChain) => {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
26
- const rpcUrlResolved = resolveRpcUrlFromEvmNetworks(dynamicChain);
27
- const rpcUrls = {
28
- default: {
29
- http: rpcUrlResolved,
30
- },
31
- public: {
32
- http: rpcUrlResolved,
33
- },
34
- };
35
- const rpcUrlProviders = ['alchemy', 'infura'];
36
- rpcUrlProviders.forEach((name) => findRpcProvider(rpcUrls, dynamicChain.privateCustomerRpcUrls, name));
37
- /**
38
- * Find the chain in Wagmi that matches the chainId of the dynamic chain.
39
- */
40
- const wagmiChain = ((_a = Object.values(allChains).find((chain) => chain.id === dynamicChain.chainId)) !== null && _a !== void 0 ? _a : {});
41
- return Object.assign(Object.assign({}, wagmiChain), { blockExplorers: Object.assign(Object.assign({}, wagmiChain === null || wagmiChain === void 0 ? void 0 : wagmiChain.blockExplorers), { default: Object.assign(Object.assign({}, (_b = wagmiChain.blockExplorers) === null || _b === void 0 ? void 0 : _b.default), { name: '', url: (_d = (_c = dynamicChain.blockExplorerUrls) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '' }) }), id: (_e = dynamicChain.chainId) !== null && _e !== void 0 ? _e : wagmiChain.id, name: (_g = (_f = dynamicChain.vanityName) !== null && _f !== void 0 ? _f : dynamicChain.name) !== null && _g !== void 0 ? _g : wagmiChain.name, nativeCurrency: (_h = dynamicChain.nativeCurrency) !== null && _h !== void 0 ? _h : wagmiChain.nativeCurrency, network: (_j = dynamicChain.name) !== null && _j !== void 0 ? _j : wagmiChain.network, rpcUrls: rpcUrls !== null && rpcUrls !== void 0 ? rpcUrls : wagmiChain.rpcUrls });
4
+ // eslint-disable-next-line import/no-namespace
5
+ const findRpcProvider = (rpcUrls, privateCustomerRpcUrls, name) => {
6
+ const findRpcUrl = privateCustomerRpcUrls === null || privateCustomerRpcUrls === void 0 ? void 0 : privateCustomerRpcUrls.find((rpcUrl) => {
7
+ if (typeof rpcUrl === 'string') {
8
+ return rpcUrl.includes(name);
9
+ }
10
+ else if (typeof rpcUrl.http === 'string') {
11
+ return rpcUrl.http.includes(name);
12
+ }
13
+ else {
14
+ return false;
15
+ }
16
+ });
17
+ if (typeof findRpcUrl === 'string') {
18
+ rpcUrls[name] = { http: [findRpcUrl] };
19
+ }
20
+ else if (typeof (findRpcUrl === null || findRpcUrl === void 0 ? void 0 : findRpcUrl.http) === 'string') {
21
+ rpcUrls[name] = { http: [findRpcUrl.http] };
22
+ }
23
+ };
24
+ const mapDynamicChainToWagmi = (dynamicChain) => {
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
26
+ const rpcUrlResolved = resolveRpcUrlFromEvmNetworks(dynamicChain);
27
+ const rpcUrls = {
28
+ default: {
29
+ http: rpcUrlResolved,
30
+ },
31
+ public: {
32
+ http: rpcUrlResolved,
33
+ },
34
+ };
35
+ const rpcUrlProviders = ['alchemy', 'infura'];
36
+ rpcUrlProviders.forEach((name) => findRpcProvider(rpcUrls, dynamicChain.privateCustomerRpcUrls, name));
37
+ /**
38
+ * Find the chain in Wagmi that matches the chainId of the dynamic chain.
39
+ */
40
+ const wagmiChain = ((_a = Object.values(allChains).find((chain) => chain.id === dynamicChain.chainId)) !== null && _a !== void 0 ? _a : {});
41
+ return Object.assign(Object.assign({}, wagmiChain), { blockExplorers: Object.assign(Object.assign({}, wagmiChain === null || wagmiChain === void 0 ? void 0 : wagmiChain.blockExplorers), { default: Object.assign(Object.assign({}, (_b = wagmiChain.blockExplorers) === null || _b === void 0 ? void 0 : _b.default), { name: '', url: (_d = (_c = dynamicChain.blockExplorerUrls) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '' }) }), id: (_e = dynamicChain.chainId) !== null && _e !== void 0 ? _e : wagmiChain.id, name: (_g = (_f = dynamicChain.vanityName) !== null && _f !== void 0 ? _f : dynamicChain.name) !== null && _g !== void 0 ? _g : wagmiChain.name, nativeCurrency: (_h = dynamicChain.nativeCurrency) !== null && _h !== void 0 ? _h : wagmiChain.nativeCurrency, network: (_j = dynamicChain.name) !== null && _j !== void 0 ? _j : wagmiChain.network, rpcUrls: rpcUrls !== null && rpcUrls !== void 0 ? rpcUrls : wagmiChain.rpcUrls });
42
42
  };
43
43
 
44
44
  export { mapDynamicChainToWagmi };
@@ -1,25 +1,25 @@
1
- import { EvmNetwork } from '@dynamic-labs/types';
2
- type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3
- type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
- type CustomProviderOptions = {
5
- /**
6
- * The URL of the RPC endpoint.
7
- */
8
- http: string;
9
- /**
10
- * The priority of this provider.
11
- */
12
- priority?: number;
13
- /**
14
- * The timeout in milliseconds for requests to this provider.
15
- */
16
- stallTimeout?: number;
17
- /**
18
- * The URL of the websocket endpoint.
19
- */
20
- webSocket?: string;
21
- };
22
- export type WagmiEvmNetworks = Omit<PartialBy<EvmNetwork, 'iconUrls' | 'networkId' | 'vanityName'>, 'privateCustomerRpcUrls'> & {
23
- privateCustomerRpcUrls: (string | CustomProviderOptions)[];
24
- };
25
- export {};
1
+ import { EvmNetwork } from '@dynamic-labs/types';
2
+ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
3
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
+ type CustomProviderOptions = {
5
+ /**
6
+ * The URL of the RPC endpoint.
7
+ */
8
+ http: string;
9
+ /**
10
+ * The priority of this provider.
11
+ */
12
+ priority?: number;
13
+ /**
14
+ * The timeout in milliseconds for requests to this provider.
15
+ */
16
+ stallTimeout?: number;
17
+ /**
18
+ * The URL of the websocket endpoint.
19
+ */
20
+ webSocket?: string;
21
+ };
22
+ export type WagmiEvmNetworks = Omit<PartialBy<EvmNetwork, 'iconUrls' | 'networkId' | 'vanityName'>, 'privateCustomerRpcUrls'> & {
23
+ privateCustomerRpcUrls: (string | CustomProviderOptions)[];
24
+ };
25
+ export {};
@@ -1 +1 @@
1
- export * from './resolveRpcUrlFromEvmNetworks';
1
+ export * from './resolveRpcUrlFromEvmNetworks';
@@ -1 +1 @@
1
- export { resolveRpcUrlFromEvmNetworks } from './resolveRpcUrlFromEvmNetworks';
1
+ export { resolveRpcUrlFromEvmNetworks } from './resolveRpcUrlFromEvmNetworks';
@@ -1,2 +1,2 @@
1
- import { WagmiEvmNetworks } from '../../types';
2
- export declare const resolveRpcUrlFromEvmNetworks: (dynamicChain: WagmiEvmNetworks) => string[];
1
+ import { WagmiEvmNetworks } from '../../types';
2
+ export declare const resolveRpcUrlFromEvmNetworks: (dynamicChain: WagmiEvmNetworks) => string[];
@@ -1,9 +1,9 @@
1
- const mapCustomProviderOptionsToString = (rpcUrl) => (typeof rpcUrl === 'string' ? rpcUrl : rpcUrl.http);
2
- const resolveRpcUrlFromEvmNetworks = (dynamicChain) => {
3
- var _a;
4
- const privateCustomerRpcUrls = (_a = dynamicChain.privateCustomerRpcUrls) !== null && _a !== void 0 ? _a : [];
5
- const customerRpcUrls = privateCustomerRpcUrls.map(mapCustomProviderOptionsToString);
6
- return customerRpcUrls.length ? customerRpcUrls : dynamicChain.rpcUrls;
1
+ const mapCustomProviderOptionsToString = (rpcUrl) => (typeof rpcUrl === 'string' ? rpcUrl : rpcUrl.http);
2
+ const resolveRpcUrlFromEvmNetworks = (dynamicChain) => {
3
+ var _a;
4
+ const privateCustomerRpcUrls = (_a = dynamicChain.privateCustomerRpcUrls) !== null && _a !== void 0 ? _a : [];
5
+ const customerRpcUrls = privateCustomerRpcUrls.map(mapCustomProviderOptionsToString);
6
+ return customerRpcUrls.length ? customerRpcUrls : dynamicChain.rpcUrls;
7
7
  };
8
8
 
9
9
  export { resolveRpcUrlFromEvmNetworks };