Skip to content

Commit

Permalink
excluded uint, uintArray in type options
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehor Podporinov authored and Yehor Podporinov committed Aug 31, 2023
1 parent 6c3d18f commit 7cbbd2a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
18 changes: 11 additions & 7 deletions forms/AbiDecodeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
/>
Expand Down Expand Up @@ -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'
Expand All @@ -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
}>()
Expand Down
16 changes: 12 additions & 4 deletions forms/AbiEncodeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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`)"
/>
Expand Down Expand Up @@ -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
}>()
Expand Down
14 changes: 11 additions & 3 deletions helpers/abi-encode-form.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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+/)
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions helpers/type.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 7cbbd2a

Please sign in to comment.