@tronweb3/tronwallet-adapter-tokenpocket 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@tronweb3/tronwallet-adapter-tokenpocket",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Wallet adapter for TokenPocket Wallet app.",
5
5
  "keywords": [
6
6
  "TRON",
7
7
  "TronWeb",
8
8
  "TokenPocket"
9
9
  ],
10
- "author": "tronprotocol",
10
+ "author": "web3-geek",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/tronprotocol/tronwallet-adapter"
13
+ "url": "https://github.com/web3-geek/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.6",
40
- "@tronweb3/tronwallet-adapter-tronlink": "^1.1.9"
39
+ "@tronweb3/tronwallet-abstract-adapter": "^1.1.8",
40
+ "@tronweb3/tronwallet-adapter-tronlink": "^1.1.11"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@testing-library/dom": "^8.20.0",
package/src/adapter.ts CHANGED
@@ -7,7 +7,6 @@ import {
7
7
  WalletNotFoundError,
8
8
  WalletDisconnectedError,
9
9
  WalletSignTransactionError,
10
- isInMobileBrowser,
11
10
  WalletGetNetworkError,
12
11
  } from '@tronweb3/tronwallet-abstract-adapter';
13
12
  import type {
@@ -16,9 +15,10 @@ import type {
16
15
  AdapterName,
17
16
  BaseAdapterConfig,
18
17
  Network,
18
+ TronWeb,
19
19
  } from '@tronweb3/tronwallet-abstract-adapter';
20
20
  import { getNetworkInfoByTronWeb } from '@tronweb3/tronwallet-adapter-tronlink';
21
- import type { TronLinkWallet } from '@tronweb3/tronwallet-adapter-tronlink';
21
+ import type { Tron } from '@tronweb3/tronwallet-adapter-tronlink';
22
22
  import { openTokenPocket, supportTokenPocket } from './utils.js';
23
23
 
24
24
  export interface TokenPocketAdapterConfig extends BaseAdapterConfig {
@@ -36,6 +36,18 @@ export interface TokenPocketAdapterConfig extends BaseAdapterConfig {
36
36
 
37
37
  export const TokenPocketAdapterName = 'TokenPocket' as AdapterName<'TokenPocket'>;
38
38
 
39
+ export interface TokenPocketWallet {
40
+ ready: boolean;
41
+ tronWeb: TronWeb;
42
+ tron: Tron;
43
+ }
44
+
45
+ declare global {
46
+ interface Window {
47
+ tokenpocket?: TokenPocketWallet;
48
+ }
49
+ }
50
+
39
51
  export class TokenPocketAdapter extends Adapter {
40
52
  name = TokenPocketAdapterName;
41
53
  url = 'https://tokenpocket.pro/';
@@ -46,7 +58,7 @@ export class TokenPocketAdapter extends Adapter {
46
58
  private _readyState: WalletReadyState = isInBrowser() ? WalletReadyState.Loading : WalletReadyState.NotFound;
47
59
  private _state: AdapterState = AdapterState.Loading;
48
60
  private _connecting: boolean;
49
- private _wallet: TronLinkWallet | null;
61
+ private _wallet: TokenPocketWallet | null;
50
62
  private _address: string | null;
51
63
 
52
64
  constructor(config: TokenPocketAdapterConfig = {}) {
@@ -64,12 +76,6 @@ export class TokenPocketAdapter extends Adapter {
64
76
  this._wallet = null;
65
77
  this._address = null;
66
78
 
67
- if (!isInMobileBrowser()) {
68
- // Currently TokenPocket extension does not support Tron.
69
- this._readyState = WalletReadyState.NotFound;
70
- this._state = AdapterState.NotFound;
71
- return;
72
- }
73
79
  if (supportTokenPocket()) {
74
80
  this._readyState = WalletReadyState.Found;
75
81
  this._updateWallet();
@@ -131,8 +137,11 @@ export class TokenPocketAdapter extends Adapter {
131
137
  }
132
138
  if (!this._wallet) return;
133
139
  this._connecting = true;
134
- const wallet = this._wallet as TronLinkWallet;
135
- const address = wallet.tronWeb.defaultAddress?.base58 || '';
140
+ const wallet = this._wallet as TokenPocketWallet;
141
+
142
+ const res = await wallet.tron.request({ method: 'eth_requestAccounts' });
143
+ const address = res[0];
144
+
136
145
  this.setAddress(address);
137
146
  this.setState(AdapterState.Connected);
138
147
  this.emit('connect', this.address || '');
@@ -171,11 +180,15 @@ export class TokenPocketAdapter extends Adapter {
171
180
  }
172
181
  }
173
182
 
174
- async multiSign(...args: any[]): Promise<SignedTransaction> {
183
+ async multiSign(
184
+ transaction: Transaction,
185
+ privateKey?: string | false,
186
+ permissionId?: number
187
+ ): Promise<SignedTransaction> {
175
188
  try {
176
189
  const wallet = await this.checkAndGetWallet();
177
190
  try {
178
- return await wallet.tronWeb.trx.multiSign(...args);
191
+ return await wallet.tronWeb.trx.multiSign(transaction, privateKey, permissionId);
179
192
  } catch (error: any) {
180
193
  if (error instanceof Error) {
181
194
  throw new WalletSignTransactionError(error.message, error);
@@ -213,7 +226,7 @@ export class TokenPocketAdapter extends Adapter {
213
226
  if (!this.connected) throw new WalletDisconnectedError();
214
227
  const wallet = this._wallet;
215
228
  if (!wallet || !wallet.tronWeb) throw new WalletDisconnectedError();
216
- return wallet as TronLinkWallet;
229
+ return wallet as TokenPocketWallet;
217
230
  }
218
231
 
219
232
  private checkIfOpenApp() {
@@ -286,19 +299,17 @@ export class TokenPocketAdapter extends Adapter {
286
299
  let state = this.state;
287
300
  let address = this.address;
288
301
  if (supportTokenPocket()) {
289
- // fake tronLink
290
302
  this._wallet = {
303
+ tron: window.tokenpocket?.tron,
291
304
  ready: window.tronWeb?.ready,
292
- tronWeb: window.tronWeb,
293
- request: () => Promise.resolve(true) as any,
294
- } as TronLinkWallet;
305
+ tronWeb: window.tokenpocket?.tronWeb,
306
+ } as TokenPocketWallet;
295
307
  address = this._wallet.tronWeb.defaultAddress?.base58 || null;
296
308
  state = window.tronWeb?.ready ? AdapterState.Connected : AdapterState.Disconnect;
297
309
  if (!window.tronWeb?.ready) {
298
310
  this.checkForWalletReady();
299
311
  }
300
312
  } else {
301
- // no tronlink support
302
313
  this._wallet = null;
303
314
  address = null;
304
315
  state = AdapterState.NotFound;
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isInBrowser, isInMobileBrowser } from '@tronweb3/tronwallet-abstract-adapter';
2
2
 
3
3
  export function supportTokenPocket() {
4
- return !!isInMobileBrowser() && !!window.tronWeb && typeof (window as any).tokenpocket !== 'undefined';
4
+ return !!window.tronWeb && typeof (window as any).tokenpocket !== 'undefined';
5
5
  }
6
6
 
7
7
  /**