mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-10-20 18:56:22 +00:00
ui-settings: one address-format option per ss58 prefix
The address format list had an entry per network, and Pezkuwi, Zagros and Bizinikiwi all use prefix 42, so it showed three options with the same value; choosing one could not be told apart from the others. prefixOptions keeps one option per prefix and lists every network using it in its text. ui-settings gets the tsconfig.spec.json the other packages with specs have, so the build leaves the spec out.
This commit is contained in:
1 parent
9f4b5ff112
commit
479df8c4f9
5 files changed
+70
-7
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2017-2026 @pezkuwi/ui-settings authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
/// <reference types="@pezkuwi/dev-test/globals.d.ts" />
|
||||||
|
|
||||||
|
import { PREFIXES, prefixOptions } from './ss58.js';
|
||||||
|
|
||||||
|
describe('ss58 prefix options', (): void => {
|
||||||
|
it('gives each prefix one option, naming every network that uses it', (): void => {
|
||||||
|
expect(prefixOptions([
|
||||||
|
{ displayName: 'Pezkuwi Relay Chain', network: 'pezkuwi', prefix: 42 },
|
||||||
|
{ displayName: 'Zagros Relay Chain', network: 'zagros', prefix: 42 },
|
||||||
|
{ displayName: 'Other', network: 'other', prefix: 7 },
|
||||||
|
{ displayName: 'Bizinikiwi', network: 'bizinikiwi', prefix: 42 }
|
||||||
|
])).toEqual([
|
||||||
|
{ info: 'pezkuwi', text: 'Pezkuwi Relay Chain / Zagros Relay Chain / Bizinikiwi', value: 42 },
|
||||||
|
{ info: 'other', text: 'Other', value: 7 }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('has no two options with the same value', (): void => {
|
||||||
|
const values = PREFIXES.map(({ value }) => value);
|
||||||
|
|
||||||
|
expect(new Set(values).size).toEqual(values.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2017-2025 @pezkuwi/ui-settings authors & contributors
|
// Copyright 2017-2026 @pezkuwi/ui-settings authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import type { Network } from '@pezkuwi/networks/types';
|
||||||
import type { Option } from '../types.js';
|
import type { Option } from '../types.js';
|
||||||
|
|
||||||
import { availableNetworks } from '@pezkuwi/networks';
|
import { availableNetworks } from '@pezkuwi/networks';
|
||||||
@@ -13,10 +14,26 @@ const defaultNetwork: Option = {
|
|||||||
value: -1
|
value: -1
|
||||||
};
|
};
|
||||||
|
|
||||||
const networks = availableNetworks.map(({ displayName, network, prefix }) => ({
|
/**
|
||||||
info: network,
|
* One option per address format. The value of an option is the ss58 prefix,
|
||||||
text: displayName,
|
* so networks that share a prefix (Pezkuwi, Zagros and Bizinikiwi all use 42)
|
||||||
value: prefix
|
* are the same choice; they are listed together in its text instead of
|
||||||
}));
|
* appearing as separate options with the same value.
|
||||||
|
*/
|
||||||
|
export function prefixOptions (networks: Pick<Network, 'displayName' | 'network' | 'prefix'>[]): Option[] {
|
||||||
|
const byPrefix = new Map<number, Option>();
|
||||||
|
|
||||||
export const PREFIXES: Option[] = [defaultNetwork, ...networks];
|
for (const { displayName, network, prefix } of networks) {
|
||||||
|
const existing = byPrefix.get(prefix);
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.text = `${existing.text} / ${displayName}`;
|
||||||
|
} else {
|
||||||
|
byPrefix.set(prefix, { info: network, text: displayName, value: prefix });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...byPrefix.values()];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PREFIXES: Option[] = [defaultNetwork, ...prefixOptions(availableNetworks)];
|
||||||
@@ -5,5 +5,8 @@
|
|||||||
"outDir": "./build",
|
"outDir": "./build",
|
||||||
"rootDir": "./src"
|
"rootDir": "./src"
|
||||||
},
|
},
|
||||||
|
"exclude": [
|
||||||
|
"**/*.spec.ts"
|
||||||
|
],
|
||||||
"references": []
|
"references": []
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "..",
|
||||||
|
"outDir": "./build",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"emitDeclarationOnly": false,
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.spec.ts"
|
||||||
|
],
|
||||||
|
"references": [
|
||||||
|
{ "path": "../ui-settings/tsconfig.build.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
{ "path": "./packages/ui-keyring/tsconfig.build.json" },
|
{ "path": "./packages/ui-keyring/tsconfig.build.json" },
|
||||||
{ "path": "./packages/ui-keyring/tsconfig.spec.json" },
|
{ "path": "./packages/ui-keyring/tsconfig.spec.json" },
|
||||||
{ "path": "./packages/ui-settings/tsconfig.build.json" },
|
{ "path": "./packages/ui-settings/tsconfig.build.json" },
|
||||||
|
{ "path": "./packages/ui-settings/tsconfig.spec.json" },
|
||||||
{ "path": "./packages/ui-shared/tsconfig.build.json" },
|
{ "path": "./packages/ui-shared/tsconfig.build.json" },
|
||||||
{ "path": "./packages/ui-shared/tsconfig.spec.json" },
|
{ "path": "./packages/ui-shared/tsconfig.spec.json" },
|
||||||
{ "path": "./packages/vue-identicon/tsconfig.build.json" }
|
{ "path": "./packages/vue-identicon/tsconfig.build.json" }
|
||||||
|
|||||||
Reference in new issue
Block a user