Skip to content

Commit 82e8911

Browse files
feat: show auth provider icon when connected to inapp wallet (#2944)
Co-authored-by: Manan Tank <manantankm@gmail.com>
1 parent bdb919f commit 82e8911

File tree

9 files changed

+82
-11
lines changed

9 files changed

+82
-11
lines changed

.changeset/shiny-bananas-juggle.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+
Show auth provider icon in connect UI when connected to in app wallet

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ export const ConnectedWalletDetails: React.FC<{
145145
}),
146146
});
147147

148-
// const [overrideWalletIconUrl, setOverrideWalletIconUrl] = useState<
149-
// string | undefined
150-
// >(undefined);
151-
152148
// const personalAccount = (activeWallet as WalletWithPersonalAccount)
153149
// ?.personalAccount;
154150

@@ -161,7 +157,6 @@ export const ConnectedWalletDetails: React.FC<{
161157
// const isActuallyMetaMask =
162158
// activeWallet && activeWallet instanceof MetaMaskWallet;
163159

164-
// const shortAddress = "<address>";
165160
const shortAddress = activeAccount?.address
166161
? shortenString(activeAccount.address, false)
167162
: "";
@@ -217,7 +212,12 @@ export const ConnectedWalletDetails: React.FC<{
217212
client={client}
218213
/>
219214
) : activeWallet?.id ? (
220-
<WalletImage size={iconSize.lg} id={activeWallet.id} client={client} />
215+
<WalletImage
216+
size={iconSize.lg}
217+
id={activeWallet.id}
218+
client={client}
219+
allowOverrides
220+
/>
221221
) : (
222222
<WalletIcon size={iconSize.lg} />
223223
)}
@@ -332,6 +332,7 @@ export const ConnectedWalletDetails: React.FC<{
332332
size={iconSize.xxl}
333333
id={activeWallet.id}
334334
client={client}
335+
allowOverrides
335336
/>
336337
) : (
337338
<WalletIcon size={iconSize.xxl} />

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/AccountSelectorButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function AccountSelectorButton(props: {
3131
id={props.activeWallet.id}
3232
size={iconSize.md}
3333
client={props.client}
34+
allowOverrides
3435
/>
3536
) : (
3637
<Container color="secondaryText" flex="row" center="both">

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ReceiveFunds.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function ReceiveFunds(props: {
4343
id={props.walletId}
4444
size={iconSize.xxl}
4545
client={client}
46+
allowOverrides
4647
/>
4748
)
4849
}

packages/thirdweb/src/react/web/ui/components/WalletImage.tsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"use client";
2+
import { useEffect, useState } from "react";
23
import type { ThirdwebClient } from "../../../../client/client.js";
34
import { getInstalledWalletProviders } from "../../../../wallets/injected/mipdStore.js";
45
import type { WalletId } from "../../../../wallets/wallet-types.js";
6+
import { getLastAuthProvider } from "../../wallets/in-app/storage.js";
7+
import { emailIcon, phoneIcon } from "../ConnectWallet/icons/dataUris.js";
8+
import {
9+
appleIconUri,
10+
facebookIconUri,
11+
googleIconUri,
12+
} from "../ConnectWallet/icons/socialLogins.js";
513
import { radius } from "../design-system/index.js";
614
import { useWalletImage } from "../hooks/useWalletInfo.js";
715
import { Img } from "./Img.js";
@@ -15,15 +23,46 @@ export function WalletImage(props: {
1523
id: WalletId;
1624
size: string;
1725
client: ThirdwebClient;
26+
allowOverrides?: boolean;
1827
}) {
19-
const mipdImage = getInstalledWalletProviders().find(
20-
(provider) => provider.info.rdns === props.id,
21-
)?.info.icon;
28+
const [image, setImage] = useState<string | undefined>(undefined);
29+
useEffect(() => {
30+
async function fetchImage() {
31+
let mipdImage = getInstalledWalletProviders().find(
32+
(provider) => provider.info.rdns === props.id,
33+
)?.info.icon;
2234

23-
if (mipdImage) {
35+
if (props.allowOverrides && props.id === "inApp") {
36+
// check last auth provider and override the IAW icon
37+
const lastAuthProvider = await getLastAuthProvider();
38+
switch (lastAuthProvider) {
39+
case "google":
40+
mipdImage = googleIconUri;
41+
break;
42+
case "apple":
43+
mipdImage = appleIconUri;
44+
break;
45+
case "facebook":
46+
mipdImage = facebookIconUri;
47+
break;
48+
case "phone":
49+
mipdImage = phoneIcon;
50+
break;
51+
case "email":
52+
mipdImage = emailIcon;
53+
break;
54+
}
55+
}
56+
57+
setImage(mipdImage);
58+
}
59+
fetchImage();
60+
}, [props.id, props.allowOverrides]);
61+
62+
if (image) {
2463
return (
2564
<Img
26-
src={mipdImage}
65+
src={image}
2766
width={props.size}
2867
height={props.size}
2968
loading="eager"

packages/thirdweb/src/react/web/wallets/in-app/InAppWalletFormUI.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { LinkButton } from "./LinkButton.js";
2323
import type { InAppWalletLocale } from "./locale/types.js";
2424
import { openOauthSignInWindow } from "./openOauthSignInWindow.js";
2525
import { socialIcons } from "./socialIcons.js";
26+
import { setLastAuthProvider } from "./storage.js";
2627
import type { InAppWalletSelectUIState } from "./types.js";
2728
import { validateEmail } from "./validateEmail.js";
2829

@@ -126,6 +127,8 @@ export const InAppWalletFormUI = (props: InAppWalletFormUIProps) => {
126127
},
127128
});
128129

130+
await setLastAuthProvider(strategy);
131+
129132
setData({
130133
socialLogin: {
131134
type: strategy,

packages/thirdweb/src/react/web/wallets/in-app/InAppWalletOTPLoginUI.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useCustomTheme } from "../../ui/design-system/CustomThemeProvider.js";
1515
import { StyledButton } from "../../ui/design-system/elements.js";
1616
import { fontSize } from "../../ui/design-system/index.js";
1717
import type { InAppWalletLocale } from "./locale/types.js";
18+
import { setLastAuthProvider } from "./storage.js";
1819

1920
type VerificationStatus =
2021
| "verifying"
@@ -84,6 +85,7 @@ export function InAppWalletOTPLoginUI(props: {
8485
verificationCode: otp,
8586
client,
8687
});
88+
await setLastAuthProvider("email");
8789
} else if ("phone" in userInfo) {
8890
await wallet.connect({
8991
chain,
@@ -92,6 +94,7 @@ export function InAppWalletOTPLoginUI(props: {
9294
verificationCode: otp,
9395
client,
9496
});
97+
await setLastAuthProvider("phone");
9598
} else {
9699
throw new Error("Invalid userInfo");
97100
}

packages/thirdweb/src/react/web/wallets/in-app/InAppWalletSocialLogin.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Text } from "../../ui/components/text.js";
1111
import { useCustomTheme } from "../../ui/design-system/CustomThemeProvider.js";
1212
import type { InAppWalletLocale } from "./locale/types.js";
1313
import { openOauthSignInWindow } from "./openOauthSignInWindow.js";
14+
import { setLastAuthProvider } from "./storage.js";
1415
import type { InAppWalletSelectUIState } from "./types.js";
1516

1617
/**
@@ -53,6 +54,7 @@ export function InAppWalletSocialLogin(props: {
5354
},
5455
client,
5556
});
57+
await setLastAuthProvider(props.socialAuth);
5658
setStatus("connected");
5759
done();
5860
} catch (e) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { AuthArgsType } from "../../../../wallets/in-app/core/authentication/type.js";
2+
import { getStorage } from "../../../core/storage.js";
3+
4+
const LAST_AUTH_PROVIDER_STORAGE_KEY = "lastAuthProvider";
5+
6+
export async function setLastAuthProvider(
7+
authProvider: AuthArgsType["strategy"],
8+
) {
9+
await getStorage().setItem(LAST_AUTH_PROVIDER_STORAGE_KEY, authProvider);
10+
}
11+
12+
export async function getLastAuthProvider() {
13+
return (await getStorage().getItem(LAST_AUTH_PROVIDER_STORAGE_KEY)) as
14+
| AuthArgsType["strategy"]
15+
| null;
16+
}

0 commit comments

Comments
 (0)