@tronweb3/tronwallet-adapter-tokenpocket 1.0.5 → 1.0.7
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/LICENSE +1 -1
- package/README.md +4 -3
- package/lib/cjs/adapter.js +51 -22
- package/lib/cjs/adapter.js.map +1 -1
- package/lib/esm/adapter.js +52 -23
- package/lib/esm/adapter.js.map +1 -1
- package/lib/types/adapter.d.ts.map +1 -1
- package/lib/umd/index.js +1658 -119115
- package/lib/umd/index.min.js +1 -33
- package/package.json +6 -6
- package/src/adapter.ts +46 -20
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tronweb3/tronwallet-adapter-tokenpocket",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Wallet adapter for TokenPocket
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Wallet adapter for TokenPocket Extension and App wallet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TRON",
|
|
7
7
|
"TronWeb",
|
|
8
8
|
"TokenPocket"
|
|
9
9
|
],
|
|
10
|
-
"author": "
|
|
10
|
+
"author": "tronweb3",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/tronweb3/tronwallet-adapter"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"type": "module",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tronweb3/tronwallet-abstract-adapter": "^1.1.
|
|
40
|
-
"@tronweb3/tronwallet-adapter-tronlink": "^1.1.
|
|
39
|
+
"@tronweb3/tronwallet-abstract-adapter": "^1.1.9",
|
|
40
|
+
"@tronweb3/tronwallet-adapter-tronlink": "^1.1.12"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@testing-library/dom": "^8.20.0",
|
package/src/adapter.ts
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
WalletDisconnectedError,
|
|
9
9
|
WalletSignTransactionError,
|
|
10
10
|
WalletGetNetworkError,
|
|
11
|
+
WalletConnectionError,
|
|
12
|
+
isInMobileBrowser,
|
|
13
|
+
WalletError,
|
|
11
14
|
} from '@tronweb3/tronwallet-abstract-adapter';
|
|
12
15
|
import type {
|
|
13
16
|
Transaction,
|
|
@@ -138,13 +141,23 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
138
141
|
if (!this._wallet) return;
|
|
139
142
|
this._connecting = true;
|
|
140
143
|
const wallet = this._wallet as TokenPocketWallet;
|
|
144
|
+
try {
|
|
145
|
+
const res = await wallet.tron.request({ method: 'eth_requestAccounts' });
|
|
146
|
+
if (!res?.[0]) {
|
|
147
|
+
throw new WalletConnectionError('Request connect error.');
|
|
148
|
+
}
|
|
149
|
+
const address = res[0];
|
|
141
150
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
151
|
+
this.setAddress(address);
|
|
152
|
+
this.setState(AdapterState.Connected);
|
|
153
|
+
this.emit('connect', this.address || '');
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
if (e instanceof WalletError) {
|
|
156
|
+
throw e;
|
|
157
|
+
} else {
|
|
158
|
+
throw new WalletConnectionError(e?.message, e);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
148
161
|
} catch (error: any) {
|
|
149
162
|
this.emit('error', error);
|
|
150
163
|
throw error;
|
|
@@ -168,10 +181,12 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
168
181
|
try {
|
|
169
182
|
return await wallet.tronWeb.trx.sign(transaction, privateKey);
|
|
170
183
|
} catch (error: any) {
|
|
171
|
-
if (error instanceof Error) {
|
|
184
|
+
if (error instanceof Error || (typeof error === 'object' && error.message)) {
|
|
172
185
|
throw new WalletSignTransactionError(error.message, error);
|
|
173
|
-
} else {
|
|
186
|
+
} else if (typeof error === 'string') {
|
|
174
187
|
throw new WalletSignTransactionError(error, new Error(error));
|
|
188
|
+
} else {
|
|
189
|
+
throw new WalletSignTransactionError('Unknown error', error);
|
|
175
190
|
}
|
|
176
191
|
}
|
|
177
192
|
} catch (error: any) {
|
|
@@ -190,10 +205,12 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
190
205
|
try {
|
|
191
206
|
return await wallet.tronWeb.trx.multiSign(transaction, privateKey, permissionId);
|
|
192
207
|
} catch (error: any) {
|
|
193
|
-
if (error instanceof Error) {
|
|
208
|
+
if (error instanceof Error || (typeof error === 'object' && error.message)) {
|
|
194
209
|
throw new WalletSignTransactionError(error.message, error);
|
|
195
|
-
} else {
|
|
210
|
+
} else if (typeof error === 'string') {
|
|
196
211
|
throw new WalletSignTransactionError(error, new Error(error));
|
|
212
|
+
} else {
|
|
213
|
+
throw new WalletSignTransactionError('Unknown error', error);
|
|
197
214
|
}
|
|
198
215
|
}
|
|
199
216
|
} catch (error: any) {
|
|
@@ -208,10 +225,12 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
208
225
|
try {
|
|
209
226
|
return await wallet.tronWeb.trx.signMessageV2(message, privateKey);
|
|
210
227
|
} catch (error: any) {
|
|
211
|
-
if (error instanceof Error) {
|
|
228
|
+
if (error instanceof Error || (typeof error === 'object' && error.message)) {
|
|
212
229
|
throw new WalletSignMessageError(error.message, error);
|
|
213
|
-
} else {
|
|
230
|
+
} else if (typeof error === 'string') {
|
|
214
231
|
throw new WalletSignMessageError(error, new Error(error));
|
|
232
|
+
} else {
|
|
233
|
+
throw new WalletSignMessageError('Unknown error', error);
|
|
215
234
|
}
|
|
216
235
|
}
|
|
217
236
|
} catch (error: any) {
|
|
@@ -246,7 +265,7 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
246
265
|
let times = 0;
|
|
247
266
|
const maxTimes = Math.floor(this.config.checkTimeout / 200);
|
|
248
267
|
const check = () => {
|
|
249
|
-
if (window
|
|
268
|
+
if (isInMobileBrowser() ? window.tronWeb?.ready : this._wallet?.ready) {
|
|
250
269
|
this.checkReadyInterval && clearInterval(this.checkReadyInterval);
|
|
251
270
|
this.checkReadyInterval = null;
|
|
252
271
|
this._updateWallet();
|
|
@@ -299,14 +318,21 @@ export class TokenPocketAdapter extends Adapter {
|
|
|
299
318
|
let state = this.state;
|
|
300
319
|
let address = this.address;
|
|
301
320
|
if (supportTokenPocket()) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
321
|
+
const tron = window.tokenpocket?.tron as Tron;
|
|
322
|
+
this._wallet = isInMobileBrowser()
|
|
323
|
+
? ({
|
|
324
|
+
tron,
|
|
325
|
+
ready: window.tronWeb?.ready,
|
|
326
|
+
tronWeb: window.tokenpocket?.tronWeb,
|
|
327
|
+
} as TokenPocketWallet)
|
|
328
|
+
: {
|
|
329
|
+
tron,
|
|
330
|
+
ready: !!(tron?.tronWeb as TronWeb).defaultAddress?.base58 || false,
|
|
331
|
+
tronWeb: tron?.tronWeb as TronWeb,
|
|
332
|
+
};
|
|
307
333
|
address = this._wallet.tronWeb.defaultAddress?.base58 || null;
|
|
308
|
-
state =
|
|
309
|
-
if (!
|
|
334
|
+
state = address ? AdapterState.Connected : AdapterState.Disconnect;
|
|
335
|
+
if (!address) {
|
|
310
336
|
this.checkForWalletReady();
|
|
311
337
|
}
|
|
312
338
|
} else {
|