Skip to content

Commit

Permalink
fix: transactionPaymentApi issue (#11208)
Browse files Browse the repository at this point in the history
* fix: transactionPaymentApi issue

* chore: changed variable name

* chore: added comment
  • Loading branch information
ap211unitech authored Jan 16, 2025
1 parent 3b6bb2c commit 606598e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions packages/page-runtime/src/Runtime/Selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ interface State {
values: RawParam[];
}

/**
* Declares the Runtime APIs that do not require extrinsic length to be prefixed when converting them to a u8 array.
* REF: https://github.com/polkadot-js/apps/blob/master/packages/react-params/src/Param/BaseBytes.tsx#L99
*/
const WITHOUT_LENGTH = ['transactionPaymentApi'];

function Selection ({ onSubmit }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [{ isValid, method, values }, setState] = useState<State>({
Expand Down Expand Up @@ -82,6 +88,7 @@ function Selection ({ onSubmit }: Props): React.ReactElement<Props> {
key={`${method.section}.${method.method}:params` /* force re-render on change */}
onChange={_onChangeValues}
params={params}
withLength={!WITHOUT_LENGTH.includes(method.section)}
/>
)}
<Button.Group>
Expand Down
4 changes: 2 additions & 2 deletions packages/react-params/src/Param/Bytes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useTranslation } from '../translate.js';
import BaseBytes from './BaseBytes.js';
import File from './File.js';

function Bytes ({ className = '', defaultValue, isDisabled, isError, label, name, onChange, onEnter, onEscape, type, withLabel }: Props): React.ReactElement<Props> {
function Bytes ({ className = '', defaultValue, isDisabled, isError, label, name, onChange, onEnter, onEscape, type, withLabel, withLength = true }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [isValid, setIsValid] = useState(false);
const [isFileDrop, setFileInput] = useState(false);
Expand Down Expand Up @@ -66,7 +66,7 @@ function Bytes ({ className = '', defaultValue, isDisabled, isError, label, name
onEscape={onEscape}
type={type}
withLabel={withLabel}
withLength
withLength={withLength}
/>
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-params/src/Param/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function formatJSON (input: string): string {
.replace(/^{_alias: {.*}, /, '{');
}

function Param ({ className = '', defaultValue, isDisabled, isError, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
function Param ({ className = '', defaultValue, isDisabled, isError, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type, withLength = true }: Props): React.ReactElement<Props> | null {
const Component = useMemo(
() => findComponent(registry, type, overrides),
[registry, type, overrides]
Expand Down Expand Up @@ -71,6 +71,7 @@ function Param ({ className = '', defaultValue, isDisabled, isError, isOptional,
overrides={overrides}
registry={registry}
type={type}
withLength={withLength}
/>
);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/react-params/src/ParamComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ interface Props {
registry: Registry;
type: TypeDef;
values?: RawParams | null;
withLength?: boolean;
}

function ParamComp ({ defaultValue, index, isDisabled, isError, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> {
function ParamComp ({ defaultValue, index, isDisabled, isError, name, onChange, onEnter, onEscape, overrides, registry, type, withLength = true }: Props): React.ReactElement<Props> {
const _onChange = useCallback(
(value: RawParamOnChangeValue): void =>
onChange(index, value),
Expand All @@ -44,6 +45,7 @@ function ParamComp ({ defaultValue, index, isDisabled, isError, name, onChange,
overrides={overrides}
registry={registry}
type={type}
withLength={withLength}
/>
</div>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/react-params/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface Props extends I18nProps {
values?: RawParams | null;
withBorder?: boolean;
withExpander?: boolean;
withLength?: boolean;
}

interface State {
Expand Down Expand Up @@ -84,7 +85,7 @@ class Params extends React.PureComponent<Props, State> {
}

public override render (): React.ReactNode {
const { children, className = '', isDisabled, isError, onEnter, onEscape, overrides, params, registry = statics.api.registry, withBorder = true, withExpander } = this.props;
const { children, className = '', isDisabled, isError, onEnter, onEscape, overrides, params, registry = statics.api.registry, withBorder = true, withExpander, withLength = true } = this.props;
const { values = this.props.values } = this.state;

if (!values?.length) {
Expand Down Expand Up @@ -113,6 +114,7 @@ class Params extends React.PureComponent<Props, State> {
overrides={overrides}
registry={registry}
type={type}
withLength={withLength}
/>
))}
{children}
Expand Down
1 change: 1 addition & 0 deletions packages/react-params/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface Props {
registry: Registry;
type: TypeDefExt;
withLabel?: boolean;
withLength?: boolean;
}

export type Size = 'full' | 'large' | 'medium' | 'small';
Expand Down

0 comments on commit 606598e

Please sign in to comment.