Skip to content

Commit 10c3b6f

Browse files
[SDK] Respect fee payer in token payment selection quotes (#7556)
1 parent c644463 commit 10c3b6f

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

.changeset/good-papers-give.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+
Respect fee payer in token payment selection quotes

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ interface UseBridgeQuoteParams {
1212
destinationAmount: bigint;
1313
client: ThirdwebClient;
1414
enabled?: boolean;
15+
feePayer?: "sender" | "receiver";
1516
}
1617

1718
export function useBridgeQuote({
1819
originToken,
1920
destinationToken,
2021
destinationAmount,
22+
feePayer,
2123
client,
2224
enabled = true,
2325
}: UseBridgeQuoteParams) {
@@ -35,6 +37,7 @@ export function useBridgeQuote({
3537
amount: destinationAmount,
3638
chainId: originToken.chainId,
3739
client,
40+
feePayer,
3841
receiver: destinationToken.address,
3942
sender: originToken.address,
4043
tokenAddress: originToken.address,
@@ -59,6 +62,7 @@ export function useBridgeQuote({
5962
destinationToken.chainId,
6063
destinationToken.address,
6164
destinationAmount.toString(),
65+
feePayer,
6266
],
6367
refetchInterval: 60000, // 30 seconds
6468
retry: 3, // 1 minute

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ export function BridgeOrchestrator({
275275
connectOptions={connectOptions}
276276
destinationAmount={state.context.destinationAmount}
277277
destinationToken={state.context.destinationToken}
278+
feePayer={
279+
uiOptions.mode === "direct_payment"
280+
? uiOptions.paymentInfo.feePayer
281+
: undefined
282+
}
278283
includeDestinationToken={uiOptions.mode !== "fund_wallet"}
279284
onBack={() => {
280285
send({ type: "BACK" });

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export interface PaymentSelectionProps {
7777
* @default ["crypto", "card"]
7878
*/
7979
paymentMethods?: ("crypto" | "card")[];
80+
81+
/**
82+
* Fee payer
83+
*/
84+
feePayer?: "sender" | "receiver";
8085
}
8186

8287
type Step =
@@ -97,6 +102,7 @@ export function PaymentSelection({
97102
connectLocale,
98103
includeDestinationToken,
99104
paymentMethods = ["crypto", "card"],
105+
feePayer,
100106
}: PaymentSelectionProps) {
101107
const connectedWallets = useConnectedWallets();
102108
const activeWallet = useActiveWallet();
@@ -113,6 +119,7 @@ export function PaymentSelection({
113119
toChainId: destinationToken.chainId,
114120
toToken: destinationToken.address,
115121
});
122+
return true;
116123
},
117124
queryKey: ["payment_selection"],
118125
});
@@ -267,6 +274,7 @@ export function PaymentSelection({
267274
destinationToken.decimals,
268275
)}
269276
destinationToken={destinationToken}
277+
feePayer={feePayer}
270278
onBack={handleBackToWalletSelection}
271279
onPaymentMethodSelected={handlePaymentMethodSelected}
272280
paymentMethods={suitableTokenPaymentMethods}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface TokenSelectionProps {
2121
onBack: () => void;
2222
destinationToken: Token;
2323
destinationAmount: bigint;
24+
feePayer?: "sender" | "receiver";
2425
}
2526

2627
// Individual payment method token row component
@@ -30,6 +31,7 @@ interface PaymentMethodTokenRowProps {
3031
destinationAmount: bigint;
3132
client: ThirdwebClient;
3233
onPaymentMethodSelected: (paymentMethod: PaymentMethod) => void;
34+
feePayer?: "sender" | "receiver";
3335
}
3436

3537
function PaymentMethodTokenRow({
@@ -38,6 +40,7 @@ function PaymentMethodTokenRow({
3840
destinationAmount,
3941
client,
4042
onPaymentMethodSelected,
43+
feePayer,
4144
}: PaymentMethodTokenRowProps) {
4245
const theme = useCustomTheme();
4346

@@ -50,6 +53,7 @@ function PaymentMethodTokenRow({
5053
client,
5154
destinationAmount,
5255
destinationToken,
56+
feePayer,
5357
originToken: paymentMethod.originToken,
5458
});
5559

@@ -158,6 +162,7 @@ export function TokenSelection({
158162
onBack,
159163
destinationToken,
160164
destinationAmount,
165+
feePayer,
161166
}: TokenSelectionProps) {
162167
const theme = useCustomTheme();
163168

@@ -271,6 +276,7 @@ export function TokenSelection({
271276
client={client}
272277
destinationAmount={destinationAmount}
273278
destinationToken={destinationToken}
279+
feePayer={feePayer}
274280
key={`${method.originToken.address}-${method.originToken.chainId}`}
275281
onPaymentMethodSelected={onPaymentMethodSelected}
276282
paymentMethod={method}

0 commit comments

Comments
 (0)