-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #425 from deltaDAO/feat/form-whitelist
feat: add whitelist & blacklist inputs
- Loading branch information
Showing
15 changed files
with
213 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/components/@shared/FormInput/InputElement/Credential/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.addressListContainer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: calc(var(--spacer) / 4); | ||
margin-top: calc(var(--spacer) / 2); | ||
} |
86 changes: 86 additions & 0 deletions
86
src/components/@shared/FormInput/InputElement/Credential/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useField } from 'formik' | ||
import React, { useState, ChangeEvent, FormEvent, useEffect } from 'react' | ||
import Button from '../../../atoms/Button' | ||
import styles from './index.module.css' | ||
import { isAddress } from 'ethers/lib/utils.js' | ||
import { toast } from 'react-toastify' | ||
import InputGroup from '../../InputGroup' | ||
import InputElement from '..' | ||
import { InputProps } from '../..' | ||
|
||
export default function Credentials(props: InputProps) { | ||
const [field, meta, helpers] = useField(props.name) | ||
const [addressList, setAddressList] = useState<string[]>(field.value || []) | ||
const [value, setValue] = useState('') | ||
|
||
useEffect(() => { | ||
helpers.setValue(addressList) | ||
}, [addressList]) | ||
|
||
function handleDeleteAddress(value: string) { | ||
const newInput = addressList.filter((input) => input !== value) | ||
setAddressList(newInput) | ||
helpers.setValue(newInput) | ||
} | ||
|
||
function handleAddValue(e: FormEvent<HTMLButtonElement>) { | ||
e.preventDefault() | ||
if (!isAddress(value)) { | ||
toast.error('Wallet address is invalid') | ||
return | ||
} | ||
if (addressList.includes(value.toLowerCase())) { | ||
toast.error('Wallet address already added into hte list') | ||
return | ||
} | ||
setAddressList((addressList) => [...addressList, value.toLowerCase()]) | ||
setValue('') | ||
} | ||
|
||
return ( | ||
<div> | ||
<InputGroup> | ||
<InputElement | ||
name="address" | ||
placeholder={props.placeholder} | ||
value={value} | ||
onChange={(e: ChangeEvent<HTMLInputElement>) => | ||
setValue(e.target.value) | ||
} | ||
/> | ||
<Button | ||
style="primary" | ||
size="small" | ||
onClick={(e: FormEvent<HTMLButtonElement>) => { | ||
e.preventDefault() | ||
handleAddValue(e) | ||
}} | ||
> | ||
Add | ||
</Button> | ||
</InputGroup> | ||
<div> | ||
{addressList.length > 0 && | ||
addressList.map((value, i) => { | ||
return ( | ||
<div className={styles.addressListContainer} key={value}> | ||
<InputGroup> | ||
<InputElement name={`address[${i}]`} value={value} disabled /> | ||
<Button | ||
style="primary" | ||
size="small" | ||
onClick={(e: React.SyntheticEvent) => { | ||
e.preventDefault() | ||
handleDeleteAddress(value) | ||
}} | ||
> | ||
Remove | ||
</Button> | ||
</InputGroup> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters