* 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
28 lines
944 B
TypeScript
28 lines
944 B
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 bestNumber from '../chain/bestNumber';
|
|
|
|
export default function sessionProgress (api: ApiPromise): DeriveSubscription {
|
|
return (cb: (count: BN) => any): PromiseSubscription =>
|
|
api.combineLatest([
|
|
bestNumber(api),
|
|
api.query.session.sessionLength,
|
|
api.query.session.lastLengthChange
|
|
], ([bestNumber, sessionLength, lastLengthChange]) =>
|
|
cb(
|
|
(bestNumber || new BN(0))
|
|
.sub(lastLengthChange || new BN(0))
|
|
.add(sessionLength || new BN(1))
|
|
.mod(sessionLength || new BN(1))
|
|
)
|
|
);
|
|
}
|