@dynamic-labs/ethereum 0.18.100-viem.0 → 0.19.0-alpha.1

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 (94) hide show
  1. package/CHANGELOG.md +24 -47
  2. package/package.json +9 -10
  3. package/src/EthWalletConnector.cjs +193 -185
  4. package/src/EthWalletConnector.d.ts +39 -293
  5. package/src/EthWalletConnector.js +194 -186
  6. package/src/constants.d.ts +1 -1
  7. package/src/ethProviderHelper.cjs +204 -213
  8. package/src/ethProviderHelper.d.ts +36 -35
  9. package/src/ethProviderHelper.js +204 -213
  10. package/src/index.cjs +5 -5
  11. package/src/index.d.ts +8 -8
  12. package/src/index.js +5 -5
  13. package/src/injected/BackpackEvm.cjs +14 -14
  14. package/src/injected/BackpackEvm.d.ts +5 -5
  15. package/src/injected/BackpackEvm.js +14 -14
  16. package/src/injected/BloctoInjected.cjs +5 -5
  17. package/src/injected/BloctoInjected.d.ts +4 -4
  18. package/src/injected/BloctoInjected.js +5 -5
  19. package/src/injected/BraveEvm.cjs +5 -5
  20. package/src/injected/BraveEvm.d.ts +4 -4
  21. package/src/injected/BraveEvm.js +5 -5
  22. package/src/injected/Dawn.cjs +5 -5
  23. package/src/injected/Dawn.d.ts +4 -4
  24. package/src/injected/Dawn.js +5 -5
  25. package/src/injected/ExodusEvm.cjs +5 -5
  26. package/src/injected/ExodusEvm.d.ts +4 -4
  27. package/src/injected/ExodusEvm.js +5 -5
  28. package/src/injected/Frame.cjs +5 -5
  29. package/src/injected/Frame.d.ts +4 -4
  30. package/src/injected/Frame.js +5 -5
  31. package/src/injected/GameStop.cjs +5 -5
  32. package/src/injected/GameStop.d.ts +4 -4
  33. package/src/injected/GameStop.js +5 -5
  34. package/src/injected/InjectedWalletBase.cjs +65 -70
  35. package/src/injected/InjectedWalletBase.d.ts +24 -24
  36. package/src/injected/InjectedWalletBase.js +65 -70
  37. package/src/injected/MetaMask.cjs +6 -6
  38. package/src/injected/MetaMask.d.ts +5 -5
  39. package/src/injected/MetaMask.js +6 -6
  40. package/src/injected/Opera.cjs +5 -5
  41. package/src/injected/Opera.d.ts +4 -4
  42. package/src/injected/Opera.js +5 -5
  43. package/src/injected/PhantomEvm.cjs +27 -27
  44. package/src/injected/PhantomEvm.d.ts +5 -5
  45. package/src/injected/PhantomEvm.js +27 -27
  46. package/src/injected/Rabby.cjs +6 -6
  47. package/src/injected/Rabby.d.ts +5 -5
  48. package/src/injected/Rabby.js +6 -6
  49. package/src/injected/Superb.cjs +5 -5
  50. package/src/injected/Superb.d.ts +4 -4
  51. package/src/injected/Superb.js +5 -5
  52. package/src/injected/Trust.cjs +6 -6
  53. package/src/injected/Trust.d.ts +5 -5
  54. package/src/injected/Trust.js +6 -6
  55. package/src/injected/UnknownInjectedWallet.cjs +5 -5
  56. package/src/injected/UnknownInjectedWallet.d.ts +4 -4
  57. package/src/injected/UnknownInjectedWallet.js +5 -5
  58. package/src/injected/Zerion.cjs +6 -6
  59. package/src/injected/Zerion.d.ts +5 -5
  60. package/src/injected/Zerion.js +6 -6
  61. package/src/injected/index.cjs +16 -16
  62. package/src/injected/index.d.ts +16 -16
  63. package/src/injected/index.js +16 -16
  64. package/src/polyfills.cjs +11 -11
  65. package/src/polyfills.d.ts +1 -1
  66. package/src/polyfills.js +11 -11
  67. package/src/types.d.ts +23 -25
  68. package/src/utils/findEvmNetwork.cjs +13 -13
  69. package/src/utils/findEvmNetwork.d.ts +6 -6
  70. package/src/utils/findEvmNetwork.js +13 -13
  71. package/src/utils/isString.d.ts +1 -1
  72. package/src/utils/isUnsupportedProviderError/index.d.ts +1 -1
  73. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +6 -6
  74. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -6
  75. package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +6 -6
  76. package/src/utils/last.d.ts +1 -1
  77. package/src/utils/parseIntSafe.cjs +13 -13
  78. package/src/utils/parseIntSafe.d.ts +1 -1
  79. package/src/utils/parseIntSafe.js +13 -13
  80. package/src/walletConnect/client/client.cjs +176 -180
  81. package/src/walletConnect/client/client.d.ts +17 -17
  82. package/src/walletConnect/client/client.js +176 -180
  83. package/src/walletConnect/client/index.d.ts +1 -1
  84. package/src/walletConnect/client/types.d.ts +4 -4
  85. package/src/walletConnect/fetchWalletConnectWallets.cjs +50 -50
  86. package/src/walletConnect/fetchWalletConnectWallets.d.ts +10 -10
  87. package/src/walletConnect/fetchWalletConnectWallets.js +50 -50
  88. package/src/walletConnect/index.d.ts +3 -3
  89. package/src/walletConnect/walletConnect.cjs +130 -132
  90. package/src/walletConnect/walletConnect.d.ts +50 -50
  91. package/src/walletConnect/walletConnect.js +130 -132
  92. package/src/walletConnect/walletConnectV2.cjs +374 -371
  93. package/src/walletConnect/walletConnectV2.d.ts +61 -315
  94. package/src/walletConnect/walletConnectV2.js +375 -372
