Bump to latest Substrate metadata (#5807)
* Bump to latest substrate metadata * Bump to latest Substrate metadata * Update type-support docs for metadata * Update docs again * fix compat issues * adjust types
This commit is contained in:
@@ -11,7 +11,15 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { firstMemo, memo } from '../util/index.js';
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestination: PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
|
||||
// handle compatibility between generations of structures
|
||||
function rewardDestinationCompat (rewardDestination: PalletStakingRewardDestination | Option<PalletStakingRewardDestination>): PalletStakingRewardDestination | null {
|
||||
// We ensure the type is an Option by checking if isSome is a boolean. When isSome doesn't exist it will always return undefined.
|
||||
return typeof (rewardDestination as Option<PalletStakingRewardDestination>).isSome === 'boolean'
|
||||
? (rewardDestination as Option<PalletStakingRewardDestination>).unwrapOr(null)
|
||||
: (rewardDestination as PalletStakingRewardDestination);
|
||||
}
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<PalletStakingNominations>, rewardDestinationOpts: Option<PalletStakingRewardDestination> | PalletStakingRewardDestination, validatorPrefs: PalletStakingValidatorPrefs, exposure: PalletStakingExposure, stakingLedgerOpt: Option<PalletStakingStakingLedger>): DeriveStakingQuery {
|
||||
return {
|
||||
accountId: stashId,
|
||||
controllerId: controllerIdOpt?.unwrapOr(null) || null,
|
||||
@@ -19,7 +27,7 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> |
|
||||
nominators: nominatorsOpt.isSome
|
||||
? nominatorsOpt.unwrap().targets
|
||||
: [],
|
||||
rewardDestination,
|
||||
rewardDestination: rewardDestinationCompat(rewardDestinationOpts),
|
||||
stakingLedger: stakingLedgerOpt.unwrapOrDefault(),
|
||||
stashId,
|
||||
validatorPrefs
|
||||
@@ -49,9 +57,9 @@ function getLedgers (api: DeriveApi, optIds: (Option<AccountId> | null)[], { wit
|
||||
);
|
||||
}
|
||||
|
||||
function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option<AccountId> | null)[], Option<PalletStakingNominations>[], PalletStakingRewardDestination[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> {
|
||||
function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option<AccountId> | null)[], Option<PalletStakingNominations>[], Option<PalletStakingRewardDestination>[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> {
|
||||
const emptyNoms = api.registry.createType<Option<PalletStakingNominations>>('Option<Nominations>');
|
||||
const emptyRewa = api.registry.createType<PalletStakingRewardDestination>('RewardDestination');
|
||||
const emptyRewa = api.registry.createType<Option<PalletStakingRewardDestination>>('RewardDestination');
|
||||
const emptyExpo = api.registry.createType<PalletStakingExposure>('Exposure');
|
||||
const emptyPrefs = api.registry.createType<PalletStakingValidatorPrefs>('ValidatorPrefs');
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ export interface DeriveStakingStash {
|
||||
controllerId: AccountId | null;
|
||||
exposure: PalletStakingExposure;
|
||||
nominators: AccountId[];
|
||||
rewardDestination: PalletStakingRewardDestination;
|
||||
rewardDestination: PalletStakingRewardDestination | null;
|
||||
stashId: AccountId;
|
||||
validatorPrefs: PalletStakingValidatorPrefs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user