Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
d19fcbdb
Commit
d19fcbdb
authored
Mar 24, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle button click
parent
d966aeca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
13 deletions
+31
-13
ContractMethodCallable.tsx
ui/address/contract/ContractMethodCallable.tsx
+3
-2
ContractMethodField.tsx
ui/address/contract/ContractMethodField.tsx
+16
-7
ContractMethodFieldZeroes.tsx
ui/address/contract/ContractMethodFieldZeroes.tsx
+12
-4
No files found.
ui/address/contract/ContractMethodCallable.tsx
View file @
d19fcbdb
...
@@ -68,7 +68,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -68,7 +68,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
];
];
},
[
data
]);
},
[
data
]);
const
{
control
,
handleSubmit
,
setValue
}
=
useForm
<
MethodFormFields
>
({
const
{
control
,
handleSubmit
,
setValue
,
getValues
}
=
useForm
<
MethodFormFields
>
({
defaultValues
:
_fromPairs
(
inputs
.
map
(({
name
},
index
)
=>
[
getFieldName
(
name
,
index
),
''
])),
defaultValues
:
_fromPairs
(
inputs
.
map
(({
name
},
index
)
=>
[
getFieldName
(
name
,
index
),
''
])),
});
});
...
@@ -122,8 +122,9 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
...
@@ -122,8 +122,9 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
placeholder=
{
`${ name }(${ type })`
}
placeholder=
{
`${ name }(${ type })`
}
control=
{
control
}
control=
{
control
}
setValue=
{
setValue
}
setValue=
{
setValue
}
getValues=
{
getValues
}
isDisabled=
{
isLoading
}
isDisabled=
{
isLoading
}
onC
lear
=
{
handleFormChange
}
onC
hange
=
{
handleFormChange
}
/>
/>
);
);
})
}
})
}
...
...
ui/address/contract/ContractMethodField.tsx
View file @
d19fcbdb
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
InputRightElement
,
InputRightElement
,
}
from
'
@chakra-ui/react
'
;
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
Control
,
ControllerRenderProps
,
UseFormSetValue
}
from
'
react-hook-form
'
;
import
type
{
Control
,
ControllerRenderProps
,
UseForm
GetValues
,
UseForm
SetValue
}
from
'
react-hook-form
'
;
import
{
Controller
}
from
'
react-hook-form
'
;
import
{
Controller
}
from
'
react-hook-form
'
;
import
type
{
MethodFormFields
}
from
'
./types
'
;
import
type
{
MethodFormFields
}
from
'
./types
'
;
...
@@ -18,21 +18,30 @@ import ContractMethodFieldZeroes from './ContractMethodFieldZeroes';
...
@@ -18,21 +18,30 @@ import ContractMethodFieldZeroes from './ContractMethodFieldZeroes';
interface
Props
{
interface
Props
{
control
:
Control
<
MethodFormFields
>
;
control
:
Control
<
MethodFormFields
>
;
setValue
:
UseFormSetValue
<
MethodFormFields
>
;
setValue
:
UseFormSetValue
<
MethodFormFields
>
;
getValues
:
UseFormGetValues
<
MethodFormFields
>
;
placeholder
:
string
;
placeholder
:
string
;
name
:
string
;
name
:
string
;
valueType
:
SmartContractMethodArgType
;
valueType
:
SmartContractMethodArgType
;
isDisabled
:
boolean
;
isDisabled
:
boolean
;
onC
lear
:
()
=>
void
;
onC
hange
:
()
=>
void
;
}
}
const
ContractMethodField
=
({
control
,
name
,
valueType
,
placeholder
,
setValue
,
isDisabled
,
onClear
}:
Props
)
=>
{
const
ContractMethodField
=
({
control
,
name
,
valueType
,
placeholder
,
setValue
,
getValues
,
isDisabled
,
onChange
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
HTMLInputElement
>
(
null
);
const
ref
=
React
.
useRef
<
HTMLInputElement
>
(
null
);
const
handleClear
=
React
.
useCallback
(()
=>
{
const
handleClear
=
React
.
useCallback
(()
=>
{
setValue
(
name
,
''
);
setValue
(
name
,
''
);
onC
lear
();
onC
hange
();
ref
.
current
?.
focus
();
ref
.
current
?.
focus
();
},
[
name
,
onClear
,
setValue
]);
},
[
name
,
onChange
,
setValue
]);
const
handleAddZeroesClick
=
React
.
useCallback
((
power
:
number
)
=>
{
const
value
=
getValues
()[
name
];
const
zeroes
=
Array
(
power
).
fill
(
'
0
'
).
join
(
''
);
const
newValue
=
value
?
value
+
zeroes
:
'
1
'
+
zeroes
;
setValue
(
name
,
newValue
);
onChange
();
},
[
getValues
,
name
,
onChange
,
setValue
]);
const
hasZerosControl
=
valueType
.
includes
(
'
int
'
)
&&
!
valueType
.
includes
(
'
[]
'
);
const
hasZerosControl
=
valueType
.
includes
(
'
int
'
)
&&
!
valueType
.
includes
(
'
[]
'
);
...
@@ -54,12 +63,12 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue,
...
@@ -54,12 +63,12 @@ const ContractMethodField = ({ control, name, valueType, placeholder, setValue,
/>
/>
<
InputRightElement
w=
"auto"
right=
{
1
}
>
<
InputRightElement
w=
"auto"
right=
{
1
}
>
{
field
.
value
&&
<
InputClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
}
{
field
.
value
&&
<
InputClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
}
{
hasZerosControl
&&
<
ContractMethodFieldZeroes
/>
}
{
hasZerosControl
&&
<
ContractMethodFieldZeroes
onClick=
{
handleAddZeroesClick
}
/>
}
</
InputRightElement
>
</
InputRightElement
>
</
InputGroup
>
</
InputGroup
>
</
FormControl
>
</
FormControl
>
);
);
},
[
handleClear
,
isDisabled
,
hasZerosControl
,
name
,
placeholder
]);
},
[
name
,
isDisabled
,
placeholder
,
hasZerosControl
,
handleClear
,
handleAddZeroesClick
]);
return
(
return
(
<
Controller
<
Controller
...
...
ui/address/contract/ContractMethodFieldZeroes.tsx
View file @
d19fcbdb
...
@@ -18,8 +18,12 @@ import iconEastMini from 'icons/arrows/east-mini.svg';
...
@@ -18,8 +18,12 @@ import iconEastMini from 'icons/arrows/east-mini.svg';
import
iconCheck
from
'
icons/check.svg
'
;
import
iconCheck
from
'
icons/check.svg
'
;
import
{
times
}
from
'
lib/html-entities
'
;
import
{
times
}
from
'
lib/html-entities
'
;
const
ContractMethodFieldZeroes
=
()
=>
{
interface
Props
{
const
[
selectedOption
,
setSelectedOption
]
=
React
.
useState
<
number
>
();
onClick
:
(
power
:
number
)
=>
void
;
}
const
ContractMethodFieldZeroes
=
({
onClick
}:
Props
)
=>
{
const
[
selectedOption
,
setSelectedOption
]
=
React
.
useState
<
number
|
undefined
>
(
18
);
const
[
customValue
,
setCustomValue
]
=
React
.
useState
<
number
>
();
const
[
customValue
,
setCustomValue
]
=
React
.
useState
<
number
>
();
const
{
isOpen
,
onToggle
,
onClose
}
=
useDisclosure
();
const
{
isOpen
,
onToggle
,
onClose
}
=
useDisclosure
();
...
@@ -27,6 +31,7 @@ const ContractMethodFieldZeroes = () => {
...
@@ -27,6 +31,7 @@ const ContractMethodFieldZeroes = () => {
const
id
=
Number
((
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-id
'
));
const
id
=
Number
((
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-id
'
));
if
(
!
Object
.
is
(
id
,
NaN
))
{
if
(
!
Object
.
is
(
id
,
NaN
))
{
setSelectedOption
((
prev
)
=>
prev
===
id
?
undefined
:
id
);
setSelectedOption
((
prev
)
=>
prev
===
id
?
undefined
:
id
);
setCustomValue
(
undefined
);
onClose
();
onClose
();
}
}
},
[
onClose
]);
},
[
onClose
]);
...
@@ -38,6 +43,10 @@ const ContractMethodFieldZeroes = () => {
...
@@ -38,6 +43,10 @@ const ContractMethodFieldZeroes = () => {
const
value
=
selectedOption
||
customValue
;
const
value
=
selectedOption
||
customValue
;
const
handleButtonClick
=
React
.
useCallback
(()
=>
{
value
&&
onClick
(
value
);
},
[
onClick
,
value
]);
return
(
return
(
<>
<>
{
Boolean
(
value
)
&&
(
{
Boolean
(
value
)
&&
(
...
@@ -50,8 +59,7 @@ const ContractMethodFieldZeroes = () => {
...
@@ -50,8 +59,7 @@ const ContractMethodFieldZeroes = () => {
variant=
"subtle"
variant=
"subtle"
colorScheme=
"gray"
colorScheme=
"gray"
display=
"inline"
display=
"inline"
_hover=
{
{
color
:
'
inherit
'
}
}
onClick=
{
handleButtonClick
}
cursor=
"default"
>
>
{
times
}
{
times
}
<
chakra
.
span
>
10
</
chakra
.
span
>
<
chakra
.
span
>
10
</
chakra
.
span
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment