@broxus/evm-connect 1.3.3 → 1.3.5

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
@@ -7,7 +7,7 @@ export interface EvmNetworkConfig extends NetworkConfigBase<string> {
7
7
  type: EvmBasedNetwork;
8
8
  }
9
9
  export type SupportedProviders<API extends Web3APISpec = Web3EthExecutionAPI> = EIP1193Provider<API> | Web3BaseProvider<API> | MetaMaskProvider<API>;
10
- export declare enum ConnectionType {
10
+ export declare enum EthereumConnectionType {
11
11
  INJECTED = "INJECTED",
12
12
  COINBASE_WALLET = "COINBASE_WALLET",
13
13
  WALLET_CONNECT_V2 = "WALLET_CONNECT_V2",
package/dist/cjs/types.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EIP6963Event = exports.ConnectionType = void 0;
4
- var ConnectionType;
5
- (function (ConnectionType) {
6
- ConnectionType["INJECTED"] = "INJECTED";
7
- ConnectionType["COINBASE_WALLET"] = "COINBASE_WALLET";
8
- ConnectionType["WALLET_CONNECT_V2"] = "WALLET_CONNECT_V2";
9
- ConnectionType["EIP_6963_INJECTED"] = "EIP_6963_INJECTED";
10
- })(ConnectionType || (exports.ConnectionType = ConnectionType = {}));
3
+ exports.EIP6963Event = exports.EthereumConnectionType = void 0;
4
+ var EthereumConnectionType;
5
+ (function (EthereumConnectionType) {
6
+ EthereumConnectionType["INJECTED"] = "INJECTED";
7
+ EthereumConnectionType["COINBASE_WALLET"] = "COINBASE_WALLET";
8
+ EthereumConnectionType["WALLET_CONNECT_V2"] = "WALLET_CONNECT_V2";
9
+ EthereumConnectionType["EIP_6963_INJECTED"] = "EIP_6963_INJECTED";
10
+ })(EthereumConnectionType || (exports.EthereumConnectionType = EthereumConnectionType = {}));
11
11
  var EIP6963Event;
12
12
  (function (EIP6963Event) {
13
13
  EIP6963Event["REQUEST_PROVIDER"] = "eip6963:requestProvider";
@@ -7,7 +7,7 @@ import * as React from 'react';
7
7
  import { useIntl } from 'react-intl';
8
8
  import { useEvmWalletProviders, useEvmWalletService } from '../../../context';
9
9
  import messages from '../../../intl';
10
- import { ConnectionType } from '../../../types';
10
+ import { EthereumConnectionType } from '../../../types';
11
11
  import { getEvmProviderPlatformLink } from '../../../utils';
12
12
  import './index.css';
13
13
  export const ProviderButton = observer((props) => {
@@ -16,7 +16,7 @@ export const ProviderButton = observer((props) => {
16
16
  const walletProviders = useEvmWalletProviders();
17
17
  const { providerConfig, onSelect: onSelectProvider } = props;
18
18
  const [hasProvider, setHasProvider] = React.useState(() => {
19
- if (providerConfig.connector.type === ConnectionType.WALLET_CONNECT_V2) {
19
+ if (providerConfig.connector.type === EthereumConnectionType.WALLET_CONNECT_V2) {
20
20
  return true;
21
21
  }
22
22
  return undefined;
@@ -28,7 +28,7 @@ export const ProviderButton = observer((props) => {
28
28
  }
29
29
  };
30
30
  React.useEffect(() => reaction(() => providerConfig.connector, connector => {
31
- if (connector.type !== ConnectionType.WALLET_CONNECT_V2) {
31
+ if (connector.type !== EthereumConnectionType.WALLET_CONNECT_V2) {
32
32
  setHasProvider(connector.provider != null);
33
33
  }
34
34
  }, { 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>;
@@ -10,11 +10,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { debug, error, throwException } from '@broxus/js-utils';
11
11
  import { action, makeObservable } from 'mobx';
12
12
  import { EthereumConnector } from '../core';
13
- import { ConnectionType } from '../types';
13
+ import { EthereumConnectionType } from '../types';
14
14
  import { parseChainId } from '../utils';
15
15
  export class EIP6963Connector extends EthereumConnector {
16
16
  params;
17
- type = ConnectionType.EIP_6963_INJECTED;
17
+ type = EthereumConnectionType.EIP_6963_INJECTED;
18
18
  constructor(params) {
19
19
  super(params);
20
20
  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>;
@@ -11,12 +11,12 @@ import { debug, error, throwException } from '@broxus/js-utils';
11
11
  import detectEthereumProvider from '@metamask/detect-provider';
12
12
  import { action, makeObservable, override } from 'mobx';
13
13
  import { EthereumConnector } from '../core/EthereumConnector';
14
- import { ConnectionType, EIP6963Event } from '../types';
14
+ import { EthereumConnectionType, EIP6963Event } from '../types';
15
15
  import { parseChainId } from '../utils';
16
16
  const INJECTABLE_WALLETS = ['isBraveWallet', 'isRabby', 'isLedgerConnect', 'isTrust'];
17
17
  export class MetaMask extends EthereumConnector {
18
18
  params;
19
- type = ConnectionType.INJECTED;
19
+ type = EthereumConnectionType.INJECTED;
20
20
  constructor(params) {
21
21
  super(params);
22
22
  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>);
@@ -11,10 +11,10 @@ import { debug, error, throwException } from '@broxus/js-utils';
11
11
  import EthereumProvider from '@walletconnect/ethereum-provider';
12
12
  import { action, makeObservable, override } from 'mobx';
13
13
  import { EthereumConnector } from '../core';
14
- import { ConnectionType } from '../types';
14
+ import { EthereumConnectionType } from '../types';
15
15
  export class WalletConnect extends EthereumConnector {
16
16
  params;
17
- type = ConnectionType.WALLET_CONNECT_V2;
17
+ type = EthereumConnectionType.WALLET_CONNECT_V2;
18
18
  options;
19
19
  constructor(params) {
20
20
  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;
@@ -1,10 +1,10 @@
1
1
  import { debug, storage } from '@broxus/js-utils';
2
2
  import * as React from 'react';
3
3
  import { EVM_RECENT_CONNECTION } from '../constants';
4
- import { ConnectionType } from '../types';
4
+ import { EthereumConnectionType } from '../types';
5
5
  function isRecentConnectionMeta(value) {
6
6
  const meta = { providerId: value.providerId, type: value.type };
7
- return Boolean(meta.type && ConnectionType[meta.type] && !!meta.providerId);
7
+ return Boolean(meta.type && EthereumConnectionType[meta.type] && !!meta.providerId);
8
8
  }
9
9
  export function storeRecentConnectionMeta(meta) {
10
10
  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.
@@ -28,6 +28,13 @@ export class EvmWalletService extends AbstractStore {
28
28
  error('Wallet init failed with an error', reason);
29
29
  });
30
30
  }
31
+ /**
32
+ * Define current provider connector
33
+ * @returns {EthereumConnector|undefined}
34
+ */
35
+ get connector() {
36
+ return this.providers?.find(config => config.id === this.providerId)?.connector;
37
+ }
31
38
  /**
32
39
  * Manually connect to the wallet
33
40
  * @returns {Promise<void>}
@@ -61,9 +68,6 @@ export class EvmWalletService extends AbstractStore {
61
68
  catch (e) {
62
69
  error('EVM Wallet disconnect error', e);
63
70
  }
64
- finally {
65
- //
66
- }
67
71
  }
68
72
  /**
69
73
  * Switch network or add a new one if not exists in the current connected wallet
@@ -73,15 +77,13 @@ export class EvmWalletService extends AbstractStore {
73
77
  async switchNetwork(chainIdOrParams) {
74
78
  await this.connector?.switchNetwork(chainIdOrParams);
75
79
  }
76
- async watchAsset(params) {
77
- return this.connector?.watchAsset(params);
78
- }
79
80
  /**
80
- * Define current provider connector
81
- * @returns {EthereumConnector|undefined}
81
+ * Request to the wallet for watch asset
82
+ * @param {WatchAssetParameters} params
83
+ * @returns {Promise<true | undefined>}
82
84
  */
83
- get connector() {
84
- return this.providers?.find(config => config.id === this.providerId)?.connector;
85
+ async watchAsset(params) {
86
+ return this.connector?.watchAsset(params);
85
87
  }
86
88
  /**
87
89
  * An independent RPC connection that allows you to receive data from the blockchain without being
@@ -140,7 +142,6 @@ export class EvmWalletService extends AbstractStore {
140
142
  */
141
143
  get currency() {
142
144
  return {
143
- balance: this.balance,
144
145
  decimals: this.network?.currency.decimals ?? 18,
145
146
  icon: this.network?.currency.icon,
146
147
  name: this.network?.currency.name,
@@ -210,7 +211,7 @@ export class EvmWalletService extends AbstractStore {
210
211
  * @returns {EthereumConnector["chainId"]}
211
212
  */
212
213
  get chainId() {
213
- return this.connector?.chainId;
214
+ return this.connector?.chainId ?? this.params?.defaultNetworkId;
214
215
  }
215
216
  /**
216
217
  * Returns `true` if wallet is connecting
@@ -289,6 +290,11 @@ export class EvmWalletService extends AbstractStore {
289
290
  accountDisposer;
290
291
  networkDisposer;
291
292
  }
293
+ __decorate([
294
+ computed,
295
+ __metadata("design:type", Object),
296
+ __metadata("design:paramtypes", [])
297
+ ], EvmWalletService.prototype, "connector", null);
292
298
  __decorate([
293
299
  action.bound,
294
300
  __metadata("design:type", Function),
@@ -313,11 +319,6 @@ __decorate([
313
319
  __metadata("design:paramtypes", [Object]),
314
320
  __metadata("design:returntype", Promise)
315
321
  ], EvmWalletService.prototype, "watchAsset", null);
316
- __decorate([
317
- computed,
318
- __metadata("design:type", Object),
319
- __metadata("design:paramtypes", [])
320
- ], EvmWalletService.prototype, "connector", null);
321
322
  __decorate([
322
323
  computed,
323
324
  __metadata("design:type", Object),