Fix apps-routing for staking (Westend) (#10394)

* Fix apps-routing for staking (Westend)

* comment
This commit is contained in:
Tarik Gul 2024-03-25 13:01:16 -04:00 committed by GitHub
parent b79463b576
commit 0cf860f5d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,15 +45,25 @@ function needsApiCheck (api: ApiPromise): boolean {
return false;
}
// For compatibility - `api.query.staking.ledger` returns `legacyClaimedRewards` instead of `claimedRewards` as of v1.4
try {
const v = api.registry.createType<PalletStakingStakingLedger>(
unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type),
{ claimedRewards: [1, 2, 3] }
);
assert((v as unknown as { claimedRewards: Vec<u32> }).claimedRewards.eq([1, 2, 3]), 'Needs a claimedRewards array');
if ((v as unknown as { claimedRewards: Vec<u32> }).claimedRewards) {
assert((v as unknown as { claimedRewards: Vec<u32> }).claimedRewards.eq([1, 2, 3]), 'Needs a claimedRewards array');
} else {
const v = api.registry.createType<PalletStakingStakingLedger>(
unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type),
{ legacyClaimedRewards: [1, 2, 3] }
);
assert(v.legacyClaimedRewards.eq([1, 2, 3]), 'Needs a legacyClaimedRewards array');
}
} catch {
console.warn('No known claimedRewards inside staking ledger, disabling staking route');
console.warn('No known legacyClaimedRewards or claimedRewards inside staking ledger, disabling staking route');
return false;
}