mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-07 18:57:26 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/react-components authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// TODO: We have a lot shared between this and InputExtrinsic & InputStorage
|
|
|
|
import type { DefinitionCallNamed } from '@pezkuwi/types/types';
|
|
import type { DropdownOptions } from '../util/types.js';
|
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
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 useRuntime from './useRuntime.js';
|
|
|
|
interface Props {
|
|
className?: string;
|
|
label: React.ReactNode;
|
|
onChange?: (value: DefinitionCallNamed) => void;
|
|
withLabel?: boolean;
|
|
}
|
|
|
|
function InputCalls ({ className, label, onChange, withLabel }: Props): React.ReactElement<Props> | null {
|
|
const [defs, defaultValue] = useRuntime();
|
|
const [optionsSection] = useState<DropdownOptions>(() => sectionOptions(defs));
|
|
const [optionsMethod, setOptionsMethod] = useState<DropdownOptions>(() => methodOptions(defs, defaultValue?.section));
|
|
const [value, setValue] = useState<DefinitionCallNamed | null>(() => defaultValue);
|
|
|
|
useEffect((): void => {
|
|
value && onChange && onChange(value);
|
|
}, [onChange, value]);
|
|
|
|
const _onMethodChange = useCallback(
|
|
(newValue: DefinitionCallNamed): void => {
|
|
if (value !== newValue) {
|
|
// set via callback since the method is a function itself
|
|
setValue(() => newValue);
|
|
}
|
|
},
|
|
[value]
|
|
);
|
|
|
|
const _onSectionChange = useCallback(
|
|
(newSection: string): void => {
|
|
if (value && newSection !== value.section) {
|
|
const optionsMethod = methodOptions(defs, newSection);
|
|
|
|
setOptionsMethod(optionsMethod);
|
|
_onMethodChange(defs[newSection][optionsMethod[0].value]);
|
|
}
|
|
},
|
|
[_onMethodChange, defs, value]
|
|
);
|
|
|
|
if (!value) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<LinkedWrapper
|
|
className={className}
|
|
label={label}
|
|
withLabel={withLabel}
|
|
>
|
|
<SelectSection
|
|
className='small'
|
|
onChange={_onSectionChange}
|
|
options={optionsSection}
|
|
value={value}
|
|
/>
|
|
<SelectMethod
|
|
className='large'
|
|
defs={defs}
|
|
onChange={_onMethodChange}
|
|
options={optionsMethod}
|
|
value={value}
|
|
/>
|
|
</LinkedWrapper>
|
|
);
|
|
}
|
|
|
|
export default React.memo(InputCalls);
|