@dynamic-labs/ethereum-aa 2.0.0-alpha.2 → 2.0.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/src/index.js CHANGED
@@ -2,6 +2,12 @@ import { ZeroDevConnector } from './ZeroDevConnector.js';
2
2
  export { EthereumAaConnector } from './ethereum-aa.js';
3
3
  export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
4
4
 
5
+ const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, } = {}) => {
6
+ if (bundlerProvider) {
7
+ ZeroDevConnector.bundlerProvider = bundlerProvider;
8
+ }
9
+ return ZeroDevSmartWalletConnectors;
10
+ };
5
11
  const ZeroDevSmartWalletConnectors = (props) => {
6
12
  var _a;
7
13
  if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zerodev) {
@@ -10,4 +16,4 @@ const ZeroDevSmartWalletConnectors = (props) => {
10
16
  return [];
11
17
  };
12
18
 
13
- export { ZeroDevSmartWalletConnectors };
19
+ export { ZeroDevSmartWalletConnectors, ZeroDevSmartWalletConnectorsWithConfig };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../_virtual/_tslib.cjs');
6
+ var viemUtils = require('@dynamic-labs/viem-utils');
7
+ var logger = require('./logger.cjs');
8
+
9
+ const cachedChainIdKey = 'dynamic_zd_chain_id';
10
+ const fetchChain = (projectId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
11
+ try {
12
+ const cachedChainId = localStorage.getItem(cachedChainIdKey);
13
+ if (cachedChainId) {
14
+ return viemUtils.chainsMap[cachedChainId];
15
+ }
16
+ const response = yield (yield fetch(`https://prod-api.zerodev.app/projects/${projectId}`)).json();
17
+ localStorage.setItem(cachedChainIdKey, response.chainId);
18
+ return viemUtils.chainsMap[response.chainId];
19
+ }
20
+ catch (err) {
21
+ logger.logger.error('Failed to fetch ZeroDev project settings from ZeroDev API ' +
22
+ 'This is needed to fetch the chain id so that we know which chain the smart contract is on');
23
+ throw err;
24
+ }
25
+ });
26
+
27
+ exports.cachedChainIdKey = cachedChainIdKey;
28
+ exports.fetchChain = fetchChain;
@@ -0,0 +1,3 @@
1
+ import { type Chain } from 'viem/chains';
2
+ export declare const cachedChainIdKey = "dynamic_zd_chain_id";
3
+ export declare const fetchChain: (projectId: string) => Promise<Chain>;
@@ -0,0 +1,23 @@
1
+ import { __awaiter } from '../../_virtual/_tslib.js';
2
+ import { chainsMap } from '@dynamic-labs/viem-utils';
3
+ import { logger } from './logger.js';
4
+
5
+ const cachedChainIdKey = 'dynamic_zd_chain_id';
6
+ const fetchChain = (projectId) => __awaiter(void 0, void 0, void 0, function* () {
7
+ try {
8
+ const cachedChainId = localStorage.getItem(cachedChainIdKey);
9
+ if (cachedChainId) {
10
+ return chainsMap[cachedChainId];
11
+ }
12
+ const response = yield (yield fetch(`https://prod-api.zerodev.app/projects/${projectId}`)).json();
13
+ localStorage.setItem(cachedChainIdKey, response.chainId);
14
+ return chainsMap[response.chainId];
15
+ }
16
+ catch (err) {
17
+ logger.error('Failed to fetch ZeroDev project settings from ZeroDev API ' +
18
+ 'This is needed to fetch the chain id so that we know which chain the smart contract is on');
19
+ throw err;
20
+ }
21
+ });
22
+
23
+ export { cachedChainIdKey, fetchChain };
@@ -0,0 +1,3 @@
1
+ export * from './fetchChain';
2
+ export * from './logger';
3
+ export * from './isZeroDevConnector';