From a283c0409e6e2b818a88302ca193b96723e18267 Mon Sep 17 00:00:00 2001 From: klepi21 Date: Thu, 19 Oct 2023 10:19:16 +0300 Subject: [PATCH] Update ExistingUser.tsx --- .../components/ExistingUser/ExistingUser.tsx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/views/Home/components/ExistingUser/ExistingUser.tsx b/src/views/Home/components/ExistingUser/ExistingUser.tsx index 06c6110..9d79acf 100644 --- a/src/views/Home/components/ExistingUser/ExistingUser.tsx +++ b/src/views/Home/components/ExistingUser/ExistingUser.tsx @@ -35,6 +35,8 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin const [showError, setShowError] = useState(false); const [walletDeletionHash, setWalletDeletionHash] = useState(''); const [balance, setBalance] = useState(null); // Added state for balance + const [price, setPrice] = useState(null); // Added state for price + const handleClickWords = () => { if (isWordsVisible) { @@ -64,7 +66,7 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin useEffect(() => { // Make the API call to fetch balance - fetch(`https://devnet-api.multiversx.com/accounts/${address}`) + fetch(`https://api.multiversx.com/accounts/${address}`) .then((response) => response.json()) .then((data) => { // Update the balance state with the data from the API response @@ -73,8 +75,21 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin .catch((error) => { console.error('Error fetching data:', error); }); + + // Make the API call to fetch the price + fetch('https://devnet-api.multiversx.com/economics') + .then((response) => response.json()) + .then((data) => { + // Update the price state with the data from the API response + setPrice(data.price); + }) + .catch((error) => { + console.error('Error fetching price data:', error); + }); }, [address]); + + return ( @@ -92,7 +107,7 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin Overview {balance === null ? "Loading..." : balance === 0 ? "0 EGLD" : `${balance / Math.pow(10, 18)} EGLD`} - $835.39 USD + {balance === null || price === null ? 'Calculating...' : `$${((balance/ Math.pow(10, 18)) * price).toFixed(2)} USD`} {/* Add other details like percentage change here */} @@ -204,3 +219,7 @@ function ExistingUser({ address, email, secretWords, userGid }: { address: strin } export default ExistingUser; +function setPrice(price: any) { + throw new Error('Function not implemented.'); +} +