Skip to content

Commit acdf995

Browse files
committed
requested changes
1 parent 42ba286 commit acdf995

File tree

11 files changed

+100
-76
lines changed

11 files changed

+100
-76
lines changed

apps/portal/src/app/react/v5/pay/transaction/page.mdx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,28 @@ Try out the demo for yourself in the [live playground](https://playground.thirdw
3030

3131
Any transaction sent with `useSendTransaction` or with `TransactionButton` will prompt the user to choose a different payment method if they don't have enough balance for the transaction.
3232

33-
You can turn off this behaviour by setting the `payModal` option to `false`.
33+
You can turn off this behaviour by setting the `payModal` option to `false`.
34+
35+
## Usage with TransactionWidget
36+
37+
The `TransactionWidget` component provides a complete UI for executing transactions with built-in cross-chain payment support.
38+
39+
```tsx
40+
import { TransactionWidget } from "thirdweb/react";
41+
import { prepareContractCall } from "thirdweb";
42+
43+
function MyComponent() {
44+
return (
45+
<TransactionWidget
46+
client={client}
47+
transaction={prepareContractCall({
48+
contract: myContract,
49+
method: "function mint(uint256 quantity)",
50+
params: [1n],
51+
})}
52+
amount="0.1"
53+
title="Mint NFT"
54+
/>
55+
);
56+
}
57+
```

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ export type UIOptions = Prettify<
4040
};
4141
} & (
4242
| {
43-
mode: "fund_wallet";
44-
destinationToken: Token;
45-
initialAmount?: string;
46-
presetOptions?: [number, number, number];
47-
}
43+
mode: "fund_wallet";
44+
destinationToken: Token;
45+
initialAmount?: string;
46+
presetOptions?: [number, number, number];
47+
}
4848
| {
49-
mode: "direct_payment";
50-
paymentInfo: {
51-
sellerAddress: Address;
52-
token: Token;
53-
amount: string;
54-
feePayer?: "sender" | "receiver";
55-
};
56-
}
49+
mode: "direct_payment";
50+
paymentInfo: {
51+
sellerAddress: Address;
52+
token: Token;
53+
amount: string;
54+
feePayer?: "sender" | "receiver";
55+
};
56+
}
5757
| { mode: "transaction"; transaction: PreparedTransaction }
5858
)
5959
>;
@@ -286,6 +286,7 @@ export function BridgeOrchestrator({
286286
onBack={() => {
287287
send({ type: "BACK" });
288288
}}
289+
mode={uiOptions.mode}
289290
onError={handleError}
290291
onQuoteReceived={handleQuoteReceived}
291292
paymentLinkId={paymentLinkId}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ export type BuyWidgetProps = {
166166
type UIOptionsResult =
167167
| { type: "success"; data: UIOptions }
168168
| {
169-
type: "indexing_token";
170-
token: Token;
171-
chain: Chain;
172-
}
169+
type: "indexing_token";
170+
token: Token;
171+
chain: Chain;
172+
}
173173
| {
174-
type: "unsupported_token";
175-
tokenAddress: Address;
176-
chain: Chain;
177-
};
174+
type: "unsupported_token";
175+
tokenAddress: Address;
176+
chain: Chain;
177+
};
178178

179179
/**
180180
* Widget is a prebuilt UI for purchasing a specific token.
@@ -271,7 +271,7 @@ export function BuyWidget(props: BuyWidgetProps) {
271271
queryFn: () => {
272272
trackPayEvent({
273273
client: props.client,
274-
event: "buy_widget:render",
274+
event: "ub:ui:buy_widget:render",
275275
toChainId: props.chain.id,
276276
toToken: props.tokenAddress,
277277
});
@@ -285,7 +285,7 @@ export function BuyWidget(props: BuyWidgetProps) {
285285
!props.tokenAddress ||
286286
(isAddress(props.tokenAddress) &&
287287
checksumAddress(props.tokenAddress) ===
288-
checksumAddress(NATIVE_TOKEN_ADDRESS))
288+
checksumAddress(NATIVE_TOKEN_ADDRESS))
289289
) {
290290
const ETH = await getToken(
291291
props.client,
@@ -455,10 +455,10 @@ type BuyWidgetConnectOptions = {
455455
* ```
456456
*/
457457
autoConnect?:
458-
| {
459-
timeout: number;
460-
}
461-
| boolean;
458+
| {
459+
timeout: number;
460+
}
461+
| boolean;
462462

463463
/**
464464
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ export type CheckoutWidgetProps = {
172172
type UIOptionsResult =
173173
| { type: "success"; data: UIOptions }
174174
| {
175-
type: "indexing_token";
176-
token: Token;
177-
chain: Chain;
178-
}
175+
type: "indexing_token";
176+
token: Token;
177+
chain: Chain;
178+
}
179179
| {
180-
type: "unsupported_token";
181-
tokenAddress: Address;
182-
chain: Chain;
183-
};
180+
type: "unsupported_token";
181+
tokenAddress: Address;
182+
chain: Chain;
183+
};
184184

185185
/**
186186
* Widget a prebuilt UI for purchasing a specific token.
@@ -254,7 +254,7 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
254254
queryFn: () => {
255255
trackPayEvent({
256256
client: props.client,
257-
event: "checkout_widget:render",
257+
event: "ub:ui:checkout_widget:render",
258258
toChainId: props.chain.id,
259259
toToken: props.tokenAddress,
260260
});
@@ -418,10 +418,10 @@ type CheckoutWidgetConnectOptions = {
418418
* ```
419419
*/
420420
autoConnect?:
421-
| {
422-
timeout: number;
423-
}
424-
| boolean;
421+
| {
422+
timeout: number;
423+
}
424+
| boolean;
425425

426426
/**
427427
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function ErrorBanner({
4343
trackPayEvent({
4444
client,
4545
error: error.message,
46-
event: "error",
46+
event: "ub:ui:error",
4747
});
4848
},
4949
queryKey: ["error_banner", userMessage],

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ interface QuoteLoaderProps {
8181
* Fee payer for direct transfers (defaults to sender)
8282
*/
8383
feePayer?: "sender" | "receiver";
84+
mode: "fund_wallet" | "direct_payment" | "transaction";
8485
}
8586

