diff --git a/forms/AbiDecodeForm.vue b/forms/AbiDecodeForm.vue index e30b574..c233368 100644 --- a/forms/AbiDecodeForm.vue +++ b/forms/AbiDecodeForm.vue @@ -67,12 +67,7 @@ :readonly="form.decodeMode === DECODE_MODES.auto" :label="$t('abi-decode-form.arg-type-label')" :placeholder="$t('abi-decode-form.arg-type-placeholder')" - :options=" - Object.values(ETHEREUM_TYPES).map(v => ({ - value: v, - title: v, - })) - " + :options="TYPE_OPTIONS" :error-message="getFieldErrorMessage(`args[${idx}].type`)" @blur="touchField('args')" /> @@ -174,7 +169,7 @@ import { type ArrayElement, type FieldOption } from '@/types' import { fetcher } from '@distributedlab/fetcher' import { guessAbiEncodedData, guessFragment } from '@openchainxyz/abi-guesser' import { AbiCoder, FunctionFragment, ParamType } from 'ethers' -import { debounce } from 'lodash-es' +import { debounce, without } from 'lodash-es' import { v4 as uuidv4 } from 'uuid' import { computed, reactive, ref, watch } from 'vue' import { i18n } from '~/plugins/localization' @@ -196,6 +191,15 @@ enum DECODE_MODES { manual = 'manual', } +const TYPE_OPTIONS: FieldOption[] = without( + Object.values(ETHEREUM_TYPES), + ETHEREUM_TYPES.uint, + ETHEREUM_TYPES.uintArray, +).map(v => ({ + value: v, + title: v, +})) + defineProps<{ title: string }>() diff --git a/forms/AbiEncodeForm.vue b/forms/AbiEncodeForm.vue index 0ac5f0c..f51d6e8 100644 --- a/forms/AbiEncodeForm.vue +++ b/forms/AbiEncodeForm.vue @@ -19,9 +19,7 @@ v-model="arg.type" :label="$t('abi-encode-form.arg-type-label')" :placeholder="$t('abi-encode-form.arg-type-placeholder')" - :options=" - Object.values(ETHEREUM_TYPES).map(v => ({ value: v, title: v })) - " + :options="TYPE_OPTIONS" :error-message="getFieldErrorMessage(`args[${idx}].type`)" @blur="touchField(`args[${idx}].type`)" /> @@ -111,11 +109,21 @@ import { required, withinSizeOfEthereumType, } from '@/helpers' -import { type AbiEncodeForm } from '@/types' +import { type AbiEncodeForm, type FieldOption } from '@/types' import { Interface, ParamType } from 'ethers' +import { without } from 'lodash-es' import { v4 as uuidv4 } from 'uuid' import { computed, reactive, ref, watch } from 'vue' +const TYPE_OPTIONS: FieldOption[] = without( + Object.values(ETHEREUM_TYPES), + ETHEREUM_TYPES.uint, + ETHEREUM_TYPES.uintArray, +).map(v => ({ + value: v, + title: v, +})) + defineProps<{ title: string }>() diff --git a/helpers/abi-encode-form.helpers.ts b/helpers/abi-encode-form.helpers.ts index c6edf5b..afc618f 100644 --- a/helpers/abi-encode-form.helpers.ts +++ b/helpers/abi-encode-form.helpers.ts @@ -124,7 +124,12 @@ export function withinSizeOfEthereumType(): ValidationRule { $validator: (_, arg: AbiEncodeForm.FuncArg) => { _baseType = arg.type.replace(/\d+/, '') - if (_baseType === arg.type) return true + const isUintBaseType = [ + ETHEREUM_TYPES.uint, + ETHEREUM_TYPES.uintArray, + ].includes(_baseType as ETHEREUM_TYPES) + + if (_baseType === arg.type && !isUintBaseType) return true const isArray = arg.type.includes('[]') const matchArray = arg.type.match(/\d+/) @@ -137,7 +142,10 @@ export function withinSizeOfEthereumType(): ValidationRule { case ETHEREUM_TYPES.bytesArray: return checkBytesAmount(v as BytesLike, sizeOfType) case ETHEREUM_TYPES.uintArray: - return checkUintIsWithinRange(v as BigNumber.Value, sizeOfType) + return checkUintIsWithinRange( + v as BigNumber.Value, + sizeOfType || 256, + ) default: return true } @@ -151,7 +159,7 @@ export function withinSizeOfEthereumType(): ValidationRule { case ETHEREUM_TYPES.bytes: return checkBytesAmount(arg.value, sizeOfType) case ETHEREUM_TYPES.uint: - return checkUintIsWithinRange(arg.value, sizeOfType) + return checkUintIsWithinRange(arg.value, sizeOfType || 256) default: return true } diff --git a/helpers/type.helpers.ts b/helpers/type.helpers.ts index 0f7a0ca..b07f776 100644 --- a/helpers/type.helpers.ts +++ b/helpers/type.helpers.ts @@ -64,6 +64,8 @@ export function checkIsStringArrayJsonString(value: unknown): boolean { } export function checkIsUintLike(value: unknown): boolean { + if (typeof value === 'string' && value.includes('e')) return false + const bigNumber = BigNumber(value as BigNumber.Value) return bigNumber.isPositive() && bigNumber.isFinite() }