Skip to content

Commit

Permalink
♻️ Amend
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <[email protected]>
  • Loading branch information
pcaversaccio committed Sep 2, 2024
1 parent 5a01df6 commit 27fbf2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ task(
createReceipt[i] = await createReceipt[i].wait();

result[i] = {
network,
network: network,
chainId: chainId.toString(),
contract: hre.config.xdeploy.contract,
txHash: createReceipt[i].hash,
Expand Down Expand Up @@ -199,7 +199,7 @@ task(
);
} catch (err) {
result[i] = {
network,
network: network,
chainId: undefined,
contract: hre.config.xdeploy.contract,
txHash: undefined,
Expand Down Expand Up @@ -290,7 +290,7 @@ task(
createReceipt[i] = await createReceipt[i].wait();

result[i] = {
network,
network: network,
chainId: chainId.toString(),
contract: hre.config.xdeploy.contract,
txHash: createReceipt[i].hash,
Expand Down Expand Up @@ -332,7 +332,7 @@ task(
);
} catch (err) {
result[i] = {
network,
network: network,
chainId: undefined,
contract: hre.config.xdeploy.contract,
txHash: undefined,
Expand Down
36 changes: 13 additions & 23 deletions src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// List of supported networks with corresponding block explorers
// List of supported networks with corresponding block explorer links
export const networksInfo = {
localhost: "N/A",
hardhat: "N/A",
Expand Down Expand Up @@ -91,30 +91,20 @@ export const networksInfo = {
zetaChainMain: "https://explorer.zetachain.com/",
} as const;

// Define a type `SupportedNetwork` that represents the union of all possible network names
// from the `networksInfo` object. This type ensures that any value assigned to a variable
// of type `SupportedNetwork` is a valid network key in `networksInfo`. It provides
// compile-time safety by preventing the use of unsupported or misspelled network names,
// allowing us to catch potential errors early and ensure consistency when working with
// network-specific functions or data
export type SupportedNetwork = keyof typeof networksInfo;

export const networks = Object.keys(networksInfo);

export const explorers = Object.values(networksInfo);

export const getTxHashLink = (network: SupportedNetwork, hash: string) => {
const explorer = networksInfo[network] as string;

if (network.slice(0, 8) == "filecoin") {
return `${explorer}message/${hash}`;
} else if (network.slice(0, 16) == "seiArcticTestnet") {
return `${explorer}transactions/${hash}`;
}

return `${explorer}tx/${hash}`;
};

export const getAddressLink = (network: SupportedNetwork, address: string) => {
const explorer = networksInfo[network] as string;

if (network.slice(0, 16) == "seiArcticTestnet") {
return `${explorer}account/${address}`;
}
// Generate the transaction hash link
export const getTxHashLink = (network: SupportedNetwork, hash: string) =>
`${networksInfo[network]}${network.startsWith("filecoin") ? "message" : network === "seiArcticTestnet" ? "transactions" : "tx"}/${hash}`;

return `${explorer}address/${address}`;
};
// Generate the contract address link
export const getAddressLink = (network: SupportedNetwork, address: string) =>
`${networksInfo[network]}${network === "seiArcticTestnet" ? "account" : "address"}/${address}`;

0 comments on commit 27fbf2b

Please sign in to comment.