Split track defs (slightly more scalable) (#8474)

This commit is contained in:
Jaco 2022-12-05 08:08:46 +02:00 committed by GitHub
parent 3e9acf18c7
commit 293dfe431e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 37 deletions

View File

@ -0,0 +1,32 @@
// Copyright 2017-2022 @polkadot/app-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { TrackInfo } from './types';
import { KUSAMA_GENESIS } from '../../constants';
import { kusama } from './kusama';
const KNOWN_GENE_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
[KUSAMA_GENESIS]: kusama
};
const KNOWN_SPEC_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
kusama,
// for kitchensink, we just use the root
node: {
referenda: [
{
id: 0,
name: 'root',
origin: { system: 'Root' }
}
]
}
};
export function getGovernanceTracks (api: ApiPromise, specName: string, palletReferenda: string): TrackInfo[] | undefined {
const lookup = KNOWN_GENE_TRACKS[api.genesisHash.toHex()] || KNOWN_SPEC_TRACKS[specName];
return lookup && lookup[palletReferenda];
}

View File

@ -1,20 +1,9 @@
// Copyright 2017-2022 @polkadot/app-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { TrackInfo } from './types';
import { KUSAMA_GENESIS } from '../constants';
type Origin = { system: string } | { Origins: string };
interface TrackInfo {
id: number;
name: string;
origin: Origin | Origin[];
text?: string;
}
const KUSAMA: Record<string, TrackInfo[]> = {
export const kusama: Record<string, TrackInfo[]> = {
fellowshipReferenda: [
{
@ -179,27 +168,3 @@ const KUSAMA: Record<string, TrackInfo[]> = {
}
]
};
const KNOWN_GENE_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
[KUSAMA_GENESIS]: KUSAMA
};
const KNOWN_SPEC_TRACKS: Record<string, Record<string, TrackInfo[]>> = {
kusama: KUSAMA,
// for kitchensink, we just use the root
node: {
referenda: [
{
id: 0,
name: 'root',
origin: { system: 'Root' }
}
]
}
};
export function getGovernanceTracks (api: ApiPromise, specName: string, palletReferenda: string): TrackInfo[] | undefined {
const lookup = KNOWN_GENE_TRACKS[api.genesisHash.toHex()] || KNOWN_SPEC_TRACKS[specName];
return lookup && lookup[palletReferenda];
}

View File

@ -0,0 +1,11 @@
// Copyright 2017-2022 @polkadot/app-config authors & contributors
// SPDX-License-Identifier: Apache-2.0
export type Origin = { system: string } | { Origins: string };
export interface TrackInfo {
id: number;
name: string;
origin: Origin | Origin[];
text?: string;
}