Skip to content

Commit 00708bb

Browse files
yehor-podporinovYehor Podporinov
andauthored
Fix/Default types (#53)
* updated default values for solidity types * added default subtype and value for tuple * replaced icon for default values --------- Co-authored-by: Yehor Podporinov <[email protected]>
1 parent f5a1367 commit 00708bb

File tree

5 files changed

+70
-30
lines changed

5 files changed

+70
-30
lines changed

assets/icons/keyboard-icon.svg

Lines changed: 3 additions & 0 deletions
Loading

assets/styles/_global.scss

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ textarea {
8787
@include field-text;
8888
}
8989

90-
button,
91-
a {
92-
cursor: pointer;
93-
}
94-
9590
body,
9691
span,
9792
p,
@@ -101,6 +96,15 @@ a {
10196
@include p-16-regular;
10297
}
10398

99+
button,
100+
a {
101+
cursor: pointer;
102+
103+
&:disabled {
104+
cursor: not-allowed;
105+
}
106+
}
107+
104108
main {
105109
margin-top: var(--app-height-header);
106110
padding: var(--app-padding);

enums/icon-names.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum ICON_NAMES {
1414
exclamationCircle = 'exclamation-circle',
1515
exclamationTriangle = 'exclamation-triangle',
1616
hashtag = 'hashtag',
17+
keyboard = 'keyboard',
1718
locationMarker = 'location-marker',
1819
plus = 'plus',
1920
refresh = 'refresh',

forms/AbiEncodeForm.vue

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<input-field
3939
v-if="arg.type === ETHEREUM_TYPES.tuple"
4040
:model-value="arg.subtype"
41-
is-clearable
4241
:label="$t('abi-encode-form.arg-subtype-label')"
4342
:placeholder="
4443
$t('abi-encode-form.arg-subtype-placeholder--tuple')
@@ -47,41 +46,68 @@
4746
@blur="touchField(`args[${idx}].subtype`)"
4847
@clear="removeArg(arg.id)"
4948
@update:model-value="onArgSubtypeUpdate($event as string, idx)"
50-
/>
49+
>
50+
<template #nodeRight>
51+
<button
52+
class="abi-encode-form__field-btn"
53+
:class="{ 'abi-encode-form__field-btn--filled': arg.subtype }"
54+
@click="arg.subtype = getDefaultSubtypeOfType(arg.type)"
55+
>
56+
<app-icon
57+
class="abi-encode-form__field-btn-icon"
58+
:name="$icons.keyboard"
59+
/>
60+
</button>
61+
<button
62+
class="abi-encode-form__field-btn"
63+
:class="{ 'abi-encode-form__field-btn--filled': arg.subtype }"
64+
@click="removeArg(arg.id)"
65+
>
66+
<app-icon
67+
:class="[
68+
'abi-encode-form__field-btn-icon',
69+
'abi-encode-form__field-btn-icon--x-mark',
70+
]"
71+
:name="$icons.x"
72+
/>
73+
</button>
74+
</template>
75+
</input-field>
5176
<textarea-field
5277
v-model="arg.value"
5378
size="small"
5479
:label="
5580
arg.type !== ETHEREUM_TYPES.tuple
56-
? $t('abi-encode-form.arg-subtype-label')
81+
? $t('abi-encode-form.arg-value-label')
5782
: ''
5883
"
5984
:placeholder="$t('abi-encode-form.arg-value-placeholder')"
6085
:error-message="getFieldErrorMessage(`args[${idx}].value`)"
6186
@blur="touchField(`args[${idx}].value`)"
6287
>
63-
<template v-if="arg.type !== ETHEREUM_TYPES.tuple" #nodeRight>
88+
<template #nodeRight>
6489
<button
6590
class="abi-encode-form__field-btn"
6691
:class="{ 'abi-encode-form__field-btn--filled': arg.value }"
6792
:disabled="!arg.type"
6893
@click="arg.value = getDefaultValueOfType(arg.type)"
6994
>
7095
<app-icon
71-
:class="[
72-
'abi-encode-form__field-btn-icon',
73-
'abi-encode-form__field-btn-icon--refresh',
74-
]"
75-
:name="$icons.refresh"
96+
class="abi-encode-form__field-btn-icon"
97+
:name="$icons.keyboard"
7698
/>
7799
</button>
78100
<button
101+
v-if="arg.type !== ETHEREUM_TYPES.tuple"
79102
class="abi-encode-form__field-btn"
80103
:class="{ 'abi-encode-form__field-btn--filled': arg.value }"
81104
@click="removeArg(arg.id)"
82105
>
83106
<app-icon
84-
class="abi-encode-form__field-btn-icon"
107+
:class="[
108+
'abi-encode-form__field-btn-icon',
109+
'abi-encode-form__field-btn-icon--x-mark',
110+
]"
85111
:name="$icons.x"
86112
/>
87113
</button>
@@ -141,6 +167,7 @@ import {
141167
ethereumBaseType,
142168
ethereumBaseTypeValue,
143169
formatArgSubtype,
170+
getDefaultSubtypeOfType,
144171
getDefaultValueOfType,
145172
json,
146173
parseFuncArgToValueOfEncode,
@@ -366,10 +393,10 @@ abiEncoding.value = encodeAbi([], [])
366393
.abi-encode-form .abi-encode-form__field-btn-icon {
367394
height: toRem(24);
368395
width: toRem(24);
396+
margin-right: toRem(-1);
369397
370-
&--refresh {
371-
height: toRem(18);
372-
width: toRem(18);
398+
&--x-mark {
399+
margin-right: toRem(-5);
373400
}
374401
}
375402
</style>

helpers/abi-form.helpers.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,32 +195,37 @@ export const formatArgSubtype = (subtype: AbiForm.FuncArg['subtype']) => {
195195
return subtype.replaceAll('tuple(', '(').replaceAll('(', 'tuple(')
196196
}
197197

198+
export const getDefaultSubtypeOfType = (
199+
type: AbiForm.FuncArg['type'],
200+
): string => {
201+
if (type === ETHEREUM_TYPES.tuple) {
202+
return 'tuple()'
203+
}
204+
205+
return ''
206+
}
207+
198208
export const getDefaultValueOfType = (
199209
type: AbiForm.FuncArg['type'],
200210
): string => {
201211
const baseType = type.replace(/\d+/, '')
202212
const matchArray = type.match(/\d+/)
203213
const sizeOfType = matchArray?.length ? Number(matchArray[0]) : 0
214+
const isArrayBaseType = ParamType.from(type).baseType === 'array'
215+
216+
if (isArrayBaseType) return '[]'
204217

205218
switch (baseType) {
206219
case ETHEREUM_TYPES.address:
207220
return '0x0000000000000000000000000000000000000000'
208-
case ETHEREUM_TYPES.addressArray:
209-
return '["0x0000000000000000000000000000000000000000"]'
210221
case ETHEREUM_TYPES.bool:
211222
return 'false'
212-
case ETHEREUM_TYPES.boolArray:
213-
return '[false]'
214223
case ETHEREUM_TYPES.bytes:
215-
return sizeOfType ? '0x'.concat('00'.repeat(sizeOfType)) : '0x00'
216-
case ETHEREUM_TYPES.bytesArray:
217-
return sizeOfType ? `["0x${'00'.repeat(sizeOfType)}"]` : '["0x00"]'
218-
case ETHEREUM_TYPES.stringArray:
219-
return '[""]'
224+
return sizeOfType ? '0x'.concat('00'.repeat(sizeOfType)) : '0x'
225+
case ETHEREUM_TYPES.tuple:
226+
return '[]'
220227
case ETHEREUM_TYPES.uint:
221-
return sizeOfType.toString()
222-
case ETHEREUM_TYPES.uintArray:
223-
return `["${sizeOfType}"]`
228+
return '0'
224229
default:
225230
return ''
226231
}

0 commit comments

Comments
 (0)