mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-11-24 14:49:57 +00:00
- dev ^0.86.4 at the root and in packages/apps; directives renamed by pezkuwi-dev-migrate-eslint10. - eslint --fix with the 0.86.4 config; one fix broke syntax (typescript-eslint prefer-optional-chain turned `(isStarted && onStart) && onStart()` into `(isStarted && onStart?.();` in TxButton) and is corrected by hand. - The remaining findings fixed rather than disabled: optional chains (each suggestion reviewed), `cause` on rethrown errors, `if` instead of `a && promise` in effects, parallel instead of sequential awaits in Promise.all, Error rejections, no `delete` on arrays (the storage query cache is a Map; an upload's file list no longer keeps a hole), no `[object Object]` stringification (TFunction's second argument is text or options), dead code removed (referenda's never-shown expand button, react-query's unused CoreDescriptor).
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/apps-routing authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiPromise } from '@pezkuwi/api';
|
|
import type { PezspStakingExposure } from '@pezkuwi/types/lookup';
|
|
import type { Route, TFunction } from './types.js';
|
|
|
|
import Component from '@pezkuwi/app-staking2';
|
|
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 {
|
|
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;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
export default function create (t: TFunction): Route {
|
|
return {
|
|
Component,
|
|
display: {
|
|
isHidden: true,
|
|
needsApi: [
|
|
'query.session.validators',
|
|
'query.staking.erasStakers',
|
|
'tx.staking.bond'
|
|
],
|
|
needsApiCheck
|
|
},
|
|
group: 'network',
|
|
icon: 'certificate',
|
|
name: 'test-staking',
|
|
text: t('nav.staking', 'Staking', { ns: 'apps-routing' })
|
|
};
|
|
}
|