[SOLVED] Arranging nfts owned by wallet into approved vs not approved arrays

Hi all I am having a bit of an issue solving the problem described. I get success up until the approved.push/notApproved.push points. Also I would like to see if there’s a simpler approach of doing what I am trying to do.

if a tokenAddress is approved/not approved by the owner to the contract I will need tokenIds included in the objects of the array. Kindly direct me if possible

const {data: nfts} = useEvmWalletNFTs ({address, chain: "5"})

    //place in json format
    const nfToken = [];
    
    if (nfts !== undefined ){
     
    for (let i = 0; i < nfts.length; i++){
      nfToken.push(nfts[i].toJSON())
    }
    console.log(nfToken)
   
    }

    //reduce duplicates
      let tokens = []

      
    if (nfts?.length > 0 && nfts?.length === nfToken?.length){
      for (let i = 0; i< nfToken.length; i++){
        tokens.push(nfToken[i].tokenAddress)
      }
    console.log(tokens)}

    let unique = []
    if(tokens.length === nfToken.length && nfToken?.length > 0 ){
      
    tokens.forEach(element => {
        if (!unique.includes(element)) {
            unique.push(element);
        }
    });
    
    }
    console.log(unique)
    
    useEffect(()=>{
      if(nfToken.length==tokens.length, nftAbi && seaport){
        approvalCheck()
      }
    },[nfToken, seaport,nftAbi])
 //check which nfts are approved
  const {fetch, data} = useEvmRunContractFunction()

  console.log(data)
   let approved = []
   let notApproved =[]
    async function approvalCheck() {
      for(let i = 0; i < unique.length; i++)
      {
        await fetch({
          abi: nftAbi,
          address: unique[i],
          functionName: "isApprovedForAll",
          params: {
              owner: address,
              operator: contractAddress,
          },
          chain: "5"
      })
      console.log(data)
      if (data == true || "true")
      {
        approved.push(unique[i], data)
      }
      else{
        notApproved.push(unique[i], data)
      }
        
      }   
  }
  console.log(approved)
  console.log(notApproved)

solved - no need to respond thanks

1 Like