Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Use Alchemy in production
Alexis Sellier committed 4 years ago
commit b6537bf2ce92309a50adca7bfcff60275c0f4b7f
parent 4cb4be4e6ba0e315a6daa97e63fd0fd45225a0ca
2 files changed +15 -15
modified src/config.json
@@ -41,6 +41,7 @@
    },
    "tokens": []
  },
+
  "alchemy": { "key": "cQFlLK8EokIGlJhd_soImwEyUoC7Ec8r" },
  "ceramic": { "api": "https://ceramic-clay.3boxlabs.com" },
  "radicle": { "api": "http://0.0.0.0:8888" },
  "ipfs": { "gateway": "https://ipfs.io/ipfs/" },
modified src/config.ts
@@ -35,16 +35,25 @@ export class Config {

  constructor(
    network: { name: string; chainId: number },
-
    provider: ethers.providers.JsonRpcProvider,
+
    provider: ethers.providers.JsonRpcProvider | null,
    signer: ethers.Signer & TypedDataSigner | null,
  ) {
    const cfg = (<Record<string, any>> config)[network.name];
    const api = config.radicle.api;

-
    if (!cfg) {
+
    if (! cfg) {
      throw `Network ${network.name} is not supported`;
    }

+
    // Use Alchemy in production, on mainnet.
+
    provider = network.name === "homestead" && import.meta.env.PROD
+
      ? new ethers.providers.AlchemyProvider(network.name, config.alchemy.key)
+
      : provider;
+

+
    if (! provider) {
+
      throw `No Web3 provider available.`;
+
    }
+

    const ceramic = new CeramicClient(config.ceramic.api);
    const idx = new IDX({ ceramic });

@@ -94,25 +103,15 @@ function isMetamaskInstalled(): boolean {

export async function getConfig(): Promise<Config> {
  let config: Config;
-
  const alchemyApiKey = import.meta.env.RADICLE_ALCHEMY_API_KEY;

  if (isMetamaskInstalled()) {
-
    // If we have Metamask, use it as the signer, but try to use Alchemy
-
    // as the provider.
    const metamask = new ethers.providers.Web3Provider(window.ethereum);
    const network = await metamask.ready;
-
    const provider = alchemyApiKey
-
      ? new ethers.providers.AlchemyProvider(network.name, alchemyApiKey)
-
      : metamask;
-

-
    config = new Config(network, provider, metamask.getSigner());
+
    config = new Config(network, metamask, metamask.getSigner());
  } else {
-
    // If we don't have Metamask, we use Alchemy as the provider, and we don't
-
    // provide a signer. We default to Homestead.
+
    // If we don't have Metamask, we default to Homestead.
    const network = { name: "homestead", chainId: 1 };
-
    const provider = new ethers.providers.AlchemyProvider(network.name, alchemyApiKey);
-

-
    config = new Config(network, provider, null);
+
    config = new Config(network, null, null);
  }
  console.log(config);