@onekeyfe/onekey-aptos-provider 1.1.6 → 1.1.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.
@@ -71,7 +71,10 @@ declare class ProviderAptos extends ProviderAptosBase implements IProviderAptos
71
71
  private _callBridge;
72
72
  private _handleConnected;
73
73
  private _handleDisconnected;
74
+ isAccountsChanged(account: AptosAccountInfo | undefined): boolean;
74
75
  private _handleAccountChange;
76
+ private _network;
77
+ isNetworkChanged(network: string): boolean;
75
78
  private _handleNetworkChange;
76
79
  connect(): Promise<AptosAccountInfo>;
77
80
  isConnected(): boolean;
@@ -52,26 +52,46 @@ class ProviderAptos extends ProviderAptosBase {
52
52
  _handleConnected(account, options = { emit: true }) {
53
53
  var _a;
54
54
  this._account = account;
55
- options.emit && this.emit('connect', (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null);
55
+ if (options.emit && this.isConnectionStatusChanged('connected')) {
56
+ this.connectionStatus = 'connected';
57
+ const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
58
+ this.emit('connect', address);
59
+ this.emit('accountChanged', address);
60
+ }
56
61
  }
57
62
  _handleDisconnected(options = { emit: true }) {
58
63
  this._account = null;
59
- options.emit && this.emit('disconnect');
64
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
65
+ this.connectionStatus = 'disconnected';
66
+ this.emit('disconnect');
67
+ this.emit('accountChanged', null);
68
+ }
69
+ }
70
+ isAccountsChanged(account) {
71
+ var _a;
72
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
60
73
  }
61
74
  // trigger by bridge account change event
62
75
  _handleAccountChange(payload) {
63
- var _a;
64
76
  const account = payload;
77
+ if (this.isAccountsChanged(account)) {
78
+ this.emit('accountChanged', (account === null || account === void 0 ? void 0 : account.address) || null);
79
+ }
65
80
  if (!account) {
66
81
  this._handleDisconnected();
67
- return this.emit('accountChanged', null);
82
+ return;
68
83
  }
69
84
  this._handleConnected(account, { emit: false });
70
- this.emit('accountChanged', (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null);
85
+ }
86
+ isNetworkChanged(network) {
87
+ return this._network === undefined || network !== this._network;
71
88
  }
72
89
  _handleNetworkChange(payload) {
73
90
  const network = payload;
74
- this.emit('networkChange', network !== null && network !== void 0 ? network : null);
91
+ if (this.isNetworkChanged(network)) {
92
+ this.emit('networkChange', network || null);
93
+ }
94
+ this._network = network;
75
95
  }
76
96
  connect() {
77
97
  return __awaiter(this, void 0, void 0, function* () {
@@ -55,26 +55,46 @@ class ProviderAptos extends ProviderAptosBase_1.ProviderAptosBase {
55
55
  _handleConnected(account, options = { emit: true }) {
56
56
  var _a;
57
57
  this._account = account;
58
- options.emit && this.emit('connect', (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null);
58
+ if (options.emit && this.isConnectionStatusChanged('connected')) {
59
+ this.connectionStatus = 'connected';
60
+ const address = (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null;
61
+ this.emit('connect', address);
62
+ this.emit('accountChanged', address);
63
+ }
59
64
  }
60
65
  _handleDisconnected(options = { emit: true }) {
61
66
  this._account = null;
62
- options.emit && this.emit('disconnect');
67
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
68
+ this.connectionStatus = 'disconnected';
69
+ this.emit('disconnect');
70
+ this.emit('accountChanged', null);
71
+ }
72
+ }
73
+ isAccountsChanged(account) {
74
+ var _a;
75
+ return (account === null || account === void 0 ? void 0 : account.address) !== ((_a = this._account) === null || _a === void 0 ? void 0 : _a.address);
63
76
  }
64
77
  // trigger by bridge account change event
65
78
  _handleAccountChange(payload) {
66
- var _a;
67
79
  const account = payload;
80
+ if (this.isAccountsChanged(account)) {
81
+ this.emit('accountChanged', (account === null || account === void 0 ? void 0 : account.address) || null);
82
+ }
68
83
  if (!account) {
69
84
  this._handleDisconnected();
70
- return this.emit('accountChanged', null);
85
+ return;
71
86
  }
72
87
  this._handleConnected(account, { emit: false });
73
- this.emit('accountChanged', (_a = account === null || account === void 0 ? void 0 : account.address) !== null && _a !== void 0 ? _a : null);
88
+ }
89
+ isNetworkChanged(network) {
90
+ return this._network === undefined || network !== this._network;
74
91
  }
75
92
  _handleNetworkChange(payload) {
76
93
  const network = payload;
77
- this.emit('networkChange', network !== null && network !== void 0 ? network : null);
94
+ if (this.isNetworkChanged(network)) {
95
+ this.emit('networkChange', network || null);
96
+ }
97
+ this._network = network;
78
98
  }
79
99
  connect() {
80
100
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-aptos-provider",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
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": "1.1.6",
32
- "@onekeyfe/cross-inpage-provider-errors": "1.1.6",
33
- "@onekeyfe/cross-inpage-provider-types": "1.1.6",
34
- "@onekeyfe/extension-bridge-injected": "1.1.6",
31
+ "@onekeyfe/cross-inpage-provider-core": "1.1.7",
32
+ "@onekeyfe/cross-inpage-provider-errors": "1.1.7",
33
+ "@onekeyfe/cross-inpage-provider-types": "1.1.7",
34
+ "@onekeyfe/extension-bridge-injected": "1.1.7",
35
35
  "aptos": "^1.3.16",
36
36
  "eth-rpc-errors": "^4.0.3"
37
37
  },
38
- "gitHead": "74a047c11aa3bbc20e3b3cc0dac84eea9447083c"
38
+ "gitHead": "caaa1fd03f388765f3d8b1bf8f013c2dfbba7a1b"
39
39
  }