diff --git a/template/web/app/buy-me-coffee/_components/FormBuyCoffee.tsx b/template/web/app/buy-me-coffee/_components/FormBuyCoffee.tsx index 0b147d19..51e28df9 100644 --- a/template/web/app/buy-me-coffee/_components/FormBuyCoffee.tsx +++ b/template/web/app/buy-me-coffee/_components/FormBuyCoffee.tsx @@ -37,6 +37,17 @@ function FormBuyCoffee({ refetchMemos }: FormBuyCoffeeProps) { const contract = useBuyMeACoffeeContract(); const { fields, setField, resetFields } = useFields(initFields); + const [ethPrice, setEthPrice] = useState(null); + + useEffect(() => { + const fetchEthPrice = async () => { + const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd'); + const data = await response.json(); + setEthPrice(data.ethereum.usd); + }; + + fetchEthPrice(); + }, []); const reset = useCallback(async () => { resetFields(); @@ -87,6 +98,7 @@ function FormBuyCoffee({ refetchMemos }: FormBuyCoffeeProps) { )} // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop onClick={() => setField('coffeeCount', count)} + title={`${(GAS_COST * count).toFixed(4)} ETH / $${ethPrice ? (GAS_COST * count * ethPrice).toFixed(2) : 'loading...'} `} > {count} @@ -134,16 +146,16 @@ function FormBuyCoffee({ refetchMemos }: FormBuyCoffeeProps) { -