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
c2397691
Commit
c2397691
authored
Mar 23, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base component
parent
5c9556ca
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
10 deletions
+120
-10
ContractMethodCallable.tsx
ui/address/contract/ContractMethodCallable.tsx
+1
-0
ContractMethodField.tsx
ui/address/contract/ContractMethodField.tsx
+21
-10
ContractMethodFieldZeroes.tsx
ui/address/contract/ContractMethodFieldZeroes.tsx
+98
-0
No files found.
ui/address/contract/ContractMethodCallable.tsx
View file @
c2397691
...
...
@@ -118,6 +118,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
<
ContractMethodField
key=
{
fieldName
}
name=
{
fieldName
}
valueType=
{
type
}
placeholder=
{
`${ name }(${ type })`
}
control=
{
control
}
setValue=
{
setValue
}
...
...
ui/address/contract/ContractMethodField.tsx
View file @
c2397691
import
{
FormControl
,
Input
,
InputGroup
,
InputRightElement
}
from
'
@chakra-ui/react
'
;
import
{
FormControl
,
Input
,
InputGroup
,
InputRightElement
,
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
Control
,
ControllerRenderProps
,
UseFormSetValue
}
from
'
react-hook-form
'
;
import
{
Controller
}
from
'
react-hook-form
'
;
import
type
{
MethodFormFields
}
from
'
./types
'
;
import
type
{
SmartContractMethodArgType
}
from
'
types/api/contract
'
;
import
InputClearButton
from
'
ui/shared/InputClearButton
'
;
import
ContractMethodFieldZeroes
from
'
./ContractMethodFieldZeroes
'
;
interface
Props
{
control
:
Control
<
MethodFormFields
>
;
setValue
:
UseFormSetValue
<
MethodFormFields
>
;
placeholder
:
string
;
name
:
string
;
valueType
:
SmartContractMethodArgType
;
isDisabled
:
boolean
;
onClear
:
()
=>
void
;
}
const
ContractMethodField
=
({
control
,
name
,
placeholder
,
setValue
,
isDisabled
,
onClear
}:
Props
)
=>
{
const
ContractMethodField
=
({
control
,
name
,
valueType
,
placeholder
,
setValue
,
isDisabled
,
onClear
}:
Props
)
=>
{
const
ref
=
React
.
useRef
<
HTMLInputElement
>
(
null
);
const
handleClear
=
React
.
useCallback
(()
=>
{
...
...
@@ -25,6 +34,8 @@ const ContractMethodField = ({ control, name, placeholder, setValue, isDisabled,
ref
.
current
?.
focus
();
},
[
name
,
onClear
,
setValue
]);
const
hasZerosControl
=
valueType
.
includes
(
'
int
'
)
&&
!
valueType
.
includes
(
'
[]
'
);
const
renderInput
=
React
.
useCallback
(({
field
}:
{
field
:
ControllerRenderProps
<
MethodFormFields
>
})
=>
{
return
(
<
FormControl
...
...
@@ -32,23 +43,23 @@ const ContractMethodField = ({ control, name, placeholder, setValue, isDisabled,
flexBasis=
{
{
base
:
'
100%
'
,
lg
:
'
calc((100% - 24px) / 3 - 65px)
'
}
}
w=
{
{
base
:
'
100%
'
,
lg
:
'
auto
'
}
}
flexGrow=
{
1
}
isDisabled=
{
isDisabled
}
>
isDisabled=
{
isDisabled
}
>
<
InputGroup
size=
"xs"
>
<
Input
{
...
field
}
ref=
{
ref
}
placeholder=
{
placeholder
}
paddingRight=
{
hasZerosControl
?
'
120px
'
:
'
40px
'
}
/>
{
field
.
value
&&
(
<
InputRightElement
>
<
InputClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
</
InputRightElement
>
)
}
<
InputRightElement
w=
"auto"
right=
{
1
}
>
{
field
.
value
&&
<
InputClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
}
{
hasZerosControl
&&
<
ContractMethodFieldZeroes
/>
}
</
InputRightElement
>
</
InputGroup
>
</
FormControl
>
);
},
[
handleClear
,
isDisabled
,
name
,
placeholder
]);
},
[
handleClear
,
isDisabled
,
hasZerosControl
,
name
,
placeholder
]);
return
(
<
Controller
...
...
ui/address/contract/ContractMethodFieldZeroes.tsx
0 → 100644
View file @
c2397691
import
{
chakra
,
Popover
,
PopoverBody
,
PopoverContent
,
PopoverTrigger
,
Portal
,
IconButton
,
Button
,
List
,
ListItem
,
Icon
,
useDisclosure
,
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
iconEastMini
from
'
icons/arrows/east-mini.svg
'
;
import
iconCheck
from
'
icons/check.svg
'
;
import
{
times
}
from
'
lib/html-entities
'
;
const
ContractMethodFieldZeroes
=
()
=>
{
const
[
selectedOption
,
setSelectedOption
]
=
React
.
useState
<
number
>
();
const
{
isOpen
,
onToggle
,
onClose
}
=
useDisclosure
();
const
handleOptionClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
id
=
Number
((
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-id
'
));
if
(
!
Object
.
is
(
id
,
NaN
))
{
setSelectedOption
((
prev
)
=>
prev
===
id
?
undefined
:
id
);
onClose
();
}
},
[
onClose
]);
return
(
<>
{
selectedOption
&&
(
<
Button
px=
{
1
}
lineHeight=
{
6
}
h=
{
6
}
fontWeight=
{
500
}
ml=
{
1
}
variant=
"subtle"
colorScheme=
"gray"
display=
"inline"
_hover=
{
{
color
:
'
inherit
'
}
}
cursor=
"default"
>
{
times
}
<
chakra
.
span
>
10
</
chakra
.
span
>
<
chakra
.
span
fontSize=
"xs"
lineHeight=
{
4
}
verticalAlign=
"super"
>
{
selectedOption
}
</
chakra
.
span
>
</
Button
>
)
}
<
Popover
placement=
"bottom-end"
isLazy
isOpen=
{
isOpen
}
onClose=
{
onClose
}
>
<
PopoverTrigger
>
<
div
>
<
IconButton
transform=
{
isOpen
?
'
rotate(90deg)
'
:
'
rotate(-90deg)
'
}
transitionDuration=
"none"
variant=
"subtle"
colorScheme=
"gray"
as=
{
iconEastMini
}
boxSize=
{
6
}
aria
-
label=
"Open menu"
cursor=
"pointer"
ml=
{
1
}
onClick=
{
onToggle
}
/>
</
div
>
</
PopoverTrigger
>
<
Portal
>
<
PopoverContent
w=
"110px"
>
<
PopoverBody
py=
{
2
}
>
<
List
>
{
[
8
,
12
,
16
,
18
,
20
].
map
((
id
)
=>
(
<
ListItem
key=
{
id
}
py=
{
2
}
data
-
id=
{
id
}
onClick=
{
handleOptionClick
}
display=
"flex"
justifyContent=
"space-between"
alignItems=
"center"
cursor=
"pointer"
>
<
span
>
10*
{
id
}
</
span
>
{
selectedOption
===
id
&&
<
Icon
as=
{
iconCheck
}
boxSize=
{
6
}
color=
"blue.600"
/>
}
</
ListItem
>
))
}
</
List
>
</
PopoverBody
>
</
PopoverContent
>
</
Portal
>
</
Popover
>
</>
);
};
export
default
React
.
memo
(
ContractMethodFieldZeroes
);
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