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
1abfc6b4
Unverified
Commit
1abfc6b4
authored
Jun 20, 2022
by
tom goriunov
Committed by
GitHub
Jun 20, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12 from tom2drum/validation
fields limits and validation
parents
e68aa5d2
10b29dab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
10 deletions
+41
-10
AddressModal.tsx
components/AddressModal/AddressModal.tsx
+41
-10
No files found.
components/AddressModal/AddressModal.tsx
View file @
1abfc6b4
...
...
@@ -22,6 +22,7 @@ import {
import
type
{
TWatchlistItem
}
from
'
../../data/watchlist
'
;
const
NOTIFICATIONS
=
[
'
xDAI
'
,
'
ERC-20
'
,
'
ERC-721, ERC-1155 (NFT)
'
];
const
ADDRESS_LENGTH
=
42
;
type
Props
=
{
isOpen
:
boolean
;
...
...
@@ -36,15 +37,34 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
const
[
address
,
setAddress
]
=
useState
<
string
>
();
const
[
tag
,
setTag
]
=
useState
<
string
>
();
const
[
notification
,
setNotification
]
=
useState
<
boolean
>
();
const
[
addressError
,
setAddressError
]
=
useState
<
boolean
>
(
false
);
const
isValidAddress
=
(
address
:
string
)
=>
address
.
length
===
ADDRESS_LENGTH
;
useEffect
(()
=>
{
setAddress
(
data
?.
address
);
setAddressError
(
false
);
setTag
(
data
?.
tag
);
setNotification
(
data
?.
notification
);
},
[
data
]);
const
onAddressChange
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
setAddress
(
event
.
target
.
value
),
[
setAddress
]);
const
onTagChange
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
setTag
(
event
.
target
.
value
),
[
setTag
]);
const
onAddressChange
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
if
(
addressError
&&
isValidAddress
(
event
.
target
.
value
))
{
setAddressError
(
false
);
}
setAddress
(
event
.
target
.
value
);
},
[
addressError
]);
const
validateAddress
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
if
(
!
isValidAddress
(
event
.
target
.
value
))
{
setAddressError
(
true
);
}
},
[
]);
const
onTagChange
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
setTag
(
event
.
target
.
value
)
},
[
]);
const
onNotificationChange
=
useCallback
((
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
setNotification
(
event
.
target
.
checked
),
[
setNotification
]);
const
onButtonClick
=
useCallback
(()
=>
{
...
...
@@ -53,22 +73,33 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
onClose
()
},
[
address
,
tag
,
notification
,
onClose
]);
const
title
=
data
?
'
Edit watchlist address
'
:
'
New Address to Watchlist
'
;
return
(
<
Modal
isOpen=
{
isOpen
}
onClose=
{
onClose
}
size=
"md"
>
<
ModalOverlay
/>
<
ModalContent
>
<
ModalHeader
fontWeight=
"500"
>
New Address to Watchlist
</
ModalHeader
>
<
ModalHeader
fontWeight=
"500"
>
{
title
}
</
ModalHeader
>
<
ModalCloseButton
/>
<
ModalBody
>
{
!
data
&&
(
<
Text
lineHeight=
"30px"
marginBottom=
"40px"
>
An Email notification can be sent to you when an address on your watch list sends or receives any transactions.
</
Text
>
)
}
<
FormControl
variant=
"floating"
id=
"address"
marginBottom=
"20px"
isRequired
>
<
Input
placeholder=
" "
onChange=
{
onAddressChange
}
value=
{
address
||
''
}
/>
<
Input
placeholder=
" "
onChange=
{
onAddressChange
}
value=
{
address
||
''
}
isInvalid=
{
addressError
}
onBlur=
{
validateAddress
}
maxLength=
{
ADDRESS_LENGTH
}
/>
<
FormLabel
>
Address (0x...)
</
FormLabel
>
</
FormControl
>
<
FormControl
variant=
"floating"
id=
"tag"
marginBottom=
"30px"
isRequired
>
<
Input
placeholder=
" "
onChange=
{
onTagChange
}
value=
{
tag
||
''
}
/>
<
Input
placeholder=
" "
onChange=
{
onTagChange
}
value=
{
tag
||
''
}
maxLength=
{
35
}
/>
<
FormLabel
>
Private tag (max 35 characters)
</
FormLabel
>
</
FormControl
>
<
Text
color=
"gray.600"
fontSize=
"14px"
marginBottom=
"32px"
>
...
...
@@ -98,8 +129,8 @@ const AddressModal: React.FC<Props> = ({ isOpen, onClose, data }) => {
</
ModalBody
>
<
ModalFooter
justifyContent=
"flex-start"
>
<
Button
colorScheme=
"blue"
onClick=
{
onButtonClick
}
>
Add address
<
Button
colorScheme=
"blue"
onClick=
{
onButtonClick
}
disabled=
{
addressError
}
>
{
data
?
'
Save changes
'
:
'
Add address
'
}
</
Button
>
</
ModalFooter
>
</
ModalContent
>
...
...
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