@tronweb3/tronwallet-adapter-tokenpocket 1.0.1 → 1.0.2
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 +1710 -0
- package/lib/umd/index.min.js +1 -0
- package/package.json +5 -4
package/lib/umd/index.js
ADDED
|
@@ -0,0 +1,1710 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@tronweb3/tronwallet-adapter-tokenpocket"] = factory());
|
|
5
|
+
})(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
|
+
|
|
9
|
+
function getDefaultExportFromCjs (x) {
|
|
10
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var cjs$2 = {};
|
|
14
|
+
|
|
15
|
+
var adapter$2 = {};
|
|
16
|
+
|
|
17
|
+
var cjs$1 = {};
|
|
18
|
+
|
|
19
|
+
var adapter$1 = {};
|
|
20
|
+
|
|
21
|
+
var eventemitter3 = {exports: {}};
|
|
22
|
+
|
|
23
|
+
(function (module) {
|
|
24
|
+
|
|
25
|
+
var has = Object.prototype.hasOwnProperty
|
|
26
|
+
, prefix = '~';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Constructor to create a storage for our `EE` objects.
|
|
30
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
31
|
+
*
|
|
32
|
+
* @constructor
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
function Events() {}
|
|
36
|
+
|
|
37
|
+
//
|
|
38
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
39
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
40
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
41
|
+
// character to make sure that the built-in object properties are not
|
|
42
|
+
// overridden or used as an attack vector.
|
|
43
|
+
//
|
|
44
|
+
if (Object.create) {
|
|
45
|
+
Events.prototype = Object.create(null);
|
|
46
|
+
|
|
47
|
+
//
|
|
48
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
49
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
50
|
+
//
|
|
51
|
+
if (!new Events().__proto__) prefix = false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Representation of a single event listener.
|
|
56
|
+
*
|
|
57
|
+
* @param {Function} fn The listener function.
|
|
58
|
+
* @param {*} context The context to invoke the listener with.
|
|
59
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
60
|
+
* @constructor
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
function EE(fn, context, once) {
|
|
64
|
+
this.fn = fn;
|
|
65
|
+
this.context = context;
|
|
66
|
+
this.once = once || false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Add a listener for a given event.
|
|
71
|
+
*
|
|
72
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
73
|
+
* @param {(String|Symbol)} event The event name.
|
|
74
|
+
* @param {Function} fn The listener function.
|
|
75
|
+
* @param {*} context The context to invoke the listener with.
|
|
76
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
77
|
+
* @returns {EventEmitter}
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
function addListener(emitter, event, fn, context, once) {
|
|
81
|
+
if (typeof fn !== 'function') {
|
|
82
|
+
throw new TypeError('The listener must be a function');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var listener = new EE(fn, context || emitter, once)
|
|
86
|
+
, evt = prefix ? prefix + event : event;
|
|
87
|
+
|
|
88
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
89
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
90
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
91
|
+
|
|
92
|
+
return emitter;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Clear event by name.
|
|
97
|
+
*
|
|
98
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
99
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
function clearEvent(emitter, evt) {
|
|
103
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
104
|
+
else delete emitter._events[evt];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
109
|
+
* `EventEmitter` interface.
|
|
110
|
+
*
|
|
111
|
+
* @constructor
|
|
112
|
+
* @public
|
|
113
|
+
*/
|
|
114
|
+
function EventEmitter() {
|
|
115
|
+
this._events = new Events();
|
|
116
|
+
this._eventsCount = 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Return an array listing the events for which the emitter has registered
|
|
121
|
+
* listeners.
|
|
122
|
+
*
|
|
123
|
+
* @returns {Array}
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
127
|
+
var names = []
|
|
128
|
+
, events
|
|
129
|
+
, name;
|
|
130
|
+
|
|
131
|
+
if (this._eventsCount === 0) return names;
|
|
132
|
+
|
|
133
|
+
for (name in (events = this._events)) {
|
|
134
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (Object.getOwnPropertySymbols) {
|
|
138
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return names;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Return the listeners registered for a given event.
|
|
146
|
+
*
|
|
147
|
+
* @param {(String|Symbol)} event The event name.
|
|
148
|
+
* @returns {Array} The registered listeners.
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
152
|
+
var evt = prefix ? prefix + event : event
|
|
153
|
+
, handlers = this._events[evt];
|
|
154
|
+
|
|
155
|
+
if (!handlers) return [];
|
|
156
|
+
if (handlers.fn) return [handlers.fn];
|
|
157
|
+
|
|
158
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
159
|
+
ee[i] = handlers[i].fn;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return ee;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Return the number of listeners listening to a given event.
|
|
167
|
+
*
|
|
168
|
+
* @param {(String|Symbol)} event The event name.
|
|
169
|
+
* @returns {Number} The number of listeners.
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
173
|
+
var evt = prefix ? prefix + event : event
|
|
174
|
+
, listeners = this._events[evt];
|
|
175
|
+
|
|
176
|
+
if (!listeners) return 0;
|
|
177
|
+
if (listeners.fn) return 1;
|
|
178
|
+
return listeners.length;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Calls each of the listeners registered for a given event.
|
|
183
|
+
*
|
|
184
|
+
* @param {(String|Symbol)} event The event name.
|
|
185
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
186
|
+
* @public
|
|
187
|
+
*/
|
|
188
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
189
|
+
var evt = prefix ? prefix + event : event;
|
|
190
|
+
|
|
191
|
+
if (!this._events[evt]) return false;
|
|
192
|
+
|
|
193
|
+
var listeners = this._events[evt]
|
|
194
|
+
, len = arguments.length
|
|
195
|
+
, args
|
|
196
|
+
, i;
|
|
197
|
+
|
|
198
|
+
if (listeners.fn) {
|
|
199
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
200
|
+
|
|
201
|
+
switch (len) {
|
|
202
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
203
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
204
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
205
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
206
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
207
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
211
|
+
args[i - 1] = arguments[i];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
listeners.fn.apply(listeners.context, args);
|
|
215
|
+
} else {
|
|
216
|
+
var length = listeners.length
|
|
217
|
+
, j;
|
|
218
|
+
|
|
219
|
+
for (i = 0; i < length; i++) {
|
|
220
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
221
|
+
|
|
222
|
+
switch (len) {
|
|
223
|
+
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
224
|
+
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
225
|
+
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
226
|
+
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
227
|
+
default:
|
|
228
|
+
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
229
|
+
args[j - 1] = arguments[j];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return true;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Add a listener for a given event.
|
|
242
|
+
*
|
|
243
|
+
* @param {(String|Symbol)} event The event name.
|
|
244
|
+
* @param {Function} fn The listener function.
|
|
245
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
246
|
+
* @returns {EventEmitter} `this`.
|
|
247
|
+
* @public
|
|
248
|
+
*/
|
|
249
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
250
|
+
return addListener(this, event, fn, context, false);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Add a one-time listener for a given event.
|
|
255
|
+
*
|
|
256
|
+
* @param {(String|Symbol)} event The event name.
|
|
257
|
+
* @param {Function} fn The listener function.
|
|
258
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
259
|
+
* @returns {EventEmitter} `this`.
|
|
260
|
+
* @public
|
|
261
|
+
*/
|
|
262
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
263
|
+
return addListener(this, event, fn, context, true);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Remove the listeners of a given event.
|
|
268
|
+
*
|
|
269
|
+
* @param {(String|Symbol)} event The event name.
|
|
270
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
271
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
272
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
273
|
+
* @returns {EventEmitter} `this`.
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
277
|
+
var evt = prefix ? prefix + event : event;
|
|
278
|
+
|
|
279
|
+
if (!this._events[evt]) return this;
|
|
280
|
+
if (!fn) {
|
|
281
|
+
clearEvent(this, evt);
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
var listeners = this._events[evt];
|
|
286
|
+
|
|
287
|
+
if (listeners.fn) {
|
|
288
|
+
if (
|
|
289
|
+
listeners.fn === fn &&
|
|
290
|
+
(!once || listeners.once) &&
|
|
291
|
+
(!context || listeners.context === context)
|
|
292
|
+
) {
|
|
293
|
+
clearEvent(this, evt);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
297
|
+
if (
|
|
298
|
+
listeners[i].fn !== fn ||
|
|
299
|
+
(once && !listeners[i].once) ||
|
|
300
|
+
(context && listeners[i].context !== context)
|
|
301
|
+
) {
|
|
302
|
+
events.push(listeners[i]);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
//
|
|
307
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
308
|
+
//
|
|
309
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
310
|
+
else clearEvent(this, evt);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return this;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Remove all listeners, or those of the specified event.
|
|
318
|
+
*
|
|
319
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
320
|
+
* @returns {EventEmitter} `this`.
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
324
|
+
var evt;
|
|
325
|
+
|
|
326
|
+
if (event) {
|
|
327
|
+
evt = prefix ? prefix + event : event;
|
|
328
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
329
|
+
} else {
|
|
330
|
+
this._events = new Events();
|
|
331
|
+
this._eventsCount = 0;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return this;
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
//
|
|
338
|
+
// Alias methods names because people roll like that.
|
|
339
|
+
//
|
|
340
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
341
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
342
|
+
|
|
343
|
+
//
|
|
344
|
+
// Expose the prefix.
|
|
345
|
+
//
|
|
346
|
+
EventEmitter.prefixed = prefix;
|
|
347
|
+
|
|
348
|
+
//
|
|
349
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
350
|
+
//
|
|
351
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
352
|
+
|
|
353
|
+
//
|
|
354
|
+
// Expose the module.
|
|
355
|
+
//
|
|
356
|
+
{
|
|
357
|
+
module.exports = EventEmitter;
|
|
358
|
+
}
|
|
359
|
+
} (eventemitter3));
|
|
360
|
+
|
|
361
|
+
var eventemitter3Exports = eventemitter3.exports;
|
|
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));
|
|
430
|
+
|
|
431
|
+
var errors = {};
|
|
432
|
+
|
|
433
|
+
Object.defineProperty(errors, "__esModule", { value: true });
|
|
434
|
+
errors.WalletGetNetworkError = errors.WalletSwitchChainError = errors.WalletWindowClosedError = errors.WalletWalletLoadError = errors.WalletSignTransactionError = errors.WalletSignMessageError = errors.WalletDisconnectionError = errors.WalletConnectionError = errors.WalletDisconnectedError = errors.WalletNotSelectedError = errors.WalletNotFoundError = errors.WalletError = void 0;
|
|
435
|
+
class WalletError extends Error {
|
|
436
|
+
constructor(message, error) {
|
|
437
|
+
super(message);
|
|
438
|
+
this.error = error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
errors.WalletError = WalletError;
|
|
442
|
+
/**
|
|
443
|
+
* Occurs when wallet is not installed.
|
|
444
|
+
*/
|
|
445
|
+
class WalletNotFoundError extends WalletError {
|
|
446
|
+
constructor() {
|
|
447
|
+
super(...arguments);
|
|
448
|
+
this.name = 'WalletNotFoundError';
|
|
449
|
+
this.message = 'The wallet is not found.';
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
errors.WalletNotFoundError = WalletNotFoundError;
|
|
453
|
+
/**
|
|
454
|
+
* Occurs when connect to a wallet but there is no wallet selected.
|
|
455
|
+
*/
|
|
456
|
+
class WalletNotSelectedError extends WalletError {
|
|
457
|
+
constructor() {
|
|
458
|
+
super(...arguments);
|
|
459
|
+
this.name = 'WalletNotSelectedError';
|
|
460
|
+
this.message = 'No wallet is selected. Please select a wallet.';
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
errors.WalletNotSelectedError = WalletNotSelectedError;
|
|
464
|
+
/**
|
|
465
|
+
* Occurs when wallet is disconnected.
|
|
466
|
+
* Used by some wallets which won't connect automatically when call `signMessage()` or `signTransaction()`.
|
|
467
|
+
*/
|
|
468
|
+
class WalletDisconnectedError extends WalletError {
|
|
469
|
+
constructor() {
|
|
470
|
+
super(...arguments);
|
|
471
|
+
this.name = 'WalletDisconnectedError';
|
|
472
|
+
this.message = 'The wallet is disconnected. Please connect first.';
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
errors.WalletDisconnectedError = WalletDisconnectedError;
|
|
476
|
+
/**
|
|
477
|
+
* Occurs when try to connect a wallet.
|
|
478
|
+
*/
|
|
479
|
+
class WalletConnectionError extends WalletError {
|
|
480
|
+
constructor() {
|
|
481
|
+
super(...arguments);
|
|
482
|
+
this.name = 'WalletConnectionError';
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
errors.WalletConnectionError = WalletConnectionError;
|
|
486
|
+
/**
|
|
487
|
+
* Occurs when try to disconnect a wallet.
|
|
488
|
+
*/
|
|
489
|
+
class WalletDisconnectionError extends WalletError {
|
|
490
|
+
constructor() {
|
|
491
|
+
super(...arguments);
|
|
492
|
+
this.name = 'WalletDisconnectionError';
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
errors.WalletDisconnectionError = WalletDisconnectionError;
|
|
496
|
+
/**
|
|
497
|
+
* Occurs when call `signMessage()`.
|
|
498
|
+
*/
|
|
499
|
+
class WalletSignMessageError extends WalletError {
|
|
500
|
+
constructor() {
|
|
501
|
+
super(...arguments);
|
|
502
|
+
this.name = 'WalletSignMessageError';
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
errors.WalletSignMessageError = WalletSignMessageError;
|
|
506
|
+
/**
|
|
507
|
+
* Occurs when call `signTransaction()`.
|
|
508
|
+
*/
|
|
509
|
+
class WalletSignTransactionError extends WalletError {
|
|
510
|
+
constructor() {
|
|
511
|
+
super(...arguments);
|
|
512
|
+
this.name = 'WalletSignTransactionError';
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
errors.WalletSignTransactionError = WalletSignTransactionError;
|
|
516
|
+
/**
|
|
517
|
+
* Occurs when load wallet
|
|
518
|
+
*/
|
|
519
|
+
class WalletWalletLoadError extends WalletError {
|
|
520
|
+
constructor() {
|
|
521
|
+
super(...arguments);
|
|
522
|
+
this.name = 'WalletWalletLoadError';
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
errors.WalletWalletLoadError = WalletWalletLoadError;
|
|
526
|
+
/**
|
|
527
|
+
* Occurs when walletconnect QR window is closed.
|
|
528
|
+
*/
|
|
529
|
+
class WalletWindowClosedError extends WalletError {
|
|
530
|
+
constructor() {
|
|
531
|
+
super(...arguments);
|
|
532
|
+
this.name = 'WalletWindowClosedError';
|
|
533
|
+
this.message = 'The QR window is closed.';
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
errors.WalletWindowClosedError = WalletWindowClosedError;
|
|
537
|
+
/**
|
|
538
|
+
* Occurs when request wallet to switch chain.
|
|
539
|
+
*/
|
|
540
|
+
class WalletSwitchChainError extends WalletError {
|
|
541
|
+
constructor() {
|
|
542
|
+
super(...arguments);
|
|
543
|
+
this.name = 'WalletSwitchChainError';
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
errors.WalletSwitchChainError = WalletSwitchChainError;
|
|
547
|
+
/**
|
|
548
|
+
* Occurs when get network infomation.
|
|
549
|
+
*/
|
|
550
|
+
class WalletGetNetworkError extends WalletError {
|
|
551
|
+
constructor() {
|
|
552
|
+
super(...arguments);
|
|
553
|
+
this.name = 'WalletGetNetworkError';
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
errors.WalletGetNetworkError = WalletGetNetworkError;
|
|
557
|
+
|
|
558
|
+
var types$1 = {};
|
|
559
|
+
|
|
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));
|
|
579
|
+
|
|
580
|
+
var utils$2 = {};
|
|
581
|
+
|
|
582
|
+
Object.defineProperty(utils$2, "__esModule", { value: true });
|
|
583
|
+
utils$2.isInMobileBrowser = utils$2.checkAdapterState = utils$2.isInBrowser = void 0;
|
|
584
|
+
/**
|
|
585
|
+
* check simply if current environment is browser or not
|
|
586
|
+
* @returns boolean
|
|
587
|
+
*/
|
|
588
|
+
function isInBrowser() {
|
|
589
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined';
|
|
590
|
+
}
|
|
591
|
+
utils$2.isInBrowser = isInBrowser;
|
|
592
|
+
/**
|
|
593
|
+
*
|
|
594
|
+
* @param {Function} check funcion to check if wallet is installed. return true if wallet is detected.
|
|
595
|
+
* @returns
|
|
596
|
+
*/
|
|
597
|
+
function checkAdapterState(check) {
|
|
598
|
+
if (!isInBrowser())
|
|
599
|
+
return;
|
|
600
|
+
const disposers = [];
|
|
601
|
+
function dispose() {
|
|
602
|
+
for (const dispose of disposers) {
|
|
603
|
+
dispose();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function checkAndDispose() {
|
|
607
|
+
if (check()) {
|
|
608
|
+
dispose();
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const interval = setInterval(checkAndDispose, 500);
|
|
612
|
+
disposers.push(() => clearInterval(interval));
|
|
613
|
+
if (document.readyState === 'loading') {
|
|
614
|
+
document.addEventListener('DOMContentLoaded', checkAndDispose, { once: true });
|
|
615
|
+
disposers.push(() => document.removeEventListener('DOMContentLoaded', checkAndDispose));
|
|
616
|
+
}
|
|
617
|
+
if (document.readyState !== 'complete') {
|
|
618
|
+
window.addEventListener('load', checkAndDispose, { once: true });
|
|
619
|
+
disposers.push(() => window.removeEventListener('load', checkAndDispose));
|
|
620
|
+
}
|
|
621
|
+
checkAndDispose();
|
|
622
|
+
// stop all task after 1min
|
|
623
|
+
setTimeout(dispose, 60 * 1000);
|
|
624
|
+
}
|
|
625
|
+
utils$2.checkAdapterState = checkAdapterState;
|
|
626
|
+
/**
|
|
627
|
+
* Simplily detect mobile device
|
|
628
|
+
*/
|
|
629
|
+
function isInMobileBrowser() {
|
|
630
|
+
return (typeof navigator !== 'undefined' &&
|
|
631
|
+
navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i));
|
|
632
|
+
}
|
|
633
|
+
utils$2.isInMobileBrowser = isInMobileBrowser;
|
|
634
|
+
|
|
635
|
+
(function (exports) {
|
|
636
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
637
|
+
if (k2 === undefined) k2 = k;
|
|
638
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
639
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
640
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
641
|
+
}
|
|
642
|
+
Object.defineProperty(o, k2, desc);
|
|
643
|
+
}) : (function(o, m, k, k2) {
|
|
644
|
+
if (k2 === undefined) k2 = k;
|
|
645
|
+
o[k2] = m[k];
|
|
646
|
+
}));
|
|
647
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
648
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
649
|
+
};
|
|
650
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
651
|
+
__exportStar(adapter$1, exports);
|
|
652
|
+
__exportStar(errors, exports);
|
|
653
|
+
__exportStar(types$1, exports);
|
|
654
|
+
__exportStar(utils$2, exports);
|
|
655
|
+
|
|
656
|
+
} (cjs$1));
|
|
657
|
+
|
|
658
|
+
var cjs = {};
|
|
659
|
+
|
|
660
|
+
var adapter = {};
|
|
661
|
+
|
|
662
|
+
var utils$1 = {};
|
|
663
|
+
|
|
664
|
+
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
665
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
666
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
667
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
668
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
669
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
670
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
671
|
+
});
|
|
672
|
+
};
|
|
673
|
+
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;
|
|
675
|
+
const tronwallet_abstract_adapter_1$1 = cjs$1;
|
|
676
|
+
function supportTron() {
|
|
677
|
+
return !!(window.tron && window.tron.isTronLink);
|
|
678
|
+
}
|
|
679
|
+
utils$1.supportTron = supportTron;
|
|
680
|
+
function supportTronLink() {
|
|
681
|
+
return !!(supportTron() || window.tronLink || window.tronWeb);
|
|
682
|
+
}
|
|
683
|
+
utils$1.supportTronLink = supportTronLink;
|
|
684
|
+
/**
|
|
685
|
+
* Detect if in TronLinkApp
|
|
686
|
+
* Tron DApp running in the DApp Explorer injects iTron objects automatically to offer customized App service.
|
|
687
|
+
* See [here](https://docs.tronlink.org/tronlink-app/dapp-support/dapp-explorer)
|
|
688
|
+
*/
|
|
689
|
+
function isInTronLinkApp() {
|
|
690
|
+
return (0, tronwallet_abstract_adapter_1$1.isInBrowser)() && typeof window.iTron !== 'undefined';
|
|
691
|
+
}
|
|
692
|
+
utils$1.isInTronLinkApp = isInTronLinkApp;
|
|
693
|
+
function openTronLink({ dappIcon, dappName } = { dappIcon: '', dappName: '' }) {
|
|
694
|
+
if (!supportTronLink() && (0, tronwallet_abstract_adapter_1$1.isInMobileBrowser)() && !isInTronLinkApp()) {
|
|
695
|
+
let defaultDappName = '', defaultDappIcon = '';
|
|
696
|
+
try {
|
|
697
|
+
defaultDappName = document.title;
|
|
698
|
+
const link = document.querySelector('link[rel*="icon"]');
|
|
699
|
+
if (link) {
|
|
700
|
+
defaultDappIcon = new URL(link.getAttribute('href') || '', location.href).toString();
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
catch (e) {
|
|
704
|
+
// console.error(e);
|
|
705
|
+
}
|
|
706
|
+
const { origin, pathname, search, hash } = window.location;
|
|
707
|
+
const url = origin + pathname + search + (hash.includes('?') ? hash : `${hash}?_=1`);
|
|
708
|
+
const params = {
|
|
709
|
+
action: 'open',
|
|
710
|
+
actionId: Date.now() + '',
|
|
711
|
+
callbackUrl: 'http://someurl.com',
|
|
712
|
+
dappIcon: dappIcon || defaultDappIcon,
|
|
713
|
+
dappName: dappName || defaultDappName,
|
|
714
|
+
url,
|
|
715
|
+
protocol: 'TronLink',
|
|
716
|
+
version: '1.0',
|
|
717
|
+
chainId: '0x2b6653dc',
|
|
718
|
+
};
|
|
719
|
+
window.location.href = `tronlinkoutside://pull.activity?param=${encodeURIComponent(JSON.stringify(params))}`;
|
|
720
|
+
return true;
|
|
721
|
+
}
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
utils$1.openTronLink = openTronLink;
|
|
725
|
+
function waitTronwebReady(tronObj) {
|
|
726
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
727
|
+
return new Promise((resolve, reject) => {
|
|
728
|
+
const interval = setInterval(() => {
|
|
729
|
+
if (tronObj.tronWeb) {
|
|
730
|
+
clearInterval(interval);
|
|
731
|
+
clearTimeout(timeout);
|
|
732
|
+
resolve();
|
|
733
|
+
}
|
|
734
|
+
}, 50);
|
|
735
|
+
const timeout = setTimeout(() => {
|
|
736
|
+
clearInterval(interval);
|
|
737
|
+
reject('`window.tron.tronweb` is not ready.');
|
|
738
|
+
}, 2000);
|
|
739
|
+
});
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
utils$1.waitTronwebReady = waitTronwebReady;
|
|
743
|
+
|
|
744
|
+
(function (exports) {
|
|
745
|
+
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
746
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
747
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
748
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
749
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
750
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
751
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
752
|
+
});
|
|
753
|
+
};
|
|
754
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
755
|
+
exports.TronLinkAdapter = exports.TronLinkAdapterName = exports.getNetworkInfoByTronWeb = exports.chainIdNetworkMap = void 0;
|
|
756
|
+
const tronwallet_abstract_adapter_1 = cjs$1;
|
|
757
|
+
const utils_js_1 = utils$1;
|
|
758
|
+
exports.chainIdNetworkMap = {
|
|
759
|
+
'0x2b6653dc': tronwallet_abstract_adapter_1.NetworkType.Mainnet,
|
|
760
|
+
'0x94a9059e': tronwallet_abstract_adapter_1.NetworkType.Shasta,
|
|
761
|
+
'0xcd8690dc': tronwallet_abstract_adapter_1.NetworkType.Nile,
|
|
762
|
+
};
|
|
763
|
+
function getNetworkInfoByTronWeb(tronWeb) {
|
|
764
|
+
var _a, _b, _c;
|
|
765
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
766
|
+
const { blockID = '' } = yield tronWeb.trx.getBlockByNumber(0);
|
|
767
|
+
const chainId = `0x${blockID.slice(-8)}`;
|
|
768
|
+
return {
|
|
769
|
+
networkType: exports.chainIdNetworkMap[chainId] || tronwallet_abstract_adapter_1.NetworkType.Unknown,
|
|
770
|
+
chainId,
|
|
771
|
+
fullNode: ((_a = tronWeb.fullNode) === null || _a === void 0 ? void 0 : _a.host) || '',
|
|
772
|
+
solidityNode: ((_b = tronWeb.solidityNode) === null || _b === void 0 ? void 0 : _b.host) || '',
|
|
773
|
+
eventServer: ((_c = tronWeb.eventServer) === null || _c === void 0 ? void 0 : _c.host) || '',
|
|
774
|
+
};
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
exports.getNetworkInfoByTronWeb = getNetworkInfoByTronWeb;
|
|
778
|
+
exports.TronLinkAdapterName = 'TronLink';
|
|
779
|
+
class TronLinkAdapter extends tronwallet_abstract_adapter_1.Adapter {
|
|
780
|
+
// record if first connect event has emitted or not
|
|
781
|
+
constructor(config = {}) {
|
|
782
|
+
super();
|
|
783
|
+
this.name = exports.TronLinkAdapterName;
|
|
784
|
+
this.url = 'https://www.tronlink.org/';
|
|
785
|
+
this.icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAABdCAYAAADHcWrDAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAABdoAMABAAAAAEAAABdAAAAAMkTBfIAAAFZaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldG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eszEpEWoDLbmhEdbEPk1p8U5NTxqF5AAxORyUbVWI1PNbQEJhW9uI5n2laql36zE5T6/IXJi7Nu3H1CsO0r4OmmY2M5CT8oGmmw3IMjURZsWh3h/3pGbas3OKXE5hJy4lMs8s1WESwbAMOejwdUoaIVaR/nt6JKK1GoVAQDEF61lG4+Ks2GPRgQbId3InZl7cxQBeWLJ70ZYzHUYdigs4WHPX4txA9L8qfs34UfM7J2B6NFVmDxLB6i92q0KkLtfcPhX0vSqq3H6geC/98RHg/VwL0MW8e/hjvVy/Xim34CVG+21h+ePawjAk4HDG1byFN4q+r/dQH74aaDGOtFvnw4wC+2BJzo8db/XnJc1Njr7EMua7DuJAdXXXTrq8fI2lpUyPvz8LSjjXLjCEXHIw8Ft8eu65sqmTkjok4K+AvNnyZH0Xsb+eO/wWrg46Do/7gYAAAAABJRU5ErkJggg==';
|
|
786
|
+
this._readyState = (0, tronwallet_abstract_adapter_1.isInBrowser)() ? tronwallet_abstract_adapter_1.WalletReadyState.Loading : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
787
|
+
this._state = tronwallet_abstract_adapter_1.AdapterState.Loading;
|
|
788
|
+
// https://github.com/tronprotocol/tips/blob/master/tip-1193.md
|
|
789
|
+
this._supportNewTronProtocol = false;
|
|
790
|
+
this._tronLinkMessageHandler = (e) => {
|
|
791
|
+
var _a, _b, _c, _d, _e;
|
|
792
|
+
const message = (_a = e.data) === null || _a === void 0 ? void 0 : _a.message;
|
|
793
|
+
if (!message) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
if (message.action === 'accountsChanged') {
|
|
797
|
+
setTimeout(() => {
|
|
798
|
+
var _a;
|
|
799
|
+
const preAddr = this.address || '';
|
|
800
|
+
if ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.ready) {
|
|
801
|
+
const address = message.data.address;
|
|
802
|
+
this.setAddress(address);
|
|
803
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
this.setAddress(null);
|
|
807
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
808
|
+
}
|
|
809
|
+
this.emit('accountsChanged', this.address || '', preAddr);
|
|
810
|
+
if (!preAddr && this.address) {
|
|
811
|
+
this.emit('connect', this.address);
|
|
812
|
+
}
|
|
813
|
+
else if (preAddr && !this.address) {
|
|
814
|
+
this.emit('disconnect');
|
|
815
|
+
}
|
|
816
|
+
}, 200);
|
|
817
|
+
}
|
|
818
|
+
else if (message.action === 'setNode') {
|
|
819
|
+
this.emit('chainChanged', { chainId: ((_c = (_b = message.data) === null || _b === void 0 ? void 0 : _b.node) === null || _c === void 0 ? void 0 : _c.chainId) || '' });
|
|
820
|
+
}
|
|
821
|
+
else if (message.action === 'connect') {
|
|
822
|
+
const address = ((_e = (_d = this._wallet.tronWeb) === null || _d === void 0 ? void 0 : _d.defaultAddress) === null || _e === void 0 ? void 0 : _e.base58) || '';
|
|
823
|
+
this.setAddress(address);
|
|
824
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
825
|
+
this.emit('connect', address);
|
|
826
|
+
}
|
|
827
|
+
else if (message.action === 'disconnect') {
|
|
828
|
+
this.setAddress(null);
|
|
829
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
830
|
+
this.emit('disconnect');
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
this._onChainChanged = (data) => {
|
|
834
|
+
this.emit('chainChanged', data);
|
|
835
|
+
};
|
|
836
|
+
this._onAccountsChanged = () => {
|
|
837
|
+
var _a, _b, _c;
|
|
838
|
+
const preAddr = this.address || '';
|
|
839
|
+
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)) || '';
|
|
840
|
+
if (!curAddr) {
|
|
841
|
+
// change to a new address and if it's disconnected, data will be empty
|
|
842
|
+
// tronlink will emit accountsChanged many times, only process when connected
|
|
843
|
+
this.setAddress(null);
|
|
844
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
const address = curAddr;
|
|
848
|
+
this.setAddress(address);
|
|
849
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
850
|
+
}
|
|
851
|
+
this.emit('accountsChanged', this.address || '', preAddr);
|
|
852
|
+
if (!preAddr && this.address) {
|
|
853
|
+
this.emit('connect', this.address);
|
|
854
|
+
}
|
|
855
|
+
else if (preAddr && !this.address) {
|
|
856
|
+
this.emit('disconnect');
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
this._checkPromise = null;
|
|
860
|
+
this._updateWallet = () => {
|
|
861
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
862
|
+
let state = this.state;
|
|
863
|
+
let address = this.address;
|
|
864
|
+
if ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)()) {
|
|
865
|
+
if (window.tronLink) {
|
|
866
|
+
this._wallet = window.tronLink;
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
this._wallet = {
|
|
870
|
+
ready: !!((_a = window.tronWeb) === null || _a === void 0 ? void 0 : _a.defaultAddress),
|
|
871
|
+
tronWeb: window.tronWeb,
|
|
872
|
+
request: () => Promise.resolve(true),
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
address = ((_c = (_b = this._wallet.tronWeb) === null || _b === void 0 ? void 0 : _b.defaultAddress) === null || _c === void 0 ? void 0 : _c.base58) || null;
|
|
876
|
+
state = address ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
|
|
877
|
+
}
|
|
878
|
+
else if (window.tron && window.tron.isTronLink) {
|
|
879
|
+
this._supportNewTronProtocol = true;
|
|
880
|
+
this._wallet = window.tron;
|
|
881
|
+
this._listenTronEvent();
|
|
882
|
+
address = (this._wallet.tronWeb && ((_e = (_d = this._wallet.tronWeb) === null || _d === void 0 ? void 0 : _d.defaultAddress) === null || _e === void 0 ? void 0 : _e.base58)) || null;
|
|
883
|
+
state = address ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
|
|
884
|
+
}
|
|
885
|
+
else if (window.tronLink) {
|
|
886
|
+
this._wallet = window.tronLink;
|
|
887
|
+
this._listenTronLinkEvent();
|
|
888
|
+
address = ((_g = (_f = this._wallet.tronWeb) === null || _f === void 0 ? void 0 : _f.defaultAddress) === null || _g === void 0 ? void 0 : _g.base58) || null;
|
|
889
|
+
state = this._wallet.ready ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
|
|
890
|
+
}
|
|
891
|
+
else if (window.tronWeb) {
|
|
892
|
+
// fake tronLink
|
|
893
|
+
this._wallet = {
|
|
894
|
+
ready: window.tronWeb.ready,
|
|
895
|
+
tronWeb: window.tronWeb,
|
|
896
|
+
request: () => Promise.resolve(true),
|
|
897
|
+
};
|
|
898
|
+
address = ((_h = this._wallet.tronWeb.defaultAddress) === null || _h === void 0 ? void 0 : _h.base58) || null;
|
|
899
|
+
state = this._wallet.ready ? tronwallet_abstract_adapter_1.AdapterState.Connected : tronwallet_abstract_adapter_1.AdapterState.Disconnect;
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
// no tronlink support
|
|
903
|
+
this._wallet = null;
|
|
904
|
+
address = null;
|
|
905
|
+
state = tronwallet_abstract_adapter_1.AdapterState.NotFound;
|
|
906
|
+
}
|
|
907
|
+
// In TronLink App, account should be connected
|
|
908
|
+
if ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)() && state === tronwallet_abstract_adapter_1.AdapterState.Disconnect) {
|
|
909
|
+
this.checkForWalletReadyForApp();
|
|
910
|
+
}
|
|
911
|
+
this.setAddress(address);
|
|
912
|
+
this.setState(state);
|
|
913
|
+
};
|
|
914
|
+
this.checkReadyInterval = null;
|
|
915
|
+
const { checkTimeout = 30 * 1000, dappIcon = '', dappName = '', openUrlWhenWalletNotFound = true, openTronLinkAppOnMobile = true, } = config;
|
|
916
|
+
if (typeof checkTimeout !== 'number') {
|
|
917
|
+
throw new Error('[TronLinkAdapter] config.checkTimeout should be a number');
|
|
918
|
+
}
|
|
919
|
+
this.config = {
|
|
920
|
+
checkTimeout,
|
|
921
|
+
openTronLinkAppOnMobile,
|
|
922
|
+
openUrlWhenWalletNotFound,
|
|
923
|
+
dappIcon,
|
|
924
|
+
dappName,
|
|
925
|
+
};
|
|
926
|
+
this._connecting = false;
|
|
927
|
+
this._wallet = null;
|
|
928
|
+
this._address = null;
|
|
929
|
+
if (!(0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
930
|
+
this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
931
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.NotFound);
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
if ((0, utils_js_1.supportTron)() || ((0, tronwallet_abstract_adapter_1.isInMobileBrowser)() && (window.tronLink || window.tronWeb))) {
|
|
935
|
+
this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.Found;
|
|
936
|
+
this._updateWallet();
|
|
937
|
+
}
|
|
938
|
+
else {
|
|
939
|
+
this._checkWallet().then(() => {
|
|
940
|
+
if (this.connected) {
|
|
941
|
+
this.emit('connect', this.address || '');
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
get address() {
|
|
947
|
+
return this._address;
|
|
948
|
+
}
|
|
949
|
+
get state() {
|
|
950
|
+
return this._state;
|
|
951
|
+
}
|
|
952
|
+
get readyState() {
|
|
953
|
+
return this._readyState;
|
|
954
|
+
}
|
|
955
|
+
get connecting() {
|
|
956
|
+
return this._connecting;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Get network information used by TronLink.
|
|
960
|
+
* @returns {Network} Current network information.
|
|
961
|
+
*/
|
|
962
|
+
network() {
|
|
963
|
+
var _a;
|
|
964
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
965
|
+
try {
|
|
966
|
+
yield this._checkWallet();
|
|
967
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
|
|
968
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
969
|
+
const tronWeb = ((_a = this._wallet) === null || _a === void 0 ? void 0 : _a.tronWeb) || window.tronWeb;
|
|
970
|
+
if (!tronWeb)
|
|
971
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
972
|
+
try {
|
|
973
|
+
return yield getNetworkInfoByTronWeb(tronWeb);
|
|
974
|
+
}
|
|
975
|
+
catch (e) {
|
|
976
|
+
throw new tronwallet_abstract_adapter_1.WalletGetNetworkError(e === null || e === void 0 ? void 0 : e.message, e);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
catch (e) {
|
|
980
|
+
this.emit('error', e);
|
|
981
|
+
throw e;
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
connect() {
|
|
986
|
+
var _a, _b;
|
|
987
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
988
|
+
try {
|
|
989
|
+
this.checkIfOpenTronLink();
|
|
990
|
+
if (this.connected || this.connecting)
|
|
991
|
+
return;
|
|
992
|
+
yield this._checkWallet();
|
|
993
|
+
if (this.state === tronwallet_abstract_adapter_1.AdapterState.NotFound) {
|
|
994
|
+
if (this.config.openUrlWhenWalletNotFound !== false && (0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
995
|
+
window.open(this.url, '_blank');
|
|
996
|
+
}
|
|
997
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
998
|
+
}
|
|
999
|
+
// lower version only support window.tronWeb, no window.tronLink
|
|
1000
|
+
if (!this._wallet)
|
|
1001
|
+
return;
|
|
1002
|
+
this._connecting = true;
|
|
1003
|
+
if (this._supportNewTronProtocol) {
|
|
1004
|
+
const wallet = this._wallet;
|
|
1005
|
+
try {
|
|
1006
|
+
const res = yield wallet.request({ method: 'eth_requestAccounts' });
|
|
1007
|
+
const address = res[0];
|
|
1008
|
+
this.setAddress(address);
|
|
1009
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
1010
|
+
this._listenTronEvent();
|
|
1011
|
+
if (!this._wallet.tronWeb) {
|
|
1012
|
+
yield (0, utils_js_1.waitTronwebReady)(this._wallet);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
catch (error) {
|
|
1016
|
+
let message = (error === null || error === void 0 ? void 0 : error.message) || error || 'Connect TronLink wallet failed.';
|
|
1017
|
+
if (error.code === -32002) {
|
|
1018
|
+
message =
|
|
1019
|
+
'The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed.';
|
|
1020
|
+
}
|
|
1021
|
+
if (error.code === 4001) {
|
|
1022
|
+
message = 'The user rejected connection.';
|
|
1023
|
+
}
|
|
1024
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError(message, error);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
else if (window.tronLink) {
|
|
1028
|
+
const wallet = this._wallet;
|
|
1029
|
+
try {
|
|
1030
|
+
const res = yield wallet.request({ method: 'tron_requestAccounts' });
|
|
1031
|
+
if (!res) {
|
|
1032
|
+
// 1. wallet is locked
|
|
1033
|
+
// 2. tronlink is first installed and there is no wallet account
|
|
1034
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('TronLink wallet is locked or no wallet account is avaliable.');
|
|
1035
|
+
}
|
|
1036
|
+
if (res.code === 4000) {
|
|
1037
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('The same DApp has already initiated a request to connect to TronLink wallet, and the pop-up window has not been closed.');
|
|
1038
|
+
}
|
|
1039
|
+
if (res.code === 4001) {
|
|
1040
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('The user rejected connection.');
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
catch (error) {
|
|
1044
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError(error === null || error === void 0 ? void 0 : error.message, error);
|
|
1045
|
+
}
|
|
1046
|
+
const address = ((_a = wallet.tronWeb.defaultAddress) === null || _a === void 0 ? void 0 : _a.base58) || '';
|
|
1047
|
+
this.setAddress(address);
|
|
1048
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
1049
|
+
this._listenTronLinkEvent();
|
|
1050
|
+
}
|
|
1051
|
+
else if (window.tronWeb) {
|
|
1052
|
+
const wallet = this._wallet;
|
|
1053
|
+
const address = ((_b = wallet.tronWeb.defaultAddress) === null || _b === void 0 ? void 0 : _b.base58) || '';
|
|
1054
|
+
this.setAddress(address);
|
|
1055
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
throw new tronwallet_abstract_adapter_1.WalletConnectionError('Cannot connect wallet.');
|
|
1059
|
+
}
|
|
1060
|
+
this.connected && this.emit('connect', this.address || '');
|
|
1061
|
+
}
|
|
1062
|
+
catch (error) {
|
|
1063
|
+
this.emit('error', error);
|
|
1064
|
+
throw error;
|
|
1065
|
+
}
|
|
1066
|
+
finally {
|
|
1067
|
+
this._connecting = false;
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
disconnect() {
|
|
1072
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
|
+
if (this._supportNewTronProtocol) {
|
|
1074
|
+
this._stopListenTronEvent();
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
this._stopListenTronLinkEvent();
|
|
1078
|
+
}
|
|
1079
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
this.setAddress(null);
|
|
1083
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
1084
|
+
this.emit('disconnect');
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
signTransaction(transaction, privateKey) {
|
|
1088
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1089
|
+
try {
|
|
1090
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1091
|
+
try {
|
|
1092
|
+
return yield wallet.tronWeb.trx.sign(transaction, privateKey);
|
|
1093
|
+
}
|
|
1094
|
+
catch (error) {
|
|
1095
|
+
if (error instanceof Error) {
|
|
1096
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
1097
|
+
}
|
|
1098
|
+
else {
|
|
1099
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
catch (error) {
|
|
1104
|
+
this.emit('error', error);
|
|
1105
|
+
throw error;
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
multiSign(...args) {
|
|
1110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1111
|
+
try {
|
|
1112
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1113
|
+
try {
|
|
1114
|
+
return yield wallet.tronWeb.trx.multiSign(...args);
|
|
1115
|
+
}
|
|
1116
|
+
catch (error) {
|
|
1117
|
+
if (error instanceof Error) {
|
|
1118
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
1119
|
+
}
|
|
1120
|
+
else {
|
|
1121
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
catch (error) {
|
|
1126
|
+
this.emit('error', error);
|
|
1127
|
+
throw error;
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
signMessage(message, privateKey) {
|
|
1132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1133
|
+
try {
|
|
1134
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1135
|
+
try {
|
|
1136
|
+
return yield wallet.tronWeb.trx.signMessageV2(message, privateKey);
|
|
1137
|
+
}
|
|
1138
|
+
catch (error) {
|
|
1139
|
+
if (error instanceof Error) {
|
|
1140
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error.message, error);
|
|
1141
|
+
}
|
|
1142
|
+
else {
|
|
1143
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error, new Error(error));
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
catch (error) {
|
|
1148
|
+
this.emit('error', error);
|
|
1149
|
+
throw error;
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Switch to target chain. If current chain is the same as target chain, the call will success immediately.
|
|
1155
|
+
* Available chainIds:
|
|
1156
|
+
* - Mainnet: 0x2b6653dc
|
|
1157
|
+
* - Shasta: 0x94a9059e
|
|
1158
|
+
* - Nile: 0xcd8690dc
|
|
1159
|
+
* @param chainId chainId
|
|
1160
|
+
*/
|
|
1161
|
+
switchChain(chainId) {
|
|
1162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1163
|
+
try {
|
|
1164
|
+
yield this._checkWallet();
|
|
1165
|
+
if (this.state === tronwallet_abstract_adapter_1.AdapterState.NotFound) {
|
|
1166
|
+
if (this.config.openUrlWhenWalletNotFound !== false && (0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
1167
|
+
window.open(this.url, '_blank');
|
|
1168
|
+
}
|
|
1169
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
1170
|
+
}
|
|
1171
|
+
if (!this._supportNewTronProtocol) {
|
|
1172
|
+
throw new tronwallet_abstract_adapter_1.WalletSwitchChainError("Current version of TronLink doesn't support switch chain operation.");
|
|
1173
|
+
}
|
|
1174
|
+
const wallet = this._wallet;
|
|
1175
|
+
try {
|
|
1176
|
+
yield wallet.request({
|
|
1177
|
+
method: 'wallet_switchEthereumChain',
|
|
1178
|
+
params: [{ chainId }],
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
catch (e) {
|
|
1182
|
+
throw new tronwallet_abstract_adapter_1.WalletSwitchChainError((e === null || e === void 0 ? void 0 : e.message) || e, e instanceof Error ? e : new Error(e));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
catch (error) {
|
|
1186
|
+
this.emit('error', error);
|
|
1187
|
+
throw error;
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
checkAndGetWallet() {
|
|
1192
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1193
|
+
this.checkIfOpenTronLink();
|
|
1194
|
+
yield this._checkWallet();
|
|
1195
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
|
|
1196
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1197
|
+
const wallet = this._wallet;
|
|
1198
|
+
if (!wallet || !wallet.tronWeb)
|
|
1199
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1200
|
+
return wallet;
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
_listenTronLinkEvent() {
|
|
1204
|
+
this._stopListenTronLinkEvent();
|
|
1205
|
+
window.addEventListener('message', this._tronLinkMessageHandler);
|
|
1206
|
+
}
|
|
1207
|
+
_stopListenTronLinkEvent() {
|
|
1208
|
+
window.removeEventListener('message', this._tronLinkMessageHandler);
|
|
1209
|
+
}
|
|
1210
|
+
checkIfOpenTronLink() {
|
|
1211
|
+
const { dappName = '', dappIcon = '' } = this.config;
|
|
1212
|
+
if (this.config.openTronLinkAppOnMobile === false) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if ((0, utils_js_1.openTronLink)({ dappIcon, dappName })) {
|
|
1216
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
// following code is for TIP-1193
|
|
1220
|
+
_listenTronEvent() {
|
|
1221
|
+
this._stopListenTronEvent();
|
|
1222
|
+
this._stopListenTronLinkEvent();
|
|
1223
|
+
const wallet = this._wallet;
|
|
1224
|
+
wallet.on('chainChanged', this._onChainChanged);
|
|
1225
|
+
wallet.on('accountsChanged', this._onAccountsChanged);
|
|
1226
|
+
}
|
|
1227
|
+
_stopListenTronEvent() {
|
|
1228
|
+
const wallet = this._wallet;
|
|
1229
|
+
wallet.removeListener('chainChanged', this._onChainChanged);
|
|
1230
|
+
wallet.removeListener('accountsChanged', this._onAccountsChanged);
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* check if wallet exists by interval, the promise only resolve when wallet detected or timeout
|
|
1234
|
+
* @returns if wallet exists
|
|
1235
|
+
*/
|
|
1236
|
+
_checkWallet() {
|
|
1237
|
+
if (this.readyState === tronwallet_abstract_adapter_1.WalletReadyState.Found) {
|
|
1238
|
+
return Promise.resolve(true);
|
|
1239
|
+
}
|
|
1240
|
+
if (this._checkPromise) {
|
|
1241
|
+
return this._checkPromise;
|
|
1242
|
+
}
|
|
1243
|
+
const interval = 100;
|
|
1244
|
+
const checkTronTimes = Math.floor(2000 / interval);
|
|
1245
|
+
const maxTimes = Math.floor(this.config.checkTimeout / interval);
|
|
1246
|
+
let times = 0, timer;
|
|
1247
|
+
this._checkPromise = new Promise((resolve) => {
|
|
1248
|
+
const check = () => {
|
|
1249
|
+
times++;
|
|
1250
|
+
const isSupport = times < checkTronTimes && !(0, tronwallet_abstract_adapter_1.isInMobileBrowser)() ? (0, utils_js_1.supportTron)() : (0, utils_js_1.supportTronLink)();
|
|
1251
|
+
if (isSupport || times > maxTimes) {
|
|
1252
|
+
timer && clearInterval(timer);
|
|
1253
|
+
this._readyState = isSupport ? tronwallet_abstract_adapter_1.WalletReadyState.Found : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
1254
|
+
this._updateWallet();
|
|
1255
|
+
this.emit('readyStateChanged', this.readyState);
|
|
1256
|
+
resolve(isSupport);
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
timer = setInterval(check, interval);
|
|
1260
|
+
check();
|
|
1261
|
+
});
|
|
1262
|
+
return this._checkPromise;
|
|
1263
|
+
}
|
|
1264
|
+
checkForWalletReadyForApp() {
|
|
1265
|
+
if (this.checkReadyInterval) {
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
let times = 0;
|
|
1269
|
+
const maxTimes = Math.floor(this.config.checkTimeout / 200);
|
|
1270
|
+
const check = () => {
|
|
1271
|
+
var _a, _b;
|
|
1272
|
+
if (window.tronLink ? (_a = window.tronLink.tronWeb) === null || _a === void 0 ? void 0 : _a.defaultAddress : (_b = window.tronWeb) === null || _b === void 0 ? void 0 : _b.defaultAddress) {
|
|
1273
|
+
this.checkReadyInterval && clearInterval(this.checkReadyInterval);
|
|
1274
|
+
this.checkReadyInterval = null;
|
|
1275
|
+
this._updateWallet();
|
|
1276
|
+
this.emit('connect', this.address || '');
|
|
1277
|
+
}
|
|
1278
|
+
else if (times > maxTimes) {
|
|
1279
|
+
this.checkReadyInterval && clearInterval(this.checkReadyInterval);
|
|
1280
|
+
this.checkReadyInterval = null;
|
|
1281
|
+
}
|
|
1282
|
+
else {
|
|
1283
|
+
times++;
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
this.checkReadyInterval = setInterval(check, 200);
|
|
1287
|
+
}
|
|
1288
|
+
setAddress(address) {
|
|
1289
|
+
this._address = address;
|
|
1290
|
+
}
|
|
1291
|
+
setState(state) {
|
|
1292
|
+
const preState = this.state;
|
|
1293
|
+
if (state !== preState) {
|
|
1294
|
+
this._state = state;
|
|
1295
|
+
this.emit('stateChanged', state);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
exports.TronLinkAdapter = TronLinkAdapter;
|
|
1300
|
+
|
|
1301
|
+
} (adapter));
|
|
1302
|
+
|
|
1303
|
+
var types = {};
|
|
1304
|
+
|
|
1305
|
+
Object.defineProperty(types, "__esModule", { value: true });
|
|
1306
|
+
|
|
1307
|
+
(function (exports) {
|
|
1308
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1309
|
+
if (k2 === undefined) k2 = k;
|
|
1310
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1311
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1312
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
1313
|
+
}
|
|
1314
|
+
Object.defineProperty(o, k2, desc);
|
|
1315
|
+
}) : (function(o, m, k, k2) {
|
|
1316
|
+
if (k2 === undefined) k2 = k;
|
|
1317
|
+
o[k2] = m[k];
|
|
1318
|
+
}));
|
|
1319
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
1320
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1321
|
+
};
|
|
1322
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1323
|
+
__exportStar(adapter, exports);
|
|
1324
|
+
__exportStar(types, exports);
|
|
1325
|
+
__exportStar(utils$1, exports);
|
|
1326
|
+
|
|
1327
|
+
} (cjs));
|
|
1328
|
+
|
|
1329
|
+
var utils = {};
|
|
1330
|
+
|
|
1331
|
+
Object.defineProperty(utils, "__esModule", { value: true });
|
|
1332
|
+
utils.openTokenPocket = utils.isInTokenPocket = utils.supportTokenPocket = void 0;
|
|
1333
|
+
const tronwallet_abstract_adapter_1 = cjs$1;
|
|
1334
|
+
function supportTokenPocket() {
|
|
1335
|
+
return !!window.tronWeb && typeof window.tokenpocket !== 'undefined';
|
|
1336
|
+
}
|
|
1337
|
+
utils.supportTokenPocket = supportTokenPocket;
|
|
1338
|
+
/**
|
|
1339
|
+
* Detect if in TokenPocketApp
|
|
1340
|
+
* There will be a `tokenpocket` object on window
|
|
1341
|
+
*/
|
|
1342
|
+
function isInTokenPocket() {
|
|
1343
|
+
return (0, tronwallet_abstract_adapter_1.isInBrowser)() && typeof window.tokenpocket !== 'undefined';
|
|
1344
|
+
}
|
|
1345
|
+
utils.isInTokenPocket = isInTokenPocket;
|
|
1346
|
+
function openTokenPocket() {
|
|
1347
|
+
if (!supportTokenPocket() && (0, tronwallet_abstract_adapter_1.isInMobileBrowser)() && !isInTokenPocket()) {
|
|
1348
|
+
const { origin, pathname, search, hash } = window.location;
|
|
1349
|
+
const url = origin + pathname + search + hash;
|
|
1350
|
+
const params = {
|
|
1351
|
+
action: 'open',
|
|
1352
|
+
actionId: Date.now() + '',
|
|
1353
|
+
callbackUrl: 'http://someurl.com',
|
|
1354
|
+
blockchain: 'Tron',
|
|
1355
|
+
chain: 'Tron',
|
|
1356
|
+
url,
|
|
1357
|
+
protocol: 'TokenPocket',
|
|
1358
|
+
version: '1.0',
|
|
1359
|
+
};
|
|
1360
|
+
window.location.href = `tpdapp://open?params=${encodeURIComponent(JSON.stringify(params))}`;
|
|
1361
|
+
return true;
|
|
1362
|
+
}
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
utils.openTokenPocket = openTokenPocket;
|
|
1366
|
+
|
|
1367
|
+
(function (exports) {
|
|
1368
|
+
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1369
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1370
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1371
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1372
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1373
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1374
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1375
|
+
});
|
|
1376
|
+
};
|
|
1377
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1378
|
+
exports.TokenPocketAdapter = exports.TokenPocketAdapterName = void 0;
|
|
1379
|
+
const tronwallet_abstract_adapter_1 = cjs$1;
|
|
1380
|
+
const tronwallet_adapter_tronlink_1 = cjs;
|
|
1381
|
+
const utils_js_1 = utils;
|
|
1382
|
+
exports.TokenPocketAdapterName = 'TokenPocket';
|
|
1383
|
+
class TokenPocketAdapter extends tronwallet_abstract_adapter_1.Adapter {
|
|
1384
|
+
constructor(config = {}) {
|
|
1385
|
+
super();
|
|
1386
|
+
this.name = exports.TokenPocketAdapterName;
|
|
1387
|
+
this.url = 'https://tokenpocket.pro/';
|
|
1388
|
+
this.icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGc+CjxwYXRoIGQ9Ik0xMDQxLjUyIDBILTI3VjEwMjRIMTA0MS41MlYwWiIgZmlsbD0iIzI5ODBGRSIvPgo8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfNDA4XzIyNSkiPgo8cGF0aCBkPSJNNDA2Ljc5NiA0MzguNjQzSDQwNi45MjdDNDA2Ljc5NiA0MzcuODU3IDQwNi43OTYgNDM2Ljk0IDQwNi43OTYgNDM2LjE1NFY0MzguNjQzWiIgZmlsbD0iIzI5QUVGRiIvPgo8cGF0aCBkPSJNNjY3LjYwMiA0NjMuNTMzSDUyMy4yNDlWNzI0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U3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IndoaXRlIi8+CjxzdG9wIG9mZnNldD0iMC45NjY3IiBzdG9wLWNvbG9yPSJ3aGl0ZSIgc3RvcC1vcGFjaXR5PSIwLjMyMzMiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSJ3aGl0ZSIgc3RvcC1vcGFjaXR5PSIwLjMiLz4KPC9saW5lYXJHcmFkaWVudD4KPGNsaXBQYXRoIGlkPSJjbGlwMF80MDhfMjI1Ij4KPHJlY3Qgd2lkdGg9IjcyOC40NDgiIGhlaWdodD0iNDcwIiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMTY4IDI3NykiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K';
|
|
1389
|
+
this._readyState = (0, tronwallet_abstract_adapter_1.isInBrowser)() ? tronwallet_abstract_adapter_1.WalletReadyState.Loading : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
1390
|
+
this._state = tronwallet_abstract_adapter_1.AdapterState.Loading;
|
|
1391
|
+
this.checkReadyInterval = null;
|
|
1392
|
+
this._checkPromise = null;
|
|
1393
|
+
this._updateWallet = () => {
|
|
1394
|
+
var _a, _b, _c, _d;
|
|
1395
|
+
let state = this.state;
|
|
1396
|
+
let address = this.address;
|
|
1397
|
+
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)) {
|
|
1407
|
+
this.checkForWalletReady();
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
// no tronlink support
|
|
1412
|
+
this._wallet = null;
|
|
1413
|
+
address = null;
|
|
1414
|
+
state = tronwallet_abstract_adapter_1.AdapterState.NotFound;
|
|
1415
|
+
}
|
|
1416
|
+
this.setAddress(address);
|
|
1417
|
+
this.setState(state);
|
|
1418
|
+
};
|
|
1419
|
+
const { checkTimeout = 2 * 1000, openUrlWhenWalletNotFound = true, openAppWithDeeplink = true } = config;
|
|
1420
|
+
if (typeof checkTimeout !== 'number') {
|
|
1421
|
+
throw new Error('[TokenPocketAdapter] config.checkTimeout should be a number');
|
|
1422
|
+
}
|
|
1423
|
+
this.config = {
|
|
1424
|
+
checkTimeout,
|
|
1425
|
+
openAppWithDeeplink,
|
|
1426
|
+
openUrlWhenWalletNotFound,
|
|
1427
|
+
};
|
|
1428
|
+
this._connecting = false;
|
|
1429
|
+
this._wallet = null;
|
|
1430
|
+
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
|
+
if ((0, utils_js_1.supportTokenPocket)()) {
|
|
1438
|
+
this._readyState = tronwallet_abstract_adapter_1.WalletReadyState.Found;
|
|
1439
|
+
this._updateWallet();
|
|
1440
|
+
}
|
|
1441
|
+
else {
|
|
1442
|
+
this._checkWallet().then(() => {
|
|
1443
|
+
if (this.connected) {
|
|
1444
|
+
this.emit('connect', this.address || '');
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
get address() {
|
|
1450
|
+
return this._address;
|
|
1451
|
+
}
|
|
1452
|
+
get state() {
|
|
1453
|
+
return this._state;
|
|
1454
|
+
}
|
|
1455
|
+
get readyState() {
|
|
1456
|
+
return this._readyState;
|
|
1457
|
+
}
|
|
1458
|
+
get connecting() {
|
|
1459
|
+
return this._connecting;
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Get network information.
|
|
1463
|
+
* @returns {Network} Current network information.
|
|
1464
|
+
*/
|
|
1465
|
+
network() {
|
|
1466
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1467
|
+
try {
|
|
1468
|
+
yield this._checkWallet();
|
|
1469
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected)
|
|
1470
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1471
|
+
const wallet = this._wallet;
|
|
1472
|
+
if (!wallet || !wallet.tronWeb)
|
|
1473
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1474
|
+
try {
|
|
1475
|
+
return yield (0, tronwallet_adapter_tronlink_1.getNetworkInfoByTronWeb)(wallet.tronWeb);
|
|
1476
|
+
}
|
|
1477
|
+
catch (e) {
|
|
1478
|
+
throw new tronwallet_abstract_adapter_1.WalletGetNetworkError(e === null || e === void 0 ? void 0 : e.message, e);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
catch (e) {
|
|
1482
|
+
this.emit('error', e);
|
|
1483
|
+
throw e;
|
|
1484
|
+
}
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
connect() {
|
|
1488
|
+
var _a;
|
|
1489
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1490
|
+
try {
|
|
1491
|
+
this.checkIfOpenApp();
|
|
1492
|
+
if (this.connected || this.connecting)
|
|
1493
|
+
return;
|
|
1494
|
+
yield this._checkWallet();
|
|
1495
|
+
if (this.readyState === tronwallet_abstract_adapter_1.WalletReadyState.NotFound) {
|
|
1496
|
+
if (this.config.openUrlWhenWalletNotFound !== false && (0, tronwallet_abstract_adapter_1.isInBrowser)()) {
|
|
1497
|
+
window.open(this.url, '_blank');
|
|
1498
|
+
}
|
|
1499
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
1500
|
+
}
|
|
1501
|
+
if (!this._wallet)
|
|
1502
|
+
return;
|
|
1503
|
+
this._connecting = true;
|
|
1504
|
+
const wallet = this._wallet;
|
|
1505
|
+
const address = ((_a = wallet.tronWeb.defaultAddress) === null || _a === void 0 ? void 0 : _a.base58) || '';
|
|
1506
|
+
this.setAddress(address);
|
|
1507
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Connected);
|
|
1508
|
+
this.emit('connect', this.address || '');
|
|
1509
|
+
}
|
|
1510
|
+
catch (error) {
|
|
1511
|
+
this.emit('error', error);
|
|
1512
|
+
throw error;
|
|
1513
|
+
}
|
|
1514
|
+
finally {
|
|
1515
|
+
this._connecting = false;
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
disconnect() {
|
|
1520
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1521
|
+
if (this.state !== tronwallet_abstract_adapter_1.AdapterState.Connected) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
this.setAddress(null);
|
|
1525
|
+
this.setState(tronwallet_abstract_adapter_1.AdapterState.Disconnect);
|
|
1526
|
+
this.emit('disconnect');
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
signTransaction(transaction, privateKey) {
|
|
1530
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1531
|
+
try {
|
|
1532
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1533
|
+
try {
|
|
1534
|
+
return yield wallet.tronWeb.trx.sign(transaction, privateKey);
|
|
1535
|
+
}
|
|
1536
|
+
catch (error) {
|
|
1537
|
+
if (error instanceof Error) {
|
|
1538
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
1539
|
+
}
|
|
1540
|
+
else {
|
|
1541
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
catch (error) {
|
|
1546
|
+
this.emit('error', error);
|
|
1547
|
+
throw error;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
multiSign(...args) {
|
|
1552
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1553
|
+
try {
|
|
1554
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1555
|
+
try {
|
|
1556
|
+
return yield wallet.tronWeb.trx.multiSign(...args);
|
|
1557
|
+
}
|
|
1558
|
+
catch (error) {
|
|
1559
|
+
if (error instanceof Error) {
|
|
1560
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error.message, error);
|
|
1561
|
+
}
|
|
1562
|
+
else {
|
|
1563
|
+
throw new tronwallet_abstract_adapter_1.WalletSignTransactionError(error, new Error(error));
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
catch (error) {
|
|
1568
|
+
this.emit('error', error);
|
|
1569
|
+
throw error;
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
signMessage(message, privateKey) {
|
|
1574
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1575
|
+
try {
|
|
1576
|
+
const wallet = yield this.checkAndGetWallet();
|
|
1577
|
+
try {
|
|
1578
|
+
return yield wallet.tronWeb.trx.signMessageV2(message, privateKey);
|
|
1579
|
+
}
|
|
1580
|
+
catch (error) {
|
|
1581
|
+
if (error instanceof Error) {
|
|
1582
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error.message, error);
|
|
1583
|
+
}
|
|
1584
|
+
else {
|
|
1585
|
+
throw new tronwallet_abstract_adapter_1.WalletSignMessageError(error, new Error(error));
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
catch (error) {
|
|
1590
|
+
this.emit('error', error);
|
|
1591
|
+
throw error;
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
checkAndGetWallet() {
|
|
1596
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1597
|
+
this.checkIfOpenApp();
|
|
1598
|
+
yield this._checkWallet();
|
|
1599
|
+
if (!this.connected)
|
|
1600
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1601
|
+
const wallet = this._wallet;
|
|
1602
|
+
if (!wallet || !wallet.tronWeb)
|
|
1603
|
+
throw new tronwallet_abstract_adapter_1.WalletDisconnectedError();
|
|
1604
|
+
return wallet;
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
checkIfOpenApp() {
|
|
1608
|
+
if (this.config.openAppWithDeeplink === false) {
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
if ((0, utils_js_1.openTokenPocket)()) {
|
|
1612
|
+
throw new tronwallet_abstract_adapter_1.WalletNotFoundError();
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
checkForWalletReady() {
|
|
1616
|
+
if (this.checkReadyInterval) {
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
let times = 0;
|
|
1620
|
+
const maxTimes = Math.floor(this.config.checkTimeout / 200);
|
|
1621
|
+
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) {
|
|
1624
|
+
this.checkReadyInterval && clearInterval(this.checkReadyInterval);
|
|
1625
|
+
this.checkReadyInterval = null;
|
|
1626
|
+
this._updateWallet();
|
|
1627
|
+
this.emit('connect', this.address || '');
|
|
1628
|
+
}
|
|
1629
|
+
else if (times > maxTimes) {
|
|
1630
|
+
this.checkReadyInterval && clearInterval(this.checkReadyInterval);
|
|
1631
|
+
this.checkReadyInterval = null;
|
|
1632
|
+
}
|
|
1633
|
+
else {
|
|
1634
|
+
times++;
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
this.checkReadyInterval = setInterval(check, 200);
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* check if wallet exists by interval, the promise only resolve when wallet detected or timeout
|
|
1641
|
+
* @returns if wallet exists
|
|
1642
|
+
*/
|
|
1643
|
+
_checkWallet() {
|
|
1644
|
+
if (this.readyState === tronwallet_abstract_adapter_1.WalletReadyState.Found) {
|
|
1645
|
+
return Promise.resolve(true);
|
|
1646
|
+
}
|
|
1647
|
+
if (this._checkPromise) {
|
|
1648
|
+
return this._checkPromise;
|
|
1649
|
+
}
|
|
1650
|
+
const interval = 100;
|
|
1651
|
+
const maxTimes = Math.floor(this.config.checkTimeout / interval);
|
|
1652
|
+
let times = 0, timer;
|
|
1653
|
+
this._checkPromise = new Promise((resolve) => {
|
|
1654
|
+
const check = () => {
|
|
1655
|
+
times++;
|
|
1656
|
+
const isSupport = (0, utils_js_1.supportTokenPocket)();
|
|
1657
|
+
if (isSupport || times > maxTimes) {
|
|
1658
|
+
timer && clearInterval(timer);
|
|
1659
|
+
this._readyState = isSupport ? tronwallet_abstract_adapter_1.WalletReadyState.Found : tronwallet_abstract_adapter_1.WalletReadyState.NotFound;
|
|
1660
|
+
this._updateWallet();
|
|
1661
|
+
this.emit('readyStateChanged', this.readyState);
|
|
1662
|
+
resolve(isSupport);
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
timer = setInterval(check, interval);
|
|
1666
|
+
check();
|
|
1667
|
+
});
|
|
1668
|
+
return this._checkPromise;
|
|
1669
|
+
}
|
|
1670
|
+
setAddress(address) {
|
|
1671
|
+
this._address = address;
|
|
1672
|
+
}
|
|
1673
|
+
setState(state) {
|
|
1674
|
+
const preState = this.state;
|
|
1675
|
+
if (state !== preState) {
|
|
1676
|
+
this._state = state;
|
|
1677
|
+
this.emit('stateChanged', state);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
exports.TokenPocketAdapter = TokenPocketAdapter;
|
|
1682
|
+
|
|
1683
|
+
} (adapter$2));
|
|
1684
|
+
|
|
1685
|
+
(function (exports) {
|
|
1686
|
+
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
1687
|
+
if (k2 === undefined) k2 = k;
|
|
1688
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1689
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1690
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
1691
|
+
}
|
|
1692
|
+
Object.defineProperty(o, k2, desc);
|
|
1693
|
+
}) : (function(o, m, k, k2) {
|
|
1694
|
+
if (k2 === undefined) k2 = k;
|
|
1695
|
+
o[k2] = m[k];
|
|
1696
|
+
}));
|
|
1697
|
+
var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
|
|
1698
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1699
|
+
};
|
|
1700
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1701
|
+
__exportStar(adapter$2, exports);
|
|
1702
|
+
__exportStar(utils, exports);
|
|
1703
|
+
|
|
1704
|
+
} (cjs$2));
|
|
1705
|
+
|
|
1706
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(cjs$2);
|
|
1707
|
+
|
|
1708
|
+
return index;
|
|
1709
|
+
|
|
1710
|
+
}));
|