Skip to content

Commit

Permalink
Merge pull request #14 from SharifElfouly/bug/conversion-error
Browse files Browse the repository at this point in the history
fix conversion error
  • Loading branch information
shafu0x authored Oct 7, 2022
2 parents 3dcf240 + 2d55bdc commit 78f3777
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/components/Deposit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Deposit({ tokenId, reload, setReload, onClose }) {
addressOrName: CONTRACT_dNFT,
contractInterface: dNFTabi,
functionName: "deposit",
args: [tokenId, dyad ? String(dyad * 10 ** 21) : "0"],
args: [tokenId, dyad ? String(dyad * 10 ** 18) : "0"],
onError: (error) => {
console.log("error deposit", error);
},
Expand Down Expand Up @@ -54,8 +54,8 @@ export default function Deposit({ tokenId, reload, setReload, onClose }) {
args: [address, CONTRACT_dNFT],
onSuccess: (data) => {
const allowance = parseInt(data._hex);
console.log("allowance", allowance / 10 ** 21);
setIsApproved(allowance / 10 ** 21 >= parseFloat(dyad));
console.log("allowance", allowance / 10 ** 18);
setIsApproved(allowance / 10 ** 18 >= parseFloat(dyad));
},
});

Expand Down
26 changes: 15 additions & 11 deletions src/components/NFT.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export default function NFT({

const { address } = useAccount();

const [rank, setRank] = useState();
const [xp, setXP] = useState();
const [dyad, setDyad] = useState();
const [dyadBalance, setDyadBalance] = useState();

const [tokenId, setTokenId] = useState();

const { isOpen, onOpen, onClose } = useDisclosure();
const {
isOpen: isOpenSync,
Expand Down Expand Up @@ -60,8 +61,9 @@ export default function NFT({
},
],
onSuccess: (data) => {
console.log("tokenOfOwnerByIndex", parseInt(data[0]._hex));
if (data && data[0]) {
setRank(parseInt(data[0]._hex));
setTokenId(parseInt(data[0]._hex));
}
},
});
Expand All @@ -72,19 +74,19 @@ export default function NFT({
addressOrName: CONTRACT_dNFT,
contractInterface: abi,
functionName: "xp",
args: [rank],
args: [tokenId],
},
{
addressOrName: CONTRACT_dNFT,
contractInterface: abi,
functionName: "dyadMinted",
args: [rank],
args: [tokenId],
},
{
addressOrName: CONTRACT_dNFT,
contractInterface: abi,
functionName: "virtualDyadBalance",
args: [rank],
args: [tokenId],
},
],
onSuccess: (data) => {
Expand Down Expand Up @@ -112,7 +114,7 @@ export default function NFT({
#{calcRank(xps, xp)}
</td>
<td style={TD}> {formatUSD(dNFT_PRICE)} </td>
<td style={TD}>{dyad && dyad / 10 ** 21} </td>
<td style={TD}>{dyad && Math.round((dyad / 10 ** 18) * 100) / 100} </td>
<td style={TD}>
<div className="flex flex-col text-s" style={{ color: borderColor }}>
<div>
Expand All @@ -127,7 +129,9 @@ export default function NFT({
<td style={TD}>
<Button onClick={onOpen}>mint</Button>
</td>
<td style={TD}>{dyadBalance && dyadBalance / 10 ** 21}</td>
<td style={TD}>
{dyadBalance && Math.round((dyadBalance / 10 ** 18) * 100) / 100}{" "}
</td>
<td style={TD}>
<Button onClick={onOpenDeposit}>deposit</Button>
</td>
Expand All @@ -146,30 +150,30 @@ export default function NFT({
</tr>
<Popup isOpen={isOpen} onClose={onClose}>
<Mint
tokenId={rank}
tokenId={tokenId}
reload={reload}
setReload={setReload}
onClose={onClose}
/>
</Popup>
<Popup isOpen={isOpenDeposit} onClose={onCloseDeposit}>
<Deposit
tokenId={rank}
tokenId={tokenId}
reload={reload}
setReload={setReload}
onClose={onCloseDeposit}
/>
</Popup>
<Popup isOpen={isOpenWithdraw} onClose={onCloseWithdraw}>
<Withdraw
tokenId={rank}
tokenId={tokenId}
reload={reload}
setReload={setReload}
onClose={onCloseWithdraw}
/>
</Popup>
<Popup isOpen={isOpenSync} onClose={onCloseSync}>
<Sync address={address} tokenId={rank} />
<Sync address={address} tokenId={tokenId} />
</Popup>
</>
);
Expand Down
5 changes: 1 addition & 4 deletions src/components/Withdraw.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Withdraw({ tokenId, reload, setReload, onClose }) {
addressOrName: CONTRACT_dNFT,
contractInterface: abi,
functionName: "withdraw",
args: [tokenId, dyad ? String(dyad * 10 ** 21) : "0"],
args: [tokenId, dyad ? String(dyad * 10 ** 18) : "0"],
onError: (error) => {
console.log("error", error);
},
Expand Down Expand Up @@ -67,12 +67,9 @@ export default function Withdraw({ tokenId, reload, setReload, onClose }) {
</div>
<div className="">$DYAD</div>
</div>
{/* <div>to</div> */}
{/* <div className="text-2xl">${wETH * ethToUSD} ETH</div> */}
<Button
isDisabled={!write}
onClick={() => {
console.log(4444);
write?.();
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/consts/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
// export const CONTRACT_dNFT = "0xecb504d39723b0be0e3a9aa33d646642d1051ee1";

// goerli
export const CONTRACT_dNFT = "0x4FE817eA30e3aA39B2Fc9CdD06623BBECC357D6b";
export const CONTRACT_DYAD = "0x5665610c733070c228714157e5daEDDD756d1F28";
export const CONTRACT_dNFT = "0xEf569857eF000566272cDfc5Bf5E8681f347A871";
export const CONTRACT_DYAD = "0x23D4b7E8A70F844E23C734F7405A32103ffA24D7";

1 comment on commit 78f3777

@vercel
Copy link

@vercel vercel bot commented on 78f3777 Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.