@onekeyfe/onekey-ton-provider 2.2.37-alpha.1 → 2.2.37
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
1
|
+
import { IInpageProviderConfig, IProviderBaseConnectionStatus } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
2
|
import { ProviderTonBase } from './ProviderTonBase';
|
|
3
3
|
import { AppRequest, ConnectEvent, ConnectRequest, DeviceInfo, RpcMethod, WalletEvent, WalletResponse, WalletResponseError } from '@tonconnect/protocol';
|
|
4
4
|
import { AccountInfo, SignDataRequest, SignDataResult, SignProofRequest, SignProofResult, TransactionRequest, WalletInfo } from './types';
|
|
@@ -37,6 +37,7 @@ export declare class ProviderTon extends ProviderTonBase implements IProviderTon
|
|
|
37
37
|
walletInfo?: WalletInfo;
|
|
38
38
|
protocolVersion: number;
|
|
39
39
|
isWalletBrowser: boolean;
|
|
40
|
+
connectionStatus: IProviderBaseConnectionStatus;
|
|
40
41
|
constructor(props: OneKeyTonProviderProps);
|
|
41
42
|
private _getPlatform;
|
|
42
43
|
private _getDeviceInfo;
|
|
@@ -51,10 +52,11 @@ export declare class ProviderTon extends ProviderTonBase implements IProviderTon
|
|
|
51
52
|
_connect(protocolVersion?: number, message?: ConnectRequest): Promise<ConnectEvent>;
|
|
52
53
|
connect(protocolVersion?: number, message?: ConnectRequest): Promise<ConnectEvent>;
|
|
53
54
|
restoreConnection(): Promise<ConnectEvent>;
|
|
54
|
-
convertError<T extends RpcMethod>(id: string, error: unknown): WalletResponseError<T>;
|
|
55
|
+
convertError<T extends RpcMethod>(id: string, error: unknown, method: string): WalletResponseError<T>;
|
|
55
56
|
send<T extends RpcMethod>(message: AppRequest<T>): Promise<WalletResponse<T>>;
|
|
56
57
|
private _sendTransaction;
|
|
57
58
|
private _signData;
|
|
59
|
+
disconnect(): Promise<void>;
|
|
58
60
|
private _disconnect;
|
|
59
61
|
listen(callback: (event: WalletEvent) => void): void;
|
|
60
62
|
}
|
|
@@ -16,6 +16,9 @@ const PROVIDER_EVENTS = {
|
|
|
16
16
|
'accountChanged': 'accountChanged',
|
|
17
17
|
'message_low_level': 'message_low_level',
|
|
18
18
|
};
|
|
19
|
+
const TonResponseError = {
|
|
20
|
+
ParameterError: 1,
|
|
21
|
+
};
|
|
19
22
|
function isWalletEventMethodMatch({ method, name }) {
|
|
20
23
|
return method === `wallet_events_${name}`;
|
|
21
24
|
}
|
|
@@ -62,6 +65,7 @@ export class ProviderTon extends ProviderTonBase {
|
|
|
62
65
|
};
|
|
63
66
|
this.protocolVersion = 2;
|
|
64
67
|
this.isWalletBrowser = false;
|
|
68
|
+
this.connectionStatus = 'disconnected';
|
|
65
69
|
// void this._getDeviceInfo();
|
|
66
70
|
this._registerEvents();
|
|
67
71
|
}
|
|
@@ -261,14 +265,27 @@ export class ProviderTon extends ProviderTonBase {
|
|
|
261
265
|
restoreConnection() {
|
|
262
266
|
return this._connect();
|
|
263
267
|
}
|
|
264
|
-
convertError(id, error) {
|
|
268
|
+
convertError(id, error, method) {
|
|
265
269
|
const { code, message } = error;
|
|
266
270
|
if (code === 4001) {
|
|
271
|
+
let errorMessage = ConnectEventErrorMessage.USER_DECLINED;
|
|
272
|
+
if (method === 'sendTransaction' || method === 'signData') {
|
|
273
|
+
errorMessage = SendTransactionErrorMessage.USER_REJECTS_ERROR;
|
|
274
|
+
}
|
|
267
275
|
return {
|
|
268
276
|
id,
|
|
269
277
|
error: {
|
|
270
278
|
code: SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR,
|
|
271
|
-
message:
|
|
279
|
+
message: errorMessage,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
else if (code === TonResponseError.ParameterError) {
|
|
284
|
+
return {
|
|
285
|
+
id,
|
|
286
|
+
error: {
|
|
287
|
+
code: SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR,
|
|
288
|
+
message: message,
|
|
272
289
|
},
|
|
273
290
|
};
|
|
274
291
|
}
|
|
@@ -315,7 +332,7 @@ export class ProviderTon extends ProviderTonBase {
|
|
|
315
332
|
}
|
|
316
333
|
}
|
|
317
334
|
catch (error) {
|
|
318
|
-
return this.convertError(id, error);
|
|
335
|
+
return this.convertError(id, error, message.method);
|
|
319
336
|
}
|
|
320
337
|
if (res === undefined) {
|
|
321
338
|
return {
|
|
@@ -349,13 +366,18 @@ export class ProviderTon extends ProviderTonBase {
|
|
|
349
366
|
return res;
|
|
350
367
|
});
|
|
351
368
|
}
|
|
369
|
+
disconnect() {
|
|
370
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
371
|
+
yield this._disconnect();
|
|
372
|
+
});
|
|
373
|
+
}
|
|
352
374
|
_disconnect() {
|
|
353
375
|
return __awaiter(this, void 0, void 0, function* () {
|
|
354
376
|
yield this._callBridge({
|
|
355
377
|
method: 'disconnect',
|
|
356
378
|
params: [],
|
|
357
379
|
});
|
|
358
|
-
this._handleDisconnected();
|
|
380
|
+
this._handleDisconnected({ emit: true });
|
|
359
381
|
});
|
|
360
382
|
}
|
|
361
383
|
listen(callback) {
|
|
@@ -21,6 +21,9 @@ const PROVIDER_EVENTS = {
|
|
|
21
21
|
'accountChanged': 'accountChanged',
|
|
22
22
|
'message_low_level': 'message_low_level',
|
|
23
23
|
};
|
|
24
|
+
const TonResponseError = {
|
|
25
|
+
ParameterError: 1,
|
|
26
|
+
};
|
|
24
27
|
function isWalletEventMethodMatch({ method, name }) {
|
|
25
28
|
return method === `wallet_events_${name}`;
|
|
26
29
|
}
|
|
@@ -67,6 +70,7 @@ class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
|
67
70
|
};
|
|
68
71
|
this.protocolVersion = 2;
|
|
69
72
|
this.isWalletBrowser = false;
|
|
73
|
+
this.connectionStatus = 'disconnected';
|
|
70
74
|
// void this._getDeviceInfo();
|
|
71
75
|
this._registerEvents();
|
|
72
76
|
}
|
|
@@ -266,14 +270,27 @@ class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
|
266
270
|
restoreConnection() {
|
|
267
271
|
return this._connect();
|
|
268
272
|
}
|
|
269
|
-
convertError(id, error) {
|
|
273
|
+
convertError(id, error, method) {
|
|
270
274
|
const { code, message } = error;
|
|
271
275
|
if (code === 4001) {
|
|
276
|
+
let errorMessage = types_1.ConnectEventErrorMessage.USER_DECLINED;
|
|
277
|
+
if (method === 'sendTransaction' || method === 'signData') {
|
|
278
|
+
errorMessage = types_1.SendTransactionErrorMessage.USER_REJECTS_ERROR;
|
|
279
|
+
}
|
|
272
280
|
return {
|
|
273
281
|
id,
|
|
274
282
|
error: {
|
|
275
283
|
code: protocol_1.SEND_TRANSACTION_ERROR_CODES.USER_REJECTS_ERROR,
|
|
276
|
-
message:
|
|
284
|
+
message: errorMessage,
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
else if (code === TonResponseError.ParameterError) {
|
|
289
|
+
return {
|
|
290
|
+
id,
|
|
291
|
+
error: {
|
|
292
|
+
code: protocol_1.SEND_TRANSACTION_ERROR_CODES.BAD_REQUEST_ERROR,
|
|
293
|
+
message: message,
|
|
277
294
|
},
|
|
278
295
|
};
|
|
279
296
|
}
|
|
@@ -320,7 +337,7 @@ class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
|
320
337
|
}
|
|
321
338
|
}
|
|
322
339
|
catch (error) {
|
|
323
|
-
return this.convertError(id, error);
|
|
340
|
+
return this.convertError(id, error, message.method);
|
|
324
341
|
}
|
|
325
342
|
if (res === undefined) {
|
|
326
343
|
return {
|
|
@@ -354,13 +371,18 @@ class ProviderTon extends ProviderTonBase_1.ProviderTonBase {
|
|
|
354
371
|
return res;
|
|
355
372
|
});
|
|
356
373
|
}
|
|
374
|
+
disconnect() {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
yield this._disconnect();
|
|
377
|
+
});
|
|
378
|
+
}
|
|
357
379
|
_disconnect() {
|
|
358
380
|
return __awaiter(this, void 0, void 0, function* () {
|
|
359
381
|
yield this._callBridge({
|
|
360
382
|
method: 'disconnect',
|
|
361
383
|
params: [],
|
|
362
384
|
});
|
|
363
|
-
this._handleDisconnected();
|
|
385
|
+
this._handleDisconnected({ emit: true });
|
|
364
386
|
});
|
|
365
387
|
}
|
|
366
388
|
listen(callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-ton-provider",
|
|
3
|
-
"version": "2.2.37
|
|
3
|
+
"version": "2.2.37",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"start": "tsc --watch"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@onekeyfe/cross-inpage-provider-core": "2.2.37
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.2.37
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-types": "2.2.37
|
|
33
|
-
"@onekeyfe/extension-bridge-injected": "2.2.37
|
|
34
|
-
"@tonconnect/protocol": "^2.
|
|
30
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.37",
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.2.37",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.37",
|
|
33
|
+
"@onekeyfe/extension-bridge-injected": "2.2.37",
|
|
34
|
+
"@tonconnect/protocol": "^2.3.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "0c1b9cafd7a5d6ebcf7fc20c5c279534abf85da5"
|
|
37
37
|
}
|