mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-04-22 13:37:58 +00:00
feat: initial Pezkuwi Apps rebrand from polkadot-apps
Rebranded terminology: - Polkadot → Pezkuwi - Kusama → Dicle - Westend → Zagros - Rococo → PezkuwiChain - Substrate → Bizinikiwi - parachain → teyrchain Custom logos with Kurdistan brand colors (#e6007a → #86e62a): - bizinikiwi-hexagon.svg - sora-bizinikiwi.svg - hezscanner.svg - heztreasury.svg - pezkuwiscan.svg - pezkuwistats.svg - pezkuwiassembly.svg - pezkuwiholic.svg
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
import type { DropdownOption } from '../util/types.js';
|
||||
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import Dropdown from '../Dropdown.js';
|
||||
import { filterDropdownItems } from '../util/index.js';
|
||||
import useRpcs from './useRpcs.js';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
isError?: boolean;
|
||||
onChange: (value: DefinitionRpcExt) => void;
|
||||
options: DropdownOption[];
|
||||
value: DefinitionRpcExt;
|
||||
}
|
||||
|
||||
function SelectMethod ({ className = '', isError, onChange, options, value }: Props): React.ReactElement<Props> | null {
|
||||
const rpcs = useRpcs();
|
||||
|
||||
const _transform = useCallback(
|
||||
(method: string) => rpcs[value.section][method],
|
||||
[rpcs, value]
|
||||
);
|
||||
|
||||
if (!options.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
className={`${className} ui--DropdownLinked-Items`}
|
||||
isError={isError}
|
||||
onChange={onChange}
|
||||
onSearch={filterDropdownItems}
|
||||
options={options}
|
||||
transform={_transform}
|
||||
value={value.method}
|
||||
withLabel={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(SelectMethod);
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
import type { DropdownOptions } from '../util/types.js';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Dropdown from '../Dropdown.js';
|
||||
import { filterDropdownItems } from '../util/index.js';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
defaultValue?: string;
|
||||
isError?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
options: DropdownOptions;
|
||||
value: DefinitionRpcExt;
|
||||
}
|
||||
|
||||
function SelectSection ({ className = '', defaultValue, isError, onChange, options, value }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<Dropdown
|
||||
className={`${className} ui--DropdownLinked-Sections`}
|
||||
defaultValue={defaultValue}
|
||||
isError={isError}
|
||||
onChange={onChange}
|
||||
onSearch={filterDropdownItems}
|
||||
options={options}
|
||||
value={value.section}
|
||||
withLabel={false}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(SelectSection);
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// TODO: We have a lot shared between this and InputExtrinsic & InputStorage
|
||||
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
import type { DropdownOptions } from '../util/types.js';
|
||||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { useApi } from '@pezkuwi/react-hooks';
|
||||
|
||||
import LinkedWrapper from '../InputExtrinsic/LinkedWrapper.js';
|
||||
import methodOptions from './options/method.js';
|
||||
import sectionOptions from './options/section.js';
|
||||
import SelectMethod from './SelectMethod.js';
|
||||
import SelectSection from './SelectSection.js';
|
||||
import useRpcs from './useRpcs.js';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
defaultValue: DefinitionRpcExt;
|
||||
label: React.ReactNode;
|
||||
onChange?: (value: DefinitionRpcExt) => void;
|
||||
withLabel?: boolean;
|
||||
}
|
||||
|
||||
function InputRpc ({ className = '', defaultValue, label, onChange, withLabel }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const rpcs = useRpcs();
|
||||
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(() => methodOptions(api, rpcs, defaultValue.section));
|
||||
const [optionsSection] = useState<DropdownOptions>(() => sectionOptions(api));
|
||||
const [value, setValue] = useState<DefinitionRpcExt>((): DefinitionRpcExt => defaultValue);
|
||||
|
||||
useEffect((): void => {
|
||||
onChange && onChange(value);
|
||||
}, [onChange, value]);
|
||||
|
||||
const _onMethodChange = useCallback(
|
||||
(newValue: DefinitionRpcExt): void => {
|
||||
if (value !== newValue) {
|
||||
// set via callback since the method is a function itself
|
||||
setValue(() => newValue);
|
||||
}
|
||||
},
|
||||
[value]
|
||||
);
|
||||
|
||||
const _onSectionChange = useCallback(
|
||||
(newSection: string): void => {
|
||||
if (newSection !== value.section) {
|
||||
const optionsMethod = methodOptions(api, rpcs, newSection);
|
||||
|
||||
setOptionsMethod(optionsMethod);
|
||||
_onMethodChange(rpcs[newSection][optionsMethod[0].value]);
|
||||
}
|
||||
},
|
||||
[_onMethodChange, api, rpcs, value]
|
||||
);
|
||||
|
||||
return (
|
||||
<LinkedWrapper
|
||||
className={className}
|
||||
label={label}
|
||||
withLabel={withLabel}
|
||||
>
|
||||
<SelectSection
|
||||
className='small'
|
||||
onChange={_onSectionChange}
|
||||
options={optionsSection}
|
||||
value={value}
|
||||
/>
|
||||
<SelectMethod
|
||||
className='large'
|
||||
onChange={_onMethodChange}
|
||||
options={optionsMethod}
|
||||
value={value}
|
||||
/>
|
||||
</LinkedWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(InputRpc);
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
import type { DropdownOption, DropdownOptions } from '../../util/types.js';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
export default function createOptions (api: ApiPromise, rpcs: Record<string, Record<string, DefinitionRpcExt>>, sectionName: string): DropdownOptions {
|
||||
const section = rpcs[sectionName];
|
||||
|
||||
if (!section || Object.keys((api.rpc as unknown as Record<string, Record<string, unknown>>)[sectionName]).length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object
|
||||
.keys((api.rpc as unknown as Record<string, Record<string, unknown>>)[sectionName])
|
||||
.filter((s) => !s.startsWith('$'))
|
||||
.sort()
|
||||
.map((methodName) => section[methodName])
|
||||
.filter((ext): ext is DefinitionRpcExt => !!ext)
|
||||
.filter(({ isSubscription }) => !isSubscription)
|
||||
.map(({ description, method, params }): DropdownOption => {
|
||||
const inputs = params.map(({ name }) => name).join(', ');
|
||||
|
||||
return {
|
||||
className: 'ui--DropdownLinked-Item',
|
||||
key: `${sectionName}_${method}`,
|
||||
text: [
|
||||
<div
|
||||
className='ui--DropdownLinked-Item-call'
|
||||
key={`${sectionName}_${method}:call`}
|
||||
>
|
||||
{method}({inputs})
|
||||
</div>,
|
||||
<div
|
||||
className='ui--DropdownLinked-Item-text'
|
||||
key={`${sectionName}_${method}:text`}
|
||||
>
|
||||
{description || method}
|
||||
</div>
|
||||
],
|
||||
value: method
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import type { DropdownOptions } from '../../util/types.js';
|
||||
|
||||
export default function createOptions (api: ApiPromise): DropdownOptions {
|
||||
return Object
|
||||
.keys(api.rpc)
|
||||
.filter((s) => !s.startsWith('$'))
|
||||
.sort()
|
||||
.filter((section) => Object.keys((api.rpc as unknown as Record<string, Record<string, unknown>>)[section]).length !== 0)
|
||||
.map((name): { text: string; value: string } => ({
|
||||
text: name,
|
||||
value: name
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Text } from '@pezkuwi/types';
|
||||
import type { RuntimeVersion } from '@pezkuwi/types/interfaces';
|
||||
import type { DefinitionRpc, DefinitionRpcExt, Registry } from '@pezkuwi/types/types';
|
||||
|
||||
import jsonrpc from '@pezkuwi/types/interfaces/jsonrpc';
|
||||
import { getSpecRpc } from '@pezkuwi/types-known';
|
||||
|
||||
function toExt (section: string, input: Record<string, DefinitionRpc>): Record<string, DefinitionRpcExt> {
|
||||
return Object.entries(input).reduce((output: Record<string, DefinitionRpcExt>, [method, def]): Record<string, DefinitionRpcExt> => {
|
||||
output[method] = {
|
||||
isSubscription: false,
|
||||
jsonrpc: `${section}_${method}`,
|
||||
method,
|
||||
section,
|
||||
...def
|
||||
};
|
||||
|
||||
return output;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function getAllRpc (registry: Registry, chain: Text, { specName }: RuntimeVersion): Record<string, Record<string, DefinitionRpcExt>> {
|
||||
return Object
|
||||
.entries(getSpecRpc(registry, chain, specName))
|
||||
.reduce((all: Record<string, Record<string, DefinitionRpcExt>>, [section, contents]): Record<string, Record<string, DefinitionRpcExt>> => {
|
||||
all[section] ??= toExt(section, contents);
|
||||
|
||||
return all;
|
||||
}, { ...jsonrpc });
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2017-2025 @pezkuwi/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DefinitionRpcExt } from '@pezkuwi/types/types';
|
||||
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { createNamedHook, useApi } from '@pezkuwi/react-hooks';
|
||||
|
||||
import { getAllRpc } from './rpcs.js';
|
||||
|
||||
function useRpcsImpl (): Record<string, Record<string, DefinitionRpcExt>> {
|
||||
const { api } = useApi();
|
||||
|
||||
return useMemo(
|
||||
() => getAllRpc(api.registry, api.runtimeChain, api.runtimeVersion),
|
||||
[api]
|
||||
);
|
||||
}
|
||||
|
||||
export default createNamedHook('useRpcs', useRpcsImpl);
|
||||
Reference in New Issue
Block a user