Code Monkey home page Code Monkey logo

Comments (3)

mcmire avatar mcmire commented on July 28, 2024

Here is some more context for this ticket as well as ideas for how we could implement this ticket.

Currently, NetworkConfigurations (the type of the networkConfigurations property) is defined as Record<string, NetworkConfiguration & { id: string }>.

And NetworkConfiguration is defined as:

{
  rpcUrl: string;
  chainId: Hex;
  ticker: string;
  nickname?: string;
  rpcPrefs?: {
    blockExplorerUrl: string;
  };
}

All of these properties in NetworkConfiguration correspond to the fields that you can provide when you add a new network in MetaMask, and ultimately, they are used to create a custom network client like this:

createAutoManagedNetworkClient({
  type: NetworkClientType.Custom,
  chainId: networkConfiguration.chainId,
  rpcUrl: networkConfiguration.rpcUrl,
  ticker: networkConfiguration.ticker,
})

However, an Infura network configuration is different, because at the moment it is internal and isn't connected to the UI. All we need is the name of the network we want to connect to; once we have that, we can derive chainId and rpcUrl. This is demonstrated by how the Infura network client is created:

createAutoManagedNetworkClient({
  type: NetworkClientType.Infura,
  network,
  infuraProjectId: this.#infuraProjectId,
  chainId: BUILT_IN_NETWORKS[network].chainId,
  ticker: BUILT_IN_NETWORKS[network].ticker,
})

So, we could introduce an Infura network configuration like so:

{
  network: InfuraNetworkType;
}

Putting that together with the existing NetworkConfiguration type, we could have something like:

type CustomNetworkConfiguration = {
  type: NetworkClientType.Custom;
  rpcUrl: string;
  chainId: Hex;
  ticker: string;
  nickname?: string;
  rpcPrefs?: {
    blockExplorerUrl: string;
  };
};

type InfuraNetworkConfiguration = {
  type: NetworkClientType.Infura;
  network: InfuraNetworkType;
};

type NetworkConfiguration = CustomNetworkConfiguration | InfuraNetworkConfiguration;

type NetworkConfigurations = Record<string, NetworkConfiguration & { id: string }>;

Once we have this, we should be able to refactor the existing code which creates the network clients. See #createAutoManagedNetworkClientRegistry, #buildIdentifiedInfuraNetworkClientConfigurations, and #buildIdentifiedCustomNetworkClientConfigurations for more.

from core.

mcmire avatar mcmire commented on July 28, 2024

Moving this back to Product Backlog because it's dependent on the investigatory work I'm doing for #3793.

from core.

mcmire avatar mcmire commented on July 28, 2024

This ticket is being addressed by #4286.

from core.

Related Issues (20)

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.