@broxus/evm-connect 1.3.3 → 1.3.4

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 (31) hide show
  1. package/dist/cjs/components/EvmProvidersDispatcher/ProviderButton/index.js +2 -2
  2. package/dist/cjs/core/EIP6963Connector.d.ts +2 -2
  3. package/dist/cjs/core/EIP6963Connector.js +1 -1
  4. package/dist/cjs/core/EthereumConnector.d.ts +2 -2
  5. package/dist/cjs/core/MetaMask.d.ts +2 -2
  6. package/dist/cjs/core/MetaMask.js +1 -1
  7. package/dist/cjs/core/WalletConnect.d.ts +2 -2
  8. package/dist/cjs/core/WalletConnect.js +1 -1
  9. package/dist/cjs/hooks/useRecentConnectionMeta.d.ts +2 -2
  10. package/dist/cjs/hooks/useRecentConnectionMeta.js +1 -1
  11. package/dist/cjs/services/EvmWalletService.d.ts +9 -4
  12. package/dist/cjs/services/EvmWalletService.js +18 -17
  13. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  14. package/dist/cjs/types.d.ts +1 -1
  15. package/dist/cjs/types.js +8 -8
  16. package/dist/esm/components/EvmProvidersDispatcher/ProviderButton/index.js +3 -3
  17. package/dist/esm/core/EIP6963Connector.d.ts +2 -2
  18. package/dist/esm/core/EIP6963Connector.js +2 -2
  19. package/dist/esm/core/EthereumConnector.d.ts +2 -2
  20. package/dist/esm/core/MetaMask.d.ts +2 -2
  21. package/dist/esm/core/MetaMask.js +2 -2
  22. package/dist/esm/core/WalletConnect.d.ts +2 -2
  23. package/dist/esm/core/WalletConnect.js +2 -2
  24. package/dist/esm/hooks/useRecentConnectionMeta.d.ts +2 -2
  25. package/dist/esm/hooks/useRecentConnectionMeta.js +2 -2
  26. package/dist/esm/services/EvmWalletService.d.ts +9 -4
  27. package/dist/esm/services/EvmWalletService.js +18 -17
  28. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  29. package/dist/esm/types.d.ts +1 -1
  30. package/dist/esm/types.js +7 -7
  31. package/package.json +5 -5
