ghost-portal/packages/ui-api/src/derive/session/eraProgress.ts
Jaco Greeff 014ae780e4
Split ui-api, update API version (#589)
* Split ui-api, update API version

* Update (awaiting API changes to go through)

* Cleanup ui-api exports

* Bump API (SubscriptionPromise support)

* Linting fixes

* Update renames

* Do display balances.Transfer (shows for non-owned accounts)

* Bump API
2019-01-12 09:38:07 +01:00

31 lines
1.1 KiB
TypeScript

// Copyright 2017-2019 @polkadot/ui-api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { PromiseSubscription } from '@polkadot/api/promise/types';
import { DeriveSubscription } from '../types';
import BN from 'bn.js';
import ApiPromise from '@polkadot/api/promise';
import sessionProgress from './sessionProgress';
export default function eraProgress (api: ApiPromise): DeriveSubscription {
return (cb: (count: BN) => any): PromiseSubscription =>
api.combineLatest([
sessionProgress(api),
api.query.session.currentIndex,
api.query.session.sessionLength,
api.query.staking.lastEraLengthChange,
api.query.staking.sessionsPerEra
], ([sessionProgress, currentIndex, sessionLength, lastEraLengthChange, sessionsPerEra]) =>
cb(
(currentIndex || new BN(0))
.sub(lastEraLengthChange || new BN(0))
.mod(sessionsPerEra || new BN(1))
.mul(sessionLength || new BN(1))
.add(sessionProgress || new BN(0))
)
);
}