Skip to content

Commit

Permalink
Support switch chain (#22)
Browse files Browse the repository at this point in the history
* feat(network): add darwinia network to the app

* fix(darwinia chain): add transporter

* feat(koi and crab): add koi and crab networks

* fix(text and title): fix logo and text  changes by network changes

* first try

* fix rpc

* Test only crab

* Mainnet is needed for other components

* remove no use code

---------

Co-authored-by: Hamid Roohi <[email protected]>
  • Loading branch information
hackfisher and hamidroohi92 authored Oct 9, 2024
1 parent d016827 commit eb9ca57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Footer from "./footer";

export const Layout: React.FC<{ children: ReactNode }> = (props) => {
return (
<div className="flex flex-col items-center bg-[#000]">
<div className="relative flex flex-col items-center bg-[#000]">
<div className="flex w-full flex-col items-center">
<Image
src="/images/1920bg1.png"
Expand All @@ -22,7 +22,7 @@ export const Layout: React.FC<{ children: ReactNode }> = (props) => {
className="absolute left-0 right-0 top-0 h-[100vh] w-[100vw] object-contain object-left-top"
/>
<Navbar />
<div className="relative z-10 flex w-full justify-center">
<div className="relative z-10 z-10 flex w-full justify-center">
<span className="absolute left-0 top-0 block h-[20px] w-[20px] bg-[#fff]" />
<div className="flex w-full flex-col items-center px-4 py-6 md:w-4/5 md:p-6 lg:w-2/3 xl:py-10 2xl:w-3/5">
{props.children}
Expand Down
21 changes: 14 additions & 7 deletions components/nav/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import Link from "next/link";
import { useState } from "react";
import { MobileNavDialog } from "./mobileNavDialog";
import { NavLink, type INavLink } from "./navLink";
import { useChainId } from "wagmi";

export const Navbar: React.FC = () => {
const [open, setOpen] = useState(false);
const chainId = useChainId();

console.log("chain id", chainId);

const navLinks: INavLink[] = [
// { path: "/", id: "dashboard", name: "Dashboard", icon: IconType.APP_DASHBOARD },
Expand All @@ -23,21 +27,24 @@ export const Navbar: React.FC = () => {

return (
<>
<nav className="h-30 top-0 w-full flex-col gap-2 border-b border-b-neutral-100 p-3 md:px-6 md:pb-0 md:pt-5 lg:gap-3">
<nav className="h-30 top-0 z-10 w-full flex-col gap-2 border-b border-b-neutral-100 p-3 md:px-6 md:pb-0 md:pt-5 lg:gap-3">
<div className="flex w-full items-center justify-between">
<Link
href="/"
className={classNames(
"flex items-center gap-x-3 rounded-full md:rounded-lg",
"flex cursor-pointer items-center gap-x-3 rounded-full md:rounded-lg",
"outline-none focus:outline-none focus-visible:ring focus-visible:ring-primary focus-visible:ring-offset" // focus styles
)}
>
<Image src="/images/logo-icon.png" width="36" height="36" className="shrink-0" alt="Ring Dao" />
{(chainId === 46 || chainId === 701) && (
<Image src="/images/logo-icon.png" width="36" height="36" className="shrink-0" alt="Ring Dao" />
)}
<Image src="/images/logo.png" width="100" height="36" className="shrink-0" alt="Ring Dao" />

{/* <span className="hidden py-1 text-lg font-semibold leading-tight text-[#fff] sm:block md:text-xl">
Aragonette
</span> */}
{chainId === 701 && (
<span className="hidden py-1 text-lg font-semibold leading-tight text-[#fff] sm:block md:text-xl">
Test Version
</span>
)}
</Link>
<div className="z-20 flex items-center gap-x-2">
<div className="shrink-0">
Expand Down
8 changes: 5 additions & 3 deletions context/Web3Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PUB_WALLET_ICON,
PUB_WEB3_ENDPOINT,
} from "@/constants";
import { mainnet } from "viem/chains";
import {mainnet, darwinia, crab} from "viem/chains";

// wagmi config
const metadata = {
Expand All @@ -21,11 +21,13 @@ const metadata = {
};

export const config = createConfig({
chains: [PUB_CHAIN, mainnet],
chains: [PUB_CHAIN, mainnet, darwinia, crab],
ssr: true,
transports: {
[PUB_CHAIN.id]: http(PUB_WEB3_ENDPOINT, { batch: true }),
[mainnet.id]: http(PUB_WEB3_ENDPOINT, { batch: true }),
[mainnet.id]: http(mainnet.rpcUrls.default.http[0], { batch: true }),
[darwinia.id]: http(darwinia.rpcUrls.default.http[0], { batch: true }),
[crab.id]: http(crab.rpcUrls.default.http[0], { batch: true }),
},
connectors: [
walletConnect({
Expand Down

0 comments on commit eb9ca57

Please sign in to comment.