Subscribe to accounts info in Signer / ParityBar (#4738) (#4856)

This commit is contained in:
Nicolas Gotchac 2017-03-10 15:46:13 +01:00 committed by Jaco Greeff
parent bc9464fcbd
commit dd529575f6

View File

@ -74,28 +74,27 @@ export default class AccountStore {
this._api.parity.getNewDappsAddresses(), this._api.parity.getNewDappsAddresses(),
this._api.parity.allAccountsInfo() this._api.parity.allAccountsInfo()
]) ])
.then(([whitelist, accounts]) => { .then(([whitelist, allAccounts]) => {
transaction(() => { transaction(() => {
this.setLoading(false); const accounts = Object
this.setAccounts( .keys(allAccounts)
Object
.keys(accounts)
.filter((address) => { .filter((address) => {
const account = accounts[address]; const account = allAccounts[address];
const isAccount = account.uuid || (account.meta && account.meta.hardware); const isAccount = account.uuid || (account.meta && account.meta.hardware);
const isWhitelisted = !whitelist || whitelist.includes(address); const isWhitelisted = !whitelist || whitelist.includes(address);
return isAccount && isWhitelisted; return isAccount && isWhitelisted;
}) })
.map((address) => { .map((address) => {
const account = accounts[address]; return {
...allAccounts[address],
checked: address === this.defaultAccount,
address
};
});
account.address = address; this.setLoading(false);
account.checked = address === this.defaultAccount; this.setAccounts(accounts);
return account;
})
);
}); });
}) })
.catch((error) => { .catch((error) => {
@ -117,6 +116,13 @@ export default class AccountStore {
} }
}); });
return Promise.all([ promiseDefaultAccount, promiseEthAccounts ]); const promiseAccountsInfo = this._api
.subscribe('parity_allAccountsInfo', (error, accountsInfo) => {
if (!error) {
this.loadAccounts();
}
});
return Promise.all([ promiseDefaultAccount, promiseEthAccounts, promiseAccountsInfo ]);
} }
} }