【问题标题】:Adding multiple API calls to a map in reactjs using axios使用 axios 向 reactjs 中的地图添加多个 API 调用
【发布时间】:2022-12-13 09:32:38
【问题描述】:

我需要我的 API 调用来从 moralis 中提取 NFT 数据并将其添加到地图中,以便稍后进行渲染。 这一切都很好,但是对 moralis 的每次调用限制为 100 行。我使用游标分页添加了第二个 API 调用。两个 API 调用都单独工作,但是当我尝试将两者都添加到地图时,它只呈现最近的一个。有没有办法显示集合中的所有内容?提前致谢!!

这是我目前必须调用 API 的代码:

async function callApi() {
        var provider = await web3Modal.connect();
        web3 = new Web3(provider);
        await provider.send('eth_requestAccounts');
        var accounts = await web3.eth.getAccounts();
        account = accounts[0];
        vaultcontract = new web3.eth.Contract(VAULTABI, STAKINGCONTRACT);
        let config = { 'X-API-Key': moralisapikey, 'accept': 'application/json', cursor: '' };
        const nfts0 = await axios.get((moralisapi + `nft/${NFTCONTRACT}/owners?chain=polygon&format=decimal&limit=100`), { headers: config })
            .then(output => {
                const { result } = output.data
                return result;
            })
        const nfts1 = await axios.get((moralisapi + `nft/${NFTCONTRACT}/owners?chain=polygon&format=decimal&limit=100`), { headers: config })
            .then(output => {
                const { result } = output.data
                return result;
            })
        const nfts = (nfts0, nfts1)
        const apicall = await Promise.all(nfts.map(async i => {
            let item = {
                tokenId: i.token_id,
                holder: i.owner_of,
                wallet: account,
            }
            return item
        }))
        const stakednfts = await vaultcontract.methods.tokensOfOwner(account).call()
            .then(id => {
                return id;
            })
        const nftstk = await Promise.all(stakednfts.map(async i => {
            let stkid = {
                tokenId: i,
            }
            return stkid
        }))
        getNfts(apicall)
        getStk(nftstk)
        console.log(apicall);
        setLoadingState('loaded')
    } 

【问题讨论】:

    标签: reactjs api axios pagination moralis


    【解决方案1】:

    pudiste resolver el problema que tenías?, tengo el mismo error que el tuyo :/ puedes ayudarme!!!

    【讨论】:

    猜你喜欢
    • 2019-09-10
    • 1970-01-01
    • 2018-12-07
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    • 2019-11-12
    相关资源
    最近更新 更多