-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: getExplorers function and updated Blockscout explorer URL (#19)
- Loading branch information
Showing
4 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NetworksSchema } from "./types"; | ||
import networks from "./networks"; | ||
|
||
export const getExplorers = ( | ||
input: string, | ||
inputType: "address" | "tx", | ||
networkKey: keyof NetworksSchema | ||
): string[] => { | ||
const network = networks[networkKey as keyof typeof networks]; | ||
if (!network) { | ||
throw new Error("Network not found"); | ||
} | ||
|
||
if (!("apps" in network) || !Array.isArray(network.apps)) { | ||
throw new Error("Explorers not available for the provided network"); | ||
} | ||
|
||
const explorerApps = network.apps.filter((app) => app.type === "explorer"); | ||
|
||
const urls: string[] = []; | ||
for (const app of explorerApps) { | ||
if (inputType === "address" && app.address) { | ||
urls.push(app.url + app.address.replace("${address}", input)); | ||
} else if (inputType === "tx" && app.tx) { | ||
urls.push(app.url + app.tx.replace("${tx}", input)); | ||
} | ||
} | ||
|
||
return urls; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./getEndpoints"; | ||
export * from "./getHardhatConfigNetworks"; | ||
export * from "./getSupportedNetworks"; | ||
export * from "./getExplorers"; | ||
export { default as networks } from "./networks"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters