From e0c792c0309fb84a981990a77cd0538e3a374bb7 Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 18 Dec 2023 21:06:08 +0200 Subject: [PATCH] Disable staking for unknown rewards handling (#10108) * Disable staking for unknown rewards handling * claimedRewards * Adjust * Remove unused import * No need for ?. protect --- packages/apps-routing/src/staking.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/apps-routing/src/staking.ts b/packages/apps-routing/src/staking.ts index 184a574c14..b4a08e47ab 100644 --- a/packages/apps-routing/src/staking.ts +++ b/packages/apps-routing/src/staking.ts @@ -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( + unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type), + { claimedRewards: [1, 2, 3] } + ); + + assert((v as unknown as { claimedRewards: Vec }).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; }