Add derive functions (#540)

* Make types work

* Add test for derive

* Skip e2e

* Change description

* Add some comments

* Add caching

* Integrate cache

* Add tests

* Add test

* Fix types in tests

* Add e2e tests

* Add comments

* Fix lint

* Bump versions

* Remove useless stuff

* Address grumbles
This commit is contained in:
Amaury Martiny
2019-01-09 10:59:56 +01:00
committed by Jaco Greeff
parent 22123f9491
commit f6c93e48b7
17 changed files with 589 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
// Copyright 2017-2019 @polkadot/ui-react-rx authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
export * from './sessionProgress';
@@ -0,0 +1,26 @@
// Copyright 2017-2019 @polkadot/ui-react-rx 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 BN from 'bn.js';
import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import ApiRx from '@polkadot/api/rx';
import { BlockNumber } from '@polkadot/types/index';
import { bestNumber } from '../chain';
export function sessionProgress (api: ApiRx) {
return (): Observable<BN> =>
combineLatest([
bestNumber(api)(),
api.query.session.sessionLength(),
api.query.session.lastLengthChange()
]).pipe(map(
([bestNumber, sessionLength, lastLengthChange]) =>
(bestNumber as BlockNumber || new BN(0))
.sub(lastLengthChange as BlockNumber || new BN(0))
.add(sessionLength as BlockNumber || new BN(1))
.mod(sessionLength as BlockNumber || new BN(1))
));
}