@tronweb3/tronwallet-adapter-tokenpocket 1.0.4 → 1.0.6

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/lib/umd/index.js CHANGED
@@ -360,73 +360,74 @@
360
360
 
361
361
  var eventemitter3Exports = eventemitter3.exports;
362
362
 
363
- (function (exports) {
364
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
365
- return (mod && mod.__esModule) ? mod : { "default": mod };
366
- };
367
- Object.defineProperty(exports, "__esModule", { value: true });
368
- exports.Adapter = exports.AdapterState = exports.WalletReadyState = exports.EventEmitter = void 0;
369
- const eventemitter3_1 = __importDefault(eventemitter3Exports);
370
- exports.EventEmitter = eventemitter3_1.default;
371
- (function (WalletReadyState) {
372
- /**
373
- * Adapter will start to check if wallet exists after adapter instance is created.
374
- */
375
- WalletReadyState["Loading"] = "Loading";
376
- /**
377
- * When checking ends and wallet is not found, readyState will be NotFound.
378
- */
379
- WalletReadyState["NotFound"] = "NotFound";
380
- /**
381
- * When checking ends and wallet is found, readyState will be Found.
382
- */
383
- WalletReadyState["Found"] = "Found";
384
- })(exports.WalletReadyState || (exports.WalletReadyState = {}));
385
- /**
386
- * Adapter state
387
- */
388
- var AdapterState;
389
- (function (AdapterState) {
390
- /**
391
- * If adapter is checking the wallet, the state is Loading.
392
- */
393
- AdapterState["Loading"] = "Loading";
394
- /**
395
- * If wallet is not installed, the state is NotFound.
396
- */
397
- AdapterState["NotFound"] = "NotFound";
398
- /**
399
- * If wallet is installed but is not connected to current Dapp, the state is Disconnected.
400
- */
401
- AdapterState["Disconnect"] = "Disconnected";
402
- /**
403
- * Wallet is connected to current Dapp.
404
- */
405
- AdapterState["Connected"] = "Connected";
406
- })(AdapterState = exports.AdapterState || (exports.AdapterState = {}));
407
- class Adapter extends eventemitter3_1.default {
408
- get connected() {
409
- return this.state === AdapterState.Connected;
410
- }
411
- /**
412
- * Some wallets such as TronLink don't support disconnect() method.
413
- */
414
- disconnect() {
415
- console.info("The current adapter doesn't support disconnect by DApp.");
416
- return Promise.resolve();
417
- }
418
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
419
- multiSign(...args) {
420
- return Promise.reject("The current wallet doesn't support multiSign.");
421
- }
422
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
423
- switchChain(_chainId) {
424
- return Promise.reject("The current wallet doesn't support switch chain.");
425
- }
426
- }
427
- exports.Adapter = Adapter;
428
-
429
- } (adapter$1));
363
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
364
+ return (mod && mod.__esModule) ? mod : { "default": mod };
365
+ };
366
+ Object.defineProperty(adapter$1, "__esModule", { value: true });
367
+ adapter$1.Adapter = adapter$1.AdapterState = adapter$1.WalletReadyState = adapter$1.EventEmitter = void 0;
368
+ const eventemitter3_1 = __importDefault(eventemitter3Exports);
369
+ adapter$1.EventEmitter = eventemitter3_1.default;
370
+ /**
371
+ * Wallet ready state.
372
+ */
373
+ var WalletReadyState;
374
+ (function (WalletReadyState) {
375
+ /**
376
+ * Adapter will start to check if wallet exists after adapter instance is created.
377
+ */
378
+ WalletReadyState["Loading"] = "Loading";
379
+ /**
380
+ * When checking ends and wallet is not found, readyState will be NotFound.
381
+ */
382
+ WalletReadyState["NotFound"] = "NotFound";
383
+ /**
384
+ * When checking ends and wallet is found, readyState will be Found.
385
+ */
386
+ WalletReadyState["Found"] = "Found";
387
+ })(WalletReadyState || (adapter$1.WalletReadyState = WalletReadyState = {}));
388
+ /**
389
+ * Adapter state
390
+ */
391
+ var AdapterState;
392
+ (function (AdapterState) {
393
+ /**
394
+ * If adapter is checking the wallet, the state is Loading.
395
+ */
396
+ AdapterState["Loading"] = "Loading";
397
+ /**
398
+ * If wallet is not installed, the state is NotFound.
399
+ */
400
+ AdapterState["NotFound"] = "NotFound";
401
+ /**
402
+ * If wallet is installed but is not connected to current Dapp, the state is Disconnected.
403
+ */
404
+ AdapterState["Disconnect"] = "Disconnected";
405
+ /**
406
+ * Wallet is connected to current Dapp.
407
+ */
408
+ AdapterState["Connected"] = "Connected";
409
+ })(AdapterState || (adapter$1.AdapterState = AdapterState = {}));
410
+ class Adapter extends eventemitter3_1.default {
411
+ get connected() {
412
+ return this.state === AdapterState.Connected;
413
+ }
414
+ /**
415
+ * Some wallets such as TronLink don't support disconnect() method.
416
+ */
417
+ disconnect() {
418
+ console.info("The current adapter doesn't support disconnect by DApp.");
419
+ return Promise.resolve();
420
+ }
421
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
422
+ multiSign(...args) {
423
+ return Promise.reject("The current wallet doesn't support multiSign.");
424
+ }
425
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
426
+ switchChain(_chainId) {
427
+ return Promise.reject("The current wallet doesn't support switch chain.");
428
+ }
429
+ }
430
+ adapter$1.Adapter = Adapter;
430
431
 
