Skip to content

Commit ca0b8d3

Browse files
committed
feat: support object auth option with default value
1 parent c77b4d8 commit ca0b8d3

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

packages/thirdweb/src/react/native/ui/connect/ConnectModal.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ function WalletLoadingView({
475475
authProvider?: InAppWalletAuth;
476476
}) {
477477
const walletInfo = useWalletInfo(wallet.id);
478+
const authProviderName = typeof authProvider === 'string' ? authProvider : authProvider?.type;
478479
return (
479480
<View
480481
style={{
@@ -491,7 +492,7 @@ function WalletLoadingView({
491492
animate={true}
492493
roundLoader={authProvider === "passkey"}
493494
>
494-
{authProvider ? (
495+
{authProviderName ? (
495496
<View
496497
style={{
497498
borderRadius: spacing.md,
@@ -501,7 +502,7 @@ function WalletLoadingView({
501502
<RNImage
502503
theme={theme}
503504
size={80}
504-
data={getAuthProviderImage(authProvider)}
505+
data={getAuthProviderImage(authProviderName)}
505506
color={theme.colors.accentButtonBg}
506507
/>
507508
</View>
@@ -516,14 +517,14 @@ function WalletLoadingView({
516517
</WalletLoadingThumbnail>
517518
<Spacer size="xl" />
518519
<ThemedText theme={theme} type="subtitle">
519-
{authProvider
520-
? `Connecting with ${capitalizeFirstLetter(authProvider)}`
520+
{authProviderName
521+
? `Connecting with ${capitalizeFirstLetter(authProviderName)}`
521522
: "Awaiting confirmation"}
522523
</ThemedText>
523524
<Spacer size="sm" />
524525
<ThemedText theme={theme} type="subtext">
525-
{authProvider
526-
? `Signing into your ${capitalizeFirstLetter(authProvider)} account`
526+
{authProviderName
527+
? `Signing into your ${capitalizeFirstLetter(authProviderName)} account`
527528
: `Accept the connection request in ${walletInfo.data?.name}`}
528529
</ThemedText>
529530
</View>

packages/thirdweb/src/react/native/ui/connect/InAppWalletUI.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import type {
99
PreAuthArgsType,
1010
} from "../../../../wallets/in-app/core/authentication/types.js";
1111
import type {
12+
AuthOption,
1213
InAppWalletAuth,
1314
InAppWalletSocialAuth,
15+
AuthOptionWithOptions,
1416
} from "../../../../wallets/in-app/core/wallet/types.js";
1517
import { preAuthenticate } from "../../../../wallets/in-app/native/auth/index.js";
1618
import { hasStoredPasskey } from "../../../../wallets/in-app/native/auth/passkeys.js";
@@ -91,16 +93,25 @@ export function InAppWalletUI(props: InAppWalletFormUIProps) {
9193

9294
const [inputMode, setInputMode] = useState<"email" | "phone">("email");
9395

96+
const hasAuthOption = useCallback((key: AuthOption) => {
97+
return authOptions.find((opt) => typeof opt === 'string' ? opt === key : opt.type === key);
98+
}, [authOptions]);
99+
100+
const getAuthOptionDefaultValue = useCallback((key: AuthOption) => {
101+
const option = authOptions.find((opt) => typeof opt === 'object' && opt.type === key) as AuthOptionWithOptions | undefined;
102+
return option?.defaultValue;
103+
}, [authOptions]);
104+
94105
return (
95106
<View style={styles.container}>
96107
<View style={styles.row}>
97108
{socialLogins.map((auth) => (
98109
<SocialLogin key={auth} auth={auth} {...props} />
99110
))}
100111
</View>
101-
{authOptions.includes("email") ? (
112+
{hasAuthOption("email") ? (
102113
inputMode === "email" ? (
103-
<PreOtpLogin auth="email" {...props} />
114+
<PreOtpLogin auth="email" defaultValue={getAuthOptionDefaultValue('email')} {...props} />
104115
) : (
105116
<ThemedButtonWithIcon
106117
theme={theme}
@@ -110,9 +121,9 @@ export function InAppWalletUI(props: InAppWalletFormUIProps) {
110121
/>
111122
)
112123
) : null}
113-
{authOptions.includes("phone") ? (
124+
{hasAuthOption("phone") ? (
114125
inputMode === "phone" ? (
115-
<PreOtpLogin auth="phone" {...props} />
126+
<PreOtpLogin auth="phone" defaultValue={getAuthOptionDefaultValue('phone')} {...props} />
116127
) : (
117128
<ThemedButtonWithIcon
118129
theme={theme}
@@ -122,7 +133,7 @@ export function InAppWalletUI(props: InAppWalletFormUIProps) {
122133
/>
123134
)
124135
) : null}
125-
{authOptions.includes("passkey") ? (
136+
{hasAuthOption("passkey") ? (
126137
<ThemedButtonWithIcon
127138
theme={theme}
128139
title="Passkey"
@@ -132,7 +143,7 @@ export function InAppWalletUI(props: InAppWalletFormUIProps) {
132143
}}
133144
/>
134145
) : null}
135-
{authOptions.includes("guest") ? <GuestLogin {...props} /> : null}
146+
{hasAuthOption("guest") ? <GuestLogin {...props} /> : null}
136147
</View>
137148
);
138149
}
@@ -205,10 +216,11 @@ function SocialLogin(
205216
function PreOtpLogin(
206217
props: InAppWalletFormUIProps & {
207218
auth: PreAuthArgsType["strategy"];
219+
defaultValue?: string;
208220
},
209221
) {
210-
const { theme, auth, client, setScreen, wallet } = props;
211-
const [phoneOrEmail, setPhoneNumberOrEmail] = useState("");
222+
const { theme, auth, client, setScreen, wallet, defaultValue = ''} = props;
223+
const [phoneOrEmail, setPhoneNumberOrEmail] = useState(defaultValue);
212224

213225
const sendCode = useMutation({
214226
mutationFn: async (options: {

packages/thirdweb/src/wallets/in-app/core/wallet/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export type WalletUser = UserStatus;
3939

4040
export type InAppWalletSocialAuth = SocialAuthOption;
4141
export type InAppWalletOAuth = OAuthOption;
42-
export type InAppWalletAuth = AuthOption;
42+
export type AuthOptionWithOptions = {type: AuthOption, defaultValue: string };
43+
export type InAppWalletAuth = AuthOption | AuthOptionWithOptions;
44+
export type { AuthOption };
4345

4446
export type ExecutionModeOptions =
4547
| {

0 commit comments

Comments
 (0)