@dynamic-labs/ethereum 2.0.0-alpha.9 → 2.1.0-alpha.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 +316 -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
@@ -6,11 +6,15 @@ import { INFURA_ID } from '../../constants.js';
6
6
 
7
7
  const jsonRpcUrl = `https://mainnet.infura.io/v3/${INFURA_ID}`;
8
8
  const chainId = 1;
9
+ // storing a reference to the coinbase sdk so that we can call getQrUrl on it when we need a fresh qr code
10
+ let coinbaseSdk;
11
+ // storing a reference to the coinbase provider because the provider methods work better when
12
+ // they are called on the same instance
9
13
  let coinbaseProvider;
10
- const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
14
+ const getCoinbaseClient = ({ opts: { appLogoUrl, appName = '', evmNetworks = [] } = {}, }) => {
11
15
  var _a, _b;
12
16
  if (!coinbaseProvider) {
13
- const coinbaseWalletSDK = new CoinbaseWalletSDK({
17
+ coinbaseSdk = new CoinbaseWalletSDK({
14
18
  appLogoUrl,
15
19
  appName,
16
20
  enableMobileWalletLink: true,
@@ -21,21 +25,17 @@ const getCoinbaseProvider = ({ opts: { appLogoUrl, appName = '', evmNetworks = [
21
25
  const rpcUrl = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) ||
22
26
  ((_b = network === null || network === void 0 ? void 0 : network.rpcUrls) === null || _b === void 0 ? void 0 : _b[0]) ||
23
27
  jsonRpcUrl;
24
- coinbaseProvider = coinbaseWalletSDK.makeWeb3Provider(rpcUrl, chainId);
28
+ coinbaseProvider = coinbaseSdk.makeWeb3Provider(rpcUrl, chainId);
25
29
  }
26
- return coinbaseProvider;
30
+ return { provider: coinbaseProvider, sdk: coinbaseSdk };
27
31
  };
28
32
  const killCoinbaseSession = () => __awaiter(void 0, void 0, void 0, function* () {
29
33
  yield (coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.close());
30
- coinbaseProvider === null || coinbaseProvider === void 0 ? void 0 : coinbaseProvider.disconnect();
31
- // We needed to remove the provider, because after a disconnect the initial settings that
32
- // were set in the SDK reset, and they need to be initialized again.
33
- coinbaseProvider = undefined;
34
34
  });
35
- const fetchPublicAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const getAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, void 0, void 0, function* () {
36
36
  var _a;
37
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
38
- const { qrUrl } = provider;
37
+ const { provider, sdk } = getCoinbaseClient({ opts: coinbaseProviderOpts });
38
+ const qrUrl = sdk.getQrUrl();
39
39
  if (!qrUrl) {
40
40
  throw new DynamicError('no qr url available');
41
41
  }
@@ -46,7 +46,7 @@ const fetchPublicAddress = (coinbaseProviderOpts, opts) => __awaiter(void 0, voi
46
46
  return address;
47
47
  });
48
48
  const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, void 0, void 0, function* () {
49
- const provider = getCoinbaseProvider({ opts: coinbaseProviderOpts });
49
+ const { provider } = getCoinbaseClient({ opts: coinbaseProviderOpts });
50
50
  const [address] = yield provider.request({
51
51
  method: 'eth_requestAccounts',
52
52
  });
@@ -62,4 +62,4 @@ const signMessage = (coinbaseProviderOpts, messageToSign) => __awaiter(void 0, v
62
62
  }
63
63
  });
64
64
 
65
- export { fetchPublicAddress, getCoinbaseProvider, killCoinbaseSession, signMessage };
65
+ export { getAddress, getCoinbaseClient, killCoinbaseSession, signMessage };
@@ -1,4 +1,4 @@
1
- import { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
1
+ import CoinbaseWalletSDK, { CoinbaseWalletProvider } from '@coinbase/wallet-sdk';
2
2
  import { GenericNetwork } from '@dynamic-labs/types';
3
3
  export type GetCoinbaseProviderOpts = {
4
4
  appLogoUrl?: string;
@@ -8,7 +8,10 @@ export type GetCoinbaseProviderOpts = {
8
8
  export type CoinbaseProviderHandlerOpts = {
9
9
  onDisconnect(): Promise<void>;
10
10
  };
11
- export type GetCoinbaseProvider = (args: {
11
+ export type GetCoinbaseClient = (args: {
12
12
  handlers?: CoinbaseProviderHandlerOpts;
13
13
  opts?: GetCoinbaseProviderOpts;
14
- }) => CoinbaseWalletProvider;
14
+ }) => {
15
+ provider: CoinbaseWalletProvider;
16
+ sdk: CoinbaseWalletSDK;
17
+ };
@@ -5,14 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _tslib = require('../../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
7
  var walletBook = require('@dynamic-labs/wallet-book');
8
- require('../polyfills.cjs');
9
- require('@dynamic-labs/turnkey');
10
- require('@dynamic-labs/utils');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
9
  var ethProviderHelper = require('../ethProviderHelper.cjs');
12
10
  var EthWalletConnector = require('../EthWalletConnector.cjs');
13
- require('../walletConnect/walletConnect.cjs');
14
11
  var client = require('./client/client.cjs');
15
- require('@dynamic-labs/rpc-provider-ethereum');
16
12
 
17
13
  class Coinbase extends EthWalletConnector.EthWalletConnector {
18
14
  constructor(_a) {
@@ -31,10 +27,14 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
31
27
  const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
32
28
  if (!wallet)
33
29
  return;
34
- this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet);
30
+ this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet, this);
35
31
  }
36
32
  setupEventListeners() {
37
33
  var _a, _b, _c;
34
+ if (!this.isInstalledOnBrowser()) {
35
+ this.setupCoinbaseProviderEventListeners();
36
+ return;
37
+ }
38
38
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
39
39
  if (!provider) {
40
40
  return;
@@ -44,28 +44,28 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
44
44
  return;
45
45
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
46
46
  }
47
- getWalletClient() {
47
+ getWalletClient(chainId) {
48
48
  var _a;
49
49
  if (this.isInstalledOnBrowser()) {
50
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
50
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
51
51
  }
52
52
  return viem.createWalletClient({
53
- transport: viem.custom(client.getCoinbaseProvider({
53
+ transport: viem.custom(client.getCoinbaseClient({
54
54
  opts: this.coinbaseProviderOpts,
55
- })),
55
+ }).provider),
56
56
  });
57
57
  }
58
58
  isInstalledOnBrowser() {
59
59
  var _a;
60
60
  return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
61
61
  }
62
- fetchPublicAddress(opts) {
62
+ getAddress(opts) {
63
63
  var _a;
64
64
  return _tslib.__awaiter(this, void 0, void 0, function* () {
65
65
  if (this.isInstalledOnBrowser()) {
66
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
66
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
67
67
  }
68
- return client.fetchPublicAddress(this.coinbaseProviderOpts, opts);
68
+ return client.getAddress(this.coinbaseProviderOpts, opts);
69
69
  });
70
70
  }
71
71
  signMessage(messageToSign) {
@@ -84,6 +84,23 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
84
84
  client.killCoinbaseSession();
85
85
  });
86
86
  }
87
+ setupCoinbaseProviderEventListeners() {
88
+ const { provider } = client.getCoinbaseClient({
89
+ opts: this.coinbaseProviderOpts,
90
+ });
91
+ if (!provider) {
92
+ return;
93
+ }
94
+ const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
95
+ provider.on('accountsChanged', handleAccountChange);
96
+ provider.on('chainChanged', handleChainChange);
97
+ provider.on('disconnect', handleDisconnect);
98
+ this.teardownEventListeners = () => {
99
+ provider.removeListener('accountsChanged', handleAccountChange);
100
+ provider.removeListener('chainChanged', handleChainChange);
101
+ provider.removeListener('disconnect', handleDisconnect);
102
+ };
103
+ }
87
104
  }
88
105
 
89
106
  exports.Coinbase = Coinbase;
@@ -1,5 +1,5 @@
1
- import { Chain, FetchPublicAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
- import { EthProviderHelper } from '..';
1
+ import { Chain, GetAddressOpts } from '@dynamic-labs/wallet-connector-core';
2
+ import { EthProviderHelper } from '../ethProviderHelper';
3
3
  import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
4
4
  type CoinbaseOpts = EthWalletConnectorOpts & {
5
5
  appLogoUrl?: string;
@@ -15,7 +15,7 @@ export declare class Coinbase extends EthWalletConnector {
15
15
  ethProviderHelper: EthProviderHelper | undefined;
16
16
  constructor({ appName, appLogoUrl, evmNetworks, ...props }: CoinbaseOpts);
17
17
  setupEventListeners(): void;
18
- getWalletClient(): {
18
+ getWalletClient(chainId?: string): {
19
19
  account: import("viem").Account | undefined;
20
20
  batch?: {
21
21
  multicall?: boolean | {
@@ -531,8 +531,9 @@ export declare class Coinbase extends EthWalletConnector {
531
531
  } & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, undefined, undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<undefined, undefined>>) => client_1) => import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client_1]: client_1[K_1]; } & import("viem").WalletActions<undefined, undefined>>;
532
532
  } | undefined;
533
533
  isInstalledOnBrowser(): boolean;
534
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
534
+ getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
535
535
  signMessage(messageToSign: string): Promise<string | undefined>;
536
536
  endSession(): Promise<void>;
537
+ private setupCoinbaseProviderEventListeners;
537
538
  }
538
539
  export {};
@@ -1,14 +1,10 @@
1
1
  import { __rest, __awaiter } from '../../_virtual/_tslib.js';
2
2
  import { createWalletClient, custom } from 'viem';
3
3
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
- import '../polyfills.js';
5
- import '@dynamic-labs/turnkey';
6
- import '@dynamic-labs/utils';
4
+ import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
7
5
  import { EthProviderHelper } from '../ethProviderHelper.js';
8
6
  import { EthWalletConnector } from '../EthWalletConnector.js';
9
- import '../walletConnect/walletConnect.js';
10
- import { getCoinbaseProvider, fetchPublicAddress, signMessage, killCoinbaseSession } from './client/client.js';
11
- import '@dynamic-labs/rpc-provider-ethereum';
7
+ import { getCoinbaseClient, getAddress, signMessage, killCoinbaseSession } from './client/client.js';
12
8
 
13
9
  class Coinbase extends EthWalletConnector {
14
10
  constructor(_a) {
@@ -27,10 +23,14 @@ class Coinbase extends EthWalletConnector {
27
23
  const wallet = findWalletBookWallet(this.walletBook, this.key);
28
24
  if (!wallet)
29
25
  return;
30
- this.ethProviderHelper = new EthProviderHelper(wallet);
26
+ this.ethProviderHelper = new EthProviderHelper(wallet, this);
31
27
  }
32
28
  setupEventListeners() {
33
29
  var _a, _b, _c;
30
+ if (!this.isInstalledOnBrowser()) {
31
+ this.setupCoinbaseProviderEventListeners();
32
+ return;
33
+ }
34
34
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
35
35
  if (!provider) {
36
36
  return;
@@ -40,28 +40,28 @@ class Coinbase extends EthWalletConnector {
40
40
  return;
41
41
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
42
42
  }
43
- getWalletClient() {
43
+ getWalletClient(chainId) {
44
44
  var _a;
45
45
  if (this.isInstalledOnBrowser()) {
46
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
46
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
47
47
  }
48
48
  return createWalletClient({
49
- transport: custom(getCoinbaseProvider({
49
+ transport: custom(getCoinbaseClient({
50
50
  opts: this.coinbaseProviderOpts,
51
- })),
51
+ }).provider),
52
52
  });
53
53
  }
54
54
  isInstalledOnBrowser() {
55
55
  var _a;
56
56
  return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
57
57
  }
58
- fetchPublicAddress(opts) {
58
+ getAddress(opts) {
59
59
  var _a;
60
60
  return __awaiter(this, void 0, void 0, function* () {
61
61
  if (this.isInstalledOnBrowser()) {
62
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
62
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
63
63
  }
64
- return fetchPublicAddress(this.coinbaseProviderOpts, opts);
64
+ return getAddress(this.coinbaseProviderOpts, opts);
65
65
  });
66
66
  }
67
67
  signMessage(messageToSign) {
@@ -80,6 +80,23 @@ class Coinbase extends EthWalletConnector {
80
80
  killCoinbaseSession();
81
81
  });
82
82
  }
83
+ setupCoinbaseProviderEventListeners() {
84
+ const { provider } = getCoinbaseClient({
85
+ opts: this.coinbaseProviderOpts,
86
+ });
87
+ if (!provider) {
88
+ return;
89
+ }
90
+ const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
91
+ provider.on('accountsChanged', handleAccountChange);
92
+ provider.on('chainChanged', handleChainChange);
93
+ provider.on('disconnect', handleDisconnect);
94
+ this.teardownEventListeners = () => {
95
+ provider.removeListener('accountsChanged', handleAccountChange);
96
+ provider.removeListener('chainChanged', handleChainChange);
97
+ provider.removeListener('disconnect', handleDisconnect);
98
+ };
99
+ }
83
100
  }
84
101
 
85
102
  export { Coinbase };
@@ -6,11 +6,13 @@ var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
7
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
8
  var utils = require('@dynamic-labs/utils');
9
+ var viemUtils = require('@dynamic-labs/viem-utils');
9
10
  var eip6963Provider = require('./eip6963Provider.cjs');
10
11
 
11
12
  class EthProviderHelper {
12
- constructor(wallet) {
13
+ constructor(wallet, connector) {
13
14
  this.wallet = wallet;
15
+ this.connector = connector;
14
16
  }
15
17
  getInstalledProvider() {
16
18
  const eip6963Config = this.getEip6963Config();
@@ -75,29 +77,32 @@ class EthProviderHelper {
75
77
  findProvider() {
76
78
  return this.getInstalledProvider();
77
79
  }
78
- findWalletClient() {
80
+ findWalletClient(chainId) {
79
81
  const provider = this.findProvider();
80
82
  if (!provider) {
81
83
  return undefined;
82
84
  }
83
85
  return viem.createWalletClient({
86
+ account: this.connector.getActiveAccount(),
87
+ chain: chainId ? viemUtils.chainsMap[chainId] : undefined,
84
88
  transport: viem.custom(provider),
85
89
  });
86
90
  }
87
- fetchPublicAddress() {
91
+ getAddress() {
88
92
  return _tslib.__awaiter(this, void 0, void 0, function* () {
89
93
  const client = this.findWalletClient();
90
94
  if (!client) {
91
95
  return Promise.resolve(undefined);
92
96
  }
93
- return this.fetchPublicAddressWithProvider(client);
97
+ return this.getAddressWithProvider(client);
94
98
  });
95
99
  }
96
- fetchPublicAddressWithProvider(client) {
100
+ getAddressWithProvider(client) {
97
101
  return _tslib.__awaiter(this, void 0, void 0, function* () {
98
102
  try {
99
103
  const [lowercaseAddress] = yield client.requestAddresses();
100
104
  const publicAddress = viem.getAddress(lowercaseAddress);
105
+ this.connector.setActiveAccount(publicAddress);
101
106
  return publicAddress;
102
107
  }
103
108
  catch (err) {
@@ -108,7 +113,7 @@ class EthProviderHelper {
108
113
  }
109
114
  signMessage(messageToSign) {
110
115
  return _tslib.__awaiter(this, void 0, void 0, function* () {
111
- const walletAddress = yield this.fetchPublicAddress();
116
+ const walletAddress = yield this.getAddress();
112
117
  if (!walletAddress) {
113
118
  return Promise.resolve(undefined);
114
119
  }
@@ -2,9 +2,11 @@ import { Hex, WalletClient } from 'viem';
2
2
  import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
3
3
  import { WalletSchema } from '@dynamic-labs/wallet-book';
4
4
  import { IEthereum, ProviderFlag } from './types';
5
+ import { EthWalletConnector } from '.';
5
6
  export declare class EthProviderHelper {
6
7
  private wallet;
7
- constructor(wallet: WalletSchema);
8
+ private connector;
9
+ constructor(wallet: WalletSchema, connector: EthWalletConnector);
8
10
  getInstalledProvider(): IEthereum | undefined;
9
11
  getEip6963Config(): {
10
12
  rdns: string;
@@ -27,9 +29,9 @@ export declare class EthProviderHelper {
27
29
  eip6963ProviderLookup(rdns: string): IEthereum | undefined;
28
30
  isInstalledHelper(): boolean;
29
31
  findProvider(): IEthereum | undefined;
30
- findWalletClient(): WalletClient | undefined;
31
- fetchPublicAddress(): Promise<Hex | undefined>;
32
- fetchPublicAddressWithProvider(client: WalletClient): Promise<Hex | undefined>;
32
+ findWalletClient(chainId?: string): WalletClient | undefined;
33
+ getAddress(): Promise<Hex | undefined>;
34
+ getAddressWithProvider(client: WalletClient): Promise<Hex | undefined>;
33
35
  signMessage(messageToSign: string): Promise<string | undefined>;
34
36
  _setupEventListeners(walletConnector: WalletConnector): {
35
37
  tearDownEventListeners: () => void;
@@ -2,11 +2,13 @@ import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { createWalletClient, custom, getAddress } from 'viem';
3
3
  import { ProviderLookup, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
4
4
  import { getProvidersFromWindow } from '@dynamic-labs/utils';
5
+ import { chainsMap } from '@dynamic-labs/viem-utils';
5
6
  import { Eip6963ProviderSingleton } from './eip6963Provider.js';
6
7
 
7
8
  class EthProviderHelper {
8
- constructor(wallet) {
9
+ constructor(wallet, connector) {
9
10
  this.wallet = wallet;
11
+ this.connector = connector;
10
12
  }
11
13
  getInstalledProvider() {
12
14
  const eip6963Config = this.getEip6963Config();
@@ -71,29 +73,32 @@ class EthProviderHelper {
71
73
  findProvider() {
72
74
  return this.getInstalledProvider();
73
75
  }
74
- findWalletClient() {
76
+ findWalletClient(chainId) {
75
77
  const provider = this.findProvider();
76
78
  if (!provider) {
77
79
  return undefined;
78
80
  }
79
81
  return createWalletClient({
82
+ account: this.connector.getActiveAccount(),
83
+ chain: chainId ? chainsMap[chainId] : undefined,
80
84
  transport: custom(provider),
81
85
  });
82
86
  }
83
- fetchPublicAddress() {
87
+ getAddress() {
84
88
  return __awaiter(this, void 0, void 0, function* () {
85
89
  const client = this.findWalletClient();
86
90
  if (!client) {
87
91
  return Promise.resolve(undefined);
88
92
  }
89
- return this.fetchPublicAddressWithProvider(client);
93
+ return this.getAddressWithProvider(client);
90
94
  });
91
95
  }
92
- fetchPublicAddressWithProvider(client) {
96
+ getAddressWithProvider(client) {
93
97
  return __awaiter(this, void 0, void 0, function* () {
94
98
  try {
95
99
  const [lowercaseAddress] = yield client.requestAddresses();
96
100
  const publicAddress = getAddress(lowercaseAddress);
101
+ this.connector.setActiveAccount(publicAddress);
97
102
  return publicAddress;
98
103
  }
99
104
  catch (err) {
@@ -104,7 +109,7 @@ class EthProviderHelper {
104
109
  }
105
110
  signMessage(messageToSign) {
106
111
  return __awaiter(this, void 0, void 0, function* () {
107
- const walletAddress = yield this.fetchPublicAddress();
112
+ const walletAddress = yield this.getAddress();
108
113
  if (!walletAddress) {
109
114
  return Promise.resolve(undefined);
110
115
  }
package/src/index.cjs CHANGED
@@ -14,12 +14,13 @@ require('@dynamic-labs/rpc-provider-ethereum');
14
14
  var EthWalletConnector = require('./EthWalletConnector.cjs');
15
15
  var ethProviderHelper = require('./ethProviderHelper.cjs');
16
16
  var constants = require('./constants.cjs');
17
+ var isEthWalletConnector = require('./utils/isEthWalletConnector/isEthWalletConnector.cjs');
17
18
 
18
19
  const EthereumWalletConnectors = (props) => [
19
20
  ...fetchInjectedWalletConnectors.injectedWalletOverrides,
20
21
  ...fetchInjectedWalletConnectors.fetchInjectedWalletConnector(props),
21
22
  ...fetchWalletConnectWallets.fetchWalletConnectWallets(props),
22
- ...turnkey.TurnkeyWalletConnectors(props),
23
+ ...turnkey.TurnkeyEVMWalletConnectors(props),
23
24
  coinbase.Coinbase,
24
25
  fetchWalletConnectWallets.getWalletConnectConnector(),
25
26
  ];
@@ -31,4 +32,5 @@ exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOv
31
32
  exports.EthWalletConnector = EthWalletConnector.EthWalletConnector;
32
33
  exports.EthProviderHelper = ethProviderHelper.EthProviderHelper;
33
34
  exports.INFURA_ID = constants.INFURA_ID;
35
+ exports.isEthWalletConnector = isEthWalletConnector.isEthWalletConnector;
34
36
  exports.EthereumWalletConnectors = EthereumWalletConnectors;
package/src/index.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from './EthWalletConnector';
6
6
  export * from './ethProviderHelper';
7
7
  export * from './constants';
8
8
  export * from './types';
9
+ export * from './utils';
9
10
  export declare const EthereumWalletConnectors: (props: any) => WalletConnectorConstructor[];
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import './polyfills.js';
2
- import { TurnkeyWalletConnectors } from '@dynamic-labs/turnkey';
2
+ import { TurnkeyEVMWalletConnectors } from '@dynamic-labs/turnkey';
3
3
  export { PhantomEvm } from './injected/PhantomEvm.js';
4
4
  export { ExodusEvm } from './injected/ExodusEvm.js';
5
5
  import { injectedWalletOverrides, fetchInjectedWalletConnector } from './injected/fetchInjectedWalletConnectors.js';
@@ -11,12 +11,13 @@ import '@dynamic-labs/rpc-provider-ethereum';
11
11
  export { EthWalletConnector } from './EthWalletConnector.js';
12
12
  export { EthProviderHelper } from './ethProviderHelper.js';
13
13
  export { INFURA_ID } from './constants.js';
14
+ export { isEthWalletConnector } from './utils/isEthWalletConnector/isEthWalletConnector.js';
14
15
 
15
16
  const EthereumWalletConnectors = (props) => [
16
17
  ...injectedWalletOverrides,
17
18
  ...fetchInjectedWalletConnector(props),
18
19
  ...fetchWalletConnectWallets(props),
19
- ...TurnkeyWalletConnectors(props),
20
+ ...TurnkeyEVMWalletConnectors(props),
20
21
  Coinbase,
21
22
  getWalletConnectConnector(),
22
23
  ];
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _tslib = require('../../_virtual/_tslib.cjs');
4
4
  var walletBook = require('@dynamic-labs/wallet-book');
5
+ var utils = require('@dynamic-labs/utils');
5
6
  var ethProviderHelper = require('../ethProviderHelper.cjs');
6
7
  var EthWalletConnector = require('../EthWalletConnector.cjs');
7
8
  var walletConnect = require('../walletConnect/walletConnect.cjs');
@@ -20,18 +21,34 @@ class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
20
21
  this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
21
22
  }
22
23
  if (this.wallet && !this.ethProviderHelper) {
23
- this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(this.wallet);
24
+ this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(this.wallet, this);
24
25
  }
25
26
  // this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
26
27
  return this.ethProviderHelper;
27
28
  }
28
29
  getMobileOrInstalledWallet() {
29
- if (this.walletConnectorFallback && !this.isInstalledOnBrowser()) {
30
- if (!this.wallet)
31
- this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
32
- return new walletConnect.WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
30
+ var _a, _b;
31
+ if (!this.wallet) {
32
+ this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
33
+ }
34
+ if (this.isInstalledOnBrowser()) {
35
+ return this;
36
+ }
37
+ // this is to handle the case where the user is in a webview.
38
+ // when the user is in a webview, customers should set the deepLinkPreference prop to universal,
39
+ // in which case this condition will be false, and the SDK will use WalletConnect (if available)
40
+ if (((_b = (_a = this.wallet) === null || _a === void 0 ? void 0 : _a.mobile) === null || _b === void 0 ? void 0 : _b.inAppBrowser) &&
41
+ this.constructorProps.deepLinkPreference !== 'universal' &&
42
+ utils.isMobile()) {
43
+ return this;
44
+ }
45
+ // this is the case where the wallet is not installed on the browser and
46
+ // it does not support WalletConnect. in this case, the SDK will instruct
47
+ // the user to download the wallet extension
48
+ if (!this.walletConnectorFallback) {
49
+ return this;
33
50
  }
34
- return this;
51
+ return new walletConnect.WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
35
52
  }
36
53
  setupEventListeners() {
37
54
  const provider = this.getWalletClient();
@@ -43,23 +60,23 @@ class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
43
60
  const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
44
61
  this.teardownEventListeners = tearDownEventListeners;
45
62
  }
46
- getWalletClient() {
63
+ getWalletClient(chainId) {
47
64
  var _a;
48
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient();
65
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
49
66
  }
50
67
  isInstalledOnBrowser() {
51
68
  var _a;
52
69
  return ((_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
53
70
  }
54
- fetchPublicAddress() {
71
+ getAddress() {
55
72
  var _a;
56
73
  return _tslib.__awaiter(this, void 0, void 0, function* () {
57
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.fetchPublicAddress();
74
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.getAddress();
58
75
  });
59
76
  }
60
77
  connect() {
61
78
  return _tslib.__awaiter(this, void 0, void 0, function* () {
62
- yield this.fetchPublicAddress();
79
+ yield this.getAddress();
63
80
  });
64
81
  }
65
82
  signMessage(messageToSign) {
@@ -14,9 +14,9 @@ declare abstract class InjectedWalletBase extends EthWalletConnector {
14
14
  getEthProviderHelper(): EthProviderHelper | undefined;
15
15
  getMobileOrInstalledWallet(): InjectedWalletBase;
16
16
  setupEventListeners(): void;
17
- getWalletClient(): WalletClient | undefined;
17
+ getWalletClient(chainId?: string): WalletClient | undefined;
18
18
  isInstalledOnBrowser(): boolean;
19
- fetchPublicAddress(): Promise<string | undefined>;
19
+ getAddress(): Promise<string | undefined>;
20
20
  connect(): Promise<void>;
21
21
  signMessage(messageToSign: string): Promise<string | undefined>;
22
22
  proveOwnership(messageToSign: string): Promise<string | undefined>;