Fix RPC params change (#4083)
This commit is contained in:
parent
34fbe34e31
commit
b9113f7375
@ -37,29 +37,28 @@ function Selection ({ queueRpc }: Props): React.ReactElement<Props> {
|
||||
});
|
||||
|
||||
const _nextState = useCallback(
|
||||
(newState: Partial<State>): void =>
|
||||
setState((prevState: State): State => {
|
||||
const { accountId = prevState.accountId, rpc = prevState.rpc, values = prevState.values } = newState;
|
||||
const reqCount = rpc.params.reduce((count, { isOptional }): number => count + (isOptional ? 0 : 1), 0);
|
||||
const isValid = values.reduce((isValid, value) => isValid && value.isValid === true, reqCount <= values.length);
|
||||
(newState: Partial<State>) => setState((prevState: State): State => {
|
||||
const { accountId = prevState.accountId, rpc = prevState.rpc, values = prevState.values } = newState;
|
||||
const reqCount = rpc.params.reduce((count, { isOptional }) => count + (isOptional ? 0 : 1), 0);
|
||||
const isValid = values.reduce((isValid, value) => isValid && value.isValid === true, reqCount <= values.length);
|
||||
|
||||
return {
|
||||
accountId,
|
||||
isValid,
|
||||
rpc,
|
||||
values
|
||||
};
|
||||
}),
|
||||
return {
|
||||
accountId,
|
||||
isValid,
|
||||
rpc,
|
||||
values
|
||||
};
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
const _onChangeMethod = useCallback(
|
||||
(rpc: DefinitionRpcExt): void => _nextState({ rpc, values: [] }),
|
||||
(rpc: DefinitionRpcExt) => _nextState({ rpc, values: [] }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
const _onChangeValues = useCallback(
|
||||
(values: RawParam[]): void => _nextState({ values }),
|
||||
(values: RawParam[]) => _nextState({ values }),
|
||||
[_nextState]
|
||||
);
|
||||
|
||||
@ -68,7 +67,7 @@ function Selection ({ queueRpc }: Props): React.ReactElement<Props> {
|
||||
accountId,
|
||||
rpc,
|
||||
values: values
|
||||
.filter(({ value }): boolean => !isNull(value))
|
||||
.filter(({ value }) => !isNull(value))
|
||||
.map(({ value }): any => value)
|
||||
}),
|
||||
[accountId, queueRpc, rpc, values]
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DefinitionRpcExt } from '@polkadot/types/types';
|
||||
import type { DropdownOptions } from '../util/types';
|
||||
import type { DropdownOption } from '../util/types';
|
||||
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
@ -14,13 +14,13 @@ interface Props {
|
||||
className?: string;
|
||||
isError?: boolean;
|
||||
onChange: (value: DefinitionRpcExt) => void;
|
||||
options: DropdownOptions;
|
||||
options: DropdownOption[];
|
||||
value: DefinitionRpcExt;
|
||||
}
|
||||
|
||||
function SelectMethod ({ className = '', isError, onChange, options, value }: Props): React.ReactElement<Props> | null {
|
||||
const _transform = useCallback(
|
||||
() => rpcs[value.section][value.method],
|
||||
(method: string) => rpcs[value.section][method],
|
||||
[value]
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user