File tree Expand file tree Collapse file tree 11 files changed +100
-76
lines changed
apps/portal/src/app/react/v5/pay/transaction Expand file tree Collapse file tree 11 files changed +100
-76
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,28 @@ Try out the demo for yourself in the [live playground](https://playground.thirdw
30
30
31
31
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.
32
32
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
+ ```
Original file line number Diff line number Diff line change @@ -40,20 +40,20 @@ export type UIOptions = Prettify<
40
40
} ;
41
41
} & (
42
42
| {
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
+ }
48
48
| {
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
+ }
57
57
| { mode : "transaction" ; transaction : PreparedTransaction }
58
58
)
59
59
> ;
@@ -286,6 +286,7 @@ export function BridgeOrchestrator({
286
286
onBack = { ( ) => {
287
287
send ( { type : "BACK" } ) ;
288
288
} }
289
+ mode = { uiOptions . mode }
289
290
onError = { handleError }
290
291
onQuoteReceived = { handleQuoteReceived }
291
292
paymentLinkId = { paymentLinkId }
Original file line number Diff line number Diff line change @@ -166,15 +166,15 @@ export type BuyWidgetProps = {
166
166
type UIOptionsResult =
167
167
| { type : "success" ; data : UIOptions }
168
168
| {
169
- type : "indexing_token" ;
170
- token : Token ;
171
- chain : Chain ;
172
- }
169
+ type : "indexing_token" ;
170
+ token : Token ;
171
+ chain : Chain ;
172
+ }
173
173
| {
174
- type : "unsupported_token" ;
175
- tokenAddress : Address ;
176
- chain : Chain ;
177
- } ;
174
+ type : "unsupported_token" ;
175
+ tokenAddress : Address ;
176
+ chain : Chain ;
177
+ } ;
178
178
179
179
/**
180
180
* Widget is a prebuilt UI for purchasing a specific token.
@@ -271,7 +271,7 @@ export function BuyWidget(props: BuyWidgetProps) {
271
271
queryFn : ( ) => {
272
272
trackPayEvent ( {
273
273
client : props . client ,
274
- event : "buy_widget:render" ,
274
+ event : "ub:ui: buy_widget:render" ,
275
275
toChainId : props . chain . id ,
276
276
toToken : props . tokenAddress ,
277
277
} ) ;
@@ -285,7 +285,7 @@ export function BuyWidget(props: BuyWidgetProps) {
285
285
! props . tokenAddress ||
286
286
( isAddress ( props . tokenAddress ) &&
287
287
checksumAddress ( props . tokenAddress ) ===
288
- checksumAddress ( NATIVE_TOKEN_ADDRESS ) )
288
+ checksumAddress ( NATIVE_TOKEN_ADDRESS ) )
289
289
) {
290
290
const ETH = await getToken (
291
291
props . client ,
@@ -455,10 +455,10 @@ type BuyWidgetConnectOptions = {
455
455
* ```
456
456
*/
457
457
autoConnect ?:
458
- | {
459
- timeout : number ;
460
- }
461
- | boolean ;
458
+ | {
459
+ timeout : number ;
460
+ }
461
+ | boolean ;
462
462
463
463
/**
464
464
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.
Original file line number Diff line number Diff line change @@ -172,15 +172,15 @@ export type CheckoutWidgetProps = {
172
172
type UIOptionsResult =
173
173
| { type : "success" ; data : UIOptions }
174
174
| {
175
- type : "indexing_token" ;
176
- token : Token ;
177
- chain : Chain ;
178
- }
175
+ type : "indexing_token" ;
176
+ token : Token ;
177
+ chain : Chain ;
178
+ }
179
179
| {
180
- type : "unsupported_token" ;
181
- tokenAddress : Address ;
182
- chain : Chain ;
183
- } ;
180
+ type : "unsupported_token" ;
181
+ tokenAddress : Address ;
182
+ chain : Chain ;
183
+ } ;
184
184
185
185
/**
186
186
* Widget a prebuilt UI for purchasing a specific token.
@@ -254,7 +254,7 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
254
254
queryFn : ( ) => {
255
255
trackPayEvent ( {
256
256
client : props . client ,
257
- event : "checkout_widget:render" ,
257
+ event : "ub:ui: checkout_widget:render" ,
258
258
toChainId : props . chain . id ,
259
259
toToken : props . tokenAddress ,
260
260
} ) ;
@@ -418,10 +418,10 @@ type CheckoutWidgetConnectOptions = {
418
418
* ```
419
419
*/
420
420
autoConnect ?:
421
- | {
422
- timeout : number ;
423
- }
424
- | boolean ;
421
+ | {
422
+ timeout : number ;
423
+ }
424
+ | boolean ;
425
425
426
426
/**
427
427
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ export function ErrorBanner({
43
43
trackPayEvent ( {
44
44
client,
45
45
error : error . message ,
46
- event : "error" ,
46
+ event : "ub:ui: error" ,
47
47
} ) ;
48
48
} ,
49
49
queryKey : [ "error_banner" , userMessage ] ,
Original file line number Diff line number Diff line change @@ -81,9 +81,11 @@ interface QuoteLoaderProps {
81
81
* Fee payer for direct transfers (defaults to sender)
82
82
*/
83
83
feePayer ?: "sender" | "receiver" ;
84
+ mode : "fund_wallet" | "direct_payment" | "transaction" ;
84
85
}
85
86
86
87
export function QuoteLoader ( {
88
+ mode,
87
89
destinationToken,
88
90
paymentMethod,
89
91
amount,
@@ -119,7 +121,7 @@ export function QuoteLoader({
119
121
? paymentMethod . originToken . chainId
120
122
: undefined ,
121
123
client,
122
- event : " loading_quote" ,
124
+ event : `ub:ui: loading_quote: ${ mode } ` ,
123
125
fromToken :
124
126
paymentMethod . type === "wallet"
125
127
? paymentMethod . originToken . address
@@ -202,7 +204,7 @@ function getBridgeParams(args: {
202
204
if (
203
205
paymentMethod . originToken . chainId === destinationToken . chainId &&
204
206
paymentMethod . originToken . address . toLowerCase ( ) ===
205
- destinationToken . address . toLowerCase ( )
207
+ destinationToken . address . toLowerCase ( )
206
208
) {
207
209
return {
208
210
amount : toUnits ( amount , destinationToken . decimals ) ,
Original file line number Diff line number Diff line change @@ -172,15 +172,15 @@ export type TransactionWidgetProps = {
172
172
type UIOptionsResult =
173
173
| { type : "success" ; data : UIOptions }
174
174
| {
175
- type : "indexing_token" ;
176
- token : Token ;
177
- chain : Chain ;
178
- }
175
+ type : "indexing_token" ;
176
+ token : Token ;
177
+ chain : Chain ;
178
+ }
179
179
| {
180
- type : "unsupported_token" ;
181
- tokenAddress : Address ;
182
- chain : Chain ;
183
- } ;
180
+ type : "unsupported_token" ;
181
+ tokenAddress : Address ;
182
+ chain : Chain ;
183
+ } ;
184
184
185
185
/**
186
186
* Widget a prebuilt UI for purchasing a specific token.
@@ -279,7 +279,7 @@ export function TransactionWidget(props: TransactionWidgetProps) {
279
279
trackPayEvent ( {
280
280
chainId : props . transaction . chain . id ,
281
281
client : props . client ,
282
- event : "transaction_widget:render" ,
282
+ event : "ub:ui: transaction_widget:render" ,
283
283
toToken : props . tokenAddress ,
284
284
} ) ;
285
285
} ,
@@ -443,10 +443,10 @@ type TransactionWidgetConnectOptions = {
443
443
* ```
444
444
*/
445
445
autoConnect ?:
446
- | {
447
- timeout : number ;
448
- }
449
- | boolean ;
446
+ | {
447
+ timeout : number ;
448
+ }
449
+ | boolean ;
450
450
451
451
/**
452
452
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ export function UnsupportedTokenScreen(props: UnsupportedTokenScreenProps) {
32
32
trackPayEvent ( {
33
33
chainId : chain . id ,
34
34
client,
35
- event : "unsupported_token" ,
35
+ event : "ub:ui: unsupported_token" ,
36
36
fromToken : tokenAddress ,
37
37
} ) ;
38
38
} ,
Original file line number Diff line number Diff line change @@ -72,14 +72,14 @@ export function PaymentDetails({
72
72
73
73
useQuery ( {
74
74
queryFn : ( ) => {
75
- if ( preparedQuote . type === "buy" || preparedQuote . type === "sell" ) {
75
+ if ( preparedQuote . type === "buy" || preparedQuote . type === "sell" || preparedQuote . type === "transfer" ) {
76
76
trackPayEvent ( {
77
- chainId : preparedQuote . intent . originChainId ,
77
+ chainId : preparedQuote . type === "transfer" ? preparedQuote . intent . chainId : preparedQuote . intent . originChainId ,
78
78
client,
79
79
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 ,
83
83
} ) ;
84
84
}
85
85
} ,
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ export function SuccessScreen({
63
63
trackPayEvent ( {
64
64
chainId : preparedQuote . intent . originChainId ,
65
65
client : client ,
66
- event : "success_screen" ,
66
+ event : "ub:ui: success_screen" ,
67
67
fromToken : preparedQuote . intent . originTokenAddress ,
68
68
toChainId : preparedQuote . intent . destinationChainId ,
69
69
toToken : preparedQuote . intent . destinationTokenAddress ,
You can’t perform that action at this time.
0 commit comments