@dynamic-labs/ethereum 2.1.0-alpha.2 → 2.1.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.
@@ -5,103 +5,70 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
7
  var viem = require('viem');
8
- var walletBook = require('@dynamic-labs/wallet-book');
9
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
- var ethProviderHelper = require('../ethProviderHelper.cjs');
11
9
  var EthWalletConnector = require('../EthWalletConnector.cjs');
12
- var client = require('./client/client.cjs');
10
+ var helpers = require('./helpers.cjs');
13
11
 
14
12
  class Coinbase extends EthWalletConnector.EthWalletConnector {
15
13
  constructor(_a) {
16
- var { appName, appLogoUrl, evmNetworks } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks"]);
14
+ var { appName, appLogoUrl, evmNetworks, coinbaseWalletPreference } = _a, props = _tslib.__rest(_a, ["appName", "appLogoUrl", "evmNetworks", "coinbaseWalletPreference"]);
17
15
  super(Object.assign({ evmNetworks }, props));
18
16
  this.name = 'Coinbase';
19
17
  this.overrideKey = 'coinbase';
20
18
  this.supportedChains = ['EVM', 'ETH'];
21
19
  this.connectedChain = 'EVM';
22
- this.canConnectViaQrCode = true;
23
- this.coinbaseProviderOpts = {
24
- appLogoUrl: appLogoUrl,
25
- appName: appName,
26
- evmNetworks: evmNetworks,
27
- };
28
- const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
29
- if (!wallet)
30
- return;
31
- this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet, this);
32
- }
33
- setupEventListeners() {
34
- var _a, _b, _c;
35
- if (!this.isInstalledOnBrowser()) {
36
- this.setupCoinbaseProviderEventListeners();
37
- return;
38
- }
39
- const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
40
- if (!provider) {
41
- return;
42
- }
43
- const setupResponse = (_c = (_b = this.ethProviderHelper) === null || _b === void 0 ? void 0 : _b._setupEventListeners) === null || _c === void 0 ? void 0 : _c.call(_b, this);
44
- if (!(setupResponse === null || setupResponse === void 0 ? void 0 : setupResponse.tearDownEventListeners))
45
- return;
46
- this.teardownEventListeners = setupResponse.tearDownEventListeners;
47
- }
48
- getWalletClient(chainId) {
49
- var _a;
50
- if (this.isInstalledOnBrowser()) {
51
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
52
- }
53
- return viem.createWalletClient({
54
- transport: viem.custom(client.getCoinbaseClient({
55
- opts: this.coinbaseProviderOpts,
56
- }).provider),
20
+ this.canConnectViaQrCode = false;
21
+ this.canConnectViaCustodialService = true;
22
+ this.coinbaseProvider = helpers.getCoinbaseProvider({
23
+ opts: {
24
+ appLogoUrl: appLogoUrl,
25
+ appName: appName,
26
+ evmNetworks: evmNetworks,
27
+ walletPreference: coinbaseWalletPreference,
28
+ },
57
29
  });
58
30
  }
59
- isInstalledOnBrowser() {
60
- var _a;
61
- return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
62
- }
63
- getAddress(opts) {
31
+ getAddress() {
64
32
  return _tslib.__awaiter(this, void 0, void 0, function* () {
65
- var _a;
66
- if (this.isInstalledOnBrowser()) {
67
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
68
- }
69
- return client.getAddress(this.coinbaseProviderOpts, opts);
33
+ const [address] = yield this.coinbaseProvider.request({
34
+ method: 'eth_requestAccounts',
35
+ });
36
+ return address;
70
37
  });
71
38
  }
72
39
  signMessage(messageToSign) {
73
40
  return _tslib.__awaiter(this, void 0, void 0, function* () {
74
- var _a;
75
- if (this.isInstalledOnBrowser()) {
76
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
41
+ const [address] = yield this.coinbaseProvider.request({
42
+ method: 'eth_requestAccounts',
43
+ });
44
+ try {
45
+ return yield this.coinbaseProvider.request({
46
+ method: 'personal_sign',
47
+ params: [viem.toHex(viem.toBytes(messageToSign)), address.toLowerCase()],
48
+ });
49
+ }
50
+ catch (err) {
51
+ return undefined;
77
52
  }
78
- return client.signMessage(this.coinbaseProviderOpts, messageToSign);
79
- });
80
- }
81
- endSession() {
82
- return _tslib.__awaiter(this, void 0, void 0, function* () {
83
- if (this.isInstalledOnBrowser())
84
- return;
85
- client.killCoinbaseSession();
86
53
  });
87
54
  }
88
- setupCoinbaseProviderEventListeners() {
89
- const { provider } = client.getCoinbaseClient({
90
- opts: this.coinbaseProviderOpts,
91
- });
92
- if (!provider) {
93
- return;
94
- }
55
+ setupEventListeners() {
95
56
  const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
96
- provider.on('accountsChanged', handleAccountChange);
97
- provider.on('chainChanged', handleChainChange);
98
- provider.on('disconnect', handleDisconnect);
57
+ this.coinbaseProvider.on('accountsChanged', handleAccountChange);
58
+ this.coinbaseProvider.on('chainChanged', handleChainChange);
59
+ this.coinbaseProvider.on('disconnect', handleDisconnect);
99
60
  this.teardownEventListeners = () => {
100
- provider.removeListener('accountsChanged', handleAccountChange);
101
- provider.removeListener('chainChanged', handleChainChange);
102
- provider.removeListener('disconnect', handleDisconnect);
61
+ this.coinbaseProvider.removeListener('accountsChanged', handleAccountChange);
62
+ this.coinbaseProvider.removeListener('chainChanged', handleChainChange);
63
+ this.coinbaseProvider.removeListener('disconnect', handleDisconnect);
103
64
  };
104
65
  }
66
+ getWalletClient() {
67
+ return viem.createWalletClient({
68
+ // add account and chain
69
+ transport: viem.custom(this.coinbaseProvider),
70
+ });
71
+ }
105
72
  }
106
73
 
107
74
  exports.Coinbase = Coinbase;