diff --git a/app/page.tsx b/app/page.tsx index b4956d5..e75da47 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,6 +7,7 @@ import GetEventImages from '@/components/sc/getEventImages'; import GetEventTickets from '@/components/sc/getEventTickets'; import BuyTicket from '@/components/sc/buyTicket'; import TransferTicket from '@/components/sc/transferTicket'; +import CentsToFlare from '@/components/sc/centsToFlare'; export default function Home() { return ( @@ -47,6 +48,8 @@ export default function Home() { + +
{ + const [cents, setCents] = useState(''); + const [flareValue, setFlareValue] = useState(null); + const [isWalletConnected, setIsWalletConnected] = useState(false); + const [walletAddress, setWalletAddress] = useState(null); + + // Connect Wallet + const handleConnectWallet = async () => { + if (typeof window.ethereum !== 'undefined' && window.ethereum.request) { + try { + const accounts = await window.ethereum.request({ + method: 'eth_requestAccounts', + }); + if (accounts.length > 0) { + setIsWalletConnected(true); + setWalletAddress(accounts[0]); + console.log('Wallet connected:', accounts[0]); + } + } catch (error) { + console.error('Error connecting to wallet:', error); + } + } else { + alert('Please install MetaMask or another Ethereum wallet'); + } + }; + + // Call centsToFlare function from smart contract + const handleConvertCentsToFlare = async () => { + if (!cents) { + alert('Please enter a value in cents.'); + return; + } + + try { + const provider = new ethers.providers.Web3Provider(window.ethereum); + const contract = getContract().connect(provider); + + // Convert cents to equivalent FLR + const flareValueInWei = await contract.centsToFlare(cents); + const flareValueInEth = ethers.utils.formatEther(flareValueInWei); // Convert Wei to FLR (Ether format) + + setFlareValue(flareValueInEth); + console.log('Equivalent in FLR:', flareValueInEth); + } catch (error) { + console.error('Error converting cents to FLR:', error); + setFlareValue(null); + } + }; + + return ( +
+

Cents to FLR Converter

+ {!isWalletConnected ? ( + + ) : ( +
+

Connected Wallet: {walletAddress}

+ setCents(e.target.value)} + className="border p-2 mb-2" + /> + + + {flareValue && ( +

+ Equivalent in FLR: {flareValue} FLR +

+ )} +
+ )} +
+ ); +}; + +export default CentsToFlare;