Skip to content

Commit af6a306

Browse files
authored
[SDK] Feature: country Code on Payment Widgets (#7966)
1 parent 4b319c3 commit af6a306

File tree

13 files changed

+52
-0
lines changed

13 files changed

+52
-0
lines changed

.changeset/purple-foxes-wear.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+
Adds `country` code option to payment widgets

packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuotesForProviders.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ type UseBuyWithFiatQuotesForProvidersParams = {
3333
* The fiat currency (e.g., "USD"). Defaults to "USD".
3434
*/
3535
currency?: string;
36+
/**
37+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
38+
*/
39+
country?: string;
3640
};
3741

3842
/**
@@ -89,6 +93,7 @@ export function useBuyWithFiatQuotesForProviders(
8993
onramp: provider,
9094
receiver: params.receiver,
9195
tokenAddress: params.tokenAddress,
96+
country: params.country,
9297
});
9398
},
9499
queryKey: ["onramp-prepare", provider, params],

packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export type SendTransactionPayModalConfig =
9090
},
9191
) => void;
9292
showThirdwebBranding?: boolean;
93+
/**
94+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
95+
*/
96+
country?: string;
9397
}
9498
| false;
9599

packages/thirdweb/src/react/web/hooks/transaction/useSendTransaction.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export function useSendTransaction(config: SendTransactionConfig = {}) {
137137
if (payModal === false) return;
138138
setRootEl(
139139
<TransactionModal
140+
country={payModal?.country}
140141
client={data.tx.client}
141142
localeId={payModal?.locale || "en_US"}
142143
modalMode={data.mode}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export interface BridgeOrchestratorProps {
125125
*/
126126
paymentMethods?: ("crypto" | "card")[];
127127

128+
/**
129+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
130+
*/
131+
country: string | undefined;
132+
128133
/**
129134
* Whether to show thirdweb branding in the widget.
130135
* @default true
@@ -148,6 +153,7 @@ export function BridgeOrchestrator({
148153
paymentMethods = ["crypto", "card"],
149154
showThirdwebBranding = true,
150155
supportedTokens,
156+
country = "US",
151157
}: BridgeOrchestratorProps) {
152158
// Initialize adapters
153159
const adapters = useMemo(
@@ -319,6 +325,7 @@ export function BridgeOrchestrator({
319325
receiverAddress={state.context.receiverAddress}
320326
currency={uiOptions.currency}
321327
supportedTokens={supportedTokens}
328+
country={country}
322329
/>
323330
)}
324331

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ export type BuyWidgetProps = {
184184
*/
185185
currency?: SupportedFiatCurrency;
186186

187+
/**
188+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
189+
*/
190+
country?: string;
191+
187192
/**
188193
* Custom label for the main action button.
189194
*/
@@ -432,6 +437,7 @@ export function BuyWidget(props: BuyWidgetProps) {
432437
// Show normal bridge orchestrator
433438
content = (
434439
<BridgeOrchestrator
440+
country={props.country}
435441
supportedTokens={props.supportedTokens}
436442
client={props.client}
437443
connectLocale={localeQuery.data}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ export type CheckoutWidgetProps = {
193193
*/
194194
currency?: SupportedFiatCurrency;
195195

196+
/**
197+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
198+
*/
199+
country?: string;
200+
196201
/**
197202
* Custom label for the main action button.
198203
*/
@@ -400,6 +405,7 @@ export function CheckoutWidget(props: CheckoutWidgetProps) {
400405
// Show normal bridge orchestrator
401406
content = (
402407
<BridgeOrchestrator
408+
country={props.country}
403409
client={props.client}
404410
connectLocale={localeQuery.data}
405411
connectOptions={props.connectOptions}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ export type TransactionWidgetProps = {
193193
*/
194194
currency?: SupportedFiatCurrency;
195195

196+
/** The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support. */
197+
country?: string;
198+
196199
/**
197200
* Custom label for the main action button.
198201
*/
@@ -442,6 +445,7 @@ export function TransactionWidget(props: TransactionWidgetProps) {
442445
// Show normal bridge orchestrator
443446
content = (
444447
<BridgeOrchestrator
448+
country={props.country}
445449
supportedTokens={props.supportedTokens}
446450
client={props.client}
447451
connectLocale={localeQuery.data}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface FiatProviderSelectionProps {
2828
toAddress: string;
2929
toAmount?: string;
3030
currency?: SupportedFiatCurrency;
31+
country: string | undefined;
3132
}
3233

3334
const PROVIDERS = [
@@ -59,6 +60,7 @@ export function FiatProviderSelection({
5960
toAddress,
6061
toAmount,
6162
currency,
63+
country,
6264
}: FiatProviderSelectionProps) {
6365
const theme = useCustomTheme();
6466

@@ -70,6 +72,7 @@ export function FiatProviderSelection({
7072
currency: currency || "USD",
7173
receiver: checksumAddress(toAddress),
7274
tokenAddress: checksumAddress(toTokenAddress),
75+
country,
7376
});
7477

7578
const quotes = useMemo(() => {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export interface PaymentSelectionProps {
9191
*/
9292
currency?: SupportedFiatCurrency;
9393

94+
/**
95+
* The user's ISO 3166 alpha-2 country code. This is used to determine onramp provider support.
96+
*/
97+
country: string | undefined;
98+
9499
supportedTokens?: SupportedTokens;
95100
}
96101

@@ -115,6 +120,7 @@ export function PaymentSelection({
115120
supportedTokens,
116121
feePayer,
117122
currency,
123+
country,
118124
}: PaymentSelectionProps) {
119125
const connectedWallets = useConnectedWallets();
120126
const activeWallet = useActiveWallet();
@@ -298,6 +304,7 @@ export function PaymentSelection({
298304

299305
{currentStep.type === "fiatProviderSelection" && (
300306
<FiatProviderSelection
307+
country={country}
301308
client={client}
302309
onProviderSelected={handleOnrampProviderSelected}
303310
toAddress={receiverAddress || ""}

0 commit comments

Comments
 (0)