@@ -45,7 +45,7 @@ exports.ProviderButton = (0, mobx_react_lite_1.observer)((props) => {
45
45
  const walletProviders = (0, context_1.useEvmWalletProviders)();
46
46
  const { providerConfig, onSelect: onSelectProvider } = props;
47
47
  const [hasProvider, setHasProvider] = React.useState(() => {
48
- if (providerConfig.connector.type === types_1.ConnectionType.WALLET_CONNECT_V2) {
48
+ if (providerConfig.connector.type === types_1.EthereumConnectionType.WALLET_CONNECT_V2) {
49
49
  return true;
50
50
  }
51
51
  return undefined;
@@ -57,7 +57,7 @@ exports.ProviderButton = (0, mobx_react_lite_1.observer)((props) => {
57
57
  }
58
58
  };
59
59
  React.useEffect(() => (0, mobx_1.reaction)(() => providerConfig.connector, connector => {
60
- if (connector.type !== types_1.ConnectionType.WALLET_CONNECT_V2) {
60
+ if (connector.type !== types_1.EthereumConnectionType.WALLET_CONNECT_V2) {
61
61
  setHasProvider(connector.provider != null);
62
62
  }
63
63
  }, { fireImmediately: true }), [providerConfig.connector]);
@@ -1,14 +1,14 @@
1
1
  import { type EIP6963ProviderInfo } from 'web3/lib/commonjs/web3_eip6963';
2
2
  import { type EthExecutionAPI, type ProviderConnectInfo } from 'web3-types';
3
3
  import { EthereumConnector, type EthereumConnectorCtorParams } from '../core';
4
- import { type AddEthereumChainParams, ConnectionType, type SupportedProviders } from '../types';
4
+ import { type AddEthereumChainParams, EthereumConnectionType, type SupportedProviders } from '../types';
5
5
  export interface EIP6963ConnectorCtorParams extends EthereumConnectorCtorParams {
6
6
  info: EIP6963ProviderInfo;
7
7
  provider: Readonly<SupportedProviders<EthExecutionAPI>>;
8
8
  }
9
9
  export declare class EIP6963Connector extends EthereumConnector {
10
10
  protected readonly params: Readonly<EIP6963ConnectorCtorParams>;
11
- readonly type = ConnectionType.EIP_6963_INJECTED;
11
+ readonly type = EthereumConnectionType.EIP_6963_INJECTED;
12
12
  constructor(params: Readonly<EIP6963ConnectorCtorParams>);
13
13
  connect(chainIdOrParams?: number | AddEthereumChainParams): Promise<void>;
14
14
  disconnect(): Promise<void>;
@@ -17,7 +17,7 @@ const types_1 = require("../types");
17
17
  const utils_1 = require("../utils");
18
18
  class EIP6963Connector extends core_1.EthereumConnector {
19
19
  params;
20
- type = types_1.ConnectionType.EIP_6963_INJECTED;
20
+ type = types_1.EthereumConnectionType.EIP_6963_INJECTED;
21
21
  constructor(params) {
22
22
  super(params);
23
23
  this.params = params;
@@ -1,6 +1,6 @@
1
1
  import { AbstractStore } from '@broxus/js-core';
2
2
  import { type EthExecutionAPI, type ProviderRpcError } from 'web3-types';
3
- import { type AddEthereumChainParams, type ConnectionType, type SupportedProviders, type WatchAssetParameters } from '../types';
3
+ import { type AddEthereumChainParams, type EthereumConnectionType, type SupportedProviders, type WatchAssetParameters } from '../types';
4
4
  export interface EthereumConnectorCtorParams {
5
5
  onDisconnect?: (err: ProviderRpcError) => Promise<void> | void;
6
6
  }
@@ -16,7 +16,7 @@ export interface EthereumConnectorState {
16
16
  }
17
17
  export declare abstract class EthereumConnector extends AbstractStore<EthereumConnectorData, EthereumConnectorState> {
18
18
  protected readonly params?: Readonly<EthereumConnectorCtorParams> | undefined;
19
- readonly type?: ConnectionType;
19
+ readonly type?: EthereumConnectionType;
20
20
  /**
21
21
  * An
22
22
  * EIP-1193 ({@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md}) and
@@ -1,7 +1,7 @@
1
1
  import detectEthereumProvider from '@metamask/detect-provider';
2
2
  import { type EthExecutionAPI, type MetaMaskProvider, type ProviderConnectInfo } from 'web3-types';
3
3
  import { EthereumConnector, type EthereumConnectorCtorParams } from '../core/EthereumConnector';
4
- import { type AddEthereumChainParams, ConnectionType } from '../types';
4
+ import { type AddEthereumChainParams, EthereumConnectionType } from '../types';
5
5
  interface MetaMaskEthereumProvider extends MetaMaskProvider<EthExecutionAPI> {
6
6
  isConnected?: () => boolean;
7
7
  providers?: MetaMaskEthereumProvider[];
@@ -13,7 +13,7 @@ export interface MetaMaskCtorParams extends EthereumConnectorCtorParams {
13
13
  }
14
14
  export declare class MetaMask extends EthereumConnector {
15
15
  protected readonly params?: Readonly<MetaMaskCtorParams> | undefined;
16
- readonly type = ConnectionType.INJECTED;
16
+ readonly type = EthereumConnectionType.INJECTED;
17
17
  provider?: MetaMaskEthereumProvider;
18
18
  constructor(params?: Readonly<MetaMaskCtorParams> | undefined);
19
19
  connect(chainIdOrParams?: number | AddEthereumChainParams): Promise<void>;
@@ -22,7 +22,7 @@ const utils_1 = require("../utils");
22
22
  const INJECTABLE_WALLETS = ['isBraveWallet', 'isRabby', 'isLedgerConnect', 'isTrust'];
23
23
  class MetaMask extends EthereumConnector_1.EthereumConnector {
24
24
  params;
25
- type = types_1.ConnectionType.INJECTED;
25
+ type = types_1.EthereumConnectionType.INJECTED;
26
26
  constructor(params) {
27
27
  super(params);
28
28
  this.params = params;
@@ -1,6 +1,6 @@
1
1
  import EthereumProvider, { type EthereumProviderOptions } from '@walletconnect/ethereum-provider';
2
2
  import { EthereumConnector, type EthereumConnectorCtorParams } from '../core';
3
- import { type AddEthereumChainParams, ConnectionType } from '../types';
3
+ import { type AddEthereumChainParams, EthereumConnectionType } from '../types';
4
4
  export interface WalletConnectOptions extends Omit<EthereumProviderOptions, 'rpcMap'> {
5
5
  rpcMap?: Record<number, string | string[]>;
6
6
  }
@@ -9,7 +9,7 @@ export interface WalletConnectCtorParams extends EthereumConnectorCtorParams {
9
9
  }
10
10
  export declare class WalletConnect extends EthereumConnector {
11
11
  protected readonly params: Readonly<WalletConnectCtorParams>;
12
- readonly type = ConnectionType.WALLET_CONNECT_V2;
12
+ readonly type = EthereumConnectionType.WALLET_CONNECT_V2;
13
13
  provider?: EthereumProvider;
14
14
  protected readonly options: WalletConnectOptions;
15
15
  constructor(params: Readonly<WalletConnectCtorParams>);
@@ -20,7 +20,7 @@ const core_1 = require("../core");
20
20
  const types_1 = require("../types");
21
21
  class WalletConnect extends core_1.EthereumConnector {
22
22
  params;
23
- type = types_1.ConnectionType.WALLET_CONNECT_V2;
23
+ type = types_1.EthereumConnectionType.WALLET_CONNECT_V2;
24
24
  options;
25
25
  constructor(params) {
26
26
  super(params);
@@ -1,9 +1,9 @@
1
- import { ConnectionType } from '../types';
1
+ import { EthereumConnectionType } from '../types';
2
2
  export interface RecentConnectionMeta {
3
3
  chainId?: string;
4
4
  disconnected?: boolean;
5
5
  providerId: string;
6
- type?: ConnectionType;
6
+ type?: EthereumConnectionType;
7
7
  }
8
8
  export declare function storeRecentConnectionMeta(meta: RecentConnectionMeta | undefined): void;
9
9
  export declare function getRecentConnectionMeta(): RecentConnectionMeta | undefined;
@@ -30,7 +30,7 @@ const constants_1 = require("../constants");
30
30
  const types_1 = require("../types");
31
31
  function isRecentConnectionMeta(value) {
32
32
  const meta = { providerId: value.providerId, type: value.type };
33
- return Boolean(meta.type && types_1.ConnectionType[meta.type] && !!meta.providerId);
33
+ return Boolean(meta.type && types_1.EthereumConnectionType[meta.type] && !!meta.providerId);
34
34
  }
35
35
  function storeRecentConnectionMeta(meta) {
36
36
  if (!meta) {
@@ -26,6 +26,11 @@ export interface EvmWalletServiceState {
26
26
  export declare class EvmWalletService extends AbstractStore<EvmWalletServiceData, EvmWalletServiceState> {
27
27
  protected readonly params?: Readonly<EvmWalletServiceCtorParams> | undefined;
28
28
  constructor(params?: Readonly<EvmWalletServiceCtorParams> | undefined);
29
+ /**
30
+ * Define current provider connector
31
+ * @returns {EthereumConnector|undefined}
32
+ */
33
+ get connector(): EthereumConnector | undefined;
29
34
  /**
30
35
  * Manually connect to the wallet
31
36
  * @returns {Promise<void>}
@@ -42,12 +47,12 @@ export declare class EvmWalletService extends AbstractStore<EvmWalletServiceData
42
47
  * @returns {Promise<void>}
43
48
  */
44
49
  switchNetwork(chainIdOrParams: number | AddEthereumChainParams): Promise<void>;
45
- watchAsset(params: WatchAssetParameters): Promise<true | undefined>;
46
50
  /**
47
- * Define current provider connector
48
- * @returns {EthereumConnector|undefined}
51
+ * Request to the wallet for watch asset
52
+ * @param {WatchAssetParameters} params
53
+ * @returns {Promise<true | undefined>}
49
54
  */
50
- get connector(): EthereumConnector | undefined;
55
+ watchAsset(params: WatchAssetParameters): Promise<true | undefined>;
51
56
  /**
52
57
  * An independent RPC connection that allows you to receive data from the blockchain without being
53
58
  * able to send transactions.
@@ -34,6 +34,13 @@ class EvmWalletService extends js_core_1.AbstractStore {
34
34
  (0, js_utils_1.error)('Wallet init failed with an error', reason);
35
35
  });
36
36
  }
37
+ /**
38
+ * Define current provider connector
39
+ * @returns {EthereumConnector|undefined}
40
+ */
41
+ get connector() {
42
+ return this.providers?.find(config => config.id === this.providerId)?.connector;
43
+ }
37
44
  /**
38
45
  * Manually connect to the wallet
39
46
  * @returns {Promise<void>}
@@ -67,9 +74,6 @@ class EvmWalletService extends js_core_1.AbstractStore {
67
74
  catch (e) {
68
75
  (0, js_utils_1.error)('EVM Wallet disconnect error', e);
69
76
  }
70
- finally {
71
- //
72
- }
73
77
  }
74
78
  /**
75
79
  * Switch network or add a new one if not exists in the current connected wallet
@@ -79,15 +83,13 @@ class EvmWalletService extends js_core_1.AbstractStore {
79
83
  async switchNetwork(chainIdOrParams) {
80
84
  await this.connector?.switchNetwork(chainIdOrParams);
81
85
  }
82
- async watchAsset(params) {
83
- return this.connector?.watchAsset(params);
84
- }
85
86
  /**
86
- * Define current provider connector
87
- * @returns {EthereumConnector|undefined}
87
+ * Request to the wallet for watch asset
88
+ * @param {WatchAssetParameters} params
89
+ * @returns {Promise<true | undefined>}
88
90
  */
89
- get connector() {
90
- return this.providers?.find(config => config.id === this.providerId)?.connector;
91
+ async watchAsset(params) {
92
+ return this.connector?.watchAsset(params);
91
93
  }
92
94
  /**
93
95
  * An independent RPC connection that allows you to receive data from the blockchain without being
@@ -146,7 +148,6 @@ class EvmWalletService extends js_core_1.AbstractStore {
146
148
  */
147
149
  get currency() {
148
150
  return {
149
- balance: this.balance,
150
151
  decimals: this.network?.currency.decimals ?? 18,
151
152
  icon: this.network?.currency.icon,
152
153
  name: this.network?.currency.name,
@@ -216,7 +217,7 @@ class EvmWalletService extends js_core_1.AbstractStore {
216
217
  * @returns {EthereumConnector["chainId"]}
217
218
  */
218
219
  get chainId() {
219
- return this.connector?.chainId;
220
+ return this.connector?.chainId ?? this.params?.defaultNetworkId;
220
221
  }
221
222
  /**
222
223
  * Returns `true` if wallet is connecting
@@ -296,6 +297,11 @@ class EvmWalletService extends js_core_1.AbstractStore {
296
297
  networkDisposer;
297
298
  }
298
299
  exports.EvmWalletService = EvmWalletService;
300
+ __decorate([
301
+ mobx_1.computed,
302
+ __metadata("design:type", Object),
303
+ __metadata("design:paramtypes", [])
304
+ ], EvmWalletService.prototype, "connector", null);
299
305
  __decorate([
300
306
  mobx_1.action.bound,
301
307
  __metadata("design:type", Function),
@@ -320,11 +326,6 @@ __decorate([
320
326
  __metadata("design:paramtypes", [Object]),
321
327
  __metadata("design:returntype", Promise)
322
328
  ], EvmWalletService.prototype, "watchAsset", null);
323
- __decorate([
324
- mobx_1.computed,
325
- __metadata("design:type", Object),
326
- __metadata("design:paramtypes", [])
327
- ], EvmWalletService.prototype, "connector", null);
328
329
  __decorate([
329
330
  mobx_1.computed,
330
331
  __metadata("design:type", Object),