Add .keys on storage entries (#2032)
* Add .keys on storage entries * Pass isOptional to storage type unwrap * Linked maps TS types
This commit is contained in:
@@ -13,12 +13,7 @@ import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
interface Mapped {
|
||||
nominators: DeriveEraNominatorExposure;
|
||||
validators: DeriveEraValidatorExposure;
|
||||
}
|
||||
|
||||
function mapStakers (stakers: [StorageKey, Exposure][]): Mapped {
|
||||
function mapStakers (era: EraIndex, stakers: [StorageKey, Exposure][]): DeriveEraExposure {
|
||||
const nominators: DeriveEraNominatorExposure = {};
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
|
||||
@@ -35,7 +30,7 @@ function mapStakers (stakers: [StorageKey, Exposure][]): Mapped {
|
||||
});
|
||||
});
|
||||
|
||||
return { nominators, validators };
|
||||
return { era, nominators, validators };
|
||||
}
|
||||
|
||||
export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraExposure[]> {
|
||||
@@ -56,10 +51,9 @@ export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean | BN |
|
||||
])
|
||||
),
|
||||
map(([eras, erasStakers]): DeriveEraExposure[] =>
|
||||
eras.map((era, index): DeriveEraExposure => ({
|
||||
era,
|
||||
...mapStakers(erasStakers[index])
|
||||
}))
|
||||
eras.map((era, index): DeriveEraExposure =>
|
||||
mapStakers(era, erasStakers[index])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Exposure } from '@polkadot/types/interfaces';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DeriveStakingValidators } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
@@ -16,11 +16,11 @@ function queryNextStakers (api: ApiInterfaceRx): Observable<AccountId[]> {
|
||||
// only populate for next era in the last session, so track both here - entries are not
|
||||
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
|
||||
return api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }): Observable<[StorageKey, Exposure][]> =>
|
||||
api.query.staking.erasStakers.entries(activeEra.addn(1)).pipe(take(1))
|
||||
switchMap(({ activeEra }): Observable<StorageKey[]> =>
|
||||
api.query.staking.erasStakers.keys(activeEra.addn(1)).pipe(take(1))
|
||||
),
|
||||
map((entries): AccountId[] =>
|
||||
entries.map(([key]): AccountId => key.args[1] as AccountId)
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user