Commit 4f799da1 authored by tom's avatar tom

bool validation

parent 88abf613
...@@ -17,7 +17,7 @@ import type { SmartContractMethodArgType } from 'types/api/contract'; ...@@ -17,7 +17,7 @@ import type { SmartContractMethodArgType } from 'types/api/contract';
import ClearButton from 'ui/shared/ClearButton'; import ClearButton from 'ui/shared/ClearButton';
import ContractMethodFieldZeroes from './ContractMethodFieldZeroes'; import ContractMethodFieldZeroes from './ContractMethodFieldZeroes';
import { INT_REGEXP, getIntBoundaries } from './utils'; import { INT_REGEXP, getIntBoundaries, formatBooleanValue } from './utils';
interface Props { interface Props {
control: Control<MethodFormFields>; control: Control<MethodFormFields>;
...@@ -122,6 +122,13 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue, ...@@ -122,6 +122,13 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue,
return true; return true;
} }
if (valueType === 'bool') {
const formattedValue = formatBooleanValue(value);
if (formattedValue === undefined) {
return 'Invalid boolean format. Allowed values: 0, 1, true, false';
}
}
return true; return true;
}, [ intMatch, valueType ]); }, [ intMatch, valueType ]);
......
...@@ -11,6 +11,25 @@ export const getIntBoundaries = (power: number, isUnsigned: boolean) => { ...@@ -11,6 +11,25 @@ export const getIntBoundaries = (power: number, isUnsigned: boolean) => {
return [ min, max ]; return [ min, max ];
}; };
export const formatBooleanValue = (value: string) => {
const formattedValue = value.toLowerCase();
switch (formattedValue) {
case 'true':
case '1': {
return 'true';
}
case 'false':
case '0': {
return 'false';
}
default:
return;
}
};
export const getNativeCoinValue = (value: string | Array<unknown>) => { export const getNativeCoinValue = (value: string | Array<unknown>) => {
const _value = Array.isArray(value) ? value[0] : value; const _value = Array.isArray(value) ? value[0] : value;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment