Staking overview derive (#1537)

* Staking overview derive

* Expand derives

* Extract currentIndex/currentEra

* WIP

* Controllers opt

* Add memo

* Memomize the whole lot

* Doc building fixes

* Doc fixes #2
This commit is contained in:
Jaco Greeff
2019-11-02 23:10:10 +01:00
committed by GitHub
parent 1d92b7bead
commit 7cc961f789
44 changed files with 493 additions and 307 deletions
+5 -5
View File
@@ -14,7 +14,7 @@ import { bnMax } from '@polkadot/util';
import { info } from '../accounts/info';
import { bestNumber } from '../chain/bestNumber';
import { DerivedBalances } from '../types';
import { drr } from '../util';
import { drr, memo } from '../util';
type ResultBalance = [Balance, Balance, BalanceLock[], Option<VestingSchedule>];
type Result = [AccountId, BlockNumber, ResultBalance, Index];
@@ -77,11 +77,11 @@ function queryBalances (api: ApiInterfaceRx, accountId: AccountId): Observable<R
* });
* ```
*/
export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalances> {
export const all = memo((api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalances> => {
const bestNumberCall = bestNumber(api);
const infoCall = info(api);
return (address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> => {
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> => {
return infoCall(address).pipe(
switchMap(({ accountId }): Observable<Result> =>
(accountId
@@ -102,5 +102,5 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId |
map(calcBalances),
drr()
);
};
}
});
}, true);