Skip to content

Revert "brige embed (#7222)" #7345

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

Merged
merged 1 commit into from
Jun 16, 2025
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
5 changes: 0 additions & 5 deletions .changeset/icy-eyes-show.md

This file was deleted.

4 changes: 1 addition & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Welcome, AI copilots! This guide captures the coding standards, architectural de
- Biome governs formatting and linting; its rules live in biome.json.
- Run pnpm biome check --apply before committing.
- Avoid editor‑specific configs; rely on the shared settings.
- make sure everything builds after each file change by running `pnpm build`


Expand All @@ -40,8 +39,7 @@ Welcome, AI copilots! This guide captures the coding standards, architectural de
- Co‑locate tests: foo.ts ↔ foo.test.ts.
- Use real function invocations with stub data; avoid brittle mocks.
- For network interactions, use Mock Service Worker (MSW) to intercept fetch/HTTP calls, mocking only scenarios that are hard to reproduce.
- Keep tests deterministic and side‑effect free; Vitest is pre‑configured.
- to run the tests: `cd packages thirdweb & pnpm test:dev <filename>`
- Keep tests deterministic and side‑effect free; Jest is pre‑configured.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export function PayModalButton(props: {
payOptions={{
onPurchaseSuccess(info) {
if (
info?.type === "crypto" &&
info?.status.status !== "NOT_FOUND"
info.type === "crypto" &&
info.status.status !== "NOT_FOUND"
) {
trackEvent({
category: "pay",
Expand All @@ -58,7 +58,7 @@ export function PayModalButton(props: {
});
}

if (info?.type === "fiat" && info.status.status !== "NOT_FOUND") {
if (info.type === "fiat" && info.status.status !== "NOT_FOUND") {
trackEvent({
category: "pay",
action: "buy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function PayPageEmbed({
onPurchaseSuccess: (result) => {
if (!redirectUri) return;
const url = new URL(redirectUri);
switch (result?.type) {
switch (result.type) {
case "crypto": {
url.searchParams.set("status", result.status.status);
if (
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/buttons/MismatchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const MismatchButton = forwardRef<
payOptions={{
onPurchaseSuccess(info) {
if (
info?.type === "crypto" &&
info.type === "crypto" &&
info.status.status !== "NOT_FOUND"
) {
trackEvent({
Expand All @@ -308,7 +308,7 @@ export const MismatchButton = forwardRef<
}

if (
info?.type === "fiat" &&
info.type === "fiat" &&
info.status.status !== "NOT_FOUND"
) {
trackEvent({
Expand Down
3 changes: 1 addition & 2 deletions apps/playground-web/src/app/connect/pay/commerce/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function BuyMerch() {
sellerAddress: "0xEb0effdFB4dC5b3d5d3aC6ce29F3ED213E95d675",
},
metadata: {
name: "Black Hoodie",
description: "Size L. Ships worldwide.",
name: "Black Hoodie (Size L)",
image: "/drip-hoodie.png",
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type PayEmbedPlaygroundOptions = {
mode?: "fund_wallet" | "direct_payment" | "transaction";
title: string | undefined;
image: string | undefined;
description: string | undefined;

// fund_wallet mode options
buyTokenAddress: string | undefined;
Expand Down
20 changes: 0 additions & 20 deletions apps/playground-web/src/app/connect/pay/embed/LeftSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,26 +496,6 @@ export function LeftSection(props: {
/>
</div>
</div>

{/* Modal description */}
<div className="flex flex-col gap-2">
<Label htmlFor="modal-description">Image</Label>
<Input
id="modal-description"
placeholder="Your own description here"
className="bg-card"
value={options.payOptions.description}
onChange={(e) =>
setOptions((v) => ({
...v,
payOptions: {
...payOptions,
description: e.target.value,
},
}))
}
/>
</div>
</div>
</CollapsibleSection>

Expand Down
16 changes: 6 additions & 10 deletions apps/playground-web/src/app/connect/pay/embed/RightSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,15 @@ export function RightSection(props: {
(props.options.payOptions.mode === "transaction"
? "Transaction"
: props.options.payOptions.mode === "direct_payment"
? "Product Name"
? "Purchase"
: "Buy Crypto"),
description:
props.options.payOptions.description || "Your own description here",
image:
props.options.payOptions.image ||
props.options.payOptions.mode === "direct_payment"
? `https://placehold.co/600x400/${
props.options.theme.type === "dark"
? "1d1d23/7c7a85"
: "f2eff3/6f6d78"
}?text=Your%20Product%20Here&font=roboto`
: undefined,
`https://placehold.co/600x400/${
props.options.theme.type === "dark"
? "1d1d23/7c7a85"
: "f2eff3/6f6d78"
}?text=Your%20Product%20Here&font=roboto`,
},

// Mode-specific options
Expand Down
1 change: 0 additions & 1 deletion apps/playground-web/src/app/connect/pay/embed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const defaultConnectOptions: PayEmbedPlaygroundOptions = {
mode: "fund_wallet",
title: "",
image: "",
description: "",
buyTokenAddress: NATIVE_TOKEN_ADDRESS,
buyTokenAmount: "0.01",
buyTokenChain: base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export function BuyMerchPreview() {
},
metadata: {
name: "Black Hoodie (Size L)",
description: "Size L. Ships worldwide.",
image: "/drip-hoodie.png",
},
}}
Expand Down
3 changes: 1 addition & 2 deletions packages/thirdweb/knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"src/exports/**",
"scripts/**/*.{ts,mjs}",
"src/cli/bin.ts",
"src/transaction/actions/send-batch-transaction.ts",
"src/react/core/hooks/useBridgeRoutes.ts"
"src/transaction/actions/send-batch-transaction.ts"
],
"project": ["src/**/*.{ts,tsx}", "scripts/**/*.mjs"],
"ignore": ["src/**/__generated__/**", "**/*.bench.ts"],
Expand Down
1 change: 0 additions & 1 deletion packages/thirdweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@
"@radix-ui/react-focus-scope": "1.1.7",
"@radix-ui/react-icons": "1.3.2",
"@radix-ui/react-tooltip": "1.2.7",
"@storybook/react": "9.0.8",
"@tanstack/react-query": "5.80.7",
"@thirdweb-dev/engine": "workspace:*",
"@thirdweb-dev/insight": "workspace:*",
Expand Down
5 changes: 0 additions & 5 deletions packages/thirdweb/src/bridge/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
sortBy,
limit,
offset,
includePrices,
} = options;

const clientFetch = getClientFetch(client);
Expand Down Expand Up @@ -160,9 +159,6 @@ export async function routes(options: routes.Options): Promise<routes.Result> {
if (sortBy) {
url.searchParams.set("sortBy", sortBy);
}
if (includePrices) {
url.searchParams.set("includePrices", includePrices.toString());
}

const response = await clientFetch(url.toString());
if (!response.ok) {
Expand All @@ -189,7 +185,6 @@ export declare namespace routes {
transactionHash?: ox__Hex.Hex;
sortBy?: "popularity";
maxSteps?: number;
includePrices?: boolean;
limit?: number;
offset?: number;
};
Expand Down
83 changes: 1 addition & 82 deletions packages/thirdweb/src/bridge/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {

export declare namespace tokens {
/**
* Input parameters for {@link tokens}.
* Input parameters for {@link Bridge.tokens}.
*/
type Options = {
/** Your {@link ThirdwebClient} instance. */
Expand All @@ -182,84 +182,3 @@ export declare namespace tokens {
*/
type Result = Token[];
}

/**
* Adds a token to the Universal Bridge for indexing.
*
* This function requests the Universal Bridge to index a specific token on a given chain.
* Once indexed, the token will be available for cross-chain operations.
*
* @example
* ```typescript
* import { Bridge } from "thirdweb";
*
* // Add a token for indexing
* const result = await Bridge.add({
* client: thirdwebClient,
* chainId: 1,
* tokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
* });
* ```
*
* @param options - The options for adding a token.
* @param options.client - Your thirdweb client.
* @param options.chainId - The chain ID where the token is deployed.
* @param options.tokenAddress - The contract address of the token to add.
*
* @returns A promise that resolves when the token has been successfully submitted for indexing.
*
* @throws Will throw an error if there is an issue adding the token.
* @bridge
* @beta
*/
export async function add(options: add.Options): Promise<add.Result> {
const { client, chainId, tokenAddress } = options;

const clientFetch = getClientFetch(client);
const url = `${getThirdwebBaseUrl("bridge")}/v1/tokens`;

const requestBody = {
chainId,
tokenAddress,
};

const response = await clientFetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(requestBody),
});

if (!response.ok) {
const errorJson = await response.json();
throw new ApiError({
code: errorJson.code || "UNKNOWN_ERROR",
message: errorJson.message || response.statusText,
correlationId: errorJson.correlationId || undefined,
statusCode: response.status,
});
}

const { data }: { data: Token } = await response.json();
return data;
}

export declare namespace add {
/**
* Input parameters for {@link add}.
*/
type Options = {
/** Your {@link ThirdwebClient} instance. */
client: ThirdwebClient;
/** The chain ID where the token is deployed. */
chainId: number;
/** The contract address of the token to add. */
tokenAddress: string;
};

/**
* The result returned from {@link Bridge.add}.
*/
type Result = Token;
}
2 changes: 1 addition & 1 deletion packages/thirdweb/src/bridge/types/BridgeAction.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type Action = "approval" | "transfer" | "buy" | "sell" | "fee";
export type Action = "approval" | "transfer" | "buy" | "sell";
11 changes: 0 additions & 11 deletions packages/thirdweb/src/bridge/types/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { stringify } from "../../utils/json.js";

type ErrorCode =
| "INVALID_INPUT"
| "ROUTE_NOT_FOUND"
Expand All @@ -24,13 +22,4 @@ export class ApiError extends Error {
this.correlationId = args.correlationId;
this.statusCode = args.statusCode;
}

override toString() {
return stringify({
code: this.code,
message: this.message,
statusCode: this.statusCode,
correlationId: this.correlationId,
});
}
}
4 changes: 2 additions & 2 deletions packages/thirdweb/src/pay/buyWithFiat/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@
provider?: FiatProvider,
): "stripe" | "coinbase" | "transak" => {
switch (provider) {
case "stripe":
case "STRIPE":

Check warning on line 294 in packages/thirdweb/src/pay/buyWithFiat/getQuote.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithFiat/getQuote.ts#L294

Added line #L294 was not covered by tests
return "stripe";
case "transak":
case "TRANSAK":

Check warning on line 296 in packages/thirdweb/src/pay/buyWithFiat/getQuote.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/pay/buyWithFiat/getQuote.ts#L296

Added line #L296 was not covered by tests
return "transak";
default: // default to coinbase when undefined or any other value
return "coinbase";
Expand Down
8 changes: 4 additions & 4 deletions packages/thirdweb/src/pay/convert/cryptoToFiat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Address } from "abitype";
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";
import { isAddress } from "../../utils/address.js";
import { getToken } from "./get-token.js";
import { getTokenPrice } from "./get-token.js";
import type { SupportedFiatCurrency } from "./type.js";

/**
Expand Down Expand Up @@ -73,11 +73,11 @@ export async function convertCryptoToFiat(
"Invalid fromTokenAddress. Expected a valid EVM contract address",
);
}
const token = await getToken(client, fromTokenAddress, chain.id);
if (token.priceUsd === 0) {
const price = await getTokenPrice(client, fromTokenAddress, chain.id);
if (!price) {
throw new Error(
`Error: Failed to fetch price for token ${fromTokenAddress} on chainId: ${chain.id}`,
);
}
return { result: token.priceUsd * fromAmount };
return { result: price * fromAmount };
}
8 changes: 4 additions & 4 deletions packages/thirdweb/src/pay/convert/fiatToCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Address } from "abitype";
import type { Chain } from "../../chains/types.js";
import type { ThirdwebClient } from "../../client/client.js";
import { isAddress } from "../../utils/address.js";
import { getToken } from "./get-token.js";
import { getTokenPrice } from "./get-token.js";
import type { SupportedFiatCurrency } from "./type.js";

/**
Expand Down Expand Up @@ -72,11 +72,11 @@ export async function convertFiatToCrypto(
if (!isAddress(to)) {
throw new Error("Invalid `to`. Expected a valid EVM contract address");
}
const token = await getToken(client, to, chain.id);
if (!token || token.priceUsd === 0) {
const price = await getTokenPrice(client, to, chain.id);
if (!price || price === 0) {
throw new Error(
`Error: Failed to fetch price for token ${to} on chainId: ${chain.id}`,
);
}
return { result: fromAmount / token.priceUsd };
return { result: fromAmount / price };
Comment on lines +75 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Explicitly coerce price to a finite number before division

If getTokenPrice ever yields a string or non-finite value, fromAmount / price will explode with Infinity or NaN. Coercing & validating once keeps the math safe.

-  const price = await getTokenPrice(client, to, chain.id);
+  const rawPrice = await getTokenPrice(client, to, chain.id);
+  const price =
+    typeof rawPrice === "string" ? Number.parseFloat(rawPrice) : rawPrice;

Consider replacing the current !price || price === 0 guard with
if (!Number.isFinite(price) || price === 0) for robustness.

🤖 Prompt for AI Agents
In packages/thirdweb/src/pay/convert/fiatToCrypto.ts around lines 75 to 81, the
current check for price uses !price || price === 0, which does not guard against
non-finite values or strings. Update the condition to explicitly coerce price to
a number and check if it is finite using Number.isFinite(price) and also check
for zero. This ensures that the division fromAmount / price is safe and avoids
Infinity or NaN results.

}
Loading
Loading