diff --git a/src/components/NFT.jsx b/src/components/NFT.jsx index e3ffb07..4ed9490 100644 --- a/src/components/NFT.jsx +++ b/src/components/NFT.jsx @@ -96,12 +96,7 @@ export default function NFT({ index, xps, xpsAverage }) { /> - + )} diff --git a/src/components/Sync.jsx b/src/components/Sync.jsx index c4c84c8..665741c 100644 --- a/src/components/Sync.jsx +++ b/src/components/Sync.jsx @@ -3,11 +3,12 @@ import { useContractWrite, usePrepareContractWrite } from "wagmi"; import { CONTRACT_POOL } from "../consts/contract"; import PopupContent from "./PopupContent"; import useGasCost from "../hooks/useGasCost"; -import { SwapRightOutlined } from "@ant-design/icons"; import useNftSyncSimulation from "../hooks/useNftSyncSimulation"; import { DOCS_URL } from "../consts/consts"; +import SyncLastEthPrice from "./SyncLastEthPrice"; +import SyncXp from "./SyncXp"; -export default function Sync({ onClose, setTxHash, tokenId, nft }) { +export default function Sync({ onClose, setTxHash, nft }) { const { config } = usePrepareContractWrite({ addressOrName: CONTRACT_POOL, contractInterface: PoolABI["abi"], @@ -23,7 +24,7 @@ export default function Sync({ onClose, setTxHash, tokenId, nft }) { }); const { gasCost } = useGasCost(config); - const { nftAfterSimulation, isLoading } = useNftSyncSimulation(tokenId); + const { isLoading } = useNftSyncSimulation(nft.id); return ( window.open(DOCS_URL + "/pool#sync")} >
- {nftAfterSimulation && ( - <> -
-
Before
-
After
-
-
-
-
XP
-
{nft.xp}
-
-
- -
-
- {parseInt(nftAfterSimulation[2]._hex)} -
-
+
-
- {parseInt(nftAfterSimulation[2]._hex) - nft.xp} -
-
-
-
-
- - )} + <> +
+
Before
+
After
+
+ + +
+
+ help sync ALL DYAD NFT's for all players!
diff --git a/src/components/SyncLastEthPrice.jsx b/src/components/SyncLastEthPrice.jsx new file mode 100644 index 0000000..aab770e --- /dev/null +++ b/src/components/SyncLastEthPrice.jsx @@ -0,0 +1,36 @@ +import { SwapRightOutlined } from "@ant-design/icons"; +import useEthPrice from "../hooks/useEthPrice"; +import useLastEthPrice from "../hooks/useLastEthPrice"; +import { round } from "../utils/currency"; + +export default function SyncLastEthPrice() { + const { ethPrice } = useEthPrice(); + const { lastEthPrice } = useLastEthPrice(); + + return ( +
+
+
Price
+
{lastEthPrice}
+
+
+ +
+
+ {ethPrice} +
+
+ {lastEthPrice - ethPrice < 0 ? ( + + + ) : ( + - + )} +
+
+ {Math.abs(round(lastEthPrice - ethPrice, 2))} +
+
+
+
+ ); +} diff --git a/src/components/SyncXp.jsx b/src/components/SyncXp.jsx new file mode 100644 index 0000000..60a0c8a --- /dev/null +++ b/src/components/SyncXp.jsx @@ -0,0 +1,31 @@ +import { SwapRightOutlined } from "@ant-design/icons"; +import useNftSyncSimulation from "../hooks/useNftSyncSimulation"; + +export default function SyncXp({ nft }) { + const { nftAfterSimulation } = useNftSyncSimulation(nft.id); + + return ( + <> + {nftAfterSimulation && ( +
+
+
XP
+
{nft.xp}
+
+
+ +
+
+ {parseInt(nftAfterSimulation[2]._hex)} +
+
+
+
+ {parseInt(nftAfterSimulation[2]._hex) - nft.xp} +
+
+
+
+ )} + + ); +} diff --git a/src/hooks/useEthPrice.js b/src/hooks/useEthPrice.js index 95bc69a..c022aa2 100644 --- a/src/hooks/useEthPrice.js +++ b/src/hooks/useEthPrice.js @@ -9,7 +9,6 @@ export default function useEthPrice() { "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=BTC,USD,EUR" ); const data = await res.json(); - console.log("data", data); setEthPrice(data.USD); } diff --git a/src/hooks/useLastEthPrice.js b/src/hooks/useLastEthPrice.js new file mode 100644 index 0000000..4630a76 --- /dev/null +++ b/src/hooks/useLastEthPrice.js @@ -0,0 +1,19 @@ +import { useState } from "react"; +import { useContractRead } from "wagmi"; +import { CONTRACT_POOL } from "../consts/contract"; +import poolABI from "../abi/Pool.json"; + +export default function useLastEthPrice() { + const [lastEthPrice, setLastEthPrice] = useState(0); + + const { refetch } = useContractRead({ + addressOrName: CONTRACT_POOL, + contractInterface: poolABI["abi"], + functionName: "lastEthPrice", + onSuccess: (data) => { + setLastEthPrice(parseInt(data._hex) / 10 ** 8); + }, + }); + + return { refetch, lastEthPrice }; +} diff --git a/src/hooks/useNft.js b/src/hooks/useNft.js index f2064c1..3e0c032 100644 --- a/src/hooks/useNft.js +++ b/src/hooks/useNft.js @@ -8,6 +8,7 @@ export default function useNft(id) { withdrawn: 0, deposit: 0, xp: 0, + id: id, }); const { refetch, isLoading, isFetching } = useContractRead({ @@ -20,6 +21,7 @@ export default function useNft(id) { withdrawn: parseInt(data[0]._hex), deposit: parseInt(data[1]._hex), xp: parseInt(data[2]._hex), + id: id, }); }, });