Skip to content
Open
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
20 changes: 15 additions & 5 deletions components/helpers/preview-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { Button } from "@/registry/nexus-elements/ui/button";
interface PreviewPanelProps {
children: ReactNode;
connectLabel: string;
renderWhenDisconnected?: boolean;
}

export function PreviewPanel({
children,
connectLabel,
renderWhenDisconnected = false,
}: Readonly<PreviewPanelProps>) {
const [mounted, setMounted] = useState(false);
const { status, connector } = useAccount();
const { data: walletClient } = useConnectorClient();
const { nexusSDK, handleInit, loading } = useNexus();
Expand Down Expand Up @@ -60,6 +63,10 @@ export function PreviewPanel({
}
}, [connector, handleInit, initializing, loading, nexusSDK, walletClient]);

useEffect(() => {
setMounted(true);
}, []);

useEffect(() => {
if (
status === "connected" &&
Expand All @@ -74,10 +81,13 @@ export function PreviewPanel({
return (
<div className="w-full">
<div className="flex flex-col w-full items-center justify-center relative">
{(status === "connected" || status === "connecting") && nexusSDK && (
<>{children}</>
)}
{status === "connected" && !nexusSDK && (
{renderWhenDisconnected && mounted && <>{children}</>}
{!renderWhenDisconnected &&
(status === "connected" || status === "connecting") &&
nexusSDK && (
<>{children}</>
)}
{!renderWhenDisconnected && status === "connected" && !nexusSDK && (
<Button
disabled={loading || initializing}
onClick={() => void initializeNexus(false)}
Expand All @@ -89,7 +99,7 @@ export function PreviewPanel({
)}
</Button>
)}
{status !== "connected" && (
{!renderWhenDisconnected && status !== "connected" && (
<p className="text-lg font-semibold">{connectLabel}</p>
)}
</div>
Expand Down
1 change: 0 additions & 1 deletion components/showcase/nexus-one-swap-showcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const NexusOneSwapShowcase = () => {
config={{
mode: "swap",
prefill: {
amount: "1",
source: {
token: USDC_ARBITRUM,
chain: 42161,
Expand Down
7 changes: 6 additions & 1 deletion components/showcase/showcase-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ const ShowcaseWrapper = ({
)}
</div>
) : (
<PreviewPanel connectLabel={connectLabel}>{children}</PreviewPanel>
<PreviewPanel
connectLabel={connectLabel}
renderWhenDisconnected={type === "nexus-one"}
>
{children}
</PreviewPanel>
)}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"postinstall": "fumadocs-mdx"
},
"dependencies": {
"@avail-project/nexus-core": "github:availproject/nexus-sdk#e1cca4979977bd00e930be9d9ff7c75f17d3a9fd",
"@avail-project/nexus-core": "1.5.0",
"@radix-ui/react-accordion": "^1.2.12",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-collapsible": "^1.1.12",
Expand Down
Loading