Skip to content

Commit

Permalink
Merge pull request #172 from terraswap/hotfix/chains.json
Browse files Browse the repository at this point in the history
hotfix: load chains.json from terra.dev
  • Loading branch information
JoowonYun authored Aug 21, 2023
2 parents 82f801c + 1256e61 commit 71768b2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/layouts/WalletConnectProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
useWallet,
WalletProvider,
getChainOptions,
WalletControllerChainOptions,
} from "@terra-money/wallet-provider"
import React, { PropsWithChildren, useEffect, useState } from "react"
Expand All @@ -10,6 +9,7 @@ import { useModal } from "components/Modal"
import ConnectListModal from "./ConnectListModal"
import { ConnectModalProvider } from "hooks/useConnectModal"
import { LCDClient } from "@terra-money/terra.js"
import { getChainOptions } from "libs/getChainOptions"

const WalletConnectProvider: React.FC<PropsWithChildren<{}>> = ({
children,
Expand Down
69 changes: 69 additions & 0 deletions src/libs/getChainOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
NetworkInfo,
WalletControllerChainOptions,
} from "@terra-money/wallet-provider"

type Response = Record<string, NetworkInfo>

const fallbackData = {
mainnet: {
name: "mainnet",
chainID: "phoenix-1",
lcd: "https://phoenix-lcd.terra.dev",
api: "https://phoenix-api.terra.dev",
hive: "https://phoenix-hive.terra.dev/graphql",
walletconnectID: 1,
},
classic: {
name: "classic",
chainID: "columbus-5",
lcd: "https://terra-classic-lcd.publicnode.com",
api: "https://terra-classic-public-api.publicnode.com",
mantle: "https://columbus-mantle.terra.dev",
walletconnectID: 2,
},
testnet: {
name: "testnet",
chainID: "pisco-1",
lcd: "https://pisco-lcd.terra.dev",
api: "https://pisco-api.terra.dev",
hive: "https://pisco-hive.terra.dev/graphql",
walletconnectID: 0,
},
localterra: {
name: "localterra",
chainID: "localterra",
lcd: "http://localhost:1317",
mantle: "http://localhost:1337",
walletconnectID: -1,
},
}
export async function getChainOptions() {
let data: Response
try {
data = (await (
await fetch("https://assets.terra.dev/chains.json")
).json()) as Response
} catch (error) {
console.log(error)
data = fallbackData
}
const chains = Object.values(data)
const walletConnectChainIds = chains.reduce<
WalletControllerChainOptions["walletConnectChainIds"]
>((result, network) => {
if (typeof network.walletconnectID === "number") {
result[network.walletconnectID] = network
} else if (!result[1] && network.name === "mainnet") {
result[1] = network
} else if (!result[0] && network.name === "testnet") {
result[0] = network
}
return result
}, {})
const chainOptions: WalletControllerChainOptions = {
defaultNetwork: walletConnectChainIds[1],
walletConnectChainIds,
}
return chainOptions
}

0 comments on commit 71768b2

Please sign in to comment.