mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-11-01 22:21:07 +00:00
- Update @pezkuwi/extension-inject to ^0.62.13 with proper /types exports - Update @pezkuwi/extension-dapp to ^0.62.13 - Update @pezkuwi/extension-compat-metamask to ^0.62.13 - Fix IconTheme type to include 'bizinikiwi' and 'pezkuwi' themes - Fix endpoint array issues (getTeleports -> direct array references) - Add type assertions for external package compatibility (acala, moonbeam, parallel) - Fix subspace.ts dynamic class typing - Fix conviction type in page-referenda - Update Pallet type names to Pezpallet prefix across codebase - Define InjectedExtension types locally for module resolution - Add styled-components DefaultTheme augmentation - Add react-copy-to-clipboard type declaration for React 18 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
95 lines
3.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/apps-routing authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiPromise } from '@pezkuwi/api';
|
|
import type { u32, Vec } from '@pezkuwi/types';
|
|
import type { PezpalletStakingStakingLedger, PezspStakingExposure } from '@pezkuwi/types/lookup';
|
|
import type { Route, TFunction } from './types.js';
|
|
|
|
import Component from '@pezkuwi/app-staking-legacy';
|
|
import { ZERO_ACCOUNT } from '@pezkuwi/react-hooks/useWeight';
|
|
import { unwrapStorageType } from '@pezkuwi/types/util';
|
|
import { assert, BN_ONE } from '@pezkuwi/util';
|
|
|
|
function needsApiCheck (api: ApiPromise): boolean {
|
|
if (typeof api.query.staking.erasStakersOverview === 'function') {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
// we need a known Exposure type
|
|
const { others: [{ value, who }], own, total } = api.registry.createType<PezspStakingExposure>(
|
|
unwrapStorageType(api.registry, api.query.staking.erasStakers.creator.meta.type),
|
|
{ others: [{ value: BN_ONE, who: ZERO_ACCOUNT }], own: BN_ONE, total: BN_ONE }
|
|
);
|
|
|
|
assert(total && own && value && who && total.eq(BN_ONE) && own.eq(BN_ONE) && value.eq(BN_ONE), 'Needs a known Exposure type');
|
|
} catch {
|
|
console.warn('Unable to create known-shape Exposure type, disabling staking route');
|
|
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
// we need to be able to bond
|
|
if (api.tx.staking.bond.meta.args.length === 3) {
|
|
// previous generation, controller account is required
|
|
// @ts-expect-error Previous generation
|
|
api.tx.staking.bond(ZERO_ACCOUNT, BN_ONE, { Account: ZERO_ACCOUNT });
|
|
} else if (api.tx.staking.bond.meta.args.length === 2) {
|
|
// current, no controller account
|
|
// @ts-expect-error Runtime type format
|
|
api.tx.staking.bond(BN_ONE, { Account: ZERO_ACCOUNT });
|
|
} else {
|
|
// unknown
|
|
return false;
|
|
}
|
|
} catch {
|
|
console.warn('Unable to create staking bond transaction, disabling staking route');
|
|
|
|
return false;
|
|
}
|
|
|
|
// For compatibility - `api.query.staking.ledger` returns `legacyClaimedRewards` instead of `claimedRewards` as of v1.4
|
|
try {
|
|
const v = api.registry.createType<PezpalletStakingStakingLedger>(
|
|
unwrapStorageType(api.registry, api.query.staking.ledger.creator.meta.type),
|
|
{ claimedRewards: [1, 2, 3] }
|
|
);
|
|
|
|
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<PezpalletStakingStakingLedger>(
|
|
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 legacyClaimedRewards or claimedRewards inside staking ledger, disabling staking route');
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
export default function create (t: TFunction): Route {
|
|
return {
|
|
Component,
|
|
display: {
|
|
needsApi: [
|
|
'query.staking.erasStakers',
|
|
'tx.staking.bond'
|
|
],
|
|
needsApiCheck
|
|
},
|
|
group: 'network',
|
|
icon: 'certificate',
|
|
name: 'legacy-staking',
|
|
text: t('nav.staking', 'Staking', { ns: 'apps-routing' })
|
|
};
|
|
}
|