mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-04-23 11:47: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,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);
|
||||
Reference in New Issue
Block a user