-
Notifications
You must be signed in to change notification settings - Fork 3
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 #37 from DyadStablecoin/useLastEthPrice
Use last eth price
- Loading branch information
Showing
7 changed files
with
102 additions
and
37 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
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,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 ( | ||
<div className="flex justify-between items-center"> | ||
<div> | ||
<div className="text-[#737E76]">Price</div> | ||
<div>{lastEthPrice}</div> | ||
</div> | ||
<div> | ||
<SwapRightOutlined /> | ||
</div> | ||
<div className="flex gap-6 items-center justify-center"> | ||
{ethPrice} | ||
<div className="flex gap-1 items-center"> | ||
<div className="text-sm "> | ||
{lastEthPrice - ethPrice < 0 ? ( | ||
<span className="text-green-300">+</span> | ||
) : ( | ||
<span className="text-red-300">-</span> | ||
)} | ||
</div> | ||
<div className="text-sm"> | ||
{Math.abs(round(lastEthPrice - ethPrice, 2))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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,31 @@ | ||
import { SwapRightOutlined } from "@ant-design/icons"; | ||
import useNftSyncSimulation from "../hooks/useNftSyncSimulation"; | ||
|
||
export default function SyncXp({ nft }) { | ||
const { nftAfterSimulation } = useNftSyncSimulation(nft.id); | ||
|
||
return ( | ||
<> | ||
{nftAfterSimulation && ( | ||
<div className="flex justify-between items-center"> | ||
<div> | ||
<div className="text-[#737E76]">XP</div> | ||
<div>{nft.xp}</div> | ||
</div> | ||
<div> | ||
<SwapRightOutlined /> | ||
</div> | ||
<div className="flex gap-6 items-center justify-between"> | ||
{parseInt(nftAfterSimulation[2]._hex)} | ||
<div className="flex gap-1 items-center"> | ||
<div className="text-sm text-green-300">+</div> | ||
<div className="text-sm"> | ||
{parseInt(nftAfterSimulation[2]._hex) - nft.xp} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
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,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 }; | ||
} |
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
487a787
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
frontend – ./
frontend-git-main-dyad.vercel.app
frontend-dyad.vercel.app
frontend-woad-five.vercel.app