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
353 changes: 148 additions & 205 deletions apps/dashboard/src/@/components/blocks/BuyAndSwapEmbed.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function TokenInfoSection(props: {
<dt className="text-xs font-medium text-muted-foreground tracking-wider uppercase">
{props.label}
</dt>
<dd className="text-3xl font-bold text-foreground tracking-tight">
<dd className="text-3xl font-semibold text-foreground tracking-tight">
{props.value}
</dd>
</dl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function UniversalBridgeEmbed(props: {
swapTab: BuyAndSwapEmbedProps["swapTab"];
pageType: "bridge" | "bridge-iframe";
currency?: SupportedFiatCurrency;
showThirdwebBranding?: boolean;
}) {
return (
<BuyAndSwapEmbed
Expand All @@ -34,6 +35,7 @@ export function UniversalBridgeEmbed(props: {
swapTab={props.swapTab}
pageType={props.pageType}
wallets={bridgeWallets}
showThirdwebBranding={props.showThirdwebBranding}
/>
);
}
16 changes: 16 additions & 0 deletions apps/dashboard/src/app/bridge/widget/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ export default async function Page(props: {
// output is buy, input is sell
const sellChain = parse(searchParams.inputChain, onlyNumber);
const sellCurrency = parse(searchParams.inputCurrency, onlyAddress);
const sellAmount = parse(searchParams.inputCurrencyAmount, onlyNumber);

const buyChain = parse(searchParams.outputChain, onlyNumber);
const buyCurrency = parse(searchParams.outputCurrency, onlyAddress);
const buyAmount = parse(searchParams.outputCurrencyAmount, onlyNumber);

const showThirdwebBranding = parse(
searchParams.showThirdwebBranding,
(v) => v !== "false",
);

const persistTokenSelections =
parse(searchParams.persistTokenSelections, (v) =>
Expand All @@ -61,11 +68,14 @@ export default async function Page(props: {
persistTokenSelections={persistTokenSelections === "true"}
pageType="bridge-iframe"
currency={currency}
showThirdwebBranding={showThirdwebBranding}
buyTab={{
buyToken: buyChain
? {
chainId: buyChain,
tokenAddress: buyCurrency || NATIVE_TOKEN_ADDRESS,
amount:
buyAmount === undefined ? undefined : buyAmount.toString(),
}
: undefined,
}}
Expand All @@ -74,12 +84,18 @@ export default async function Page(props: {
? {
chainId: sellChain,
tokenAddress: sellCurrency || NATIVE_TOKEN_ADDRESS,
amount:
sellAmount === undefined
? undefined
: sellAmount.toString(),
}
: undefined,
buyToken: buyChain
? {
chainId: buyChain,
tokenAddress: buyCurrency || NATIVE_TOKEN_ADDRESS,
amount:
buyAmount === undefined ? undefined : buyAmount.toString(),
}
: undefined,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function ChatPageContent(props: {
const userChainIdArray = userChainIds
.split(",")
.map((id) => id.trim())
.filter((id) => id !== "" && !isNaN(Number(id)));
.filter((id) => id !== "" && !Number.isNaN(Number(id)));

return {
chainIds:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use client";

import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
import { TabButtons } from "../../../../components/ui/tab-buttons";
import { LeftSection } from "./left-section";
import { RightSection } from "./right-section";
import type { BridgeWidgetPlaygroundOptions } from "./types";

const defaultOptions: BridgeWidgetPlaygroundOptions = {
integrationType: "iframe",
prefill: undefined,
currency: "USD",
showThirdwebBranding: true,
theme: {
darkColorOverrides: {},
lightColorOverrides: {},
type: "dark",
},
};

export function BridgeWidgetPlayground() {
const { theme } = useTheme();

const [options, setOptions] =
useState<BridgeWidgetPlaygroundOptions>(defaultOptions);

// change theme on global theme change
useEffect(() => {
setOptions((prev) => ({
...prev,
theme: {
...prev.theme,
type: theme === "dark" ? "dark" : "light",
},
}));
}, [theme]);

return (
<div>
<TabButtons
tabs={[
{
name: "Iframe",
onClick: () =>
setOptions({ ...options, integrationType: "iframe" }),
isActive: options.integrationType === "iframe",
},
{
name: "Script",
onClick: () =>
setOptions({ ...options, integrationType: "script" }),
isActive: options.integrationType === "script",
},
{
name: "React",
onClick: () =>
setOptions({ ...options, integrationType: "component" }),
isActive: options.integrationType === "component",
},
]}
/>

<div className="h-6" />

<div className="relative flex flex-col-reverse gap-6 xl:min-h-[900px] xl:flex-row xl:gap-6">
<div className="grow border-b pb-10 xl:mb-0 xl:border-r xl:border-b-0 xl:pr-6">
<LeftSection options={options} setOptions={setOptions} />
</div>
<RightSection options={options} />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { BridgeWidgetPlaygroundOptions } from "./types";

const BRIDGE_WIDGET_IFRAME_BASE_URL = "https://thirdweb.com/bridge/widget";

export function buildIframeUrl(
options: BridgeWidgetPlaygroundOptions,
type: "code" | "preview",
) {
const url = new URL(BRIDGE_WIDGET_IFRAME_BASE_URL);

if (type === "preview") {
// always set it to false so playground doesn't show last used tokens
url.searchParams.set("persistTokenSelections", "false");
}

// Theme (only add if light, dark is default)
if (options.theme.type === "light") {
url.searchParams.set("theme", "light");
}

// Currency (only add if not USD, USD is default)
if (options.currency && options.currency !== "USD") {
url.searchParams.set("currency", options.currency);
}

// Branding
if (options.showThirdwebBranding === false) {
url.searchParams.set("showThirdwebBranding", "false");
}

// Sell token (input)
if (options.prefill?.sellToken) {
url.searchParams.set(
"inputChain",
String(options.prefill.sellToken.chainId),
);
if (options.prefill.sellToken.tokenAddress) {
url.searchParams.set(
"inputCurrency",
options.prefill.sellToken.tokenAddress,
);
}
if (options.prefill.sellToken.amount) {
url.searchParams.set(
"inputCurrencyAmount",
options.prefill.sellToken.amount,
);
}
}

// Buy token (output)
if (options.prefill?.buyToken) {
url.searchParams.set(
"outputChain",
String(options.prefill.buyToken.chainId),
);
if (options.prefill.buyToken.tokenAddress) {
url.searchParams.set(
"outputCurrency",
options.prefill.buyToken.tokenAddress,
);
}
if (options.prefill.buyToken.amount) {
url.searchParams.set(
"outputCurrencyAmount",
options.prefill.buyToken.amount,
);
}
}

return url.toString();
}
Loading
Loading