'use client'; import React, { useState } from 'react'; import { ethers } from 'ethers'; import { getContract } from '@/lib/ethers'; // Adjust the path to your ethers helper const FlareFeed = () => { const [feedValue, setFeedValue] = useState(null); const [decimals, setDecimals] = useState(null); const [timestamp, setTimestamp] = useState(null); const handleGetFeed = async () => { try { const contract = getContract(); const feedData = await contract.getFlareFeed(); // Assuming feedData[0] is BigNumber and needs conversion const _feedValue = ethers.utils.formatEther(feedData[0].toString()); // feedData[1] and feedData[2] may be regular numbers (int8 and uint64), so no .toNumber() needed const _decimals = feedData[1]; // No need to convert if it's already an integer const _timestamp = new Date(feedData[2] * 1000).toLocaleString(); // Convert Unix timestamp to readable format setFeedValue(_feedValue); setDecimals(_decimals); setTimestamp(_timestamp); } catch (error) { console.error('Error fetching Flare feed data:', error); } }; return (

Flare Token Feed

{feedValue && (

Feed Value (FLR/USD): {feedValue}

Decimals: {decimals}

Timestamp: {timestamp}

)}
); }; export default FlareFeed;