@openocean.finance/wallet 0.4.42 → 0.4.44

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.
@@ -64,6 +64,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
64
64
  var tronlink_svg_1 = __importDefault(require("../assets/tronlink.svg"));
65
65
  var types_1 = require("../types");
66
66
  var BaseWallet_1 = __importDefault(require("./BaseWallet"));
67
+ var helper_1 = require("../helper");
67
68
  var TronLink = /** @class */ (function (_super) {
68
69
  __extends(TronLink, _super);
69
70
  function TronLink() {
@@ -83,32 +84,38 @@ var TronLink = /** @class */ (function (_super) {
83
84
  return __awaiter(this, void 0, void 0, function () {
84
85
  var _this = this;
85
86
  return __generator(this, function (_a) {
86
- return [2 /*return*/, new Promise(function (res) {
87
- if (!window.tronWeb) {
88
- throw new Error(types_1.EnumErrors.NoTronLink);
89
- }
90
- var account = window.tronWeb.defaultAddress.base58;
91
- if (!account) {
92
- setTimeout(function () {
93
- account = window.tronWeb.defaultAddress.base58;
94
- if (!account) {
95
- throw new Error(types_1.EnumErrors.NoTronLinkAccount);
96
- }
97
- else {
98
- _this.sdk = window.tronWeb;
99
- _this.address = account;
100
- _this.chainId = ''; // todo tron chainId
87
+ return [2 /*return*/, new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
88
+ var result, tronWeb, res_1, account;
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0: return [4 /*yield*/, (0, helper_1.autoWalletCheck)(function () {
92
+ return window.tronLink;
93
+ }, 3000, 30)];
94
+ case 1:
95
+ result = _a.sent();
96
+ if (!result) {
97
+ throw new Error(types_1.EnumErrors.NoTronLink);
98
+ }
99
+ if (!window.tronLink.ready) return [3 /*break*/, 2];
100
+ tronWeb = window.tronLink.tronWeb;
101
+ return [3 /*break*/, 4];
102
+ case 2: return [4 /*yield*/, window.tronLink.request({ method: 'tron_requestAccounts' })];
103
+ case 3:
104
+ res_1 = _a.sent();
105
+ if (res_1.code === 200) {
106
+ tronWeb = window.tronLink.tronWeb;
107
+ }
108
+ _a.label = 4;
109
+ case 4:
110
+ account = tronWeb.defaultAddress.base58;
111
+ this.sdk = tronWeb;
112
+ this.address = account;
113
+ this.chainId = ''; // todo tron chainId
101
114
  res(account);
102
- }
103
- }, 1000);
104
- }
105
- else {
106
- _this.sdk = window.tronWeb;
107
- _this.address = account;
108
- _this.chainId = ''; // todo tron chainId
109
- res(account);
110
- }
111
- })];
115
+ return [2 /*return*/];
116
+ }
117
+ });
118
+ }); })];
112
119
  });
113
120
  });
114
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/wallet",
3
- "version": "0.4.42",
3
+ "version": "0.4.44",
4
4
  "description": "A multi-chain wallets manager",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {