@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,44 +1,51 @@
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 updateRpcProvider = (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;
26
+ /**
27
+ * Find the chain in Wagmi that matches the chainId of the dynamic chain.
28
+ */
29
+ const wagmiChain = ((_a = Object.values(allChains).find((chain) => chain.id === dynamicChain.chainId)) !== null && _a !== void 0 ? _a : {});
30
+ return overrideWagmiChainWithDynamicSettings(wagmiChain, dynamicChain);
31
+ };
32
+ const generateRpcUrls = (dynamicChain) => {
33
+ const rpcUrlResolved = resolveRpcUrlFromEvmNetworks(dynamicChain);
34
+ const rpcUrls = {
35
+ default: {
36
+ http: rpcUrlResolved,
37
+ },
38
+ public: {
39
+ http: rpcUrlResolved,
40
+ },
41
+ };
42
+ const rpcUrlProviders = ['alchemy', 'infura'];
43
+ rpcUrlProviders.forEach((name) => updateRpcProvider(rpcUrls, dynamicChain.privateCustomerRpcUrls, name));
44
+ return rpcUrls;
45
+ };
46
+ const overrideWagmiChainWithDynamicSettings = (wagmiChain, dynamicChain) => {
47
+ var _a, _b, _c, _d, _e, _f, _g;
48
+ 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({}, (_a = wagmiChain.blockExplorers) === null || _a === void 0 ? void 0 : _a.default), { name: '', url: (_c = (_b = dynamicChain.blockExplorerUrls) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : '' }) }), contracts: (_d = dynamicChain.contracts) !== null && _d !== void 0 ? _d : wagmiChain.contracts, name: (_f = (_e = dynamicChain.vanityName) !== null && _e !== void 0 ? _e : dynamicChain.name) !== null && _f !== void 0 ? _f : wagmiChain.name, nativeCurrency: (_g = dynamicChain.nativeCurrency) !== null && _g !== void 0 ? _g : wagmiChain.nativeCurrency, rpcUrls: generateRpcUrls(dynamicChain) }));
42
49
  };
43
50
 
44
- export { mapDynamicChainToWagmi };
51
+ export { mapDynamicChainToWagmi, overrideWagmiChainWithDynamicSettings };
@@ -1,25 +1,28 @@
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
+ contracts?: {
25
+ [key: string]: any;
26
+ };
27
+ };
28
+ 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 };