@onekeyfe/onekey-solana-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.
@@ -49,6 +49,9 @@ declare type SolanaProviderEventsMap = {
49
49
  [PROVIDER_EVENTS.accountChanged]: (publicKey: PublicKey | null) => void;
50
50
  [PROVIDER_EVENTS.message_low_level]: (payload: IJsonRpcRequest) => void;
51
51
  };
52
+ declare type SolanaAccountInfo = {
53
+ publicKey: string;
54
+ };
52
55
  interface IProviderSolana extends ProviderSolanaBase {
53
56
  readonly isPhantom: true;
54
57
  readonly isGlow: true;
@@ -117,6 +120,7 @@ declare class ProviderSolana extends ProviderSolanaBase implements IProviderSola
117
120
  private _handleConnected;
118
121
  disconnect(): Promise<void>;
119
122
  private _handleDisconnected;
123
+ isAccountsChanged(account: SolanaAccountInfo | undefined): boolean;
120
124
  private _handleAccountChange;
121
125
  signAndSendTransaction(transaction: Transaction, options?: Partial<SendOptions>): Promise<{
122
126
  publicKey: string;
@@ -68,7 +68,11 @@ class ProviderSolana extends ProviderSolanaBase {
68
68
  }
69
69
  _handleConnected(publicKey, options = { emit: true }) {
70
70
  this._publicKey = publicKey;
71
- options.emit && this.emit('connect', publicKey);
71
+ if (options.emit && this.isConnectionStatusChanged('connected')) {
72
+ this.connectionStatus = 'connected';
73
+ this.emit('connect', publicKey);
74
+ this.emit('accountChanged', publicKey);
75
+ }
72
76
  }
73
77
  disconnect() {
74
78
  return __awaiter(this, void 0, void 0, function* () {
@@ -81,18 +85,36 @@ class ProviderSolana extends ProviderSolanaBase {
81
85
  }
82
86
  _handleDisconnected(options = { emit: true }) {
83
87
  this._publicKey = null;
84
- options.emit && this.emit('disconnect');
88
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
89
+ this.connectionStatus = 'disconnected';
90
+ this.emit('disconnect');
91
+ this.emit('accountChanged', null);
92
+ }
93
+ }
94
+ isAccountsChanged(account) {
95
+ var _a;
96
+ return (account === null || account === void 0 ? void 0 : account.publicKey) !== ((_a = this._publicKey) === null || _a === void 0 ? void 0 : _a.toBase58());
85
97
  }
86
98
  // trigger by bridge account change event
87
99
  _handleAccountChange(payload) {
88
100
  const account = payload.accounts[0];
101
+ let publicKey;
102
+ try {
103
+ publicKey = new PublicKey(account.publicKey);
104
+ }
105
+ catch (error) {
106
+ // noop
107
+ }
108
+ if (this.isAccountsChanged(account)) {
109
+ this.emit('accountChanged', publicKey || null);
110
+ }
89
111
  if (!account) {
90
112
  this._handleDisconnected();
91
- return this.emit('accountChanged', null);
113
+ return;
114
+ }
115
+ if (publicKey) {
116
+ this._handleConnected(publicKey, { emit: false });
92
117
  }
93
- const publicKey = new PublicKey(account.publicKey);
94
- this._handleConnected(publicKey, { emit: false });
95
- this.emit('accountChanged', publicKey);
96
118
  }
97
119
  signAndSendTransaction(transaction, options) {
98
120
  return __awaiter(this, void 0, void 0, function* () {
@@ -74,7 +74,11 @@ class ProviderSolana extends ProviderSolanaBase_1.ProviderSolanaBase {
74
74
  }
75
75
  _handleConnected(publicKey, options = { emit: true }) {
76
76
  this._publicKey = publicKey;
77
- options.emit && this.emit('connect', publicKey);
77
+ if (options.emit && this.isConnectionStatusChanged('connected')) {
78
+ this.connectionStatus = 'connected';
79
+ this.emit('connect', publicKey);
80
+ this.emit('accountChanged', publicKey);
81
+ }
78
82
  }
79
83
  disconnect() {
80
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -87,18 +91,36 @@ class ProviderSolana extends ProviderSolanaBase_1.ProviderSolanaBase {
87
91
  }
88
92
  _handleDisconnected(options = { emit: true }) {
89
93
  this._publicKey = null;
90
- options.emit && this.emit('disconnect');
94
+ if (options.emit && this.isConnectionStatusChanged('disconnected')) {
95
+ this.connectionStatus = 'disconnected';
96
+ this.emit('disconnect');
97
+ this.emit('accountChanged', null);
98
+ }
99
+ }
100
+ isAccountsChanged(account) {
101
+ var _a;
102
+ return (account === null || account === void 0 ? void 0 : account.publicKey) !== ((_a = this._publicKey) === null || _a === void 0 ? void 0 : _a.toBase58());
91
103
  }
92
104
  // trigger by bridge account change event
93
105
  _handleAccountChange(payload) {
94
106
  const account = payload.accounts[0];
107
+ let publicKey;
108
+ try {
109
+ publicKey = new web3_js_1.PublicKey(account.publicKey);
110
+ }
111
+ catch (error) {
112
+ // noop
113
+ }
114
+ if (this.isAccountsChanged(account)) {
115
+ this.emit('accountChanged', publicKey || null);
116
+ }
95
117
  if (!account) {
96
118
  this._handleDisconnected();
97
- return this.emit('accountChanged', null);
119
+ return;
120
+ }
121
+ if (publicKey) {
122
+ this._handleConnected(publicKey, { emit: false });
98
123
  }
99
- const publicKey = new web3_js_1.PublicKey(account.publicKey);
100
- this._handleConnected(publicKey, { emit: false });
101
- this.emit('accountChanged', publicKey);
102
124
  }
103
125
  signAndSendTransaction(transaction, options) {
104
126
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/onekey-solana-provider",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "keywords": [
5
5
  "cross-inpage-provider",
6
6
  "solona"
@@ -29,15 +29,15 @@
29
29
  "start": "tsc --watch"
30
30
  },
31
31
  "dependencies": {
32
- "@onekeyfe/cross-inpage-provider-core": "1.1.6",
33
- "@onekeyfe/cross-inpage-provider-errors": "1.1.6",
34
- "@onekeyfe/cross-inpage-provider-types": "1.1.6",
35
- "@onekeyfe/extension-bridge-injected": "1.1.6",
32
+ "@onekeyfe/cross-inpage-provider-core": "1.1.7",
33
+ "@onekeyfe/cross-inpage-provider-errors": "1.1.7",
34
+ "@onekeyfe/cross-inpage-provider-types": "1.1.7",
35
+ "@onekeyfe/extension-bridge-injected": "1.1.7",
36
36
  "@solana/web3.js": "^1.41.3",
37
37
  "bs58": "^5.0.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bs58": "^4.0.1"
41
41
  },
42
- "gitHead": "74a047c11aa3bbc20e3b3cc0dac84eea9447083c"
42
+ "gitHead": "caaa1fd03f388765f3d8b1bf8f013c2dfbba7a1b"
43
43
  }