Update AmountIn.js
This commit is contained in:
118
packages/react-app/src/components/AmountIn.js
vendored
118
packages/react-app/src/components/AmountIn.js
vendored
@@ -1,69 +1,67 @@
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
|
||||
import { chevronDown } from "../assets"; // icon
|
||||
import { useOnClickOutside } from "../utils"; //helps to close menu bar
|
||||
import { chevronDown } from "../assets";
|
||||
import { useOnClickOutside } from "../utils";
|
||||
import styles from "../styles";
|
||||
|
||||
const AmountIn = () => {
|
||||
const [showList, setShowList] = useState(false);
|
||||
const [activeCurrency, setActiveCurrency] = useState("Select");
|
||||
const ref = useRef()
|
||||
const AmountIn = ({ value, onChange, currencyValue, onSelect, currencies, isSwapping }) => {
|
||||
const [showList, setShowList] = useState(false);
|
||||
const [activeCurrency, setActiveCurrency] = useState("Select");
|
||||
const ref = useRef()
|
||||
|
||||
useOnClickOutside(ref, () => setShowList(false))
|
||||
useOnClickOutside(ref, () => setShowList(false))
|
||||
|
||||
useEffect(() => {
|
||||
if (Object.keys(currencies).includes(currencyValue))
|
||||
setActiveCurrency(currencies[currencyValue]);
|
||||
else setActiveCurrency("Select");
|
||||
}, [currencies, currencyValue]);
|
||||
useEffect(() => {
|
||||
if (Object.keys(currencies).includes(currencyValue))
|
||||
setActiveCurrency(currencies[currencyValue]);
|
||||
else setActiveCurrency("Select");
|
||||
}, [currencies, currencyValue]);
|
||||
|
||||
return(
|
||||
<div className={styles.amountContainer}>
|
||||
<input
|
||||
placeholder="0.0"
|
||||
type="number"
|
||||
value={value}
|
||||
disabled={isSwapping}
|
||||
onChange={(e) => typeof onChange === "function" && onChange(e.target.value)}
|
||||
className={styles.amountInput}
|
||||
/>
|
||||
|
||||
<div className="relative" onClick={() => setShowList(!showList)}>
|
||||
<button className={styles.currencyButton}>
|
||||
{activeCurrency}
|
||||
<img
|
||||
src={chevronDown}
|
||||
alt="cheveron-down"
|
||||
className={`w-4 h-4 object-contain ml-2 ${
|
||||
showList ? "rotate-180" : "rotate-0"
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{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>
|
||||
return (
|
||||
<div className={styles.amountContainer}>
|
||||
<input
|
||||
placeholder="0.0"
|
||||
type="number"
|
||||
value={value}
|
||||
disabled={isSwapping}
|
||||
onChange={(e) => typeof onChange === "function" && onChange(e.target.value)}
|
||||
className={styles.amountInput}
|
||||
/>
|
||||
|
||||
<div className="relative" onClick={() => setShowList(!showList)}>
|
||||
<button className={styles.currencyButton}>
|
||||
{activeCurrency}
|
||||
<img
|
||||
src={chevronDown}
|
||||
alt="cheveron-down"
|
||||
className={`w-4 h-4 object-contain ml-2 ${
|
||||
showList ? "rotate-180" : "rotate-0"
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{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>
|
||||
);
|
||||
};
|
||||
|
||||
export default AmountIn;
|
||||
|
||||
Reference in New Issue
Block a user