Skip to content

Commit

Permalink
fix(wallet): return accounts according to subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 23, 2023
1 parent 36920b4 commit fa900c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/AeSdkWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,23 @@ export default class AeSdkWallet extends AeSdk {
this._type = type;
}

_getAccountsForClient({ addressSubscription }: RpcClientsInfo): Accounts {
const { current, connected } = this.getAccounts();
return {
current: addressSubscription.has('current') || addressSubscription.has('connected')
? current : {},
connected: addressSubscription.has('connected') ? connected : {},
};
}

_pushAccountsToApps(): void {
if (this._clients == null) return;
Array.from(this._clients.keys())
.filter((clientId) => this._isRpcClientConnected(clientId))
.map((clientId) => this._getClient(clientId))
.filter((client) => client.addressSubscription.size !== 0)
.forEach((client) => client.rpc.notify(METHODS.updateAddress, this.getAccounts()));
.forEach((client) => client.rpc
.notify(METHODS.updateAddress, this._getAccountsForClient(client)));
}

override selectAccount(address: Encoded.AccountAddress): void {
Expand Down Expand Up @@ -230,7 +240,7 @@ export default class AeSdkWallet extends AeSdk {

return {
subscription: Array.from(client.addressSubscription),
address: this.getAccounts(),
address: this._getAccountsForClient(client),
};
},
[METHODS.address]: async (params, origin) => {
Expand Down

0 comments on commit fa900c0

Please sign in to comment.