@dynamic-labs/ethereum 2.0.0-alpha.8 → 2.0.0

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 (38) hide show
  1. package/CHANGELOG.md +329 -0
  2. package/package.json +10 -9
  3. package/src/EthWalletConnector.cjs +12 -1
  4. package/src/EthWalletConnector.d.ts +13 -10
  5. package/src/EthWalletConnector.js +12 -1
  6. package/src/coinbase/client/client.cjs +14 -14
  7. package/src/coinbase/client/client.d.ts +5 -4
  8. package/src/coinbase/client/client.js +13 -13
  9. package/src/coinbase/client/types.d.ts +6 -3
  10. package/src/coinbase/coinbase.cjs +30 -13
  11. package/src/coinbase/coinbase.d.ts +5 -4
  12. package/src/coinbase/coinbase.js +31 -14
  13. package/src/ethProviderHelper.cjs +11 -6
  14. package/src/ethProviderHelper.d.ts +6 -4
  15. package/src/ethProviderHelper.js +11 -6
  16. package/src/index.cjs +3 -1
  17. package/src/index.d.ts +1 -0
  18. package/src/index.js +3 -2
  19. package/src/injected/InjectedWalletBase.cjs +28 -11
  20. package/src/injected/InjectedWalletBase.d.ts +2 -2
  21. package/src/injected/InjectedWalletBase.js +28 -11
  22. package/src/injected/PhantomEvm.cjs +3 -3
  23. package/src/injected/PhantomEvm.d.ts +1 -1
  24. package/src/injected/PhantomEvm.js +3 -3
  25. package/src/injected/Zerion.cjs +38 -0
  26. package/src/injected/Zerion.d.ts +10 -0
  27. package/src/injected/Zerion.js +34 -0
  28. package/src/injected/fetchInjectedWalletConnectors.cjs +25 -0
  29. package/src/injected/fetchInjectedWalletConnectors.js +25 -0
  30. package/src/utils/index.d.ts +1 -0
  31. package/src/utils/isEthWalletConnector/index.d.ts +1 -0
  32. package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +7 -0
  33. package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
  34. package/src/utils/isEthWalletConnector/isEthWalletConnector.js +3 -0
  35. package/src/walletConnect/index.d.ts +1 -1
  36. package/src/walletConnect/walletConnect.cjs +114 -75
  37. package/src/walletConnect/walletConnect.d.ts +19 -18
  38. package/src/walletConnect/walletConnect.js +113 -74
@@ -1,5 +1,6 @@
1
1
  import { __awaiter } from '../../_virtual/_tslib.js';
2
2
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
3
+ import { isMobile } from '@dynamic-labs/utils';
3
4
  import { EthProviderHelper } from '../ethProviderHelper.js';
4
5
  import { EthWalletConnector } from '../EthWalletConnector.js';
5
6
  import { WalletConnect } from '../walletConnect/walletConnect.js';
@@ -18,18 +19,34 @@ class InjectedWalletBase extends EthWalletConnector {
18
19
  this.wallet = findWalletBookWallet(this.walletBook, this.key);
19
20
  }
20
21
  if (this.wallet && !this.ethProviderHelper) {
21
- this.ethProviderHelper = new EthProviderHelper(this.wallet);
22
+ this.ethProviderHelper = new EthProviderHelper(this.wallet, this);
22
23
  }
23
24
  // this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
24
25
  return this.ethProviderHelper;
25
26
  }
