Skip to content
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
18 changes: 13 additions & 5 deletions apps/dashboard/src/@/components/blocks/NetworkSelectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export function SingleNetworkSelector(props: {
popoverContentClassName?: string;
// if specified - only these chains will be shown
chainIds?: number[];
side?: "left" | "right" | "top" | "bottom";
disableChainId?: boolean;
align?: "center" | "start" | "end";
}) {
const { allChains, idToChain } = useAllChainsData();

Expand Down Expand Up @@ -142,14 +145,17 @@ export function SingleNetworkSelector(props: {
/>
{chain.name}
</span>
<Badge variant="outline" className="gap-2 max-sm:hidden">
<span className="text-muted-foreground">Chain ID</span>
{chain.chainId}
</Badge>

{!props.disableChainId && (
<Badge variant="outline" className="gap-2 max-sm:hidden">
<span className="text-muted-foreground">Chain ID</span>
{chain.chainId}
</Badge>
)}
</div>
);
},
[idToChain],
[idToChain, props.disableChainId],
);

const isLoadingChains = allChains.length === 0;
Expand All @@ -168,6 +174,8 @@ export function SingleNetworkSelector(props: {
className={props.className}
popoverContentClassName={props.popoverContentClassName}
disabled={isLoadingChains}
side={props.side}
align={props.align}
/>
);
}
13 changes: 8 additions & 5 deletions apps/dashboard/src/@/components/blocks/select-with-search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface SelectWithSearchProps
) => boolean;
renderOption?: (option: { value: string; label: string }) => React.ReactNode;
popoverContentClassName?: string;
side?: "left" | "right" | "top" | "bottom";
align?: "center" | "start" | "end";
}

export const SelectWithSearch = React.forwardRef<
Expand Down Expand Up @@ -107,7 +109,7 @@ export const SelectWithSearch = React.forwardRef<
}, [searchValue]);

return (
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen} modal>
<PopoverTrigger asChild>
<Button
ref={ref}
Expand All @@ -118,23 +120,24 @@ export const SelectWithSearch = React.forwardRef<
className,
)}
>
<div className="flex w-full items-center justify-between">
<div className="flex w-full items-center justify-between gap-2">
<span
className={cn(
"text-muted-foreground text-sm",
"truncate text-muted-foreground text-sm",
selectedOption && "text-foreground",
)}
>
{selectedOption?.label || placeholder}
</span>
<ChevronDown className="h-4 cursor-pointer text-muted-foreground" />
<ChevronDown className="size-4 cursor-pointer text-muted-foreground" />
</div>
</Button>
</PopoverTrigger>

<PopoverContent
className={cn("z-[10001] p-0", popoverContentClassName)}
align="center"
align={props.align || "center"}
side={props.side}
sideOffset={10}
onEscapeKeyDown={() => setIsPopoverOpen(false)}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import { ChainIcon } from "components/icons/ChainIcon";
import { TWTable } from "components/shared/TWTable";
import { useTrack } from "hooks/analytics/useTrack";
import { EngineBackendWalletOptions } from "lib/engine";
import { useActiveChainAsDashboardChain } from "lib/v5-adapter";
import {
useActiveChainAsDashboardChain,
useV5DashboardChain,
} from "lib/v5-adapter";
import {
DownloadIcon,
PencilIcon,
Expand All @@ -59,6 +62,7 @@ interface BackendWalletsTableProps {
isPending: boolean;
isFetched: boolean;
authToken: string;
chainId: number;
}

interface BackendWalletDashboard extends BackendWallet {
Expand All @@ -72,19 +76,21 @@ interface BackendWalletBalanceCellProps {
instanceUrl: string;
address: string;
authToken: string;
chainId: number;
}

const BackendWalletBalanceCell: React.FC<BackendWalletBalanceCellProps> = ({
instanceUrl,
address,
authToken,
chainId,
}) => {
const { data: backendWalletBalance } = useEngineBackendWalletBalance({
instanceUrl: instanceUrl,
address,
authToken,
});
const chain = useActiveChainAsDashboardChain();
const chain = useV5DashboardChain(chainId);
if (!chain || !backendWalletBalance) {
return;
}
Expand All @@ -100,7 +106,7 @@ const BackendWalletBalanceCell: React.FC<BackendWalletBalanceCellProps> = ({
</Text>
);

const explorer = chain?.explorers?.[0];
const explorer = chain.blockExplorers?.[0];
if (!explorer) {
return balanceComponent;
}
Expand All @@ -123,6 +129,7 @@ export const BackendWalletsTable: React.FC<BackendWalletsTableProps> = ({
isPending,
isFetched,
authToken,
chainId,
}) => {
const editDisclosure = useDisclosure();
const receiveDisclosure = useDisclosure();
Expand Down Expand Up @@ -163,13 +170,14 @@ export const BackendWalletsTable: React.FC<BackendWalletsTableProps> = ({
instanceUrl={instanceUrl}
address={address}
authToken={authToken}
chainId={chainId}
/>
);
},
id: "balance",
}),
];
}, [instanceUrl, authToken]);
}, [instanceUrl, authToken, chainId]);

