@@ -2,8 +2,7 @@ import { ConnectButton, useAddRecentTransaction } from "@rainbow-me/rainbowkit"
2
2
import type { NextPage } from "next"
3
3
import Head from "next/head"
4
4
import styles from "../styles/Home.module.css"
5
- import { useAccount , useContract , useProvider , useSigner } from "wagmi"
6
- import { Contract , Signer } from "ethers"
5
+ import { useContract , useSigner } from "wagmi"
7
6
import NftList from "../components/nft-list"
8
7
import React , { useEffect , useState } from "react"
9
8
import Image from "next/image"
@@ -14,12 +13,15 @@ import {
14
13
RMRKMultiResourceFactoryContractAddress ,
15
14
tokenContractDetails ,
16
15
} from "../constants"
17
- import { deployContract , getOwnedNfts , mintNft } from "../lib/transactions"
16
+ import {
17
+ deployContract ,
18
+ getCollections ,
19
+ getOwnedNfts ,
20
+ mintNft ,
21
+ } from "../lib/transactions"
18
22
19
23
const MultiResource : NextPage = ( ) => {
20
- const provider = useProvider ( )
21
- const { data : signer , isSuccess } = useSigner ( )
22
- const { address, isConnected } = useAccount ( )
24
+ const { data : signer } = useSigner ( )
23
25
const addRecentTransaction = useAddRecentTransaction ( )
24
26
const [ currentRmrkDeployment , setCurrentRmrkDeployment ] = useState < string > ( "" )
25
27
const [ rmrkCollections , setRmrkCollections ] = useState < string [ ] > ( [ ] )
@@ -98,28 +100,10 @@ const MultiResource: NextPage = () => {
98
100
setCurrentRmrkDeployment ( rmrkCollections [ Number ( e . target . value ) ] )
99
101
}
100
102
101
- async function queryCollections ( ) {
102
- if ( signer instanceof Signer ) {
103
- const collections : string [ ] = [ ]
104
- const allCollectionDeployments = await factoryContract . getCollections ( )
105
- for ( let i = 0 ; i < allCollectionDeployments . length ; i ++ ) {
106
- const collection = new Contract (
107
- allCollectionDeployments [ i ] ,
108
- abis . multiResourceAbi ,
109
- provider
110
- )
111
- if ( ( await collection . owner ( ) ) == address ) {
112
- collections . push ( allCollectionDeployments [ i ] )
113
- }
114
- }
115
-
116
- setRmrkCollections ( collections )
117
- }
118
- }
119
-
120
103
const fetchData = ( ) => {
121
- queryCollections ( ) . then ( ( r ) => {
104
+ getCollections ( { signer , factoryContract } ) . then ( ( collections ) => {
122
105
setLoading ( false )
106
+ setRmrkCollections ( collections )
123
107
} )
124
108
if ( currentRmrkDeployment . length > 0 )
125
109
getOwnedNfts ( { signer, contractAddress : currentRmrkDeployment } ) . then (
0 commit comments