26
27
  getMobileOrInstalledWallet() {
27
- if (this.walletConnectorFallback && !this.isInstalledOnBrowser()) {
28
- if (!this.wallet)
29
- this.wallet = findWalletBookWallet(this.walletBook, this.key);
30
- return new WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
28
+ var _a, _b;
29
+ if (!this.wallet) {
30
+ this.wallet = findWalletBookWallet(this.walletBook, this.key);
31
+ }
32
+ if (this.isInstalledOnBrowser()) {
33
+ return this;
34
+ }
35
+ // this is to handle the case where the user is in a webview.
36
+ // when the user is in a webview, customers should set the deepLinkPreference prop to universal,
37
+ // in which case this condition will be false, and the SDK will use WalletConnect (if available)
38
+ if (((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.inAppBrowser) &&
39
+ this.constructorProps.deepLinkPreference !== 'universal' &&
40
+ isMobile()) {
41
+ return this;
42
+ }
43
+ // this is the case where the wallet is not installed on the browser and
44
+ // it does not support WalletConnect. in this case, the SDK will instruct
45
+ // the user to download the wallet extension
46
+ if (!this.walletConnectorFallback) {
47
+ return this;
31
48
  }
32
- return this;
49
+ return new WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
33
50
  }
34
51
  setupEventListeners() {
35
52
  const provider = this.getWalletClient();
@@ -41,23 +58,23 @@ class InjectedWalletBase extends EthWalletConnector {
41
58
  const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
42
59
  this.teardownEventListeners = tearDownEventListeners;
43
60
  }
44
- getWalletClient() {
61
+ getWalletClient(chainId) {
45
62
  var _a;
46
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient();
63
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
47
64
  }
48
65
  isInstalledOnBrowser() {
49
66
  var _a;
50
67
  return ((_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
51
68
  }
52
- fetchPublicAddress() {
69
+ getAddress() {
53
70
  var _a;
54
71
  return __awaiter(this, void 0, void 0, function* () {
55
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
72
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.getAddress();
56
73
  });
57
74
  }
58
75
  connect() {
59
76
  return __awaiter(this, void 0, void 0, function* () {
60
- yield this.fetchPublicAddress();
77
+ yield this.getAddress();
61
78
  });
62
79
  }
63
80
  signMessage(messageToSign) {
@@ -14,13 +14,13 @@ class PhantomEvm extends InjectedWalletBase {
14
14
  this.overrideKey = 'phantomevm';
15
15
  this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
16
16
  }
17
- fetchPublicAddress() {
17
+ getAddress() {
18
18
  const _super = Object.create(null, {
19
- fetchPublicAddress: { get: () => super.fetchPublicAddress }
19
+ getAddress: { get: () => super.getAddress }
20
20
  });
21
21
  return _tslib.__awaiter(this, void 0, void 0, function* () {
22
22
  if (this.isInstalledOnBrowser()) {
23
- return _super.fetchPublicAddress.call(this);
23
+ return _super.getAddress.call(this);
24
24
  }
25
25
  if (utils.isMobile()) {
26
26
  utils.handleMobileWalletRedirect({
@@ -4,5 +4,5 @@ export declare class PhantomEvm extends InjectedWalletBase {
4
4
  name: string;
5
5
  overrideKey: string;
6
6
  constructor(props: EthWalletConnectorOpts);
7
- fetchPublicAddress(): Promise<string | undefined>;
7
+ getAddress(): Promise<string | undefined>;
8
8
  }
@@ -10,13 +10,13 @@ class PhantomEvm extends InjectedWalletBase {
10
10
  this.overrideKey = 'phantomevm';
11
11
  this.wallet = findWalletBookWallet(this.walletBook, this.key);
12
12
  }
13
- fetchPublicAddress() {
13
+ getAddress() {
14
14
  const _super = Object.create(null, {
15
- fetchPublicAddress: { get: () => super.fetchPublicAddress }
15
+ getAddress: { get: () => super.getAddress }
16
16
  });
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  if (this.isInstalledOnBrowser()) {
19
- return _super.fetchPublicAddress.call(this);
19
+ return _super.getAddress.call(this);
20
20
  }
21
21
  if (isMobile()) {
22
22
  handleMobileWalletRedirect({
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var InjectedWalletBase = require('./InjectedWalletBase.cjs');
6
+
7
+ // on desktop, we use EIP-6963 to connect to the wallet so the injectedConfig
8
+ // is not needed.
9
+ const zerionWalletBookConfig = {
10
+ eip6963Config: {
11
+ rdns: 'io.zerion.wallet',
12
+ },
13
+ filterFromWalletConnect: true,
14
+ injectedConfig: [
15
+ {
16
+ chain: 'evm',
17
+ // adds isMetaMask flag to the wallet connector so that the window provider works
18
+ // in the zerion in-app browser.
19
+ extensionLocators: [{ flag: 'isMetaMask', value: true }],
20
+ windowLocations: ['zerionWallet', 'zerionwallet.ethereum'],
21
+ },
22
+ ],
23
+ name: 'Zerion',
24
+ };
25
+ class Zerion extends InjectedWalletBase {
26
+ constructor(props) {
27
+ super(props);
28
+ this.name = 'Zerion';
29
+ this.overrideKey = 'zerion';
30
+ this.wallet = zerionWalletBookConfig;
31
+ }
32
+ isInstalledOnBrowser() {
33
+ var _a;
34
+ return Boolean(window.zerionWallet || ((_a = window.zerionwallet) === null || _a === void 0 ? void 0 : _a.ethereum));
35
+ }
36
+ }
37
+
38
+ exports.Zerion = Zerion;
@@ -0,0 +1,10 @@
1
+ import { WalletSchema } from '@dynamic-labs/wallet-book';
2
+ import { EthWalletConnectorOpts } from '../EthWalletConnector';
3
+ import InjectedWalletBase from './InjectedWalletBase';
4
+ export declare class Zerion extends InjectedWalletBase {
5
+ name: string;
6
+ overrideKey: string;
7
+ wallet: WalletSchema;
8
+ constructor(props: EthWalletConnectorOpts);
9
+ isInstalledOnBrowser(): boolean;
10
+ }
@@ -0,0 +1,34 @@
1
+ import InjectedWalletBase from './InjectedWalletBase.js';
2
+
3
+ // on desktop, we use EIP-6963 to connect to the wallet so the injectedConfig
4
+ // is not needed.
5
+ const zerionWalletBookConfig = {
6
+ eip6963Config: {
7
+ rdns: 'io.zerion.wallet',
8
+ },
9
+ filterFromWalletConnect: true,
10
+ injectedConfig: [
11
+ {
12
+ chain: 'evm',
13
+ // adds isMetaMask flag to the wallet connector so that the window provider works
14
+ // in the zerion in-app browser.
15
+ extensionLocators: [{ flag: 'isMetaMask', value: true }],
16
+ windowLocations: ['zerionWallet', 'zerionwallet.ethereum'],
17
+ },
18
+ ],
19
+ name: 'Zerion',
20
+ };
21
+ class Zerion extends InjectedWalletBase {
22
+ constructor(props) {
23
+ super(props);
24
+ this.name = 'Zerion';
25
+ this.overrideKey = 'zerion';
26
+ this.wallet = zerionWalletBookConfig;
27
+ }
28
+ isInstalledOnBrowser() {
29
+ var _a;
30
+ return Boolean(window.zerionWallet || ((_a = window.zerionwallet) === null || _a === void 0 ? void 0 : _a.ethereum));
31
+ }
32
+ }
33
+
34
+ export { Zerion };
@@ -2,18 +2,23 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _tslib = require('../../_virtual/_tslib.cjs');
6
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
5
7
  var InjectedWalletBase = require('./InjectedWalletBase.cjs');
6
8
  var PhantomEvm = require('./PhantomEvm.cjs');
7
9
  var ExodusEvm = require('./ExodusEvm.cjs');
10
+ var Zerion = require('./Zerion.cjs');
8
11
 
9
12
  const injectedWalletOverrides = [
10
13
  PhantomEvm.PhantomEvm,
11
14
  ExodusEvm.ExodusEvm,
15
+ Zerion.Zerion,
12
16
  ];
13
17
  const filteredInjectedWalletKeysOverrides = [
14
18
  'phantomevm',
15
19
  'coinbase',
16
20
  'exodusevm',
21
+ 'zerion',
17
22
  ];
18
23
  const fetchInjectedWalletConnector = ({ walletBook, }) => {
19
24
  var _a;
@@ -36,6 +41,26 @@ const fetchInjectedWalletConnector = ({ walletBook, }) => {
36
41
  // this is the key from the wallet book entry so that we don't purely rely on the normalized name
37
42
  this.overrideKey = key;
38
43
  }
44
+ getAddress() {
45
+ const _super = Object.create(null, {
46
+ getAddress: { get: () => super.getAddress }
47
+ });
48
+ var _a;
49
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
50
+ if (this.isInstalledOnBrowser()) {
51
+ return _super.getAddress.call(this);
52
+ }
53
+ const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
54
+ if (!inAppBrowserBase) {
55
+ const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
56
+ walletConnectorCore.logger.error(error.message);
57
+ throw error;
58
+ }
59
+ const cleanedTargetUrl = window.location.href.replace('https://', '');
60
+ window.location.href = `${inAppBrowserBase}/${cleanedTargetUrl}`;
61
+ return undefined;
62
+ });
63
+ }
39
64
  };
40
65
  });
41
66
  };
@@ -1,15 +1,20 @@
1
+ import { __awaiter } from '../../_virtual/_tslib.js';
2
+ import { logger } from '@dynamic-labs/wallet-connector-core';
1
3
  import InjectedWalletBase from './InjectedWalletBase.js';
2
4
  import { PhantomEvm } from './PhantomEvm.js';
3
5
  import { ExodusEvm } from './ExodusEvm.js';
6
+ import { Zerion } from './Zerion.js';
4
7
 
5
8
  const injectedWalletOverrides = [
6
9
  PhantomEvm,
7
10
  ExodusEvm,
11
+ Zerion,
8
12
  ];
9
13
  const filteredInjectedWalletKeysOverrides = [
10
14
  'phantomevm',
11
15
  'coinbase',
12
16
  'exodusevm',
17
+ 'zerion',
13
18
  ];
14
19
  const fetchInjectedWalletConnector = ({ walletBook, }) => {
15
20
  var _a;
@@ -32,6 +37,26 @@ const fetchInjectedWalletConnector = ({ walletBook, }) => {
32
37
  // this is the key from the wallet book entry so that we don't purely rely on the normalized name
33
38
  this.overrideKey = key;
34
39
  }
40
+ getAddress() {
41
+ const _super = Object.create(null, {
42
+ getAddress: { get: () => super.getAddress }
43
+ });
44
+ var _a;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ if (this.isInstalledOnBrowser()) {
47
+ return _super.getAddress.call(this);
48
+ }
49
+ const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
50
+ if (!inAppBrowserBase) {
51
+ const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
52
+ logger.error(error.message);
53
+ throw error;
54
+ }
55
+ const cleanedTargetUrl = window.location.href.replace('https://', '');
56
+ window.location.href = `${inAppBrowserBase}/${cleanedTargetUrl}`;
57
+ return undefined;
58
+ });
59
+ }
35
60
  };
36
61
  });
37
62
  };
@@ -0,0 +1 @@
1
+ export * from './isEthWalletConnector';
@@ -0,0 +1 @@
1
+ export { isEthWalletConnector } from './isEthWalletConnector';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isEthWalletConnector = (connector) => Boolean(connector === null || connector === void 0 ? void 0 : connector.getActiveAccount);
6
+
7
+ exports.isEthWalletConnector = isEthWalletConnector;
@@ -0,0 +1,3 @@
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ import { EthWalletConnector } from '../..';
3
+ export declare const isEthWalletConnector: (connector: WalletConnector | EthWalletConnector) => connector is EthWalletConnector;
@@ -0,0 +1,3 @@
1
+ const isEthWalletConnector = (connector) => Boolean(connector === null || connector === void 0 ? void 0 : connector.getActiveAccount);
2
+
3
+ export { isEthWalletConnector };
@@ -1,2 +1,2 @@
1
- export { WalletConnect, type WalletConnectOpts } from './walletConnect';
1
+ export { WalletConnect } from './walletConnect';
2
2
  export { fetchWalletConnectWallets } from './fetchWalletConnectWallets';