Disable staking for unknown rewards handling (#10108)

* Disable staking for unknown rewards handling

* claimedRewards

* Adjust

* Remove unused import

* No need for ?. protect
This commit is contained in:
Jaco 2023-12-18 21:06:08 +02:00 committed by GitHub
parent fd3c502890
commit e0c792c030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { PalletStakingExposure } from '@polkadot/types/lookup';
import type { u32, Vec } from '@polkadot/types';
import type { PalletStakingExposure, PalletStakingStakingLedger } from '@polkadot/types/lookup';
import type { Route, TFunction } from './types.js';
import Component from '@polkadot/app-staking';
@ -44,6 +45,19 @@ function needsApiCheck (api: ApiPromise): boolean {
return false;
}
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');
} catch {
console.warn('No known claimedRewards inside staking ledger, disabling staking route');
return false;
}
return true;
}