Re-add derive memo (def. has an impact) (#1539)
This commit is contained in:
@@ -13,7 +13,7 @@ import { createType } from '@polkadot/types';
|
||||
|
||||
import { idToIndex } from './idToIndex';
|
||||
import { indexToId } from './indexToId';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
interface Calls {
|
||||
idToIndexCall (accountId: string | AccountId): Observable<AccountIndex | undefined>;
|
||||
@@ -60,12 +60,12 @@ function retrieve (address: Address | AccountId | AccountIndex | string | null |
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> {
|
||||
export const idAndIndex = memo((api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> => {
|
||||
const calls = {
|
||||
idToIndexCall: idToIndex(api),
|
||||
indexToIdCall: indexToId(api)
|
||||
};
|
||||
|
||||
return (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
||||
retrieve(address, calls).pipe(drr());
|
||||
}
|
||||
return memo((address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
|
||||
retrieve(address, calls).pipe(drr()));
|
||||
}, true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { indexes, AccountIndexes } from './indexes';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name idToIndex
|
||||
@@ -25,15 +25,15 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function idToIndex (api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
||||
export const idToIndex = memo((api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> => {
|
||||
const indexesCall = indexes(api);
|
||||
|
||||
return (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
indexesCall().pipe(
|
||||
startWith({}),
|
||||
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
||||
(indexes || {})[accountId.toString()]
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
|
||||
import { createType, ClassOf, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name indexToId
|
||||
@@ -25,10 +25,10 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
export const indexToId = memo((api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> => {
|
||||
const querySection = api.query.indices || api.query.balances;
|
||||
|
||||
return (_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
|
||||
return memo((_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
|
||||
const accountIndex = _accountIndex instanceof ClassOf('AccountIndex')
|
||||
? _accountIndex
|
||||
: createType('AccountIndex', _accountIndex);
|
||||
@@ -40,5 +40,5 @@ export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | s
|
||||
),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { map, switchMap } from 'rxjs/operators';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export type AccountIndexes = Record<string, AccountIndex>;
|
||||
|
||||
@@ -31,8 +31,8 @@ const enumsetSize = ENUMSET_SIZE.toNumber();
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
||||
return (): Observable<AccountIndexes> =>
|
||||
export const indexes = memo((api: ApiInterfaceRx): () => Observable<AccountIndexes> => {
|
||||
return memo((): Observable<AccountIndexes> =>
|
||||
api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
||||
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
||||
// a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the
|
||||
@@ -54,5 +54,5 @@ export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes>
|
||||
return result;
|
||||
}, {} as AccountIndexes)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -12,7 +12,7 @@ import { map, switchMap } from 'rxjs/operators';
|
||||
import { Bytes, Option, u32 } from '@polkadot/types';
|
||||
import { u8aToString } from '@polkadot/util';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { idAndIndex } from './idAndIndex';
|
||||
|
||||
function retrieveNick (api: ApiInterfaceRx): (accountId?: AccountId) => Observable<Option<[Bytes, Balance] & Codec> | undefined> {
|
||||
@@ -26,11 +26,11 @@ function retrieveNick (api: ApiInterfaceRx): (accountId?: AccountId) => Observab
|
||||
* @name info
|
||||
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
||||
*/
|
||||
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
||||
export const info = memo((api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> => {
|
||||
const idAndIndexCall = idAndIndex(api);
|
||||
const nickCall = retrieveNick(api);
|
||||
|
||||
return (address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
idAndIndexCall(address).pipe(
|
||||
switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, Option<[Bytes, Balance] & Codec>?]> =>
|
||||
combineLatest([
|
||||
@@ -46,5 +46,5 @@ export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId
|
||||
: undefined
|
||||
})),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -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,12 +77,12 @@ 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 infoCall(address).pipe(
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> =>
|
||||
infoCall(address).pipe(
|
||||
switchMap(({ accountId }): Observable<Result> =>
|
||||
(accountId
|
||||
? combineLatest([
|
||||
@@ -101,6 +101,5 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId |
|
||||
),
|
||||
map(calcBalances),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { DerivedFees } from '../types';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
type Result = [Balance, Balance, Balance, Balance, Balance];
|
||||
|
||||
@@ -51,13 +51,13 @@ function queryV1 (api: ApiInterfaceRx): Observable<Result> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
|
||||
export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedFees> => {
|
||||
const query = api.consts.balances
|
||||
? queryV2
|
||||
: queryV1;
|
||||
|
||||
return (): Observable<DerivedFees> => {
|
||||
return query(api).pipe(
|
||||
return memo((): Observable<DerivedFees> =>
|
||||
query(api).pipe(
|
||||
map(([creationFee, existentialDeposit, transferFee, transactionBaseFee, transactionByteFee]): DerivedFees => ({
|
||||
creationFee,
|
||||
existentialDeposit,
|
||||
@@ -66,6 +66,5 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
|
||||
transferFee
|
||||
})),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -8,17 +8,16 @@ import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { DerivedBalances } from '../types';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { all } from './all';
|
||||
|
||||
export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DerivedBalances[]> {
|
||||
return (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> => {
|
||||
return (
|
||||
export const votingBalances = memo((api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DerivedBalances[]> => {
|
||||
return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> =>
|
||||
(
|
||||
!addresses || !addresses.length
|
||||
? of([] as DerivedBalances[])
|
||||
: combineLatest(addresses.map(all(api)))
|
||||
).pipe(
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,14 +11,14 @@ import { Vec } from '@polkadot/types';
|
||||
|
||||
import { info } from '../accounts/info';
|
||||
import { DerivedBalances } from '../types';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { votingBalances } from './votingBalances';
|
||||
|
||||
export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> {
|
||||
export const votingBalancesNominatorsFor = memo((api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return (address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> => {
|
||||
return infoCall(address).pipe(
|
||||
return memo((address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> =>
|
||||
infoCall(address).pipe(
|
||||
switchMap(({ accountId }): Observable<AccountId[]> =>
|
||||
accountId
|
||||
? (api.query.staking.nominatorsFor<Vec<AccountId>>(accountId))
|
||||
@@ -26,6 +26,5 @@ export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: Acc
|
||||
),
|
||||
switchMap(votingBalances(api)),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name bestNumber
|
||||
@@ -22,10 +22,10 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return (): Observable<BlockNumber> =>
|
||||
export const bestNumber = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeNewHeads().pipe(
|
||||
map((header): BlockNumber => header.number.unwrap()),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name bestNumberFinalized
|
||||
@@ -23,10 +23,10 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return (): Observable<BlockNumber> =>
|
||||
export const bestNumberFinalized = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
||||
map((header): BlockNumber => header.number.unwrap()),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { bestNumber } from './bestNumber';
|
||||
import { bestNumberFinalized } from './bestNumberFinalized';
|
||||
|
||||
@@ -26,11 +26,11 @@ import { bestNumberFinalized } from './bestNumberFinalized';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
export const bestNumberLag = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const bestNumberCall = bestNumber(api);
|
||||
const bestNumberFinalizedCall = bestNumberFinalized(api);
|
||||
|
||||
return (): Observable<BlockNumber> =>
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
combineLatest([
|
||||
bestNumberCall(),
|
||||
bestNumberFinalizedCall()
|
||||
@@ -39,5 +39,5 @@ export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumbe
|
||||
createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { catchError, map } from 'rxjs/operators';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name bestNumberFinalized
|
||||
@@ -27,8 +27,8 @@ import { drr } from '../util';
|
||||
* console.log(`block #${number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
return (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
export const getHeader = memo((api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> => {
|
||||
return memo((hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(hash),
|
||||
api.query.session.validators.at(hash) as Observable<Vec<AccountId>>
|
||||
@@ -43,5 +43,5 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
|
||||
of()
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { map } from 'rxjs/operators';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name subscribeNewHeads
|
||||
@@ -25,8 +25,8 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable<HeaderExtended> {
|
||||
return (): Observable<HeaderExtended> =>
|
||||
export const subscribeNewHeads = memo((api: ApiInterfaceRx): () => Observable<HeaderExtended> => {
|
||||
return memo((): Observable<HeaderExtended> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.subscribeNewHeads(),
|
||||
api.query.session.validators<Vec<AccountId>>()
|
||||
@@ -35,5 +35,5 @@ export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable<Header
|
||||
new HeaderExtended(header, validators)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN];
|
||||
|
||||
@@ -103,8 +103,8 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function fees (api: ApiInterfaceRx): () => Observable<DerivedContractFees> {
|
||||
return (): Observable<DerivedContractFees> => {
|
||||
export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedContractFees> => {
|
||||
return memo((): Observable<DerivedContractFees> => {
|
||||
if (api.query.contract && !api.query.contract.rentByteFee) {
|
||||
return queryV1(api);
|
||||
}
|
||||
@@ -122,5 +122,5 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedContractFees
|
||||
),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
});
|
||||
}, true);
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Option } from '@polkadot/types';
|
||||
import { isNull } from '@polkadot/util';
|
||||
|
||||
import { ReferendumInfoExtended } from '../type';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export function constructInfo (index: BN | number, optionInfo?: Option<ReferendumInfo>): Option<ReferendumInfoExtended> {
|
||||
const info = optionInfo
|
||||
@@ -27,14 +27,13 @@ export function constructInfo (index: BN | number, optionInfo?: Option<Referendu
|
||||
);
|
||||
}
|
||||
|
||||
export function referendumInfo (api: ApiInterfaceRx): (index: BN | number) => Observable<Option<ReferendumInfoExtended>> {
|
||||
return (index: BN | number): Observable<Option<ReferendumInfoExtended>> => {
|
||||
return (api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index))
|
||||
export const referendumInfo = memo((api: ApiInterfaceRx): (index: BN | number) => Observable<Option<ReferendumInfoExtended>> => {
|
||||
return memo((index: BN | number): Observable<Option<ReferendumInfoExtended>> =>
|
||||
(api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index))
|
||||
.pipe(
|
||||
map((optionInfo): Option<ReferendumInfoExtended> =>
|
||||
constructInfo(index, optionInfo)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,12 +11,12 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { ReferendumInfoExtended } from '../type';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { constructInfo } from './referendumInfo';
|
||||
|
||||
export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<Option<ReferendumInfoExtended>[]> {
|
||||
return (ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> => {
|
||||
return (
|
||||
export const referendumInfos = memo((api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<Option<ReferendumInfoExtended>[]> => {
|
||||
return memo((ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
(
|
||||
!ids || !ids.length
|
||||
? of([] as Option<ReferendumInfo>[])
|
||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vec<Option<ReferendumInfo>>>
|
||||
@@ -27,6 +27,5 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,15 +11,15 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec, createType } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances, DerivedReferendumVote } from '../types';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { votes } from './votes';
|
||||
import { votingBalances } from '../balances/votingBalances';
|
||||
|
||||
export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> {
|
||||
export const referendumVotesFor = memo((api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> => {
|
||||
const votesCall = votes(api);
|
||||
const votingBalancesCall = votingBalances(api);
|
||||
|
||||
return (referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
return memo((referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
combineLatest([
|
||||
@@ -36,5 +36,5 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
|
||||
} as unknown as DerivedReferendumVote))
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,13 +11,13 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { ReferendumInfoExtended } from '../type';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { referendumInfos } from './referendumInfos';
|
||||
|
||||
export function referendums (api: ApiInterfaceRx): () => Observable<Option<ReferendumInfoExtended>[]> {
|
||||
export const referendums = memo((api: ApiInterfaceRx): () => Observable<Option<ReferendumInfoExtended>[]> => {
|
||||
const referendumInfosCall = referendumInfos(api);
|
||||
|
||||
return (): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
return memo((): Observable<Option<ReferendumInfoExtended>[]> =>
|
||||
api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
||||
api.query.democracy.nextTally,
|
||||
api.query.democracy.referendumCount
|
||||
@@ -32,5 +32,5 @@ export function referendums (api: ApiInterfaceRx): () => Observable<Option<Refer
|
||||
: of([])
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -7,20 +7,18 @@ import { AccountId, Vote } from '@polkadot/types/interfaces';
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> {
|
||||
return (referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> => {
|
||||
return ((
|
||||
export const votes = memo((api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> => {
|
||||
return memo((referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> =>
|
||||
(
|
||||
!accountIds || !accountIds.length
|
||||
? of([])
|
||||
: api.query.democracy.voteOf.multi(
|
||||
? of([] as Vote[])
|
||||
: api.query.democracy.voteOf.multi<Vote>(
|
||||
accountIds.map((accountId): [BN, AccountId] =>
|
||||
[referendumId, accountId]
|
||||
)
|
||||
)
|
||||
) as Observable<Vec<Vote>>).pipe(drr());
|
||||
};
|
||||
}
|
||||
).pipe(drr()));
|
||||
}, true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Observable } from 'rxjs';
|
||||
import { Vec } from '@polkadot/types';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name approvalsOf
|
||||
@@ -23,8 +23,8 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> {
|
||||
return (who: AccountId | string): Observable<boolean[][]> =>
|
||||
export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> => {
|
||||
return memo((who: AccountId | string): Observable<boolean[][]> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi(
|
||||
@@ -39,5 +39,5 @@ export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observabl
|
||||
)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name approvalsOfAt
|
||||
@@ -25,10 +25,10 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
|
||||
return (who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
export const approvalsOfAt = memo((api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> => {
|
||||
return memo((who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
||||
api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe(
|
||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType, Vec, u32 } from '@polkadot/types';
|
||||
|
||||
import { DerivedElectionsInfo } from '../types';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex];
|
||||
type ResultElections = [Vec<AccountId>, ResultElectionsInner];
|
||||
@@ -42,7 +42,7 @@ function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo>
|
||||
api.query.elections.voteCount,
|
||||
api.query.elections.voterCount
|
||||
])
|
||||
]).pipe(map(deriveElections), drr());
|
||||
]).pipe(map(deriveElections));
|
||||
}
|
||||
|
||||
function derivePhragmen (candidates: Vec<AccountId>, members: Vec<[AccountId, Balance] & Codec>, candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
|
||||
@@ -71,8 +71,7 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||
api.consts.electionsPhragmen.desiredMembers as u32,
|
||||
api.consts.electionsPhragmen.termDuration as BlockNumber,
|
||||
api.consts.electionsPhragmen.votingBond as Balance
|
||||
)),
|
||||
drr()
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,9 +88,11 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
|
||||
return (): Observable<DerivedElectionsInfo> =>
|
||||
api.query.electionsPhragmen
|
||||
? queryPhragmen(api)
|
||||
: queryElections(api);
|
||||
}
|
||||
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> => {
|
||||
const query = api.query.electionsPhragmen
|
||||
? queryPhragmen
|
||||
: queryElections;
|
||||
|
||||
return memo((): Observable<DerivedElectionsInfo> =>
|
||||
query(api).pipe(drr()));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import BN from 'bn.js';
|
||||
import { of, combineLatest, Observable } from 'rxjs';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @name voterPositions
|
||||
@@ -26,8 +26,8 @@ import { drr } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
|
||||
return (): Observable<DerivedVoterPositions> =>
|
||||
export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> => {
|
||||
return memo((): Observable<DerivedVoterPositions> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
@@ -54,5 +54,5 @@ export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVo
|
||||
}, {});
|
||||
}),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { voterPositions } from './voterPositions';
|
||||
|
||||
/**
|
||||
@@ -25,10 +25,10 @@ import { voterPositions } from './voterPositions';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
export const voters = memo((api: ApiInterfaceRx): () => Observable<Vec<AccountId>> => {
|
||||
const voterPositionsCall = voterPositions(api);
|
||||
|
||||
return (): Observable<Vec<AccountId>> =>
|
||||
return memo((): Observable<Vec<AccountId>> =>
|
||||
voterPositionsCall().pipe(
|
||||
map((voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
createType(
|
||||
@@ -39,5 +39,5 @@ export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
)
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,16 +11,16 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Bytes, Option, u32 } from '@polkadot/types';
|
||||
|
||||
import { overview as stakingOverview } from '../staking';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session
|
||||
*/
|
||||
export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> {
|
||||
export const receivedHeartbeats = memo((api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> => {
|
||||
const stakingOverviewvCall = stakingOverview(api);
|
||||
|
||||
return (): Observable<DerivedHeartbeats> => {
|
||||
return api.query.imOnline && api.query.imOnline.receivedHeartbeats && api.query.imOnline.authoredBlocks
|
||||
return memo((): Observable<DerivedHeartbeats> =>
|
||||
api.query.imOnline && api.query.imOnline.receivedHeartbeats && api.query.imOnline.authoredBlocks
|
||||
? stakingOverviewvCall().pipe(
|
||||
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
||||
combineLatest([
|
||||
@@ -41,6 +41,5 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
),
|
||||
drr()
|
||||
)
|
||||
: of({});
|
||||
};
|
||||
}
|
||||
: of({}));
|
||||
}, true);
|
||||
|
||||
@@ -8,15 +8,15 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { info } from './info';
|
||||
|
||||
export function eraLength (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
export const eraLength = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return (): Observable<BlockNumber> =>
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ eraLength }): BlockNumber => eraLength),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -8,15 +8,15 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { info } from './info';
|
||||
|
||||
export function eraProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
export const eraProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return (): Observable<BlockNumber> =>
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ eraProgress }): BlockNumber => eraProgress),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,10 +10,10 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { u32 } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
export function indexes (api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
|
||||
return (): Observable<DeriveSessionIndexes> =>
|
||||
export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> => {
|
||||
return memo((): Observable<DeriveSessionIndexes> =>
|
||||
api.queryMulti<[SessionIndex, EraIndex, u32]>([
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.currentEra,
|
||||
@@ -23,5 +23,5 @@ export function indexes (api: ApiInterfaceRx): () => Observable<DeriveSessionInd
|
||||
currentIndex, currentEra, validatorCount
|
||||
})),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, u64, createType } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { bestNumber } from '../chain';
|
||||
import { indexes } from './indexes';
|
||||
|
||||
@@ -127,7 +127,7 @@ function infoLatestBabe (api: ApiInterfaceRx, { indexesCall }: Calls): Observabl
|
||||
/**
|
||||
* @description Retrieves all the session and era info and calculates specific values on it as the length of the session and eras
|
||||
*/
|
||||
export function info (api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> {
|
||||
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> => {
|
||||
const calls = {
|
||||
bestNumberCall: bestNumber(api),
|
||||
indexesCall: indexes(api)
|
||||
@@ -138,6 +138,6 @@ export function info (api: ApiInterfaceRx): () => Observable<DerivedSessionInfo>
|
||||
: infoLatestAura // 2.x with Aura (not all info there)
|
||||
: infoV1;
|
||||
|
||||
return (): Observable<DerivedSessionInfo> =>
|
||||
query(api, calls).pipe(drr());
|
||||
}
|
||||
return memo((): Observable<DerivedSessionInfo> =>
|
||||
query(api, calls).pipe(drr()));
|
||||
}, true);
|
||||
|
||||
@@ -8,15 +8,15 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { info } from './info';
|
||||
|
||||
export function sessionProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
export const sessionProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => {
|
||||
const infoCall = info(api);
|
||||
|
||||
return (): Observable<BlockNumber> =>
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
infoCall().pipe(
|
||||
map(({ sessionProgress }): BlockNumber => sessionProgress),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,13 +10,13 @@ import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
/**
|
||||
* @description From the list of stash accounts, retrieve the list of controllers
|
||||
*/
|
||||
export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> {
|
||||
return (): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
export const controllers = memo((api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> => {
|
||||
return memo((): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
api.query.staking.validators<[AccountId[]] & Codec>().pipe(
|
||||
switchMap(([stashIds]): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
combineLatest([
|
||||
@@ -28,5 +28,5 @@ export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[]
|
||||
])
|
||||
),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -18,7 +18,7 @@ import { isUndefined } from '@polkadot/util';
|
||||
import { bestNumber } from '../chain/bestNumber';
|
||||
import { eraLength } from '../session/eraLength';
|
||||
import { recentlyOffline } from './recentlyOffline';
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
interface Calls {
|
||||
bestNumberCall (): Observable<BlockNumber>;
|
||||
@@ -203,8 +203,7 @@ function retrieveV1 (api: ApiInterfaceRx, calls: Calls, controllerId: AccountId)
|
||||
stakingLedger.isSome
|
||||
? retrieveInfoV1(api, calls, controllerId, stakingLedger.unwrap().stash, controllerId)
|
||||
: of({ accountId: controllerId, nextSessionIds: [], sessionIds: [] })
|
||||
),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -216,26 +215,23 @@ function retrieveV2 (api: ApiInterfaceRx, calls: Calls, stashId: AccountId): Obs
|
||||
controllerId.isSome
|
||||
? retrieveInfoV2(api, calls, stashId, stashId, controllerId.unwrap())
|
||||
: of({ accountId: stashId, nextSessionIds: [], sessionIds: [] })
|
||||
),
|
||||
drr()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||
*/
|
||||
export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
|
||||
export const info = memo((api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> => {
|
||||
const calls = {
|
||||
eraLengthCall: eraLength(api),
|
||||
bestNumberCall: bestNumber(api),
|
||||
recentlyOfflineCall: recentlyOffline(api)
|
||||
};
|
||||
const query = api.consts.session
|
||||
? retrieveV2
|
||||
: retrieveV1;
|
||||
|
||||
return (_accountId: Uint8Array | string): Observable<DerivedStaking> => {
|
||||
const accountId = createType('AccountId', _accountId);
|
||||
|
||||
return api.consts.session
|
||||
? retrieveV2(api, calls, accountId)
|
||||
: retrieveV1(api, calls, accountId);
|
||||
};
|
||||
}
|
||||
return memo((accountId: Uint8Array | string): Observable<DerivedStaking> =>
|
||||
query(api, calls, createType('AccountId', accountId)).pipe(drr()));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
// NOTE Unused ATM, preparing for V2-only
|
||||
|
||||
@@ -52,14 +52,14 @@ function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<Result
|
||||
]);
|
||||
}
|
||||
|
||||
export function infoStash (api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> {
|
||||
export const infoStash = memo((api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> => {
|
||||
const query = api.consts.session
|
||||
? retrieveV2
|
||||
: retrieveV1;
|
||||
|
||||
return (stashId: AccountId): Observable<DerivedStakingStash> =>
|
||||
return memo((stashId: AccountId): Observable<DerivedStakingStash> =>
|
||||
query(api, stashId).pipe(
|
||||
map((result): DerivedStakingStash => parse(stashId, result)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -10,16 +10,16 @@ import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { createType, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { indexes as sessionIndexes } from '../session';
|
||||
|
||||
/**
|
||||
* @description Retrieve the staking overview, including elected and points earned
|
||||
*/
|
||||
export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> {
|
||||
export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> => {
|
||||
const sessionIndexesCall = sessionIndexes(api);
|
||||
|
||||
return (): Observable<DerivedStakingOverview> =>
|
||||
return memo((): Observable<DerivedStakingOverview> =>
|
||||
combineLatest([
|
||||
sessionIndexesCall(),
|
||||
api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([
|
||||
@@ -40,5 +40,5 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
|
||||
})),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DerivedRecentlyOffline } from '../types';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
|
||||
type OfflineResult = [AccountId, BlockNumber, BN][] & Codec;
|
||||
|
||||
@@ -35,8 +35,8 @@ function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline
|
||||
/**
|
||||
* @description Retrieve a keyed record of accounts recently reported to be offline
|
||||
*/
|
||||
export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
|
||||
return (): Observable<DerivedRecentlyOffline> =>
|
||||
export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> => {
|
||||
return memo((): Observable<DerivedRecentlyOffline> =>
|
||||
(
|
||||
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
|
||||
// replacement as actually use and implement it
|
||||
@@ -46,5 +46,5 @@ export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedR
|
||||
).pipe(
|
||||
map(expandDerived),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
@@ -8,18 +8,18 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { drr } from '../util';
|
||||
import { drr, memo } from '../util';
|
||||
import { overview } from './overview';
|
||||
|
||||
/**
|
||||
* @description Retrieve latest list of validators
|
||||
*/
|
||||
export function validators (api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
||||
export const validators = memo((api: ApiInterfaceRx): () => Observable<AccountId[]> => {
|
||||
const overviewCall = overview(api);
|
||||
|
||||
return (): Observable<AccountId[]> =>
|
||||
return memo((): Observable<AccountId[]> =>
|
||||
overviewCall().pipe(
|
||||
map(({ validators }): AccountId[] => validators),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
));
|
||||
}, true);
|
||||
|
||||
Reference in New Issue
Block a user