@onekeyfe/onekey-aptos-provider 2.1.13 → 2.1.15
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,6 +1,6 @@
|
|
|
1
1
|
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
|
|
2
2
|
import { ProviderAptosBase } from './ProviderAptosBase';
|
|
3
|
-
import { AptosAccountInfo, SignMessagePayload, SignMessageResponse } from './types';
|
|
3
|
+
import { AptosAccountInfo, ProviderState, SignMessagePayload, SignMessageResponse } from './types';
|
|
4
4
|
import { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types';
|
|
5
5
|
import { Types } from 'aptos';
|
|
6
6
|
export type AptosProviderType = 'petra' | 'martian';
|
|
@@ -63,7 +63,7 @@ type OneKeyAptosProviderProps = IInpageProviderConfig & {
|
|
|
63
63
|
timeout?: number;
|
|
64
64
|
};
|
|
65
65
|
declare class ProviderAptos extends ProviderAptosBase implements IProviderAptos {
|
|
66
|
-
protected
|
|
66
|
+
protected _state: ProviderState;
|
|
67
67
|
protected aptosProviderType: AptosProviderType;
|
|
68
68
|
get publicKey(): string | null;
|
|
69
69
|
constructor(props: OneKeyAptosProviderProps);
|
|
@@ -22,12 +22,14 @@ function isWalletEventMethodMatch({ method, name }) {
|
|
|
22
22
|
}
|
|
23
23
|
class ProviderAptos extends ProviderAptosBase {
|
|
24
24
|
get publicKey() {
|
|
25
|
-
var _a, _b;
|
|
26
|
-
return (_b = (_a = this.
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
return (_c = (_b = (_a = this._state) === null || _a === void 0 ? void 0 : _a.account) === null || _b === void 0 ? void 0 : _b.publicKey) !== null && _c !== void 0 ? _c : null;
|
|
27
27
|
}
|
|
28
28
|
constructor(props) {
|
|
29
29
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || getOrCreateExtInjectedJsBridge({ timeout: props.timeout }) }));
|
|
30
|
-
this.
|
|
30
|
+
this._state = {
|
|
31
|
+
account: null,
|
|
32
|
+
};
|
|
31
33
|
this.aptosProviderType = 'petra';
|
|
32
34
|
this._registerEvents();
|
|
33
35
|
}
|
|
@@ -53,25 +55,32 @@ class ProviderAptos extends ProviderAptosBase {
|
|
|
53
55
|
}
|
|
54
56
|
_handleConnected(account, options = { emit: true }) {
|
|
55
57
|
var _a;
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
+
this._state.account = {
|
|
59
|
+
publicKey: account.publicKey,
|
|
60
|
+
address: account.address,
|
|
61
|
+
};
|
|
62
|
+
if (this.isConnectionStatusChanged('connected')) {
|
|
58
63
|
this.connectionStatus = 'connected';
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
if (options.emit) {
|
|
65
|
+
const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
|
|
66
|
+
this.emit('connect', address);
|
|
67
|
+
this.emit('accountChanged', address);
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
_handleDisconnected(options = { emit: true }) {
|
|
65
|
-
this.
|
|
66
|
-
if (
|
|
72
|
+
this._state.account = null;
|
|
73
|
+
if (this.isConnectionStatusChanged('disconnected')) {
|
|
67
74
|
this.connectionStatus = 'disconnected';
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
if (options.emit) {
|
|
76
|
+
this.emit('disconnect');
|
|
77
|
+
this.emit('accountChanged', null);
|
|
78
|
+
}
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
isAccountsChanged(account) {
|
|
73
82
|
var _a;
|
|
74
|
-
return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this.
|
|
83
|
+
return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._state.account) === null || _a === void 0 ? void 0 : _a.address);
|
|
75
84
|
}
|
|
76
85
|
// trigger by bridge account change event
|
|
77
86
|
_handleAccountChange(payload) {
|
|
@@ -97,8 +106,8 @@ class ProviderAptos extends ProviderAptosBase {
|
|
|
97
106
|
}
|
|
98
107
|
connect() {
|
|
99
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
if (this.
|
|
101
|
-
return Promise.resolve(this.
|
|
109
|
+
if (this._state.account) {
|
|
110
|
+
return Promise.resolve(this._state.account);
|
|
102
111
|
}
|
|
103
112
|
const result = yield this._callBridge({
|
|
104
113
|
method: 'connect',
|
|
@@ -111,7 +120,7 @@ class ProviderAptos extends ProviderAptosBase {
|
|
|
111
120
|
});
|
|
112
121
|
}
|
|
113
122
|
isConnected() {
|
|
114
|
-
return this.
|
|
123
|
+
return !!this._state.account;
|
|
115
124
|
}
|
|
116
125
|
account() {
|
|
117
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -13,7 +13,7 @@ import { web3Errors } from '@onekeyfe/cross-inpage-provider-errors';
|
|
|
13
13
|
class ProviderAptosMartian extends ProviderAptos {
|
|
14
14
|
get publicKey() {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
return (_b = (_a = this.
|
|
16
|
+
return (_b = (_a = this._state.account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
|
|
17
17
|
}
|
|
18
18
|
constructor(props) {
|
|
19
19
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || getOrCreateExtInjectedJsBridge({ timeout: props.timeout }) }));
|
|
@@ -25,12 +25,14 @@ function isWalletEventMethodMatch({ method, name }) {
|
|
|
25
25
|
}
|
|
26
26
|
class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
|
|
27
27
|
get publicKey() {
|
|
28
|
-
var _a, _b;
|
|
29
|
-
return (_b = (_a = this.
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
return (_c = (_b = (_a = this._state) === null || _a === void 0 ? void 0 : _a.account) === null || _b === void 0 ? void 0 : _b.publicKey) !== null && _c !== void 0 ? _c : null;
|
|
30
30
|
}
|
|
31
31
|
constructor(props) {
|
|
32
32
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || (0, extension_bridge_injected_1.getOrCreateExtInjectedJsBridge)({ timeout: props.timeout }) }));
|
|
33
|
-
this.
|
|
33
|
+
this._state = {
|
|
34
|
+
account: null,
|
|
35
|
+
};
|
|
34
36
|
this.aptosProviderType = 'petra';
|
|
35
37
|
this._registerEvents();
|
|
36
38
|
}
|
|
@@ -56,25 +58,32 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
|
|
|
56
58
|
}
|
|
57
59
|
_handleConnected(account, options = { emit: true }) {
|
|
58
60
|
var _a;
|
|
59
|
-
this.
|
|
60
|
-
|
|
61
|
+
this._state.account = {
|
|
62
|
+
publicKey: account.publicKey,
|
|
63
|
+
address: account.address,
|
|
64
|
+
};
|
|
65
|
+
if (this.isConnectionStatusChanged('connected')) {
|
|
61
66
|
this.connectionStatus = 'connected';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
if (options.emit) {
|
|
68
|
+
const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
|
|
69
|
+
this.emit('connect', address);
|
|
70
|
+
this.emit('accountChanged', address);
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
_handleDisconnected(options = { emit: true }) {
|
|
68
|
-
this.
|
|
69
|
-
if (
|
|
75
|
+
this._state.account = null;
|
|
76
|
+
if (this.isConnectionStatusChanged('disconnected')) {
|
|
70
77
|
this.connectionStatus = 'disconnected';
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
if (options.emit) {
|
|
79
|
+
this.emit('disconnect');
|
|
80
|
+
this.emit('accountChanged', null);
|
|
81
|
+
}
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
isAccountsChanged(account) {
|
|
76
85
|
var _a;
|
|
77
|
-
return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this.
|
|
86
|
+
return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._state.account) === null || _a === void 0 ? void 0 : _a.address);
|
|
78
87
|
}
|
|
79
88
|
// trigger by bridge account change event
|
|
80
89
|
_handleAccountChange(payload) {
|
|
@@ -100,8 +109,8 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
|
|
|
100
109
|
}
|
|
101
110
|
connect() {
|
|
102
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
if (this.
|
|
104
|
-
return Promise.resolve(this.
|
|
112
|
+
if (this._state.account) {
|
|
113
|
+
return Promise.resolve(this._state.account);
|
|
105
114
|
}
|
|
106
115
|
const result = yield this._callBridge({
|
|
107
116
|
method: 'connect',
|
|
@@ -114,7 +123,7 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
|
|
|
114
123
|
});
|
|
115
124
|
}
|
|
116
125
|
isConnected() {
|
|
117
|
-
return this.
|
|
126
|
+
return !!this._state.account;
|
|
118
127
|
}
|
|
119
128
|
account() {
|
|
120
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -16,7 +16,7 @@ const cross_inpage_provider_errors_1 = require("@onekeyfe/cross-inpage-provider-
|
|
|
16
16
|
class ProviderAptosMartian extends OnekeyAptosProvider_1.ProviderAptos {
|
|
17
17
|
get publicKey() {
|
|
18
18
|
var _a, _b;
|
|
19
|
-
return (_b = (_a = this.
|
|
19
|
+
return (_b = (_a = this._state.account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
|
|
20
20
|
}
|
|
21
21
|
constructor(props) {
|
|
22
22
|
super(Object.assign(Object.assign({}, props), { bridge: props.bridge || (0, extension_bridge_injected_1.getOrCreateExtInjectedJsBridge)({ timeout: props.timeout }) }));
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-aptos-provider",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.15",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "2.1.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "2.1.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "2.1.
|
|
34
|
-
"@onekeyfe/extension-bridge-injected": "2.1.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "2.1.15",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "2.1.15",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "2.1.15",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "2.1.15",
|
|
35
35
|
"aptos": "^1.3.17",
|
|
36
36
|
"eth-rpc-errors": "^4.0.3"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "23a0e8e3ef2ace42e8a0359be49ddfd2a653d281"
|
|
39
39
|
}
|