Update AmountIn.js
This commit is contained in:
27
packages/react-app/src/components/AmountIn.js
vendored
27
packages/react-app/src/components/AmountIn.js
vendored
@@ -6,7 +6,16 @@ import styles from "../styles";
|
|||||||
|
|
||||||
const AmountIn = () => {
|
const AmountIn = () => {
|
||||||
const [showList, setShowList] = useState(false);
|
const [showList, setShowList] = useState(false);
|
||||||
|
const [activeCurrency, setActiveCurrency] = useState("Select");
|
||||||
|
const ref = useRef()
|
||||||
|
|
||||||
|
useOnClickOutside(ref, () => setShowList(false))
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (Object.keys(currencies).includes(currencyValue))
|
||||||
|
setActiveCurrency(currencies[currencyValue]);
|
||||||
|
else setActiveCurrency("Select");
|
||||||
|
}, [currencies, currencyValue]);
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className={styles.amountContainer}>
|
<div className={styles.amountContainer}>
|
||||||
@@ -31,6 +40,24 @@ const AmountIn = () => {
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
{showList && (
|
{showList && (
|
||||||
|
<ul ref={ref} className={styles.currencyList}>
|
||||||
|
{Object.entries(currencies).map(([token, tokenName], index) => (
|
||||||
|
<li
|
||||||
|
key={index}
|
||||||
|
className={`${styles.currencyListItem} ${
|
||||||
|
activeCurrency === tokenName ? "bg-site-dim2" : ""
|
||||||
|
} cursor-pointer`}
|
||||||
|
onClick={() => {
|
||||||
|
if (typeof onSelect === "function") onSelect(token);
|
||||||
|
setActiveCurrency(tokenName);
|
||||||
|
setShowList(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{tokenName}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user