431
432
  var errors = {};
432
433
 
@@ -557,30 +558,31 @@
557
558
 
558
559
  var types$1 = {};
559
560
 
560
- (function (exports) {
561
- Object.defineProperty(exports, "__esModule", { value: true });
562
- exports.ChainNetwork = exports.NetworkType = void 0;
563
- (function (NetworkType) {
564
- NetworkType["Mainnet"] = "Mainnet";
565
- NetworkType["Shasta"] = "Shasta";
566
- NetworkType["Nile"] = "Nile";
567
- /**
568
- * When use custom node
569
- */
570
- NetworkType["Unknown"] = "Unknown";
571
- })(exports.NetworkType || (exports.NetworkType = {}));
572
- (function (ChainNetwork) {
573
- ChainNetwork["Mainnet"] = "Mainnet";
574
- ChainNetwork["Shasta"] = "Shasta";
575
- ChainNetwork["Nile"] = "Nile";
576
- })(exports.ChainNetwork || (exports.ChainNetwork = {}));
577
-
578
- } (types$1));
561
+ Object.defineProperty(types$1, "__esModule", { value: true });
562
+ types$1.ChainNetwork = types$1.NetworkType = void 0;
563
+ var NetworkType;
564
+ (function (NetworkType) {
565
+ NetworkType["Mainnet"] = "Mainnet";
566
+ NetworkType["Shasta"] = "Shasta";
567
+ NetworkType["Nile"] = "Nile";
568
+ /**
569
+ * When use custom node
570
+ */
571
+ NetworkType["Unknown"] = "Unknown";
572
+ })(NetworkType || (types$1.NetworkType = NetworkType = {}));
573
+ var ChainNetwork;
574
+ (function (ChainNetwork) {
575
+ ChainNetwork["Mainnet"] = "Mainnet";
576
+ ChainNetwork["Shasta"] = "Shasta";
577
+ ChainNetwork["Nile"] = "Nile";
578
+ })(ChainNetwork || (types$1.ChainNetwork = ChainNetwork = {}));
579
579
 
580
580
  var utils$2 = {};
581
581
 
582
582
  Object.defineProperty(utils$2, "__esModule", { value: true });
583
- utils$2.isInMobileBrowser = utils$2.checkAdapterState = utils$2.isInBrowser = void 0;
583
+ utils$2.isInBrowser = isInBrowser;
584
+ utils$2.checkAdapterState = checkAdapterState;
585
+ utils$2.isInMobileBrowser = isInMobileBrowser;
584
586
  /**
585
587
  * check simply if current environment is browser or not
586
588
  * @returns boolean
@@ -588,7 +590,6 @@
588
590
  function isInBrowser() {
589
591
  return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined';
590
592
  }
591
- utils$2.isInBrowser = isInBrowser;
592
593
  /**
593
594
  *
594
595
  * @param {Function} check funcion to check if wallet is installed. return true if wallet is detected.
@@ -622,7 +623,6 @@
622
623
  // stop all task after 1min
623
624
  setTimeout(dispose, 60 * 1000);
624
625
  }
625
- utils$2.checkAdapterState = checkAdapterState;
626
626
  /**
627
627
  * Simplily detect mobile device
628
628
  */
@@ -630,7 +630,6 @@
630
630
  return (typeof navigator !== 'undefined' &&
631
631
  navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i));
632
632
  }
633
- utils$2.isInMobileBrowser = isInMobileBrowser;
634
633
 
635
634
  (function (exports) {
636
635
  var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -671,16 +670,18 @@
671
670
  });
672
671
  };
673
672
  Object.defineProperty(utils$1, "__esModule", { value: true });
674
- utils$1.waitTronwebReady = utils$1.openTronLink = utils$1.isInTronLinkApp = utils$1.supportTronLink = utils$1.supportTron = void 0;
673
+ utils$1.supportTron = supportTron;
674
+ utils$1.supportTronLink = supportTronLink;
675
+ utils$1.isInTronLinkApp = isInTronLinkApp;
676
+ utils$1.openTronLink = openTronLink;
677
+ utils$1.waitTronwebReady = waitTronwebReady;
675
678
  const tronwallet_abstract_adapter_1$1 = cjs$1;
676
679
  function supportTron() {
677
680
  return !!(window.tron && window.tron.isTronLink);
678
681
  }
679
- utils$1.supportTron = supportTron;
680
682
  function supportTronLink() {
681
683
  return !!(supportTron() || window.tronLink || window.tronWeb);
682
684
  }
