diff --git a/packages/react-app/src/components/AmountIn.js b/packages/react-app/src/components/AmountIn.js index aeca9d6..da8d4bf 100644 --- a/packages/react-app/src/components/AmountIn.js +++ b/packages/react-app/src/components/AmountIn.js @@ -8,7 +8,7 @@ const AmountIn = () => { const [showList, setShowList] = useState(false); const [activeCurrency, setActiveCurrency] = useState("Select"); const ref = useRef() - + useOnClickOutside(ref, () => setShowList(false)) useEffect(() => { diff --git a/packages/react-app/src/components/AmountOut.js b/packages/react-app/src/components/AmountOut.js index e69de29..698b621 100644 --- a/packages/react-app/src/components/AmountOut.js +++ b/packages/react-app/src/components/AmountOut.js @@ -0,0 +1,67 @@ +import React, { useState, useEffect, useRef } from "react"; +import { formatUnits } from "ethers/lib/utils"; + +import { chevronDown } from "../assets"; +import { useAmountsOut, useOnClickOutside } from "../utils"; +import styles from "../styles"; + +const AmountOut = ({ fromToken, toToken, amountIn, pairContract, currencyValue, onSelect, currencies }) => { + const [showList, setShowList] = useState(false); + const [activeCurrency, setActiveCurrency] = useState("Select"); + const ref = useRef() + + const amountOut = useAmountsOut(pairContract, amountIn, fromToken, toToken) ?? 0; + + useOnClickOutside(ref, () => setShowList(false)) + + useEffect(() => { + if (Object.keys(currencies).includes(currencyValue)) { + setActiveCurrency(currencies[currencyValue]); + } else { + setActiveCurrency("Select") + } + }, [currencyValue, currencies]); + + return ( +
+ + +
setShowList(!showList)}> + + + {showList && ( + + )} +
+
+ ); +}; + +export default AmountOut; diff --git a/packages/react-app/src/components/Balance.js b/packages/react-app/src/components/Balance.js index e69de29..dacba32 100644 --- a/packages/react-app/src/components/Balance.js +++ b/packages/react-app/src/components/Balance.js @@ -0,0 +1,24 @@ +import React from "react"; +import { formatUnits, parseUnits } from "ethers/lib/utils"; + +import styles from "../styles"; + +const Balance = ({ tokenBalance }) => { + + return ( +
+

+ {tokenBalance ? ( + <> + Balance: + {formatUnits(tokenBalance ?? parseUnits("0"))} + + ) : ( + "" + )} +

+
+ ); +}; + +export default Balance;