@tomo-inc/inject-providers 0.0.14 → 0.0.15

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.
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ethErrors, EthereumRpcError } from 'eth-rpc-errors';
2
2
  import { EventEmitter } from 'events';
3
+ import { ChainTypeEnum } from '@tomo-inc/wallet-utils';
3
4
  import { JsonRpcEngine, createIdRemapMiddleware } from 'json-rpc-engine';
4
5
  import { createStreamMiddleware } from 'json-rpc-middleware-stream';
5
6
  import { toHex } from 'viem';
@@ -163,10 +164,10 @@ function isHexString(str) {
163
164
  }
164
165
 
165
166
  // src/btc/unisat.ts
166
- var chainType = "btc" /* BTC */;
167
- var BtcProvider = class extends EventEmitter {
167
+ var BitcoinProvider = class extends EventEmitter {
168
168
  constructor(productInfo, { sendRequest, onResponse }) {
169
169
  super();
170
+ this.type = ChainTypeEnum.BITCOIN;
170
171
  this._selectedAddress = null;
171
172
  this._isConnected = false;
172
173
  this._initialized = false;
@@ -209,13 +210,13 @@ var BtcProvider = class extends EventEmitter {
209
210
  };
210
211
  this.subscribeWalletEventsCallback = ({ method, data }) => {
211
212
  if (method === "accountsChanged") {
212
- const addresses = (data == null ? void 0 : data[chainType]) || [];
213
+ const addresses = (data == null ? void 0 : data[this.type]) || [];
213
214
  const accounts = addresses.map(({ address }) => address);
214
215
  this._handleAccountsChanged(accounts);
215
216
  }
216
217
  if (method === "chainChanged") {
217
218
  const { chainId, type } = data;
218
- if (type.indexOf(`${chainType}:`) === 0) {
219
+ if (type.indexOf(`${this.type}:`) === 0) {
219
220
  this._handleChainChanged({ chainId, isConnected: true });
220
221
  }
221
222
  }
@@ -239,7 +240,7 @@ var BtcProvider = class extends EventEmitter {
239
240
  throw ethErrors.rpc.invalidRequest();
240
241
  }
241
242
  const dappInfo = await getDappInfo();
242
- this.sendRequest(chainType, { method, params, dappInfo });
243
+ this.sendRequest(this.type, { method, params, dappInfo });
243
244
  const connectFuns = {
244
245
  getAccounts: true,
245
246
  requestAccounts: true
@@ -308,7 +309,7 @@ var BtcProvider = class extends EventEmitter {
308
309
  params: { txId }
309
310
  });
310
311
  };
311
- this.signMessage = async (text, type) => {
312
+ this.signMessage = async (text, type = "ecdsa") => {
312
313
  return this._request({
313
314
  method: "signMessage",
314
315
  params: {
@@ -397,6 +398,12 @@ var BtcProvider = class extends EventEmitter {
397
398
  }
398
399
  });
399
400
  };
401
+ this.sendTransaction = async (params) => {
402
+ return this._request({
403
+ method: "sendTransaction",
404
+ params
405
+ });
406
+ };
400
407
  this.name = productInfo.name;
401
408
  this.rdns = productInfo.rdns;
402
409
  this._handleAccountsChanged = this._handleAccountsChanged.bind(this);
@@ -430,10 +437,10 @@ var BtcProvider = class extends EventEmitter {
430
437
  }
431
438
  }
432
439
  };
433
- var chainType2 = "doge" /* DOGE */;
434
440
  var DogecoinProvider = class extends EventEmitter {
435
441
  constructor(productInfo, { sendRequest, onResponse }) {
436
442
  super();
443
+ this.type = ChainTypeEnum.DOGECOIN;
437
444
  this._selectedAddress = null;
438
445
  this._network = null;
439
446
  this._isConnected = false;
@@ -487,7 +494,7 @@ var DogecoinProvider = class extends EventEmitter {
487
494
  throw ethErrors.rpc.invalidRequest();
488
495
  }
489
496
  const dappInfo = await getDappInfo();
490
- this.sendRequest(chainType2, { method, params, dappInfo });
497
+ this.sendRequest(this.type, { method, params, dappInfo });
491
498
  return this.onResponse({ method }).then((res) => {
492
499
  const { data } = res || {};
493
500
  return adapter ? adapter(data) : data;
@@ -809,7 +816,6 @@ var EMITTED_NOTIFICATIONS = [
809
816
  ];
810
817
 
811
818
  // src/evm/metamask.ts
812
- var chainType3 = "evm" /* EVM */;
813
819
  var EvmProvider = class extends EventEmitter {
814
820
  /**
815
821
  * @param connectionStream - A Node.js duplex stream
@@ -833,15 +839,16 @@ var EvmProvider = class extends EventEmitter {
833
839
  }
834
840
  validateLoggerObject(logger);
835
841
  super();
842
+ this.type = ChainTypeEnum.EVM;
836
843
  this.subscribeWalletEventsCallback = ({ method, data }) => {
837
844
  if (method === "accountsChanged") {
838
- const addresses = (data == null ? void 0 : data[chainType3]) || [];
845
+ const addresses = (data == null ? void 0 : data[this.type]) || [];
839
846
  const accounts = addresses.map(({ address }) => address);
840
847
  this._handleAccountsChanged(accounts, true);
841
848
  }
842
849
  if (method === "chainChanged") {
843
850
  const { chainId, type } = data;
844
- if (type.indexOf(`${chainType3}:`) === 0) {
851
+ if (type.indexOf(`${this.type}:`) === 0) {
845
852
  const chainIdHex = toHex(parseInt(chainId));
846
853
  this._handleChainChanged({ chainId: chainIdHex, isConnected: true });
847
854
  }
@@ -1011,7 +1018,7 @@ var EvmProvider = class extends EventEmitter {
1011
1018
  };
1012
1019
  const dappInfo = await getDappInfo();
1013
1020
  args = __spreadValues(__spreadValues({}, args), { dappInfo });
1014
- this.sendRequest(chainType3, args);
1021
+ this.sendRequest(this.type, args);
1015
1022
  return this.onResponse(args).then((res) => {
1016
1023
  const { data, method: method2 } = res || {};
1017
1024
  if (method2 === "_wallet_getProviderState") {
@@ -1430,10 +1437,10 @@ var hexToTx = (hexString) => {
1430
1437
  };
1431
1438
 
1432
1439
  // src/solana/phantom.ts
1433
- var chainType4 = "sol" /* SOL */;
1434
1440
  var PhantomProvider = class extends EventEmitter {
1435
1441
  constructor(productInfo, { sendRequest, onResponse }) {
1436
1442
  super();
1443
+ this.chainType = ChainTypeEnum.SOLANA;
1437
1444
  this._isUnlocked = false;
1438
1445
  this.name = "";
1439
1446
  this.icon = "";
@@ -1478,7 +1485,7 @@ var PhantomProvider = class extends EventEmitter {
1478
1485
  };
1479
1486
  this.subscribeWalletEventsCallback = ({ method, data }) => {
1480
1487
  if (method === "accountsChanged") {
1481
- const accounts = data == null ? void 0 : data[chainType4];
1488
+ const accounts = data == null ? void 0 : data[this.chainType];
1482
1489
  this._handleAccountsChanged(accounts);
1483
1490
  }
1484
1491
  };
@@ -1500,7 +1507,7 @@ var PhantomProvider = class extends EventEmitter {
1500
1507
  throw ethErrors.rpc.invalidRequest();
1501
1508
  }
1502
1509
  const dappInfo = await getDappInfo();
1503
- this.sendRequest(chainType4, __spreadProps(__spreadValues({}, data), { dappInfo }));
1510
+ this.sendRequest(this.chainType, __spreadProps(__spreadValues({}, data), { dappInfo }));
1504
1511
  return this.onResponse(data).then((res) => {
1505
1512
  let { data: data2 } = res || {};
1506
1513
  if (data2 && data2.publicKey) {
@@ -1765,15 +1772,17 @@ Resources:`;
1765
1772
  }
1766
1773
  }
1767
1774
  };
1768
- var chainType5 = "tron" /* TRON */;
1775
+ var _fullHost = "https://api.trongrid.io";
1769
1776
  var TomoTronProvider = class extends EventEmitter {
1770
1777
  constructor(productInfo, { sendRequest, onResponse }) {
1771
1778
  super();
1779
+ this.type = ChainTypeEnum.TRON;
1772
1780
  this._isUnlocked = false;
1773
1781
  this.name = "";
1774
1782
  this.icon = "";
1775
1783
  this.ready = false;
1776
- this.tronWeb = null;
1784
+ this.tronWeb = new TronWeb({ fullHost: _fullHost });
1785
+ this.address = "";
1777
1786
  this.events = {
1778
1787
  connect: true,
1779
1788
  disconnect: true,
@@ -1789,9 +1798,9 @@ var TomoTronProvider = class extends EventEmitter {
1789
1798
  // private _pushEventHandlers: PushEventHandlers;
1790
1799
  this._requestPromise = new ReadyPromise(0);
1791
1800
  this._initTronWeb = async (res) => {
1792
- const { fullHost = "https://api.trongrid.io", address } = res || {};
1801
+ const { fullHost, address } = res || {};
1793
1802
  this.tronWeb = new TronWeb({
1794
- fullHost
1803
+ fullHost: fullHost || _fullHost
1795
1804
  });
1796
1805
  this.tronWeb.defaultAddress.base58 = address;
1797
1806
  this.tronWeb.defaultAddress.hex = TronWeb.address.toHex(address);
@@ -1860,7 +1869,7 @@ var TomoTronProvider = class extends EventEmitter {
1860
1869
  };
1861
1870
  this.subscribeWalletEventsCallback = ({ method, data }) => {
1862
1871
  if (method === "accountsChanged") {
1863
- const accounts = data == null ? void 0 : data[chainType5];
1872
+ const accounts = data == null ? void 0 : data[this.type];
1864
1873
  this._handleAccountsChanged(accounts);
1865
1874
  }
1866
1875
  };
@@ -1869,7 +1878,7 @@ var TomoTronProvider = class extends EventEmitter {
1869
1878
  throw ethErrors.rpc.invalidRequest();
1870
1879
  }
1871
1880
  const dappInfo = await getDappInfo();
1872
- this.sendRequest(chainType5, __spreadProps(__spreadValues({}, data), { dappInfo }));
1881
+ this.sendRequest(this.type, __spreadProps(__spreadValues({}, data), { dappInfo }));
1873
1882
  return this.onResponse(data).then((res) => {
1874
1883
  const { data: data2, method } = res || {};
1875
1884
  if (method === "tron_requestAccounts") {
@@ -1998,7 +2007,7 @@ var TomoTronProvider = class extends EventEmitter {
1998
2007
  });
1999
2008
  this.on("disconnect", (result) => {
2000
2009
  this._state.isConnected = false;
2001
- this.tronWeb = null;
2010
+ this.tronWeb = new TronWeb({ fullHost: _fullHost });
2002
2011
  window.postMessage(
2003
2012
  {
2004
2013
  message: {
@@ -2045,4 +2054,4 @@ var TomoTronProvider = class extends EventEmitter {
2045
2054
  }
2046
2055
  };
2047
2056
 
2048
- export { BtcProvider, DogecoinProvider, EvmProvider, PhantomProvider as SolanaProvider, TomoTronProvider as TronProvider };
2057
+ export { BitcoinProvider, DogecoinProvider, EvmProvider, PhantomProvider as SolanaProvider, TomoTronProvider as TronProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/inject-providers",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -25,7 +25,7 @@
25
25
  "json-rpc-middleware-stream": "^3.0.0",
26
26
  "tronweb": "^6.0.3",
27
27
  "viem": "^2.38.3",
28
- "@tomo-inc/wallet-utils": "0.0.16"
28
+ "@tomo-inc/wallet-utils": "0.0.17"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.0.0",
package/src/btc/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { BtcProvider } from "./unisat";
1
+ import { BitcoinProvider } from "./unisat";
2
2
 
3
- export { BtcProvider };
3
+ export { BitcoinProvider };
package/src/btc/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { ChainTypes } from "types";
2
+
1
3
  export enum TxType {
2
4
  SIGN_TX,
3
5
  SEND_BITCOIN,
@@ -14,7 +16,10 @@ export type Balance = {
14
16
  total: number;
15
17
  };
16
18
 
17
- export type IBtcProvider = {
19
+ export type SignMessageType = "ecdsa" | "bip322-simple";
20
+
21
+ export interface IBitcoinProvider {
22
+ type: ChainTypes.BITCOIN;
18
23
  connect: () => Promise<any>;
19
24
  disconnect: () => Promise<any>;
20
25
  requestAccounts: () => Promise<any>;
@@ -22,7 +27,7 @@ export type IBtcProvider = {
22
27
  getPublicKey: () => Promise<any>;
23
28
  getBalance: () => Promise<any>;
24
29
  getTransactionStatus: (params: { txId: string }) => Promise<any>;
25
- signMessage: (params: { text: string; type: string }) => Promise<any>;
30
+ signMessage: (text: string, type: SignMessageType) => Promise<any>;
26
31
  getNetwork: () => Promise<any>;
27
32
  switchNetwork: (network: Network) => Promise<any>;
28
33
  getChain: () => Promise<any>;
@@ -35,4 +40,4 @@ export type IBtcProvider = {
35
40
  pushTx: (rawtx: string) => Promise<any>;
36
41
  sendTransaction: (params: any) => Promise<any>;
37
42
  sendBitcoin: (rawtx: string) => Promise<any>;
38
- };
43
+ }
package/src/btc/unisat.ts CHANGED
@@ -3,9 +3,7 @@ import { EventEmitter } from "events";
3
3
 
4
4
  import { ChainTypes, IConnectors, IProductInfo } from "../types";
5
5
  import { ReadyPromise, domReadyCall, getDappInfo } from "../utils/index";
6
- import { Balance, ChainId, Network } from "./types";
7
-
8
- const chainType = ChainTypes.BTC;
6
+ import { Balance, ChainId, IBitcoinProvider, Network, SignMessageType } from "./types";
9
7
 
10
8
  interface StateProvider {
11
9
  accounts: string[] | null;
@@ -15,7 +13,8 @@ interface StateProvider {
15
13
  isPermanentlyDisconnected: boolean;
16
14
  }
17
15
 
18
- export class BtcProvider extends EventEmitter {
16
+ export class BitcoinProvider extends EventEmitter implements IBitcoinProvider {
17
+ type: ChainTypes.BITCOIN = ChainTypes.BITCOIN;
19
18
  _selectedAddress: string | null = null;
20
19
  _isConnected = false;
21
20
  _initialized = false;
@@ -80,14 +79,14 @@ export class BtcProvider extends EventEmitter {
80
79
 
81
80
  subscribeWalletEventsCallback = ({ method, data }: { method: string; data: any }) => {
82
81
  if (method === "accountsChanged") {
83
- const addresses = data?.[chainType] || [];
82
+ const addresses = data?.[this.type] || [];
84
83
  // addresses = addresses.filter((item) => item.subType === "default");
85
84
  const accounts = addresses.map(({ address }: { address: string }) => address);
86
85
  this._handleAccountsChanged(accounts);
87
86
  }
88
87
  if (method === "chainChanged") {
89
88
  const { chainId, type }: { chainId: string; type: string } = data;
90
- if (type.indexOf(`${chainType}:`) === 0) {
89
+ if (type.indexOf(`${this.type}:`) === 0) {
91
90
  this._handleChainChanged({ chainId, isConnected: true });
92
91
  }
93
92
  }
@@ -147,7 +146,7 @@ export class BtcProvider extends EventEmitter {
147
146
 
148
147
  //api call -> ("0: dapp -> injector -> content");
149
148
  const dappInfo = await getDappInfo();
150
- this.sendRequest(chainType, { method, params, dappInfo });
149
+ this.sendRequest(this.type, { method, params, dappInfo });
151
150
 
152
151
  const connectFuns: Record<string, boolean> = {
153
152
  getAccounts: true,
@@ -230,7 +229,7 @@ export class BtcProvider extends EventEmitter {
230
229
  });
231
230
  };
232
231
 
233
- signMessage = async (text: string, type?: "ecdsa" | "bip322-simple"): Promise<string> => {
232
+ signMessage = async (text: string, type: SignMessageType = "ecdsa"): Promise<string> => {
234
233
  return this._request({
235
234
  method: "signMessage",
236
235
  params: {
@@ -329,4 +328,11 @@ export class BtcProvider extends EventEmitter {
329
328
  },
330
329
  });
331
330
  };
331
+
332
+ sendTransaction = async (params: any) => {
333
+ return this._request({
334
+ method: "sendTransaction",
335
+ params,
336
+ });
337
+ };
332
338
  }
@@ -5,8 +5,7 @@ import { ReadyPromise, domReadyCall, getDappInfo } from "../utils/index";
5
5
  import { TxType } from "./types";
6
6
 
7
7
  import { ChainTypes, IConnectors, IProductInfo } from "../types";
8
-
9
- const chainType = ChainTypes.DOGE;
8
+ import { IDogecoinProvider } from "./interface";
10
9
 
11
10
  interface StateProvider {
12
11
  accounts: string[] | null;
@@ -16,7 +15,8 @@ interface StateProvider {
16
15
  isPermanentlyDisconnected: boolean;
17
16
  }
18
17
 
19
- export class DogecoinProvider extends EventEmitter {
18
+ export class DogecoinProvider extends EventEmitter implements IDogecoinProvider {
19
+ type: ChainTypes.DOGECOIN = ChainTypes.DOGECOIN;
20
20
  _selectedAddress: string | null = null;
21
21
  _network: string | null = null;
22
22
  _isConnected = false;
@@ -94,7 +94,7 @@ export class DogecoinProvider extends EventEmitter {
94
94
 
95
95
  //api call -> ("0: dapp -> injector -> content");
96
96
  const dappInfo = await getDappInfo();
97
- this.sendRequest(chainType, { method, params, dappInfo });
97
+ this.sendRequest(this.type, { method, params, dappInfo });
98
98
 
99
99
  //check result by method
100
100
  return this.onResponse({ method }).then((res: any) => {
@@ -1,4 +1,5 @@
1
1
  import { EventEmitter } from "events";
2
+ import { ChainTypes } from "types";
2
3
 
3
4
  /**
4
5
  * State interface for DogecoinProvider
@@ -120,7 +121,7 @@ export interface IDunesBalance {
120
121
  * Extends EventEmitter to support event handling
121
122
  */
122
123
  export interface IDogecoinProvider extends EventEmitter {
123
- type: "dogecoin";
124
+ type: ChainTypes.DOGECOIN;
124
125
 
125
126
  rdns: string;
126
127
  name: string;
@@ -1,7 +1,8 @@
1
1
  import { EventEmitter } from "events";
2
2
  import { JsonRpcRequest, JsonRpcResponse } from "json-rpc-engine";
3
- import { Maybe } from "./utils";
3
+ import { ChainTypes } from "types";
4
4
  import { RequestArguments, SendSyncJsonRpcRequest } from "./type";
5
+ import { Maybe } from "./utils";
5
6
 
6
7
  /**
7
8
  * Connect event data interface
@@ -33,8 +34,7 @@ export interface IProviderMessage {
33
34
  * Implements EIP-1193 standard
34
35
  */
35
36
  export interface IEvmProvider extends EventEmitter {
36
- type: "evm";
37
-
37
+ type: ChainTypes.EVM;
38
38
  // Public properties
39
39
  /**
40
40
  * The chain ID of the currently connected Ethereum chain.
@@ -25,6 +25,7 @@ import {
25
25
  } from "./utils";
26
26
 
27
27
  import { ChainTypes, IProductInfo } from "../types";
28
+ import { IEvmProvider } from "./interface";
28
29
  import {
29
30
  InitializeProviderOptions,
30
31
  InpageProviderOptions,
@@ -35,9 +36,8 @@ import {
35
36
  WarningEventName,
36
37
  } from "./type";
37
38
 
38
- const chainType = ChainTypes.EVM;
39
-
40
- export class EvmProvider extends EventEmitter {
39
+ export class EvmProvider extends EventEmitter implements IEvmProvider {
40
+ type: ChainTypes.EVM = ChainTypes.EVM;
41
41
  private readonly _log: ConsoleLike;
42
42
 
43
43
  private _state: InternalState;
@@ -298,7 +298,7 @@ export class EvmProvider extends EventEmitter {
298
298
  args = { ...args, ...{ dappInfo } };
299
299
  // }
300
300
 
301
- this.sendRequest(chainType, args);
301
+ this.sendRequest(this.type, args);
302
302
 
303
303
  return this.onResponse(args).then((res: any) => {
304
304
  const { data, method } = res || {};
@@ -345,7 +345,7 @@ export class EvmProvider extends EventEmitter {
345
345
  return super.addListener(eventName, listener);
346
346
  }
347
347
 
348
- on(eventName: string, listener: (...args: unknown[]) => void) {
348
+ on(eventName: string, listener: (...args: any[]) => void) {
349
349
  this._warnOfDeprecation(eventName);
350
350
  return super.on(eventName, listener);
351
351
  }
@@ -415,13 +415,13 @@ export class EvmProvider extends EventEmitter {
415
415
 
416
416
  private subscribeWalletEventsCallback = ({ method, data }: { method: string; data: any }) => {
417
417
  if (method === "accountsChanged") {
418
- const addresses = data?.[chainType] || [];
418
+ const addresses = data?.[this.type] || [];
419
419
  const accounts = addresses.map(({ address }: { address: string }) => address);
420
420
  this._handleAccountsChanged(accounts, true);
421
421
  }
422
422
  if (method === "chainChanged") {
423
423
  const { chainId, type }: { chainId: string; type: string } = data;
424
- if (type.indexOf(`${chainType}:`) === 0) {
424
+ if (type.indexOf(`${this.type}:`) === 0) {
425
425
  const chainIdHex = toHex(parseInt(chainId));
426
426
  this._handleChainChanged({ chainId: chainIdHex, isConnected: true });
427
427
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { BtcProvider } from "./btc";
1
+ import { BitcoinProvider } from "./btc";
2
2
  import { DogecoinProvider } from "./dogecoin";
3
+ import { IDogecoinProvider } from "./dogecoin/interface";
3
4
  import { EvmProvider } from "./evm";
5
+ import { IEvmProvider } from "./evm/interface";
4
6
  import { SolanaProvider } from "./solana";
5
7
  import { TronProvider } from "./tron";
6
8
 
7
- export { BtcProvider, DogecoinProvider, EvmProvider, SolanaProvider, TronProvider };
9
+ export { BitcoinProvider, DogecoinProvider, EvmProvider, SolanaProvider, TronProvider };
8
10
 
9
- import { IDogecoinProvider } from "./dogecoin/interface";
10
- import { IEvmProvider } from "./evm/interface";
11
11
  export type WalletProvider = IDogecoinProvider | IEvmProvider;
@@ -9,8 +9,6 @@ import { hexToTx, txToHex } from "./utils";
9
9
 
10
10
  import { ChainTypes, IConnectors, IProductInfo } from "../types";
11
11
  import { OriginTransaction, SignInInput } from "./types";
12
- const chainType = ChainTypes.SOL;
13
-
14
12
  interface StateProvider {
15
13
  accounts: any[] | null;
16
14
  isConnected: boolean;
@@ -20,6 +18,7 @@ interface StateProvider {
20
18
  }
21
19
 
22
20
  export class PhantomProvider extends EventEmitter {
21
+ chainType = ChainTypes.SOLANA;
23
22
  _isUnlocked = false;
24
23
  name = "";
25
24
  icon = "";
@@ -92,7 +91,7 @@ export class PhantomProvider extends EventEmitter {
92
91
 
93
92
  subscribeWalletEventsCallback = ({ method, data }: { method: string; data: any }) => {
94
93
  if (method === "accountsChanged") {
95
- const accounts = data?.[chainType];
94
+ const accounts = data?.[this.chainType];
96
95
  this._handleAccountsChanged(accounts);
97
96
  }
98
97
  };
@@ -153,7 +152,7 @@ export class PhantomProvider extends EventEmitter {
153
152
 
154
153
  const dappInfo = await getDappInfo();
155
154
 
156
- this.sendRequest(chainType, { ...data, dappInfo });
155
+ this.sendRequest(this.chainType, { ...data, dappInfo });
157
156
 
158
157
  return this.onResponse(data).then((res: any) => {
159
158
  let { data } = res || {};
@@ -5,8 +5,7 @@ import type { Transaction } from "tronweb/lib/esm/types/Transaction";
5
5
 
6
6
  import { ChainTypes, IConnectors, IProductInfo } from "../types";
7
7
  import { ReadyPromise, domReadyCall, getDappInfo } from "../utils/index";
8
-
9
- const chainType = ChainTypes.TRON;
8
+ import { ITomoTronProvider } from "./types";
10
9
 
11
10
  interface StateProvider {
12
11
  accounts: any[] | null;
@@ -16,12 +15,15 @@ interface StateProvider {
16
15
  isPermanentlyDisconnected: boolean;
17
16
  }
18
17
 
19
- export class TomoTronProvider extends EventEmitter {
18
+ const _fullHost = "https://api.trongrid.io";
19
+ export class TomoTronProvider extends EventEmitter implements ITomoTronProvider {
20
+ type: ChainTypes.TRON = ChainTypes.TRON;
20
21
  _isUnlocked = false;
21
22
  name = "";
22
23
  icon = "";
23
24
  ready = false;
24
- tronWeb: TronWeb | null = null;
25
+ tronWeb: TronWeb = new TronWeb({ fullHost: _fullHost });
26
+ address: string = "";
25
27
  sendRequest: (chainType: string, data: any) => void;
26
28
  onResponse: any;
27
29
  events = {
@@ -73,7 +75,7 @@ export class TomoTronProvider extends EventEmitter {
73
75
  this.on("disconnect", (result: any) => {
74
76
  this._state.isConnected = false;
75
77
 
76
- this.tronWeb = null;
78
+ this.tronWeb = new TronWeb({ fullHost: _fullHost });
77
79
 
78
80
  window.postMessage(
79
81
  {
@@ -100,11 +102,12 @@ export class TomoTronProvider extends EventEmitter {
100
102
  );
101
103
  });
102
104
  }
105
+ switchChain?: ((chainId: string) => Promise<void>) | undefined;
103
106
 
104
107
  private _initTronWeb = async (res: any) => {
105
- const { fullHost = "https://api.trongrid.io", address } = res || {};
108
+ const { fullHost, address } = res || {};
106
109
  this.tronWeb = new TronWeb({
107
- fullHost,
110
+ fullHost: fullHost || _fullHost,
108
111
  });
109
112
 
110
113
  this.tronWeb.defaultAddress.base58 = address;
@@ -183,7 +186,7 @@ export class TomoTronProvider extends EventEmitter {
183
186
 
184
187
  subscribeWalletEventsCallback = ({ method, data }: { method: string; data: any }) => {
185
188
  if (method === "accountsChanged") {
186
- const accounts = data?.[chainType];
189
+ const accounts = data?.[this.type];
187
190
  this._handleAccountsChanged(accounts);
188
191
  }
189
192
  };
@@ -222,7 +225,7 @@ export class TomoTronProvider extends EventEmitter {
222
225
 
223
226
  const dappInfo = await getDappInfo();
224
227
 
225
- this.sendRequest(chainType, { ...data, dappInfo });
228
+ this.sendRequest(this.type, { ...data, dappInfo });
226
229
 
227
230
  return this.onResponse(data).then((res: any) => {
228
231
  const { data, method } = res || {};
package/src/tron/types.ts CHANGED
@@ -1,7 +1,10 @@
1
- import type { Transaction, SignedTransaction } from "tronweb/lib/esm/types/Transaction";
2
- import type { TronLinkWallet } from "@tronweb3/tronwallet-adapter-tronlink"; // Import TronLink wallet class
1
+ import type { TronLinkWallet, TronWeb } from "@tronweb3/tronwallet-adapter-tronlink"; // Import TronLink wallet class
2
+ import type { SignedTransaction, Transaction } from "tronweb/lib/esm/types/Transaction";
3
+ import { ChainTypes } from "types";
3
4
 
4
5
  export interface ITomoTronProvider extends TronLinkWallet {
6
+ type: ChainTypes.TRON;
7
+ tronWeb: TronWeb;
5
8
  address: string | null;
6
9
  connect(options?: Record<string, unknown>): Promise<void | any>;
7
10
  disconnect(): Promise<void | any>;
@@ -1,5 +1,6 @@
1
- export * from "./dapp";
1
+ export { ChainTypeEnum as ChainTypes } from "@tomo-inc/wallet-utils";
2
2
 
3
+ export * from "./dapp";
3
4
  export interface IProductInfo {
4
5
  name: string;
5
6
  rdns: string;
@@ -20,15 +21,3 @@ export interface IConnectors {
20
21
  sendRequest: (chainType: string, data: any) => void;
21
22
  onResponse: (data: any) => void;
22
23
  }
23
-
24
- export enum ChainTypes {
25
- BTC = "btc",
26
- DOGE = "doge",
27
- EVM = "evm",
28
- SOL = "sol",
29
- SUI = "sui",
30
- TON = "ton",
31
- TRON = "tron",
32
- COSMOS = "cosmos",
33
- APTOS = "aptos",
34
- }