Skip to content

Commit 3de0ec8

Browse files
committed
feat(sdk): default country code
1 parent ce0da51 commit 3de0ec8

18 files changed

+129
-16
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Allows specifying a default country code for SMS input
6+
7+
```tsx
8+
<ConnectButton defaultCountryCode="GB" />
9+
```

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { WalletId } from "../../../../wallets/wallet-types.js";
1515
import type { NetworkSelectorProps } from "../../../web/ui/ConnectWallet/NetworkSelector.js";
1616
import type { WelcomeScreen } from "../../../web/ui/ConnectWallet/screens/types.js";
1717
import type { LocaleId } from "../../../web/ui/types.js";
18+
import type { SupportedSmsCountry } from "../../../web/wallets/in-app/supported-sms-countries.js";
1819
import type { Theme } from "../../design-system/index.js";
1920
import type {
2021
SupportedNFTs,
@@ -544,6 +545,11 @@ export type ConnectButtonProps = {
544545
*/
545546
locale?: LocaleId;
546547

548+
/**
549+
* Default country code to use for SMS verification.
550+
*/
551+
defaultCountryCode?: SupportedSmsCountry;
552+
547553
/**
548554
* Array of supported wallets. If not provided, default wallets will be used.
549555
* @example

packages/thirdweb/src/react/web/ui/ConnectWallet/ConnectButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function ConnectButton(props: ConnectButtonProps) {
359359
chains={props.chains}
360360
client={props.client}
361361
connectLocale={localeQuery.data}
362+
defaultCountryCode={props.defaultCountryCode}
362363
meta={{
363364
title: props.connectModal?.title,
364365
titleIconUrl: props.connectModal?.titleIcon,

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/AnyWalletConnectUI.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
1515
import type { EcosystemWalletId } from "../../../../../wallets/wallet-types.js";
1616
import { iconSize } from "../../../../core/design-system/index.js";
1717
import { useWalletInfo } from "../../../../core/utils/wallet.js";
18+
import type { SupportedSmsCountry } from "../../../wallets/in-app/supported-sms-countries.js";
1819
import { getInjectedWalletLocale } from "../../../wallets/injected/locale/getInjectedWalletLocale.js";
1920
import { GetStartedScreen } from "../../../wallets/shared/GetStartedScreen.js";
2021
import { LoadingScreen } from "../../../wallets/shared/LoadingScreen.js";
@@ -44,6 +45,7 @@ const EcosystemWalletConnectUI = /* @__PURE__ */ lazy(
4445
* @internal
4546
*/
4647
export function AnyWalletConnectUI(props: {
48+
defaultCountryCode?: SupportedSmsCountry;
4749
wallet: Wallet;
4850
done: () => void;
4951
onBack?: () => void;
@@ -241,6 +243,7 @@ export function AnyWalletConnectUI(props: {
241243
<Suspense fallback={<LoadingScreen />}>
242244
<InAppWalletConnectUI
243245
wallet={props.wallet as Wallet<"inApp">}
246+
defaultCountryCode={props.defaultCountryCode}
244247
done={props.done}
245248
goBack={props.onBack}
246249
chain={props.chain}
@@ -259,6 +262,7 @@ export function AnyWalletConnectUI(props: {
259262
<Suspense fallback={<LoadingScreen />}>
260263
<EcosystemWalletConnectUI
261264
wallet={props.wallet as Wallet<EcosystemWalletId>}
265+
defaultCountryCode={props.defaultCountryCode}
262266
done={props.done}
263267
goBack={props.onBack}
264268
chain={props.chain}

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectModal.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useSetIsWalletModalOpen,
1212
useSetSelectionData,
1313
} from "../../../providers/wallet-ui-states-provider.js";
14+
import type { SupportedSmsCountry } from "../../../wallets/in-app/supported-sms-countries.js";
1415
import { Modal } from "../../components/Modal.js";
1516
import type { LocaleId } from "../../types.js";
1617
import { onModalUnmount, reservedScreens } from "../constants.js";
@@ -40,6 +41,7 @@ type ConnectModalOptions = {
4041
client: ThirdwebClient;
4142
recommendedWallets: Wallet[] | undefined;
4243
localeId: LocaleId;
44+
defaultCountryCode?: SupportedSmsCountry;
4345
chain: Chain | undefined;
4446
showAllWallets: boolean | undefined;
4547
chains: Chain[] | undefined;
@@ -130,6 +132,7 @@ const ConnectModal = (props: ConnectModalOptions) => {
130132
}}
131133
>
132134
<ConnectModalContent
135+
defaultCountryCode={props.defaultCountryCode}
133136
shouldSetActive={props.shouldSetActive}
134137
screenSetup={screenSetup}
135138
setModalVisibility={setModalVisibility}

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/ConnectModalContent.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.
1414
import { useSetActiveWallet } from "../../../../core/hooks/wallets/useSetActiveWallet.js";
1515
import { useConnectionManager } from "../../../../core/providers/connection-manager.js";
1616
import { useSetSelectionData } from "../../../providers/wallet-ui-states-provider.js";
17+
import type { SupportedSmsCountry } from "../../../wallets/in-app/supported-sms-countries.js";
1718
import { LoadingScreen } from "../../../wallets/shared/LoadingScreen.js";
1819
import { WalletSelector } from "../WalletSelector.js";
1920
import { onModalUnmount, reservedScreens } from "../constants.js";
@@ -58,6 +59,7 @@ export const ConnectModalContent = (props: {
5859
client: ThirdwebClient;
5960
hideHeader: boolean;
6061
recommendedWallets: Wallet[] | undefined;
62+
defaultCountryCode?: SupportedSmsCountry;
6163
chain: Chain | undefined;
6264
chains: Chain[] | undefined;
6365
showAllWallets: boolean | undefined;
@@ -146,6 +148,7 @@ export const ConnectModalContent = (props: {
146148
setScreen(reservedScreens.showAll);
147149
}}
148150
done={handleConnected}
151+
defaultCountryCode={props.defaultCountryCode}
149152
goBack={props.wallets.length > 1 ? handleBack : undefined}
150153
setModalVisibility={setModalVisibility}
151154
client={props.client}
@@ -194,6 +197,7 @@ export const ConnectModalContent = (props: {
194197
return (
195198
<SmartConnectUI
196199
key={wallet.id}
200+
defaultCountryCode={props.defaultCountryCode}
197201
accountAbstraction={props.accountAbstraction}
198202
done={(smartWallet) => {
199203
handleConnected(smartWallet);
@@ -215,6 +219,7 @@ export const ConnectModalContent = (props: {
215219
return (
216220
<AnyWalletConnectUI
217221
key={wallet.id}
222+
defaultCountryCode={props.defaultCountryCode}
218223
wallet={wallet}
219224
onBack={goBack}
220225
done={() => {

packages/thirdweb/src/react/web/ui/ConnectWallet/Modal/SmartWalletConnectUI.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "../../../../core/design-system/index.js";
1515
import { useConnectionManager } from "../../../../core/providers/connection-manager.js";
1616
import { useWalletInfo } from "../../../../core/utils/wallet.js";
17+
import type { SupportedSmsCountry } from "../../../wallets/in-app/supported-sms-countries.js";
1718
import { LoadingScreen } from "../../../wallets/shared/LoadingScreen.js";
1819
import { getSmartWalletLocale } from "../../../wallets/smartWallet/locale/getSmartWalletLocale.js";
1920
import type { SmartWalletLocale } from "../../../wallets/smartWallet/locale/types.js";
@@ -32,6 +33,7 @@ import { AnyWalletConnectUI } from "./AnyWalletConnectUI.js";
3233
export function SmartConnectUI(props: {
3334
personalWallet: Wallet;
3435
done: (smartWallet: Wallet) => void;
36+
defaultCountryCode?: SupportedSmsCountry;
3537
onBack?: () => void;
3638
accountAbstraction: SmartWalletOptions;
3739
setModalVisibility: (value: boolean) => void;
@@ -69,6 +71,7 @@ export function SmartConnectUI(props: {
6971
setKeyConnected(true);
7072
}}
7173
onBack={props.onBack}
74+
defaultCountryCode={props.defaultCountryCode}
7275
setModalVisibility={props.setModalVisibility}
7376
chain={props.chain}
7477
chains={props.chains}

packages/thirdweb/src/react/web/ui/ConnectWallet/WalletSelector.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "../../../core/design-system/index.js";
1919
import { useSetSelectionData } from "../../providers/wallet-ui-states-provider.js";
2020
import { sortWallets } from "../../utils/sortWallets.js";
21+
import type { SupportedSmsCountry } from "../../wallets/in-app/supported-sms-countries.js";
2122
import { LoadingScreen } from "../../wallets/shared/LoadingScreen.js";
2223
import { Img } from "../components/Img.js";
2324
import { Spacer } from "../components/Spacer.js";
@@ -61,6 +62,7 @@ type WalletSelectorProps = {
6162
setModalVisibility: (value: boolean) => void;
6263
accountAbstraction?: SmartWalletOptions;
6364
size: "compact" | "wide";
65+
defaultCountryCode?: SupportedSmsCountry;
6466
meta: {
6567
title?: string;
6668
titleIconUrl?: string;
@@ -276,6 +278,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
276278
if (!isCompact) {
277279
topSection = (
278280
<WalletSelection
281+
defaultCountryCode={props.defaultCountryCode}
279282
wallets={nonLocalWalletConfigs}
280283
selectWallet={handleSelect}
281284
done={props.done}
@@ -305,6 +308,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
305308
if (socialWallets.length === 0) {
306309
topSection = (
307310
<WalletSelection
311+
defaultCountryCode={props.defaultCountryCode}
308312
wallets={nonLocalWalletConfigs}
309313
selectWallet={handleSelect}
310314
done={props.done}
@@ -351,6 +355,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
351355
topSection = (
352356
<Container px="xs">
353357
<WalletSelection
358+
defaultCountryCode={props.defaultCountryCode}
354359
wallets={socialWallets}
355360
selectWallet={handleSelect}
356361
done={props.done}
@@ -422,6 +427,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
422427
<>
423428
<Container px="lg">
424429
<WalletSelection
430+
defaultCountryCode={props.defaultCountryCode}
425431
wallets={eoaWallets}
426432
selectWallet={handleSelect}
427433
done={props.done}
@@ -462,6 +468,7 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
462468
else {
463469
topSection = (
464470
<WalletSelection
471+
defaultCountryCode={props.defaultCountryCode}
465472
wallets={eoaWallets}
466473
selectWallet={handleSelect}
467474
done={props.done}
@@ -598,6 +605,7 @@ const WalletSelection: React.FC<{
598605
connectLocale: ConnectLocale;
599606
client: ThirdwebClient;
600607
chain: Chain | undefined;
608+
defaultCountryCode?: SupportedSmsCountry;
601609
diableSelectionDataReset?: boolean;
602610
// If true, all options will be disabled. Used for things like requiring TOS approval.
603611
disabled?: boolean;
@@ -628,6 +636,7 @@ const WalletSelection: React.FC<{
628636
select={() => props.selectWallet(wallet)}
629637
wallet={wallet as Wallet<"inApp">}
630638
goBack={props.goBack}
639+
defaultCountryCode={props.defaultCountryCode}
631640
client={props.client}
632641
connectLocale={props.connectLocale}
633642
size={props.size}

packages/thirdweb/src/react/web/wallets/ecosystem/EcosystemWalletConnectUI.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "../../providers/wallet-ui-states-provider.js";
1010
import type { ConnectLocale } from "../../ui/ConnectWallet/locale/types.js";
1111
import { WalletAuth } from "../in-app/WalletAuth.js";
12+
import type { SupportedSmsCountry } from "../in-app/supported-sms-countries.js";
1213
import { useInAppWalletLocale } from "../in-app/useInAppWalletLocale.js";
1314
import type { ConnectWalletSelectUIState } from "../shared/ConnectWalletSocialOptions.js";
1415
import { GuestLogin } from "../shared/GuestLogin.js";
@@ -29,6 +30,7 @@ function EcosystemWalletConnectUI(props: {
2930
client: ThirdwebClient;
3031
chain: Chain | undefined;
3132
connectLocale: ConnectLocale;
33+
defaultCountryCode?: SupportedSmsCountry;
3234
size: "compact" | "wide";
3335
meta: {
3436
title?: string;

packages/thirdweb/src/react/web/wallets/ecosystem/EcosystemWalletFormUI.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { PoweredByThirdweb } from "../../ui/ConnectWallet/PoweredByTW.js";
1010
import type { ConnectLocale } from "../../ui/ConnectWallet/locale/types.js";
1111
import { Spacer } from "../../ui/components/Spacer.js";
1212
import { Container, ModalHeader } from "../../ui/components/basic.js";
13+
import type { SupportedSmsCountry } from "../in-app/supported-sms-countries.js";
1314
import { ConnectWalletSocialOptions } from "../shared/ConnectWalletSocialOptions.js";
1415
import type { InAppWalletLocale } from "../shared/locale/types.js";
1516
import { EcosystemWalletHeader } from "./EcosystemWalletHeader.js";
@@ -29,6 +30,7 @@ type EcosystemWalletFormUIProps = {
2930
privacyPolicyUrl?: string;
3031
requireApproval?: boolean;
3132
};
33+
defaultCountryCode?: SupportedSmsCountry;
3234
client: ThirdwebClient;
3335
chain: Chain | undefined;
3436
connectLocale: ConnectLocale;
@@ -80,6 +82,7 @@ export function EcosystemWalletFormUIScreen(props: EcosystemWalletFormUIProps) {
8082
p={isCompact ? undefined : "lg"}
8183
>
8284
<ConnectWalletSocialOptions
85+
defaultCountryCode={props.defaultCountryCode}
8386
disabled={props.meta.requireApproval && !isApproved}
8487
{...props}
8588
/>

0 commit comments

Comments
 (0)