Skip to content

Commit 6712911

Browse files
authored
[SDK] Chore: Remove onrampTokenAddress set to ETH (#7441)
1 parent 1387337 commit 6712911

File tree

8 files changed

+73
-8
lines changed

8 files changed

+73
-8
lines changed

.changeset/old-bats-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
A number of important fixes for payment widgets

packages/thirdweb/src/bridge/Onramp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Address as ox__Address } from "ox";
2+
import { defineChain } from "../chains/utils.js";
23
import type { ThirdwebClient } from "../client/client.js";
34
import { getThirdwebBaseUrl } from "../utils/domains.js";
45
import { getClientFetch } from "../utils/fetch.js";
@@ -237,6 +238,8 @@ export async function prepare(
237238
originAmount: BigInt(step.originAmount),
238239
transactions: step.transactions.map((tx) => ({
239240
...tx,
241+
chain: defineChain(tx.chainId),
242+
client,
240243
value: tx.value ? BigInt(tx.value) : undefined,
241244
})),
242245
}));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export async function getBuyWithFiatQuote(
326326
maxSteps: 2,
327327
onramp: onrampProvider,
328328
onrampChainId: params.onrampChainId,
329-
onrampTokenAddress: params.onrampTokenAddress ?? NATIVE_TOKEN_ADDRESS,
329+
onrampTokenAddress: params.onrampTokenAddress,
330330
paymentLinkId: params.paymentLinkId,
331331
purchaseData: params.purchaseData,
332332
receiver: params.toAddress, // force onramp to native token to avoid missing gas issues

packages/thirdweb/src/react/core/hooks/useStepExecutor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export function useStepExecutor(
237237
if (tx.action === "approval" || tx.action === "fee") {
238238
// don't poll status for approval transactions, just wait for confirmation
239239
await waitForReceipt(result);
240+
await new Promise((resolve) => setTimeout(resolve, 1000)); // Add an extra second delay for RPC to catch up to new state
240241
return;
241242
}
242243

packages/thirdweb/src/react/web/ui/Bridge/QuoteLoader.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useEffect } from "react";
44
import { trackPayEvent } from "../../../../analytics/track/pay.js";
55
import type { Token } from "../../../../bridge/types/Token.js";
66
import type { ThirdwebClient } from "../../../../client/client.js";
7-
import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
87
import { toUnits } from "../../../../utils/units.js";
98
import {
109
type BridgePrepareRequest,
@@ -191,7 +190,6 @@ function getBridgeParams(args: {
191190
currency: paymentMethod.currency,
192191
enabled: !!(destinationToken && amount && client),
193192
onramp: paymentMethod.onramp || "coinbase",
194-
onrampTokenAddress: NATIVE_TOKEN_ADDRESS,
195193
paymentLinkId: args.paymentLinkId,
196194
purchaseData: args.purchaseData,
197195
receiver,

packages/thirdweb/src/react/web/ui/Bridge/StepRunner.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ export function StepRunner({
322322

323323
<Container flex="column" gap="3xs" style={{ flex: 1 }}>
324324
<Text color="primaryText" size="sm">
325-
TEST
325+
{request.onramp.slice(0, 1).toUpperCase() +
326+
request.onramp.slice(1)}
326327
</Text>
327328
<Text color="secondaryText" size="xs">
328329
{getStepStatusText(onrampStatus)}

packages/thirdweb/src/react/web/ui/Bridge/payment-details/PaymentDetails.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"use client";
22
import { useQuery } from "@tanstack/react-query";
3+
import { useMemo } from "react";
34
import { trackPayEvent } from "../../../../../analytics/track/pay.js";
45
import type { ThirdwebClient } from "../../../../../client/client.js";
56
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
67
import { radius, spacing } from "../../../../core/design-system/index.js";
8+
import { useChainsQuery } from "../../../../core/hooks/others/useChainQuery.js";
79
import type { BridgePrepareResult } from "../../../../core/hooks/useBridgePrepare.js";
810
import type { PaymentMethod } from "../../../../core/machines/paymentMachine.js";
911
import {
@@ -102,6 +104,15 @@ export function PaymentDetails({
102104
queryKey: ["payment_details", preparedQuote.type],
103105
});
104106

107+
const chainsQuery = useChainsQuery(
108+
preparedQuote.steps.flatMap((s) => s.transactions.map((t) => t.chain)),
109+
10,
110+
);
111+
const chainsMetadata = useMemo(
112+
() => chainsQuery.map((c) => c.data),
113+
[chainsQuery],
114+
).filter((c) => !!c);
115+
105116
// Extract common data based on quote type
106117
const getDisplayData = () => {
107118
switch (preparedQuote.type) {
@@ -321,12 +332,48 @@ export function PaymentDetails({
321332
>
322333
<Container flex="column" gap="3xs" style={{ flex: 1 }}>
323334
<Text color="primaryText" size="sm">
324-
{step.originToken.symbol}{" "}
325-
{step.destinationToken.symbol}
335+
{step.destinationToken.chainId !==
336+
step.originToken.chainId ? (
337+
<>
338+
Bridge{" "}
339+
{step.originToken.symbol ===
340+
step.destinationToken.symbol
341+
? step.originToken.symbol
342+
: `${step.originToken.symbol} to ${step.destinationToken.symbol}`}
343+
</>
344+
) : (
345+
<>
346+
Swap {step.originToken.symbol} to{" "}
347+
{step.destinationToken.symbol}
348+
</>
349+
)}
326350
</Text>
327351
<Text color="secondaryText" size="xs">
328-
{step.originToken.name} to{" "}
329-
{step.destinationToken.name}
352+
{step.originToken.chainId !==
353+
step.destinationToken.chainId ? (
354+
<>
355+
{
356+
chainsMetadata.find(
357+
(c) => c.chainId === step.originToken.chainId,
358+
)?.name
359+
}{" "}
360+
to{" "}
361+
{
362+
chainsMetadata.find(
363+
(c) =>
364+
c.chainId === step.destinationToken.chainId,
365+
)?.name
366+
}
367+
</>
368+
) : (
369+
<>
370+
{
371+
chainsMetadata.find(
372+
(c) => c.chainId === step.originToken.chainId,
373+
)?.name
374+
}
375+
</>
376+
)}
330377
</Text>
331378
</Container>
332379
</Container>

packages/thirdweb/src/react/web/ui/Bridge/payment-selection/FiatProviderSelection.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export function FiatProviderSelection({
7171
return quoteQueries.map((q) => q.data).filter((q) => !!q);
7272
}, [quoteQueries]);
7373

74+
if (quoteQueries.every((q) => q.isError)) {
75+
return (
76+
<Container center="both" flex="column" style={{ minHeight: "120px" }}>
77+
<Text color="secondaryText" size="sm">
78+
No quotes available
79+
</Text>
80+
</Container>
81+
);
82+
}
83+
7484
// TODO: add a "remember my choice" checkbox
7585

7686
return (

0 commit comments

Comments
 (0)