8687
export function QuoteLoader({
88+
mode,
8789
destinationToken,
8890
paymentMethod,
8991
amount,
@@ -119,7 +121,7 @@ export function QuoteLoader({
119121
? paymentMethod.originToken.chainId
120122
: undefined,
121123
client,
122-
event: "loading_quote",
124+
event: `ub:ui:loading_quote:${mode}`,
123125
fromToken:
124126
paymentMethod.type === "wallet"
125127
? paymentMethod.originToken.address
@@ -202,7 +204,7 @@ function getBridgeParams(args: {
202204
if (
203205
paymentMethod.originToken.chainId === destinationToken.chainId &&
204206
paymentMethod.originToken.address.toLowerCase() ===
205-
destinationToken.address.toLowerCase()
207+
destinationToken.address.toLowerCase()
206208
) {
207209
return {
208210
amount: toUnits(amount, destinationToken.decimals),

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ export type TransactionWidgetProps = {
172172
type UIOptionsResult =
173173
| { type: "success"; data: UIOptions }
174174
| {
175-
type: "indexing_token";
176-
token: Token;
177-
chain: Chain;
178-
}
175+
type: "indexing_token";
176+
token: Token;
177+
chain: Chain;
178+
}
179179
| {
180-
type: "unsupported_token";
181-
tokenAddress: Address;
182-
chain: Chain;
183-
};
180+
type: "unsupported_token";
181+
tokenAddress: Address;
182+
chain: Chain;
183+
};
184184

185185
/**
186186
* Widget a prebuilt UI for purchasing a specific token.
@@ -279,7 +279,7 @@ export function TransactionWidget(props: TransactionWidgetProps) {
279279
trackPayEvent({
280280
chainId: props.transaction.chain.id,
281281
client: props.client,
282-
event: "transaction_widget:render",
282+
event: "ub:ui:transaction_widget:render",
283283
toToken: props.tokenAddress,
284284
});
285285
},
@@ -443,10 +443,10 @@ type TransactionWidgetConnectOptions = {
443443
* ```
444444
*/
445445
autoConnect?:
446-
| {
447-
timeout: number;
448-
}
449-
| boolean;
446+
| {
447+
timeout: number;
448+
}
449+
| boolean;
450450

451451
/**
452452
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function UnsupportedTokenScreen(props: UnsupportedTokenScreenProps) {
3232
trackPayEvent({
3333
chainId: chain.id,
3434
client,
35-
event: "unsupported_token",
35+
event: "ub:ui:unsupported_token",
3636
fromToken: tokenAddress,
3737
});
3838
},

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ export function PaymentDetails({
7272

7373
useQuery({
7474
queryFn: () => {
75-
if (preparedQuote.type === "buy" || preparedQuote.type === "sell") {
75+
if (preparedQuote.type === "buy" || preparedQuote.type === "sell" || preparedQuote.type === "transfer") {
7676
trackPayEvent({
77-
chainId: preparedQuote.intent.originChainId,
77+
chainId: preparedQuote.type === "transfer" ? preparedQuote.intent.chainId : preparedQuote.intent.originChainId,
7878
client,
7979
event: "payment_details",
80-
fromToken: preparedQuote.intent.originTokenAddress,
81-
toChainId: preparedQuote.intent.destinationChainId,
82-
toToken: preparedQuote.intent.destinationTokenAddress,
80+
fromToken: preparedQuote.type === "transfer" ? preparedQuote.intent.tokenAddress : preparedQuote.intent.originTokenAddress,
81+
toChainId: preparedQuote.type === "transfer" ? preparedQuote.intent.chainId : preparedQuote.intent.destinationChainId,
82+
toToken: preparedQuote.type === "transfer" ? preparedQuote.intent.tokenAddress : preparedQuote.intent.destinationTokenAddress,
8383
});
8484
}
8585
},

packages/thirdweb/src/react/web/ui/Bridge/payment-success/SuccessScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function SuccessScreen({
6363
trackPayEvent({
6464
chainId: preparedQuote.intent.originChainId,
6565
client: client,
66-
event: "success_screen",
66+
event: "ub:ui:success_screen",
6767
fromToken: preparedQuote.intent.originTokenAddress,
6868
toChainId: preparedQuote.intent.destinationChainId,
6969
toToken: preparedQuote.intent.destinationTokenAddress,

0 commit comments

Comments
 (0)