const [selectedBackendWallet, setSelectedBackendWallet] =
useState<BackendWallet>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use client";
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
import {
type EngineInstance,
useEngineBackendWallets,
useEngineWalletConfig,
} from "@3rdweb-sdk/react/hooks/useEngine";
import { NetworkSelectorButton } from "components/selects/NetworkSelectorButton";
import Link from "next/link";
import { useState } from "react";
import { useActiveWalletChain } from "thirdweb/react";
import { BackendWalletsTable } from "./backend-wallets-table";
import { CreateBackendWalletButton } from "./create-backend-wallet-button";
import { ImportBackendWalletButton } from "./import-backend-wallet-button";
Expand Down Expand Up @@ -43,6 +45,10 @@ function BackendWalletsSection(props: {
authToken: string;
}) {
const { instance, teamSlug, authToken } = props;
const activeWalletChain = useActiveWalletChain();
const [_chainId, setChainId] = useState<number>();
const chainId = _chainId || activeWalletChain?.id || 1;

const backendWallets = useEngineBackendWallets({
instanceUrl: instance.url,
authToken,
Expand Down Expand Up @@ -105,9 +111,14 @@ function BackendWalletsSection(props: {
<div className="flex justify-end">
<div className="flex items-center gap-2">
<span className="text-sm">Show balance for</span>
{/* TODO - Replace with simple network selector - there's no need for user to switch chain */}
<div className="flex flex-row">
<NetworkSelectorButton />
<SingleNetworkSelector
chainId={chainId}
onChange={setChainId}
className="min-w-40 max-w-52 lg:max-w-60"
popoverContentClassName="!w-[80vw] md:!w-[500px]"
align="end"
/>
</div>
</div>
</div>
Expand All @@ -120,6 +131,7 @@ function BackendWalletsSection(props: {
isPending={backendWallets.isPending}
isFetched={backendWallets.isFetched}
authToken={authToken}
chainId={chainId}
/>
</section>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use client";

import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
import { Spinner } from "@/components/ui/Spinner/Spinner";
import { Button } from "@/components/ui/button";
import {
Expand All @@ -24,7 +26,6 @@ import {
useAllContractList,
} from "@3rdweb-sdk/react/hooks/useRegistry";
import { zodResolver } from "@hookform/resolvers/zod";
import { NetworkSelectorButton } from "components/selects/NetworkSelectorButton";
import { useChainSlug } from "hooks/chains/chainSlug";
import { PlusIcon } from "lucide-react";
import { useState } from "react";
Expand Down Expand Up @@ -82,17 +83,22 @@ const importFormSchema = z.object({
message: "Invalid contract address",
},
),
chainId: z.coerce.number(),
});

function ImportForm() {
const router = useDashboardRouter();
const chainId = useActiveWalletChain()?.id;
const chainSlug = useChainSlug(chainId || 1);
const activeChainId = useActiveWalletChain()?.id;
const [isRedirecting, setIsRedirecting] = useState(false);

const form = useForm({
resolver: zodResolver(importFormSchema),
values: {
contractAddress: "",
chainId: activeChainId || 1,
},
});
const chainSlug = useChainSlug(form.watch("chainId"));
const addToDashboard = useAddContractMutation();
const address = useActiveAccount()?.address;
const registry = useAllContractList(address);
Expand All @@ -107,9 +113,7 @@ function ImportForm() {
<Form {...form}>
<form
onSubmit={form.handleSubmit(async (data) => {
if (!chainId) {
throw new Error("No chain ID");
}
const { chainId } = data;
let contractAddress: string;

try {
Expand Down Expand Up @@ -199,7 +203,11 @@ function ImportForm() {
<div className="h-3" />
<div>
<Label className="mb-3 inline-block">Network</Label>
<NetworkSelectorButton />
<SingleNetworkSelector
chainId={form.watch("chainId")}
onChange={(v) => form.setValue("chainId", v)}
side="top"
/>
</div>

<div className="h-8" />
Expand Down
Loading