683
- utils$1.supportTronLink = supportTronLink;
684
685
  /**
685
686
  * Detect if in TronLinkApp
686
687
  * Tron DApp running in the DApp Explorer injects iTron objects automatically to offer customized App service.
@@ -689,7 +690,6 @@
689
690
  function isInTronLinkApp() {
690
691
  return (0, tronwallet_abstract_adapter_1$1.isInBrowser)() && typeof window.iTron !== 'undefined';
691
692
  }
692
- utils$1.isInTronLinkApp = isInTronLinkApp;
693
693
  function openTronLink({ dappIcon, dappName } = { dappIcon: '', dappName: '' }) {
694
694
  if (!supportTronLink() && (0, tronwallet_abstract_adapter_1$1.isInMobileBrowser)() && !isInTronLinkApp()) {
695
695
  let defaultDappName = '', defaultDappIcon = '';
@@ -708,7 +708,7 @@
708
708
  const params = {
709
709
  action: 'open',
710
710
  actionId: Date.now() + '',
711
- callbackUrl: 'http://someurl.com',
711
+ callbackUrl: 'http://someurl.com', // no need callback
712
712
  dappIcon: dappIcon || defaultDappIcon,
713
713
  dappName: dappName || defaultDappName,
714
714
  url,
@@ -721,7 +721,6 @@
721
721
  }
722
722
  return false;
723
723
  }
724
- utils$1.openTronLink = openTronLink;
725
724
  function waitTronwebReady(tronObj) {
726
725
  return __awaiter(this, void 0, void 0, function* () {
727
726
  return new Promise((resolve, reject) => {
@@ -739,7 +738,6 @@
739
738
  });
740
739
  });
741
740
  }
742
- utils$1.waitTronwebReady = waitTronwebReady;
743
741
 
744
742
  (function (exports) {
745
743
  var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -752,7 +750,8 @@
752
750
  });
753
751
  };
754
752
  Object.defineProperty(exports, "__esModule", { value: true });
755
- exports.TronLinkAdapter = exports.TronLinkAdapterName = exports.getNetworkInfoByTronWeb = exports.chainIdNetworkMap = void 0;
753
+ exports.TronLinkAdapter = exports.TronLinkAdapterName = exports.chainIdNetworkMap = void 0;
754
+ exports.getNetworkInfoByTronWeb = getNetworkInfoByTronWeb;
756
755
  const tronwallet_abstract_adapter_1 = cjs$1;
757
756
  const utils_js_1 = utils$1;
758
757
  exports.chainIdNetworkMap = {
@@ -761,8 +760,8 @@
761
760
  '0xcd8690dc': tronwallet_abstract_adapter_1.NetworkType.Nile,
762
761
  };
763
762
  function getNetworkInfoByTronWeb(tronWeb) {
764
- var _a, _b, _c;
765
763
  return __awaiter(this, void 0, void 0, function* () {
764
+ var _a, _b, _c;
766
765
  const { blockID = '' } = yield tronWeb.trx.getBlockByNumber(0);
767
766
  const chainId = `0x${blockID.slice(-8)}`;
768
767
  return {
@@ -774,7 +773,6 @@
774
773
  };
775
774
  });
776
775
  }
777
- exports.getNetworkInfoByTronWeb = getNetworkInfoByTronWeb;
778
776
  exports.TronLinkAdapterName = 'TronLink';
779
777
  class TronLinkAdapter extends tronwallet_abstract_adapter_1.Adapter {
780
778
  // record if first connect event has emitted or not
@@ -960,8 +958,8 @@
960
958
  * @returns {Network} Current network information.
961
959
  */
