Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reading component son index #4

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions packages/nextjs/components/index/mxnFetch.tsx
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;
26 changes: 14 additions & 12 deletions packages/nextjs/components/index/protocolNumbers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useState } from "react";
import { quoterABI } from "./abis/uniabis";
import { formatEther } from "viem";
import { useContractRead } from "wagmi";
Expand All @@ -10,11 +10,6 @@ enum FEE_BIPS {
HUNDRED = 10000,
}

/**
* @param path array of token addresses
* @param fees array from FEE_BIPS enum
* @returns hexbytes string `encodePacked` per solidity
*/
export function encodePath(path: string[], fees: FEE_BIPS[]) {
if (path.length != fees.length + 1) {
throw new Error("path/fee lengths do not match");
Expand All @@ -25,7 +20,6 @@ export function encodePath(path: string[], fees: FEE_BIPS[]) {
encoded += String(path[i]).slice(2);
encoded += hexStringFees[i];
}
// encode the path token
encoded += path[path.length - 1].slice(2);
return encoded.toLowerCase();
}
Expand All @@ -50,21 +44,29 @@ const ProtocolNumbers = () => {
abi: quoterABI,
functionName: "quoteExactInput",
args: [path, BigInt(1e18).toString()],
watch: true,
});

const [latestPriceNumber, setLatestPriceNumber] = useState<number | null>(null);

useEffect(() => {
if (quotedAmountOut) {
const amount = parseFloat(formatEther(BigInt(quotedAmountOut.toString())));
setLatestPriceNumber(amount);
}
}, [quotedAmountOut]);

return (
<>
<div className="stats shadow">
<div className="stat">
<div className="stat-title">Precio de 1 Ether</div>
<div className="stat-value">
{quotedAmountOut
? new Intl.NumberFormat("es-MX", { style: "currency", currency: "MXN" }).format(
parseFloat(formatEther(BigInt(quotedAmountOut.toString()))),
)
{latestPriceNumber
? new Intl.NumberFormat("es-MX", { style: "currency", currency: "MXN" }).format(latestPriceNumber)
: "MXN0.00"}
</div>
<div className="stat-desc text-base">En $XOC Mexicanos</div>
<div className="stat-desc text-base">En pesos $XOC</div>
</div>
</div>
</>
Expand Down
43 changes: 43 additions & 0 deletions packages/nextjs/components/index/xocMinted.tsx
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;
41 changes: 23 additions & 18 deletions packages/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Image from "next/image";
import Link from "next/link";
import { benefitOne, benefitTwo } from "../components/index/data";
import type { NextPage } from "next";
import { MagnifyingGlassIcon, SparklesIcon } from "@heroicons/react/24/outline";
import { MetaHeader } from "~~/components/MetaHeader";
import Benefits from "~~/components/index/benefits";
import Cta from "~~/components/index/cta";
import Faq from "~~/components/index/faq";
import Hero from "~~/components/index/hero";
import MXNFetch from "~~/components/index/mxnFetch";
import ProtocolNumbers from "~~/components/index/protocolNumbers";
import SectionTitle from "~~/components/index/sectionTitle";
import Testimonials from "~~/components/index/testimonials";
import XOCMinted from "~~/components/index/xocMinted";
import grow from "~~/public/grow.png";

const Home: NextPage = () => {
Expand Down Expand Up @@ -47,24 +47,29 @@ const Home: NextPage = () => {
</div>
</div>
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<SparklesIcon className="h-8 w-8 fill-secondary" />
<p>
Experiment with{" "}
<Link href="/example-ui" passHref className="link">
Example UI
</Link>{" "}
to build your own UI.
</p>
<MXNFetch />
<div className="text-xl font-semibold">
<p>
Fuente:{" "}
<span className=" text-blue-400 decoration-base-300 decoration-8 font-extrabold">ChainLink </span>
</p>
</div>
</div>
<div className="flex flex-col bg-base-100 px-10 py-10 text-center items-center max-w-xs rounded-3xl">
<MagnifyingGlassIcon className="h-8 w-8 fill-secondary" />
<p>
Explore your local transactions with the{" "}
<Link href="/blockexplorer" passHref className="link">
Block Explorer
</Link>{" "}
tab.
</p>
<XOCMinted />
<div className="text-xl font-semibold">
<p>
Fuente:{" "}
<a
href="https://polygonscan.com/token/0xa411c9aa00e020e4f88bc19996d29c5b7adb4acf"
target="_blank" // Add this attribute
rel="noopener noreferrer" // Add these attributes for security reasons
className="text-purple-400 decoration-base-300 decoration-8 font-extrabold"
>
Polygonscan
</a>
</p>
</div>
</div>
</div>
</div>
Expand Down
Loading