Pass online/offline status indicators with staking accounts (#1265)

* staking online status

* restrict onlineStatus.online to validators

* get onlineStatus for stash/validator only

* tests

* fixes

* Add offline

* Revert stash, change to stashId, linting

* Heartbeat signature

* Make CodeClimate (slightly) happier

* keep compatibility

* change status type

* rv null possible

* cleanup
This commit is contained in:
kwingram25
2019-08-05 16:13:42 +00:00
committed by GitHub
parent 73f33d0168
commit 09ee77d0bc
9 changed files with 125 additions and 11 deletions
+9 -8
View File
@@ -19,6 +19,7 @@ import { isUndefined } from '@polkadot/util';
import { bestNumber } from '../chain/bestNumber';
import { eraLength } from '../session/eraLength';
import { recentlyOffline } from './recentlyOffline';
import { drr } from '../util/drr';
type MultiResult = [Option<Keys>, [
@@ -128,20 +129,20 @@ function retrieveMulti (api: ApiInterfaceRx, stashId: AccountId, controllerId: A
}
function retrieveInfo (api: ApiInterfaceRx, stashId: AccountId, controllerId: AccountId): Observable<DerivedStaking> {
return (
combineLatest([
eraLength(api)(),
bestNumber(api)(),
retrieveMulti(api, stashId, controllerId)
])
).pipe(
map(([eraLength, bestNumber, [nextKeys, [queuedKeys, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]]): DerivedStaking => {
return combineLatest([
eraLength(api)(),
bestNumber(api)(),
recentlyOffline(api)(),
retrieveMulti(api, stashId, controllerId)
]).pipe(
map(([eraLength, bestNumber, recentlyOffline, [nextKeys, [queuedKeys, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]]): DerivedStaking => {
const stakingLedger = _stakingLedger.unwrapOr(undefined);
return {
accountId: stashId,
controllerId,
nominators,
offline: recentlyOffline[stashId.toString()],
redeemable: redeemableSum(stakingLedger, eraLength, bestNumber),
rewardDestination,
stakers,