diff --git a/src/App.js b/src/App.js index 258c261..f081ca6 100644 --- a/src/App.js +++ b/src/App.js @@ -12,6 +12,7 @@ import SPAuditOutput from "./components/SPAuditOutput"; // pages import SearchOutputs from "./pages/SearchOutputs"; import ValidatorsView from "./pages/ValidatorsView"; +import Calculator from "./pages/Calculator"; function App() { @@ -33,6 +34,8 @@ function App() { {/* Validators */} }/> + {/* Calculator */} + }/> diff --git a/src/pages/Calculator.js b/src/pages/Calculator.js new file mode 100644 index 0000000..046dc8c --- /dev/null +++ b/src/pages/Calculator.js @@ -0,0 +1,76 @@ +// react +import React, {useState, useEffect, useRef} from 'react' +import {useParams} from "react-router-dom"; +import SPAssetResultCard from '../components/SPAssetResultCard'; + +// loader +import ScaleLoader from "react-spinners/ScaleLoader"; + +const Calculator = () => { + + // Data vars: + const { CID } = useParams(); + const [data, setData] = useState(null); + const [loading, setLoading] = useState(true); + const [color, setColor] = useState("#39FF14"); + + // Load CID data: + const loadCIDData = () => { + let url = `https://sp-outputs-api.vercel.app/api/cid?record=${CID}`; + console.log(url); + + fetch(url) + .then((res) => res.json()) + .then((data) => + { + console.log(data); + setData(data); + setLoading(!loading); + }); + }; + + const dataLoaded = useRef(false); + + useEffect(() => { + if (!dataLoaded.current) { + loadCIDData(); + dataLoaded.current = true; + } + }, [data, setData]); + + return ( +
+

Green Scores Calculator

+

Inputted CID: {CID}

+ + {/* CID Data */} + {!data ? ( + // Loading Data +
+ +
+ ) : ( + // Map Data results: +
+ {data.assetBlock.map((result, index) => ( +

{Object.entries(result).map(([key, value]) => ( +

+ {key} + {value} +
+ ))} +

+ ))} +
+ )} + {/* End of data mapping */} +
+ ) +} + +export default Calculator;