962
960
  network() {
963
- var _a;
964
961
  return __awaiter(this, void 0, void 0, function* () {
962
+ var _a;
965
963
  try {
966
964
  yield this._checkWallet();
967
965
  if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
@@ -983,8 +981,8 @@
983
981
  });
984
982
  }
985
983
  connect() {
986
- var _a, _b;
987
984
  return __awaiter(this, void 0, void 0, function* () {
985
+ var _a, _b;
988
986
  try {
989
987
  this.checkIfOpenTronLink();
990
988
  if (this.connected || this.connecting)
@@ -1106,12 +1104,12 @@
1106
1104
  }
1107
1105
  });
1108
1106
  }
1109
- multiSign(...args) {
1107
+ multiSign(transaction, privateKey, permissionId) {
1110
1108
  return __awaiter(this, void 0, void 0, function* () {
1111
1109
  try {
1112
1110
  const wallet = yield this.checkAndGetWallet();
1113
1111
  try {
1114
- return yield wallet.tronWeb.trx.multiSign(...args);
1112
+ return yield wallet.tronWeb.trx.multiSign(transaction, privateKey, permissionId);
1115
1113
  }
1116
1114
  catch (error) {
1117
1115
  if (error instanceof Error) {
@@ -1329,12 +1327,13 @@
1329
1327
  var utils = {};
1330
1328
 
1331
1329
  Object.defineProperty(utils, "__esModule", { value: true });
1332
- utils.openTokenPocket = utils.isInTokenPocket = utils.supportTokenPocket = void 0;
1330
+ utils.supportTokenPocket = supportTokenPocket;
1331
+ utils.isInTokenPocket = isInTokenPocket;
1332
+ utils.openTokenPocket = openTokenPocket;
1333
1333
  const tronwallet_abstract_adapter_1 = cjs$1;
1334
1334
  function supportTokenPocket() {
1335
- return !!(0, tronwallet_abstract_adapter_1.isInMobileBrowser)() && !!window.tronWeb && typeof window.tokenpocket !== 'undefined';
1335
+ return !!window.tronWeb && typeof window.tokenpocket !== 'undefined';
1336
1336
  }
1337
- utils.supportTokenPocket = supportTokenPocket;
1338
1337
  /**
1339
1338
  * Detect if in TokenPocketApp
1340
1339
  * There will be a `tokenpocket` object on window
@@ -1342,7 +1341,6 @@
1342
1341
  function isInTokenPocket() {
1343
1342
  return (0, tronwallet_abstract_adapter_1.isInBrowser)() && typeof window.tokenpocket !== 'undefined';
1344
1343
  }
1345
- utils.isInTokenPocket = isInTokenPocket;
1346
1344
  function openTokenPocket() {
1347
1345
  if (!supportTokenPocket() && (0, tronwallet_abstract_adapter_1.isInMobileBrowser)() && !isInTokenPocket()) {
1348
1346
  const { origin, pathname, search, hash } = window.location;
@@ -1350,7 +1348,7 @@
1350
1348
  const params = {
1351
1349
  action: 'open',
1352
1350
  actionId: Date.now() + '',
1353
- callbackUrl: 'http://someurl.com',
1351
+ callbackUrl: 'http://someurl.com', // no need callback
1354
1352
  blockchain: 'Tron',
1355
1353
  chain: 'Tron',
1356
1354
  url,
@@ -1362,7 +1360,6 @@
1362
1360
  }
1363
1361
  return false;
1364
1362
  }
1365
- utils.openTokenPocket = openTokenPocket;
1366
1363
 
1367
1364
  (function (exports) {
1368
1365
  var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -1388,27 +1385,57 @@
1388
1385
  this.icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGc+CjxwYXRoIGQ9Ik0xMDQxLjUyIDBILTI3VjEwMjRIMTA0MS41MlYwWiIgZmlsbD0iIzI5ODBGRSIvPgo8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfNDA4XzIyNSkiPgo8cGF0aCBkPSJNNDA2Ljc5NiA0MzguNjQzSDQwNi45MjdDNDA2Ljc5NiA0MzcuODU3IDQwNi43OTYgNDM2Ljk0IDQwNi43OTYgNDM2LjE1NFY0MzguNjQzWiIgZmlsbD0iIzI5QUVGRiIvPgo8cGF0aCBkPSJNNjY3LjYwMiA0NjMuNTMzSDUyMy4yNDlWNzI0LjA3NkM1MjMuMjQ5IDczNi4zODkgNTMzLjIwNCA3NDYuMzQ1IDU0NS41MTcgNzQ2LjM0NUg2NDUuMzMzQzY1Ny42NDcgNzQ2LjM0NSA2NjcuNjAyIDczNi4zODkgNjY3LjYwMiA3MjQuMDc2VjQ2My41MzNaIiBmaWxsPSJ3aGl0ZSIvPgo8cGF0aCBkPSJNNDUzLjU2MyAyNzdINDQ4LjcxNkgxOTAuMjY5QzE3Ny45NTUgMjc3IDE2OCAyODYuOTU1IDE2OCAyOT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MjI1Ij4KPHJlY3Qgd2lkdGg9IjcyOC40NDgiIGhlaWdodD0iNDcwIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTY4IDI3NykiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K';
1389
1386
  this._readyState = (0, tronwallet_abstract_adapter_1.isInBrowser)() ? tronwallet_abstract_adapter_1.WalletReadyState.Loading : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
1390
1387
  this._state = tronwallet_abstract_adapter_1.AdapterState.Loading;
1388
+ this.onChainChanged = (data) => {
1389
+ this.emit('chainChanged', data);
1390
+ };
1391
+ this.onAccountsChanged = () => {
1392
+ var _a, _b, _c;
1393
+ const preAddr = this.address || '';
1394
+ const curAddr = (((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.tronWeb) && ((_c = (_b = this._wallet) === null || _b === void 0 ? void 0 : _b.tronWeb.defaultAddress) === null || _c === void 0 ? void 0 : _c.base58)) || '';
1395
+ if (!curAddr) {
1396
+ this.setAddress(null);
1397
+ this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
1398
+ }
1399
+ else {
1400
+ const address = curAddr;
1401
+ this.setAddress(address);
1402
+ this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
1403
+ }
1404
+ this.emit('accountsChanged', this.address || '', preAddr);
1405
+ if (!preAddr && this.address) {
1406
+ this.emit('connect', this.address);
1407
+ }
1408
+ else if (preAddr && !this.address) {
1409
+ this.emit('disconnect');
1410
+ }
1411
+ };
1391
1412
  this.checkReadyInterval = null;
1392
1413
  this._checkPromise = null;
1393
1414
  this._updateWallet = () => {
1394
- var _a, _b, _c, _d;
1415
+ var _a, _b, _c, _d, _e;
1395
1416
  let state = this.state;
1396
1417
  let address = this.address;
1397
1418
  if ((0, utils_js_1.supportTokenPocket)()) {
1398
- // fake tronLink
1399
- this._wallet = {
1400
- ready: (_a = window.tronWeb) === null || _a === void 0 ? void 0 : _a.ready,
1401
- tronWeb: window.tronWeb,
1402
- request: () => Promise.resolve(true),
1403
- };
1404
- address = ((_b = this._wallet.tronWeb.defaultAddress) === null || _b === void 0 ? void 0 : _b.base58) || null;
1405
- state = ((_c = window.tronWeb) === null || _c === void 0 ? void 0 : _c.ready) ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
1406
- if (!((_d = window.tronWeb) === null || _d === void 0 ? void 0 : _d.ready)) {
1419
+ const tron = (_a = window.tokenpocket) === null || _a === void 0 ? void 0 : _a.tron;
1420
+ this._wallet = (0, tronwallet_abstract_adapter_1.isInMobileBrowser)()
1421
+ ? {
1422
+ tron,
1423
+ ready: (_b = window.tronWeb) === null || _b === void 0 ? void 0 : _b.ready,
1424
+ tronWeb: (_c = window.tokenpocket) === null || _c === void 0 ? void 0 : _c.tronWeb,
1425
+ }
1426
+ : {
1427
+ tron,
1428
+ ready: !!((_d = (tron === null || tron === void 0 ? void 0 : tron.tronWeb).defaultAddress) === null || _d === void 0 ? void 0 : _d.base58) || false,
1429
+ tronWeb: tron === null || tron === void 0 ? void 0 : tron.tronWeb,
1430
+ };
1431
+ address = ((_e = this._wallet.tronWeb.defaultAddress) === null || _e === void 0 ? void 0 : _e.base58) || null;
1432
+ state = address ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
1433
+ this.listenTronEvent();
1434
+ if (!address) {
1407
1435
  this.checkForWalletReady();
1408
1436
  }
1409
1437
  }
1410
1438
  else {
1411
- // no tronlink support
1412
1439
  this._wallet = null;
1413
1440
  address = null;
1414
1441
  state = tronwallet_abstract_adapter_1.AdapterState.NotFound;
@@ -1428,12 +1455,6 @@
1428
1455
  this._connecting = false;
1429
1456
  this._wallet = null;
1430
1457
  this._address = null;
1431
- if (!(0, tronwallet_abstract_adapter_1.isInMobileBrowser)()) {
1432
- // Currently TokenPocket extension does not support Tron.
1433
- this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
1434
- this._state = tronwallet_abstract_adapter_1.AdapterState.NotFound;
1435
- return;
1436
- }
1437
1458
  if ((0, utils_js_1.supportTokenPocket)()) {
1438
1459
  this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.Found;
1439
1460
  this._updateWallet();
@@ -1485,7 +1506,6 @@
1485
1506
  });
1486
1507
  }
1487
1508
  connect() {
1488
- var _a;
1489
1509
  return __awaiter(this, void 0, void 0, function* () {
1490
1510
  try {
1491
1511
  this.checkIfOpenApp();
@@ -1502,9 +1522,14 @@
1502
1522
  return;
1503
1523
  this._connecting = true;
1504
1524
  const wallet = this._wallet;
1505
- const address = ((_a = wallet.tronWeb.defaultAddress) === null || _a === void 0 ? void 0 : _a.base58) || '';
1525
+ const res = yield wallet.tron.request({ method: 'eth_requestAccounts' });
1526
+ if (!(res === null || res === void 0 ? void 0 : res[0])) {
1527
+ throw new tronwallet_abstract_adapter_1.WalletConnectionError('Request connect error.');
1528
+ }
1529
+ const address = res[0];
1506
1530
  this.setAddress(address);
1507
1531
  this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
1532
+ this.listenTronEvent();
1508
1533
  this.emit('connect', this.address || '');
1509
1534
  }
1510
1535
  catch (error) {
@@ -1548,12 +1573,12 @@
1548
1573
  }
1549
1574
  });
1550
1575
  }
1551
- multiSign(...args) {
1576
+ multiSign(transaction, privateKey, permissionId) {
1552
1577
  return __awaiter(this, void 0, void 0, function* () {
1553
1578
  try {
1554
1579
  const wallet = yield this.checkAndGetWallet();
1555
1580
  try {
1556
- return yield wallet.tronWeb.trx.multiSign(...args);
1581
+ return yield wallet.tronWeb.trx.multiSign(transaction, privateKey, permissionId);
1557
1582
  }
1558
1583
  catch (error) {
1559
1584
  if (error instanceof Error) {
@@ -1592,6 +1617,27 @@
1592
1617
  }
1593
1618
  });
1594
1619
  }
1620
+ listenTronEvent() {
1621
+ if ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)()) {
1622
+ return;
1623
+ }
1624
+ this.stopListenTronEvent();
1625
+ const wallet = this._wallet;
1626
+ if (!wallet || !wallet.tron)
1627
+ return;
1628
+ wallet.tron.on('chainChanged', this.onChainChanged);
1629
+ wallet.tron.on('accountsChanged', this.onAccountsChanged);
1630
+ }
1631
+ stopListenTronEvent() {
1632
+ if ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)()) {
1633
+ return;
1634
+ }
1635
+ const wallet = this._wallet;
1636
+ if (!wallet || !wallet.tron)
1637
+ return;
1638
+ wallet.tron.removeListener('chainChanged', this.onChainChanged);
1639
+ wallet.tron.removeListener('accountsChanged', this.onAccountsChanged);
1640
+ }
1595
1641
  checkAndGetWallet() {
1596
1642
  return __awaiter(this, void 0, void 0, function* () {
1597
1643
  this.checkIfOpenApp();
@@ -1619,8 +1665,8 @@
1619
1665
  let times = 0;
1620
1666
  const maxTimes = Math.floor(this.config.checkTimeout / 200);
1621
1667
  const check = () => {
1622
- var _a;
1623
- if ((_a = window === null || window === void 0 ? void 0 : window.tronWeb) === null || _a === void 0 ? void 0 : _a.ready) {
1668
+ var _a, _b;
1669
+ if ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)() ? (_a = window.tronWeb) === null || _a === void 0 ? void 0 : _a.ready : (_b = this._wallet) === null || _b === void 0 ? void 0 : _b.ready) {
1624
1670
  this.checkReadyInterval && clearInterval(this.checkReadyInterval);
1625
1671
  this.checkReadyInterval = null;
1626
1672
  this._updateWallet();