package/CHANGELOG.md CHANGED
@@ -1,59 +1,36 @@
1
1
 
2
- ## [0.18.100-viem.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.29...v0.18.100-viem.0) (2023-08-04)
2
+ ## [0.19.0-alpha.1](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.0...v0.19.0-alpha.1) (2023-08-10)
3
3
 
4
- ### Bug Fixes
5
-
6
- * add improves to wallet events handling
7
-
8
- ## [0.18.0-beta.29](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-beta.28...v0.18.0-beta.29) (2023-08-03)
9
-
10
-
11
- ### ⚠ BREAKING CHANGES
12
-
13
- * remove deprecated multiwallet prop (#2821)
14
-
15
- ### Bug Fixes
16
-
17
- * array of dynamicWagmiSettings not being sent, must be turned into object ([#2837](https://github.com/dynamic-labs/DynamicAuth/issues/2837)) ([fc5051d](https://github.com/dynamic-labs/DynamicAuth/commit/fc5051d3ce4c5e28d54a74cc9d74424748b52df9)), closes [#2835](https://github.com/dynamic-labs/DynamicAuth/issues/2835)
18
- * change network modal doesn't pop on secondary wallet, when primaryWallet was disconnected ([#2831](https://github.com/dynamic-labs/DynamicAuth/issues/2831)) ([4a78cc8](https://github.com/dynamic-labs/DynamicAuth/commit/4a78cc8c9004e6716fa9e35d8572c57bfd8bdc22))
19
- * connectSuccess callback is not being called when connecting new wallet after unlink ([#2829](https://github.com/dynamic-labs/DynamicAuth/issues/2829)) ([37795e5](https://github.com/dynamic-labs/DynamicAuth/commit/37795e5304d65766968ae6168d329b899c0afdfa))
20
- * **wcv2:** simulate chain change event in switchNetwork ([#2827](https://github.com/dynamic-labs/DynamicAuth/issues/2827)) ([98cff76](https://github.com/dynamic-labs/DynamicAuth/commit/98cff7687112ddbf2971fa4e42cc959f5be62014)), closes [#2809](https://github.com/dynamic-labs/DynamicAuth/issues/2809)
21
- * wrong wallet list is showing after disconnecting and network change ([#2832](https://github.com/dynamic-labs/DynamicAuth/issues/2832)) ([b7af548](https://github.com/dynamic-labs/DynamicAuth/commit/b7af5480a0f05b851cf9accb3ab0870fd2836a92))
22
-
23
-
24
- * remove deprecated multiwallet prop ([#2821](https://github.com/dynamic-labs/DynamicAuth/issues/2821)) ([d95173d](https://github.com/dynamic-labs/DynamicAuth/commit/d95173de890104b1b94b612976682c9d86ec4b17))
25
-
26
- ## [0.18.0-beta.28](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.27...v0.18.0-beta.28) (2023-08-03)
27
-
28
-
29
- ### Bug Fixes
30
-
31
- * gracefully handle walletbook fallbacks ([#2812](https://github.com/dynamic-labs/DynamicAuth/issues/2812)) ([#2822](https://github.com/dynamic-labs/DynamicAuth/issues/2822)) ([8e737d6](https://github.com/dynamic-labs/DynamicAuth/commit/8e737d602d64fa2414ba136799b8878e975a40a2))
32
-
33
- ## [0.18.0-RC.27](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.26...v0.18.0-RC.27) (2023-08-03)
34
-
35
- ### Bug Fixes
36
-
37
- * fixes circular dependency issues on usePromise
38
-
39
- ## [0.18.0-RC.26](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.24...v0.18.0-RC.26) (2023-08-02)
40
-
41
-
42
- ### ⚠ BREAKING CHANGES
43
-
44
- * displayTermsOfService prop set to false breaks message verfication (#2751)
45
4
 
46
5
  ### Features
47
6
 
48
- * send wagmi settings from wagmi connector ([#2791](https://github.com/dynamic-labs/DynamicAuth/issues/2791)) ([#2800](https://github.com/dynamic-labs/DynamicAuth/issues/2800)) ([5b65605](https://github.com/dynamic-labs/DynamicAuth/commit/5b656059361a48de57e01ad2dd81de0bc9b2c7e8))
7
+ * cleaning up email input field - delete continue button ([#2833](https://github.com/dynamic-labs/DynamicAuth/issues/2833)) ([baa399e](https://github.com/dynamic-labs/DynamicAuth/commit/baa399e387bce9570a7e7774d68dc3c92f86be1b))
8
+ * disable social buttons after provider is selected ([#2875](https://github.com/dynamic-labs/DynamicAuth/issues/2875)) ([6296ce1](https://github.com/dynamic-labs/DynamicAuth/commit/6296ce13062a8589cf6fb4741957dc9bf84552a2))
9
+ * **GVTY-65:** Allow Merging accounts when duplicated email in KYC step ([#2772](https://github.com/dynamic-labs/DynamicAuth/issues/2772)) ([8efb6ae](https://github.com/dynamic-labs/DynamicAuth/commit/8efb6aecc9445ef1798a5c6358eac27b16f661b6))
10
+ * hide network from nav if hideNetworkInDynamicWidget setting is true ([#2842](https://github.com/dynamic-labs/DynamicAuth/issues/2842)) ([f3dc9ba](https://github.com/dynamic-labs/DynamicAuth/commit/f3dc9ba987781d5d0540336f351bb9f148400eac))
11
+ * show email submit button on focus ([#2860](https://github.com/dynamic-labs/DynamicAuth/issues/2860)) ([87d8ae0](https://github.com/dynamic-labs/DynamicAuth/commit/87d8ae0806425a25835efda5f9b9abc58e5de18e))
49
12
 
50
13
 
51
14
  ### Bug Fixes
52
15
 
53
- * always call onBeforeConnectSuccess callback when wallet state changes ([#2786](https://github.com/dynamic-labs/DynamicAuth/issues/2786)) ([e2eaef3](https://github.com/dynamic-labs/DynamicAuth/commit/e2eaef3da1f80cdc7dc21e902e9c033e581242d2))
54
- * displayTermsOfService prop set to false breaks message verfication ([#2751](https://github.com/dynamic-labs/DynamicAuth/issues/2751)) ([6433732](https://github.com/dynamic-labs/DynamicAuth/commit/6433732fac87d641f2475d19ef743ac31130274f))
55
- * ensure auto-redirect back to dapp after message signing ([#2783](https://github.com/dynamic-labs/DynamicAuth/issues/2783)) ([dba4664](https://github.com/dynamic-labs/DynamicAuth/commit/dba466473ecc2afd808cdae0fd9023d38676b01f))
56
- * use css.supports only when available ([#2802](https://github.com/dynamic-labs/DynamicAuth/issues/2802)) ([7651898](https://github.com/dynamic-labs/DynamicAuth/commit/76518982a97e728ab65549f37f55b537eed4e890))
16
+ * account already exist message not displaying automatically ([#2896](https://github.com/dynamic-labs/DynamicAuth/issues/2896)) ([ba56c93](https://github.com/dynamic-labs/DynamicAuth/commit/ba56c936546428b0a1111ab5ef6e8d0d9a463bb5))
17
+ * array of dynamicWagmiSettings not being sent, must be turned into object ([#2835](https://github.com/dynamic-labs/DynamicAuth/issues/2835)) ([092c45a](https://github.com/dynamic-labs/DynamicAuth/commit/092c45afd3676fbd7c3d28f51818470de7f95768))
18
+ * change network modal doesn't pop on secondary wallet, when primaryWallet was disconnected ([#2817](https://github.com/dynamic-labs/DynamicAuth/issues/2817)) ([b68c156](https://github.com/dynamic-labs/DynamicAuth/commit/b68c1565f936d2f4275b104a0881ba5720101abd))
19
+ * connectSuccess callback is not being called when connecting new wallet after unlink ([#2814](https://github.com/dynamic-labs/DynamicAuth/issues/2814)) ([d5b34d8](https://github.com/dynamic-labs/DynamicAuth/commit/d5b34d8a073436ce39280766608578fd97567fac))
20
+ * css variables are being ignored for ConnectButton component ([#2869](https://github.com/dynamic-labs/DynamicAuth/issues/2869)) ([a54fb46](https://github.com/dynamic-labs/DynamicAuth/commit/a54fb46648758001450a33e6d86cf04765507701))
21
+ * css variables for the ConnectButton are being ignored ([#2856](https://github.com/dynamic-labs/DynamicAuth/issues/2856)) ([65a342f](https://github.com/dynamic-labs/DynamicAuth/commit/65a342f828b6a16f714fc6b6e2066e1b742b2c0a))
22
+ * don't let user update email if it's linked to an embedded wallet ([#2883](https://github.com/dynamic-labs/DynamicAuth/issues/2883)) ([99aa303](https://github.com/dynamic-labs/DynamicAuth/commit/99aa3033e62c0dee14657cb811db8d5b3597f7de))
23
+ * **GVTY-150:** blocto pop up to sign after disconnect ([#2854](https://github.com/dynamic-labs/DynamicAuth/issues/2854)) ([df5481b](https://github.com/dynamic-labs/DynamicAuth/commit/df5481b2d5438848ad96cdee402f40b520bead08))
24
+ * **GVTY-155:** update to the new design ([#2889](https://github.com/dynamic-labs/DynamicAuth/issues/2889)) ([31f7f54](https://github.com/dynamic-labs/DynamicAuth/commit/31f7f54444c623fe7d5bcf8a42f94ee22eedc3e1))
25
+ * **GVTY-159:** email update view not showing email used error ([#2887](https://github.com/dynamic-labs/DynamicAuth/issues/2887)) ([bd40e4c](https://github.com/dynamic-labs/DynamicAuth/commit/bd40e4c77cda42752d44e42b98bfcea4cfd77a80))
26
+ * **OTPOverviewView:** enable close only on close button click ([#2877](https://github.com/dynamic-labs/DynamicAuth/issues/2877)) ([2be23e7](https://github.com/dynamic-labs/DynamicAuth/commit/2be23e7ddefe67c971d863ad9069ac5b8a74f4e5))
27
+ * **transaction:** improve gas estimate in transaction confirmation ([#2767](https://github.com/dynamic-labs/DynamicAuth/issues/2767)) ([7180ae5](https://github.com/dynamic-labs/DynamicAuth/commit/7180ae50559f924ae9769b2b8d87eadc6604c754))
28
+ * use findSocialIcon instead getSocialIcon to avoid render errors ([#2834](https://github.com/dynamic-labs/DynamicAuth/issues/2834)) ([2c57f98](https://github.com/dynamic-labs/DynamicAuth/commit/2c57f98fd5c461ae4acbe2836f719ebe18bc21fc))
29
+ * **useWalletConnectorEvent:** ensure connector is initialized ([#2849](https://github.com/dynamic-labs/DynamicAuth/issues/2849)) ([9137131](https://github.com/dynamic-labs/DynamicAuth/commit/913713166af8a6e6cc15a8e362e57b328fc0a76f))
30
+ * **wcv2:** simulate chain change event in switchNetwork ([#2809](https://github.com/dynamic-labs/DynamicAuth/issues/2809)) ([2329b80](https://github.com/dynamic-labs/DynamicAuth/commit/2329b808f57644cebb664be536bc41e256d108d8))
31
+ * wrong wallet list is showing after disconnecting and network change ([#2815](https://github.com/dynamic-labs/DynamicAuth/issues/2815)) ([6cae101](https://github.com/dynamic-labs/DynamicAuth/commit/6cae1019f40be4ffe7ab0426aa159c652a770a82))
32
+
33
+ ## [0.19.0-alpha.0](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.25...v0.19.0-alpha.0) (2023-08-01)
57
34
 
58
35
  ## [0.18.0-RC.25](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.24...v0.18.0-RC.25) (2023-08-01)
59
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "0.18.100-viem.0",
3
+ "version": "0.19.0-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -29,16 +29,15 @@
29
29
  "@walletconnect/client": "1.8.0",
30
30
  "@walletconnect/ethereum-provider": "1.8.0",
31
31
  "@walletconnect/universal-provider": "2.8.3",
32
+ "ethers": "5.7.2",
32
33
  "eventemitter3": "5.0.1",
33
34
  "buffer": "6.0.3",
34
- "@dynamic-labs/rpc-providers": "0.18.100-viem.0",
35
- "@dynamic-labs/types": "0.18.100-viem.0",
36
- "@dynamic-labs/utils": "0.18.100-viem.0",
37
- "@dynamic-labs/wallet-book": "0.18.100-viem.0",
38
- "@dynamic-labs/wallet-connector-core": "0.18.100-viem.0",
39
- "stream": "0.0.2"
35
+ "@dynamic-labs/rpc-providers": "0.19.0-alpha.1",
36
+ "@dynamic-labs/types": "0.19.0-alpha.1",
37
+ "@dynamic-labs/utils": "0.19.0-alpha.1",
38
+ "@dynamic-labs/wallet-book": "0.19.0-alpha.1",
39
+ "@dynamic-labs/wallet-connector-core": "0.19.0-alpha.1",
40
+ "@ethersproject/providers": "5.7.2"
40
41
  },
41
- "peerDependencies": {
42
- "viem": "^1.1.0"
43
- }
42
+ "peerDependencies": {}
44
43
  }
@@ -3,196 +3,204 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../_virtual/_tslib.cjs');
6
- var viem = require('viem');
6
+ var ethers = require('ethers');
7
7
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
8
  var utils = require('@dynamic-labs/utils');
9
9
  var rpcProviders = require('@dynamic-labs/rpc-providers');
10
10
  var findEvmNetwork = require('./utils/findEvmNetwork.cjs');
11
11
 
12
- class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
13
- getRpcProvider() {
14
- var _a, _b, _c;
15
- return _tslib.__awaiter(this, void 0, void 0, function* () {
16
- const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
17
- if (this.evmNetworks.length === 0) {
18
- return undefined;
19
- }
20
- const configurations = {
21
- cosmos: [],
22
- evm: this.evmNetworks,
23
- solana: [],
24
- starknet: undefined,
25
- };
26
- return (_c = (_b = this.chainRpcProviders) === null || _b === void 0 ? void 0 : _b.getEvmProviderByChainId(configurations, networkId)) === null || _c === void 0 ? void 0 : _c.provider;
27
- });
28
- }
29
- constructor(props) {
30
- var _a;
31
- super(props);
32
- this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
33
- var _a;
34
- [acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
35
- ? network.privateCustomerRpcUrls
36
- : network.rpcUrls;
37
- return acc;
38
- }, {});
39
- this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
40
- this.chainRpcProviders = props.chainRpcProviders;
41
- (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerChainProviders(rpcProviders.ProviderChain.EVM, (config) => {
42
- const rpcProviders = {};
43
- if (config === null || config === void 0 ? void 0 : config.evm) {
44
- rpcProviders.evm = utils.parseEvmNetworks(config.evm).map((network) => {
45
- var _a;
46
- const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
47
- const provider = viem.createPublicClient({
48
- chain: utils.getOrMapViemChain(network),
49
- transport: viem.http(rpcUrl),
50
- });
51
- return {
52
- chainId: network.chainId,
53
- chainName: network.name,
54
- provider,
55
- };
56
- });
57
- }
58
- return rpcProviders.evm;
59
- });
60
- }
61
- getNetwork() {
62
- return _tslib.__awaiter(this, void 0, void 0, function* () {
63
- const provider = this.getWeb3Provider();
64
- if (!this.supportsNetworkSwitching || !provider) {
65
- return Promise.resolve(undefined);
66
- }
67
- return yield provider.getChainId();
68
- });
69
- }
70
- getNameService() {
71
- return _tslib.__awaiter(this, void 0, void 0, function* () {
72
- const [[address], rpcProvider] = yield Promise.all([
73
- this.getConnectedAccounts(),
74
- this.getRpcProvider(),
75
- ]);
76
- if (!address || !rpcProvider) {
77
- return;
78
- }
79
- const ensName = yield rpcProvider.getEnsName({
80
- address: address,
81
- });
82
- const ensAvatar = ensName
83
- ? yield rpcProvider.getEnsAvatar({
84
- name: ensName,
85
- })
86
- : undefined;
87
- const ensData = {
88
- avatar: ensAvatar !== null && ensAvatar !== void 0 ? ensAvatar : undefined,
89
- name: ensName !== null && ensName !== void 0 ? ensName : undefined,
90
- };
91
- return ensData;
92
- });
93
- }
94
- getSigner() {
95
- return _tslib.__awaiter(this, void 0, void 0, function* () {
96
- return this.getWeb3Provider();
97
- });
98
- }
99
- getBalance() {
100
- return _tslib.__awaiter(this, void 0, void 0, function* () {
101
- // This is equivalent to getSigner().getAddress() but does not crash
102
- // if the signer is not available
103
- const [address] = yield this.getConnectedAccounts();
104
- if (!address)
105
- return;
106
- const client = yield this.getRpcProvider();
107
- const result = yield (client === null || client === void 0 ? void 0 : client.getBalance({
108
- address: address,
109
- }));
110
- if (!result && result !== BigInt(0))
111
- return;
112
- return viem.formatEther(result);
113
- });
114
- }
115
- supportsNetworkSwitching() {
116
- return true;
117
- }
118
- switchNetwork({ networkName, networkChainId, }) {
119
- return _tslib.__awaiter(this, void 0, void 0, function* () {
120
- const network = findEvmNetwork.findEvmNetwork({
121
- chainId: networkChainId,
122
- name: networkName,
123
- networks: this.evmNetworks,
124
- });
125
- if (!network) {
126
- throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
127
- }
128
- if (!this.supportsNetworkSwitching()) {
129
- throw new utils.DynamicError('Network switching is not supported');
130
- }
131
- const provider = yield this.getWeb3Provider();
132
- if (!provider) {
133
- throw new utils.DynamicError('Provider not found');
134
- }
135
- return this.providerSwitchNetwork({ network, provider });
136
- });
137
- }
138
- getConnectedAccounts() {
139
- return _tslib.__awaiter(this, void 0, void 0, function* () {
140
- const provider = yield this.getWeb3Provider();
141
- if (!provider)
142
- return [];
143
- return provider.getAddresses();
144
- });
145
- }
146
- providerSwitchNetwork({ network, provider, }) {
147
- var _a, _b, _c;
148
- return _tslib.__awaiter(this, void 0, void 0, function* () {
149
- const { chainId } = network;
150
- const currentNetworkId = yield this.getNetwork();
151
- if (currentNetworkId && currentNetworkId === chainId) {
152
- return;
153
- }
154
- try {
155
- if (!this.supportsNetworkSwitching()) {
156
- throw new utils.DynamicError('Network switching is not supported');
157
- }
158
- return yield provider.switchChain(utils.getOrMapViemChain(network));
159
- }
160
- catch (error) {
161
- if (((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('rejected')) ||
162
- (typeof error === 'string' && error.includes('rejected'))) {
163
- throw new utils.DynamicError("User rejected the wallet's request to switch network");
164
- }
165
- else if (error.code === 4902 ||
166
- error.message.includes('Unrecognized chain') ||
167
- // https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
168
- ((_c = (_b = error === null || error === void 0 ? void 0 : error.data) === null || _b === void 0 ? void 0 : _b.orginalError) === null || _c === void 0 ? void 0 : _c.code) === 4902) {
169
- // error code indicates the chain has not been added yet
170
- // https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
171
- return this.providerAddNetwork({ network, provider });
172
- }
173
- else {
174
- throw error;
175
- }
176
- }
177
- });
178
- }
179
- providerAddNetwork({ network, provider, }) {
180
- var _a;
181
- return _tslib.__awaiter(this, void 0, void 0, function* () {
182
- try {
183
- return yield provider.addChain({ chain: utils.getOrMapViemChain(network) });
184
- }
185
- catch (error) {
186
- if (((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('rejected')) ||
187
- (typeof error === 'string' && error.includes('rejected'))) {
188
- throw new utils.DynamicError("User rejected the wallet's request to add network");
189
- }
190
- else {
191
- throw error;
192
- }
193
- }
194
- });
195
- }
12
+ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
13
+ getRpcProvider() {
14
+ var _a, _b, _c;
15
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
16
+ const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
17
+ if (this.evmNetworks.length === 0) {
18
+ return undefined;
19
+ }
20
+ const configurations = {
21
+ cosmos: [],
22
+ evm: this.evmNetworks,
23
+ solana: [],
24
+ starknet: undefined,
25
+ };
26
+ return (_c = (_b = this.chainRpcProviders) === null || _b === void 0 ? void 0 : _b.getEvmProviderByChainId(configurations, networkId)) === null || _c === void 0 ? void 0 : _c.provider;
27
+ });
28
+ }
29
+ constructor(props) {
30
+ var _a;
31
+ super(props);
32
+ this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
33
+ var _a;
34
+ [acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
35
+ ? network.privateCustomerRpcUrls
36
+ : network.rpcUrls;
37
+ return acc;
38
+ }, {});
39
+ this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
40
+ this.chainRpcProviders = props.chainRpcProviders;
41
+ (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerChainProviders(rpcProviders.ProviderChain.EVM, (config) => {
42
+ const rpcProviders = {};
43
+ if (config === null || config === void 0 ? void 0 : config.evm) {
44
+ rpcProviders.evm = utils.parseEvmNetworks(config.evm).map((network) => {
45
+ var _a;
46
+ const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
47
+ const provider = new ethers.ethers.providers.JsonRpcProvider(rpcUrl, network.chainId);
48
+ return {
49
+ chainId: network.chainId,
50
+ chainName: network.name,
51
+ provider,
52
+ };
53
+ });
54
+ }
55
+ return rpcProviders.evm;
56
+ });
57
+ }
58
+ getNetwork() {
59
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
60
+ const provider = this.getWeb3Provider();
61
+ if (!this.supportsNetworkSwitching ||
62
+ !provider ||
63
+ !('getNetwork' in provider)) {
64
+ return Promise.resolve(undefined);
65
+ }
66
+ const network = yield provider.getNetwork();
67
+ return Promise.resolve(network === null || network === void 0 ? void 0 : network.chainId);
68
+ });
69
+ }
70
+ getNameService() {
71
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
72
+ const [[address], provider] = yield Promise.all([
73
+ this.getConnectedAccounts(),
74
+ this.getRpcProvider(),
75
+ ]);
76
+ if (!address || !provider || !('lookupAddress' in provider)) {
77
+ return;
78
+ }
79
+ const [ensName, ensAvatar] = yield Promise.all([
80
+ provider.lookupAddress(address),
81
+ provider.getAvatar(address),
82
+ ]);
83
+ const ensData = {
84
+ avatar: ensAvatar !== null && ensAvatar !== void 0 ? ensAvatar : undefined,
85
+ name: ensName !== null && ensName !== void 0 ? ensName : undefined,
86
+ };
87
+ return ensData;
88
+ });
89
+ }
90
+ getSigner() {
91
+ var _a;
92
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
93
+ return (_a = this.getWeb3Provider()) === null || _a === void 0 ? void 0 : _a.getSigner();
94
+ });
95
+ }
96
+ getBalance() {
97
+ var _a;
98
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
99
+ // This is equivalent to getSigner().getAddress() but does not crash
100
+ // if the signer is not available
101
+ const [address] = yield this.getConnectedAccounts();
102
+ if (!address)
103
+ return;
104
+ const result = yield ((_a = this.getWeb3Provider()) === null || _a === void 0 ? void 0 : _a.getBalance(address));
105
+ if (!result)
106
+ return;
107
+ return ethers.ethers.utils.formatEther(result);
108
+ });
109
+ }
110
+ supportsNetworkSwitching() {
111
+ return true;
112
+ }
113
+ switchNetwork({ networkName, networkChainId, }) {
114
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
115
+ const network = findEvmNetwork.findEvmNetwork({
116
+ chainId: networkChainId,
117
+ name: networkName,
118
+ networks: this.evmNetworks,
119
+ });
120
+ if (!network) {
121
+ throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
122
+ }
123
+ if (!this.supportsNetworkSwitching()) {
124
+ throw new utils.DynamicError('Network switching is not supported');
125
+ }
126
+ const provider = this.getWeb3Provider();
127
+ if (!provider) {
128
+ throw new utils.DynamicError('Provider not found');
129
+ }
130
+ return this.providerSwitchNetwork({ network, provider });
131
+ });
132
+ }
133
+ getConnectedAccounts() {
134
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
135
+ const provider = this.getWeb3Provider();
136
+ if (!provider)
137
+ return [];
138
+ return provider.send('eth_accounts', []);
139
+ });
140
+ }
141
+ providerSwitchNetwork({ network, provider, }) {
142
+ var _a, _b, _c;
143
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
144
+ const { chainId } = network;
145
+ const currentNetworkId = yield this.getNetwork();
146
+ if (currentNetworkId && currentNetworkId === chainId) {
147
+ return;
148
+ }
149
+ try {
150
+ if (!this.supportsNetworkSwitching()) {
151
+ throw new utils.DynamicError('Network switching is not supported');
152
+ }
153
+ return yield provider.send('wallet_switchEthereumChain', [
154
+ {
155
+ chainId: `0x${chainId.toString(16)}`,
156
+ },
157
+ ]);
158
+ }
159
+ catch (error) {
160
+ if (((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('rejected')) ||
161
+ (typeof error === 'string' && error.includes('rejected'))) {
162
+ throw new utils.DynamicError("User rejected the wallet's request to switch network");
163
+ }
164
+ else if (error.code === 4902 ||
165
+ error.message.includes('Unrecognized chain') ||
166
+ // https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
167
+ ((_c = (_b = error === null || error === void 0 ? void 0 : error.data) === null || _b === void 0 ? void 0 : _b.orginalError) === null || _c === void 0 ? void 0 : _c.code) === 4902) {
168
+ // error code indicates the chain has not been added yet
169
+ // https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
170
+ return this.providerAddNetwork({ network, provider });
171
+ }
172
+ else {
173
+ throw error;
174
+ }
175
+ }
176
+ });
177
+ }
178
+ providerAddNetwork({ network, provider, }) {
179
+ var _a;
180
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
181
+ const { blockExplorerUrls, chainId, nativeCurrency, rpcUrls, name } = network;
182
+ try {
183
+ return yield provider.send('wallet_addEthereumChain', [
184
+ {
185
+ blockExplorerUrls,
186
+ chainId: `0x${chainId.toString(16)}`,
187
+ chainName: name,
188
+ nativeCurrency,
189
+ rpcUrls,
190
+ },
191
+ ]);
192
+ }
193
+ catch (error) {
194
+ if (((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('rejected')) ||
195
+ (typeof error === 'string' && error.includes('rejected'))) {
196
+ throw new utils.DynamicError("User rejected the wallet's request to add network");
197
+ }
198
+ else {
199
+ throw error;
200
+ }
201
+ }
202
+ });
203
+ }
196
204
  }
197
205
 
198
206
  exports.EthWalletConnector = EthWalletConnector;