Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ext 3 network dropdown #404

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/atoms/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ export const onRampModalAtom = atomWithURLHash("onRampOpened", false);
export const tokenSlugAtom = atomWithURLHash<string | null>("token", null);

export const activityModalAtom = atomWithURLHash("activityOpened", false);

export const chainIdUrlAtom = atomWithURLHash<number | null>("chainid", null);
20 changes: 13 additions & 7 deletions src/app/components/elements/NetworkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Network } from "core/types";

import { getNetworkIconUrl } from "fixtures/networks";
import { Page, SettingTab } from "app/nav";
import { useAccounts } from "app/hooks";
import { useAccounts, useExplorerLink } from "app/hooks";
import IconedButton from "app/components/elements/IconedButton";
import { ReactComponent as PopoverIcon } from "app/icons/popover.svg";
import { ReactComponent as WalletExplorerIcon } from "app/icons/external-link.svg";
Expand All @@ -31,8 +31,13 @@ const NetworkCard: FC<NetworkCardProps> = ({
onClick,
className,
}) => {
const { currentAccount } = useAccounts();
const explorerLink = useExplorerLink(network);

const [popoverOpened, setPopoverOpened] = useState(false);

const explorerUrl = explorerLink?.address(currentAccount.address);

return (
<DropdownMenu.Root
open={popoverOpened}
Expand Down Expand Up @@ -117,16 +122,17 @@ const NetworkCard: FC<NetworkCardProps> = ({
"flex flex-col",
)}
>
{network.explorerUrls?.length ? (
<PopoverButton
href={network.explorerUrls[0]}
Icon={WalletExplorerIcon}
>
{explorerUrl ? (
<PopoverButton href={explorerUrl} Icon={WalletExplorerIcon}>
Block Explorer
</PopoverButton>
) : null}
<PopoverButton
to={{ page: Page.Settings, setting: SettingTab.Networks }}
to={{
page: Page.Settings,
setting: SettingTab.Networks,
chainid: network.chainId,
}}
Icon={SettingsIcon}
>
Settings
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/screens/settingTabs/Networks.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { FC, useCallback, useMemo, useRef, useState } from "react";
import classNames from "clsx";
import Fuse from "fuse.js";
import { useAtomValue } from "jotai";

import { getNetworkIconUrl } from "fixtures/networks";

import { NETWORK_SEARCH_OPTIONS } from "app/defaults";
import { useLazyAllNetworks } from "app/hooks";
import { chainIdUrlAtom } from "app/atoms";
import { ToastOverflowProvider } from "app/hooks/toast";
import SearchInput from "app/components/elements/SearchInput";
import ScrollAreaContainer from "app/components/elements/ScrollAreaContainer";
Expand All @@ -17,7 +19,9 @@ const Networks: FC = () => {
const allNetworks = useLazyAllNetworks();
const scrollAreaRef = useRef<HTMLDivElement>(null);

const [tab, setTab] = useState<"new" | number | null>(null);
const chainIdUrl = useAtomValue(chainIdUrlAtom);

const [tab, setTab] = useState<"new" | number | null>(chainIdUrl);
const [searchValue, setSearchValue] = useState<string | null>(null);

const fuse = useMemo(
Expand Down
Loading