Commit 285b3a23 authored by tom's avatar tom

more strict condition

parent d19fcbdb
...@@ -14,6 +14,7 @@ import type { SmartContractMethodArgType } from 'types/api/contract'; ...@@ -14,6 +14,7 @@ import type { SmartContractMethodArgType } from 'types/api/contract';
import InputClearButton from 'ui/shared/InputClearButton'; import InputClearButton from 'ui/shared/InputClearButton';
import ContractMethodFieldZeroes from './ContractMethodFieldZeroes'; import ContractMethodFieldZeroes from './ContractMethodFieldZeroes';
import { addZeroesAllowed } from './utils';
interface Props { interface Props {
control: Control<MethodFormFields>; control: Control<MethodFormFields>;
...@@ -43,7 +44,7 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue, ...@@ -43,7 +44,7 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue,
onChange(); onChange();
}, [ getValues, name, onChange, setValue ]); }, [ getValues, name, onChange, setValue ]);
const hasZerosControl = valueType.includes('int') && !valueType.includes('[]'); const hasZerosControl = addZeroesAllowed(valueType);
const renderInput = React.useCallback(({ field }: { field: ControllerRenderProps<MethodFormFields> }) => { const renderInput = React.useCallback(({ field }: { field: ControllerRenderProps<MethodFormFields> }) => {
return ( return (
......
...@@ -7,6 +7,24 @@ export const getNativeCoinValue = (value: string | Array<string>) => { ...@@ -7,6 +7,24 @@ export const getNativeCoinValue = (value: string | Array<string>) => {
return BigNumber(_value).times(10 ** config.network.currency.decimals).toString(); return BigNumber(_value).times(10 ** config.network.currency.decimals).toString();
}; };
export const addZeroesAllowed = (valueType: string) => {
if (valueType.includes('[]')) {
return false;
}
const REGEXP = /u?int(\d+)/i;
const match = valueType.match(REGEXP);
const power = match?.[1];
if (power) {
// show control for all inputs which allows to insert 10^18 or greater numbers
return Number(power) >= 64;
}
return false;
};
interface ExtendedError extends Error { interface ExtendedError extends Error {
detectedNetwork?: { detectedNetwork?: {
chain: number; chain: number;
......
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