@onekeyfe/onekey-aptos-provider 2.1.14 → 2.1.16

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 _account: AptosAccountInfo | null;
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._account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
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._account = null;
30
+ this._state = {
31
+ account: null,
32
+ };
31
33
  this.aptosProviderType = 'petra';
32
34
  this._registerEvents();
33
35
  }
@@ -53,29 +55,32 @@ class ProviderAptos extends ProviderAptosBase {
53
55
  }
54
56
  _handleConnected(account, options = { emit: true }) {
55
57
  var _a;
56
- this._account = account;
58
+ this._state.account = {
59
+ publicKey: account.publicKey,
60
+ address: account.address,
61
+ };
57
62
  if (this.isConnectionStatusChanged('connected')) {
58
63
  this.connectionStatus = 'connected';
59
- }
60
- if (options.emit) {
61
- const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
62
- this.emit('connect', address);
63
- this.emit('accountChanged', address);
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
+ }
64
69
  }
65
70
  }
66
71
  _handleDisconnected(options = { emit: true }) {
67
- this._account = null;
72
+ this._state.account = null;
68
73
  if (this.isConnectionStatusChanged('disconnected')) {
69
74
  this.connectionStatus = 'disconnected';
70
- }
71
- if (options.emit) {
72
- this.emit('disconnect');
73
- this.emit('accountChanged', null);
75
+ if (options.emit) {
76
+ this.emit('disconnect');
77
+ this.emit('accountChanged', null);
78
+ }
74
79
  }
75
80
  }
76
81
  isAccountsChanged(account) {
77
82
  var _a;
78
- return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
83
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._state.account) === null || _a === void 0 ? void 0 : _a.address);
79
84
  }
80
85
  // trigger by bridge account change event
81
86
  _handleAccountChange(payload) {
@@ -101,8 +106,8 @@ class ProviderAptos extends ProviderAptosBase {
101
106
  }
102
107
  connect() {
103
108
  return __awaiter(this, void 0, void 0, function* () {
104
- if (this._account) {
105
- return Promise.resolve(this._account);
109
+ if (this._state.account) {
110
+ return Promise.resolve(this._state.account);
106
111
  }
107
112
  const result = yield this._callBridge({
108
113
  method: 'connect',
@@ -115,7 +120,7 @@ class ProviderAptos extends ProviderAptosBase {
115
120
  });
116
121
  }
117
122
  isConnected() {
118
- return this.isConnectionStatusChanged('connected');
123
+ return !!this._state.account;
119
124
  }
120
125
  account() {
121
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._account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
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._account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
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._account = null;
33
+ this._state = {
34
+ account: null,
35
+ };
34
36
  this.aptosProviderType = 'petra';
35
37
  this._registerEvents();
36
38
  }
@@ -56,29 +58,32 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
56
58
  }
57
59
  _handleConnected(account, options = { emit: true }) {
58
60
  var _a;
59
- this._account = account;
61
+ this._state.account = {
62
+ publicKey: account.publicKey,
63
+ address: account.address,
64
+ };
60
65
  if (this.isConnectionStatusChanged('connected')) {
61
66
  this.connectionStatus = 'connected';
62
- }
63
- if (options.emit) {
64
- const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
65
- this.emit('connect', address);
66
- this.emit('accountChanged', address);
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
+ }
67
72
  }
68
73
  }
69
74
  _handleDisconnected(options = { emit: true }) {
70
- this._account = null;
75
+ this._state.account = null;
71
76
  if (this.isConnectionStatusChanged('disconnected')) {
72
77
  this.connectionStatus = 'disconnected';
73
- }
74
- if (options.emit) {
75
- this.emit('disconnect');
76
- this.emit('accountChanged', null);
78
+ if (options.emit) {
79
+ this.emit('disconnect');
80
+ this.emit('accountChanged', null);
81
+ }
77
82
  }
78
83
  }
79
84
  isAccountsChanged(account) {
80
85
  var _a;
81
- return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
86
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._state.account) === null || _a === void 0 ? void 0 : _a.address);
82
87
  }
83
88
  // trigger by bridge account change event
84
89
  _handleAccountChange(payload) {
@@ -104,8 +109,8 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
104
109
  }
105
110
  connect() {
106
111
  return __awaiter(this, void 0, void 0, function* () {
107
- if (this._account) {
108
- return Promise.resolve(this._account);
112
+ if (this._state.account) {
113
+ return Promise.resolve(this._state.account);
109
114
  }
110
115
  const result = yield this._callBridge({
111
116
  method: 'connect',
@@ -118,7 +123,7 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
118
123
  });
119
124
  }
120
125
  isConnected() {
121
- return this.isConnectionStatusChanged('connected');
126
+ return !!this._state.account;
122
127
  }
123
128
  account() {
124
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._account) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _b !== void 0 ? _b : null;
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
@@ -2,6 +2,9 @@ export type AptosAccountInfo = {
2
2
  publicKey: string;
3
3
  address: string;
4
4
  };
5
+ export type ProviderState = {
6
+ account: AptosAccountInfo | null;
7
+ };
5
8
  export type TxnOptions = {
6
9
  sender?: string;
7
10
  sequence_number?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-aptos-provider",
3
- "version": "2.1.14",
3
+ "version": "2.1.16",
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.14",
32
- "@onekeyfe/cross-inpage-provider-errors": "2.1.14",
33
- "@onekeyfe/cross-inpage-provider-types": "2.1.14",
34
- "@onekeyfe/extension-bridge-injected": "2.1.14",
31
+ "@onekeyfe/cross-inpage-provider-core": "2.1.16",
32
+ "@onekeyfe/cross-inpage-provider-errors": "2.1.16",
33
+ "@onekeyfe/cross-inpage-provider-types": "2.1.16",
34
+ "@onekeyfe/extension-bridge-injected": "2.1.16",
35
35
  "aptos": "^1.3.17",
36
36
  "eth-rpc-errors": "^4.0.3"
37
37
  },
38
- "gitHead": "a834c7223890d2c153f04dafad9e7095cf9547dc"
38
+ "gitHead": "08f1d2c6c5b6556f50ac7003daab69cd50d84728"
39
39
  }