import React from ‘react’
import axios from “axios”;
const NativeTokens = ({wallet,chain,nativeBalance,nativeValue,setNativeBalance,setNativeValue}) => {
const getNativeBalance = async () => {
    try {
      const response = await axios.get("http://localhost:8080/nativeBalance", {
        params: {
          address: wallet,
          chain: chain,
        },
      });
 
      console.log(response);    
      if (response.data.balance && response.data.usd) {
        setNativeBalance((Number(response.data.balance) / 1e18).toFixed(3));
        setNativeValue(((Number(response.data.balance) / 1e18) * Number(response.data.usd)).toFixed(2));
       
      }
    } catch (error) {
      console.error("Error occurred while fetching native balance:", error);
     
    }
  };
 
return (
    <>
    <h1>Fetch Tokens</h1>
    <p>
      <button onClick={getNativeBalance}>Fetch Balance</button>
      <br />
      <span>
        Native Balance: {nativeBalance}, (${nativeValue})
      </span>
    </p>
  </>
)
}
export default NativeTokens
      
    