-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from La-DAO/read
Added reading components on index
- Loading branch information
Showing
4 changed files
with
125 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { houseOfReserveABI } from "../xoc-dapp/abis/xocabis"; | ||
import { formatEther } from "viem"; | ||
import { useContractRead } from "wagmi"; | ||
|
||
const MXNFetch: React.FC = () => { | ||
const [latestPrice, setLatestPrice] = useState<any>(null); | ||
const [latestPriceNumber, setLatestPriceNumber] = useState<number | bigint | any>(null); | ||
const { data: latestPriceData } = useContractRead({ | ||
address: "0xd411BE9A105Ea7701FabBe58C2834b7033EBC203", // House of Reserve (WETH) | ||
abi: houseOfReserveABI, | ||
functionName: "getLatestPrice", | ||
watch: true, | ||
}); | ||
|
||
useEffect(() => { | ||
if (latestPriceData) { | ||
setLatestPrice(latestPriceData); | ||
} | ||
}, [latestPriceData]); | ||
|
||
useEffect(() => { | ||
if (latestPrice) { | ||
setLatestPriceNumber(parseFloat(formatEther(BigInt(latestPrice?.toString() + "1000000000"))).toFixed(2)); | ||
} | ||
}, [latestPrice]); | ||
|
||
// Render the latest price data | ||
return ( | ||
<> | ||
<div className="stats shadow"> | ||
<div className="stat"> | ||
<div className="stat-title">Precio de 1 Ether</div> | ||
<div className="stat-value"> | ||
{latestPriceNumber && | ||
new Intl.NumberFormat("es-MX", { style: "currency", currency: "MXN" }).format(latestPriceNumber)} | ||
</div> | ||
<div className="stat-desc text-base">En pesos $MXN</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default MXNFetch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { approveABI } from "../xoc-dapp/abis/xocabis"; | ||
import { formatEther } from "viem"; | ||
import { useContractRead } from "wagmi"; | ||
|
||
const XOCMinted: React.FC = () => { | ||
const [latestMinted, setLatestMinted] = useState<any>(null); | ||
const [latestMintedNumber, setLatestMintedNumber] = useState<number | bigint | any>(null); | ||
const { data: latestMintedData } = useContractRead({ | ||
address: "0xa411c9Aa00E020e4f88Bc19996d29c5B7ADB4ACf", // House of Reserve (WETH) | ||
abi: approveABI, | ||
functionName: "totalSupply", | ||
watch: true, | ||
}); | ||
|
||
useEffect(() => { | ||
if (latestMintedData) { | ||
setLatestMinted(latestMintedData); | ||
} | ||
}, [latestMintedData]); | ||
|
||
useEffect(() => { | ||
if (latestMinted) { | ||
const formattedNumber = parseFloat(formatEther(BigInt(latestMinted?.toString()))).toFixed(2); | ||
const formattedString = parseFloat(formattedNumber).toLocaleString("en-US"); | ||
setLatestMintedNumber(formattedString); | ||
} | ||
}, [latestMinted]); | ||
// Render the latest price data | ||
return ( | ||
<> | ||
<div className="stats shadow"> | ||
<div className="stat"> | ||
<div className="stat-title">$XOC Minted</div> | ||
<div className="stat-value">{latestMintedNumber}</div> | ||
<div className="stat-desc text-base">in Polygon</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default XOCMinted; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters