Git Product home page Git Product logo

redux-multicall's Issues

Improve multichain support

Currently, this lib's interface (Updater + hooks) were designed with the intention of using 1 active chain at a time.
For consumers using multiple active chains, this requires inelegant solutions to use multiple copies of the hooks at once.

Explore options for supporting multiple chains in an efficient way with a consumer-friendly interface.

What determines blockPerfetch?

Currently using this package on a layer 2 Blockchain and I'm wondering what value to set for blockPerfetch as I don't know the parameters to consider.

For context, the blockchain Is Nahmii blockchain

Improved error messaging for LOADING_CALL_STATE

Hi, been experimenting using the multicall library in conjunction with the web3-react library. Ran into some difficulties with the build version, namely that in utils/callState.ts, we have:

export function toCallState(
  callResult: CallResult | undefined,
  contractInterface: utils.Interface | undefined,
  fragment: utils.FunctionFragment | undefined,
  latestBlockNumber: number | undefined
): CallState {
  if (!callResult) return INVALID_CALL_STATE
  const { valid, data, blockNumber } = callResult
  if (!valid) return INVALID_CALL_STATE
  if (valid && !blockNumber) return LOADING_CALL_STATE
  if (!contractInterface || !fragment || !latestBlockNumber) return LOADING_CALL_STATE

LOADING_CALL_STATE in particular covers several options:

  • missing values in the initial contract call (contractinterface, fragment, latestblocknumber)
  • missing blocknumber from the redux actions

The blockNumber is particularly challenging, as it is computed from several prior hooks and related function calls (useCallDataSubscription > callKeysToCalls > toCallKey), which results in:

// result =
        return { valid: true, data, blockNumber: result?.blockNumber }

So, as a user, I might suspect I'm missing the blockNumber in the result, but it's challenging to understand exactly where the error in the contract call might be, that we can fix in order to move the call from LOADING_CALL_STATE.

Would welcome some initial feedback on the causes of the above, then would be happy to start working on a PR.

Articles for react-mulitcall

I wrote a series of comprehensive articles for anyone strugling to use this library in their application
Part A - Explains what redux-multicall is and why you should use it: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-a-b263b14ac
Part B - A practical guide to setting up redux-multicall for use in your dApp: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-b-e92cccb0f2e6
Part C - Build a simple dApp that shows actual usage of redux-multicall for data fetching in your dApp: https://ajayimike.medium.com/a-guide-to-redux-multicall-building-a-real-time-dapp-part-c-89a9c11eba76

Bad setState call inside Updater

I am receiving an error when attempting to use Multicall Updater similar to the implementation in uniswap-interface

import React from 'react'
import { combineReducers, createStore } from 'redux'

import { createMulticall } from '@uniswap/redux-multicall'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from '../constants/chains'
import { useInterfaceMulticall } from '../hooks/useContract'
import useBlockNumber from '../contexts/BlockNumberContext'

const multicall = createMulticall()
const reducer = combineReducers({ [multicall.reducerPath]: multicall.reducer })

export default multicall

function getBlocksPerFetchForChainId(chainId): number {
  switch (chainId) {
    case SupportedChainId.RINKEBY:
    case SupportedChainId.ROPSTEN:
      return 5
    default:
      return 1
  }
}

export function MulticallUpdater() {
  const { chainId } = useWeb3React()
  const latestBlockNumber = useBlockNumber()
  const contract = useInterfaceMulticall()
  
  const listenerOptions = React.useMemo(
    () => ({
      blocksPerFetch: getBlocksPerFetchForChainId(chainId),
    }),
    [chainId]
  )

  return (
    <multicall.Updater
      chainId={chainId}
      latestBlockNumber={latestBlockNumber}
      contract={contract}
      listenerOptions={listenerOptions}
    />
  )
}
 Warning: Cannot update a component (`Updater`) while rendering a different component (`Updater`)

Stack Trace

Warning: Cannot update a component (`Updater`) while rendering a different component (`Updater`). To locate the bad setState() call inside `Updater`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
    at Updater
    at UpdaterContextBound
    at MulticallUpdater 
    at Updaters
    at BlockNumberProvider
    at Web3ReactProvider 
    at UserPreferencesProvider
    at Provider

Versions

node v16.8.10
react v18.2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.