Skip to content

Commit

Permalink
refactor(website): refactor to single component and make pink (#14074)
Browse files Browse the repository at this point in the history
  • Loading branch information
dionysuzx authored Jun 30, 2023
1 parent b331521 commit 8197e0c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 92 deletions.
50 changes: 50 additions & 0 deletions packages/website/components/ConnectToMetamaskButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { taikoChainConfig } from "../constants/taikoChainConfig";

type ConnectButtonProps = {
network: "Sepolia" | "Taiko";
};

async function ConnectToMetamask(network: ConnectButtonProps["network"]) {
if (!(window as any).ethereum) {
alert("Metamask not detected! Install Metamask then try again.");
}
if (
(window as any).ethereum.networkVersion ==
(network === "Sepolia" ? 11155111 : 167005)
) {
alert(`You are already connected to ${network}.`);
}
try {
if (network === "Sepolia") {
await (window as any).ethereum.request({
method: "wallet_switchEthereumChain",
params: [
{
chainId: "0xaa36a7",
},
],
});
} else {
await (window as any).ethereum.request({
method: "wallet_addEthereumChain",
params: [taikoChainConfig],
});
}
} catch (error) {
alert(
"Failed to add the network with wallet_addEthereumChain request. Add the network with https://chainlist.org/ or do it manually. Error log: " +
error.message
);
}
}

export default function ConnectToMetamaskButton(props: ConnectButtonProps) {
return (
<div
onClick={() => ConnectToMetamask(props.network)}
className="hover:cursor-pointer text-neutral-100 bg-[#E81899] hover:bg-[#d1168a] border-solid border-neutral-200 focus:ring-4 focus:outline-none focus:ring-neutral-100 font-medium rounded-lg text-sm px-3 py-2 text-center inline-flex items-center"
>
Connect to {props.network}
</div>
);
}
87 changes: 0 additions & 87 deletions packages/website/components/MetamaskNetworkButton.tsx

This file was deleted.

25 changes: 25 additions & 0 deletions packages/website/constants/taikoChainConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
interface AddEthereumChainParameter {
chainId: string; // A 0x-prefixed hexadecimal string
chainName: string;
nativeCurrency: {
name: string;
symbol: string; // 2-6 characters long
decimals: 18;
};
rpcUrls: string[];
blockExplorerUrls?: string[];
iconUrls?: string[]; // Currently ignored.
}

export const taikoChainConfig: AddEthereumChainParameter = {
chainId: "0x28c5d",
chainName: "Taiko (Alpha-3 Testnet)",
nativeCurrency: {
name: "ETH",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["https://rpc.test.taiko.xyz"],
blockExplorerUrls: ["https://explorer.test.taiko.xyz/"],
iconUrls: [],
};
10 changes: 5 additions & 5 deletions packages/website/pages/docs/reference/rpc-configuration.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ConnectToMetamask from 'components/MetamaskNetworkButton';
import ConnectToMetamaskButton from 'components/ConnectToMetamaskButton';

# RPC configuration

## Sepolia

<ConnectToMetamask buttonText={"Connect to Sepolia"} />
<br/>
<ConnectToMetamaskButton network="Sepolia" />

| Name | Value |
| ------------------ | ---------------------------- |
Expand All @@ -14,8 +14,8 @@ import ConnectToMetamask from 'components/MetamaskNetworkButton';
| Block Explorer URL | https://sepolia.etherscan.io |

## Taiko

<ConnectToMetamask buttonText={"Connect to Taiko"} />
<br/>
<ConnectToMetamaskButton network="Taiko" />

| Name | Value |
| ------------------ | ------------------------------- |
Expand Down

0 comments on commit 8197e0c

Please sign in to comment.