Skip to content

Commit

Permalink
Merge pull request #414 from yieldprotocol/fix/actionResponse
Browse files Browse the repository at this point in the history
fix: action response and others
  • Loading branch information
marcomariscal authored Aug 10, 2023
2 parents 6c57723 + b6d1eca commit 93bf18b
Show file tree
Hide file tree
Showing 21 changed files with 543 additions and 378 deletions.
18 changes: 0 additions & 18 deletions src/abi/erc1155ABI.json

This file was deleted.

18 changes: 18 additions & 0 deletions src/abi/erc1155ABI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default [
{
inputs: [
{ internalType: 'address', name: '_owner', type: 'address' },
{ internalType: 'uint256', name: '_id', type: 'uint256' },
],
name: 'balanceOf',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
] as const;
16 changes: 5 additions & 11 deletions src/components/CheckNftOwner.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect, useState } from 'react';
import { BigNumber } from 'ethers';
import { erc721ABI, useAccount, useContractRead } from 'wagmi';
import erc1155ABI from '@/abi/erc1155ABI.json';
import { Address, erc721ABI, useAccount, useContractRead } from 'wagmi';
import { shortenAddress } from '@/utils';
import useBalance from './cactiComponents/hooks/useBalance';

interface Props {
nftAddress: string;
Expand All @@ -21,20 +21,14 @@ export const NftOwner = ({ nftAddress, tokenId }: Props) => {
watch: true,
});

const { data: erc1155Data, isSuccess: is1155ReadSuccess } = useContractRead({
address: nftAddress as `0x${string}`,
abi: erc1155ABI,
functionName: 'balanceOf',
args: [account, BigNumber.from(tokenId)],
watch: true,
});
const { data: erc1155Data } = useBalance(nftAddress as Address, undefined, tokenId);

const isOwner = owner === account;

useEffect(() => {
if (is721ReadSuccess) setOwner(`${erc721Data?.toString()}` || '');
if (is1155ReadSuccess) setOwner(`Your balance: ` + erc1155Data?.toString() || '0');
}, [erc721Data, erc1155Data, is721ReadSuccess, is1155ReadSuccess]);
if (erc1155Data) setOwner(`Your balance: ` + erc1155Data.toString() || '0');
}, [erc721Data, erc1155Data, is721ReadSuccess]);

return (
<div>
Expand Down
Loading

0 comments on commit 93bf18b

Please sign in to comment.