Skip to content

Commit 88b50ff

Browse files
Refactor profile types and add utility functions for profile access
Co-authored-by: joaquim.verges <[email protected]>
1 parent 44fdfee commit 88b50ff

File tree

4 files changed

+317
-24
lines changed

4 files changed

+317
-24
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
useWalletInfo,
1313
} from "../../../../../../core/utils/wallet.js";
1414
import { useProfiles } from "../../../../../hooks/wallets/useProfiles.js";
15+
import { getProfileEmail } from "../../../../../../../wallets/in-app/core/authentication/types.js";
1516
import { Container } from "../../../../components/basic.js";
1617
import { Skeleton } from "../../../../components/Skeleton.js";
1718
import { Text } from "../../../../components/text.js";
@@ -36,7 +37,12 @@ export function WalletRow(props: {
3637
(wallet.id === "inApp" ||
3738
isEcosystemWallet(wallet) ||
3839
isSmartWallet(wallet))
39-
? profile.data?.find((p) => !!p.details.email)?.details.email
40+
? (() => {
41+
const profileWithEmail = profile.data?.find((p) => {
42+
return getProfileEmail(p) !== undefined;
43+
});
44+
return profileWithEmail ? getProfileEmail(profileWithEmail) : undefined;
45+
})()
4046
: undefined;
4147
const walletInfo = useWalletInfo(wallet?.id);
4248
const ensNameQuery = useEnsName({

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ThirdwebClient } from "../../../../../client/client.js";
44
import { useUnlinkProfile } from "../../../../../react/web/hooks/wallets/useUnlinkProfile.js";
55
import { shortenAddress } from "../../../../../utils/address.js";
66
import type { Profile } from "../../../../../wallets/in-app/core/authentication/types.js";
7+
import { getProfileEmail, getProfilePhone, getProfileAddress } from "../../../../../wallets/in-app/core/authentication/types.js";
78
import { fontSize, iconSize } from "../../../../core/design-system/index.js";
89
import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js";
910
import { getSocialIcon } from "../../../../core/utils/walletIcon.js";
@@ -24,18 +25,21 @@ import { MenuButton } from "../MenuButton.js";
2425
import type { WalletDetailsModalScreen } from "./types.js";
2526

2627
function getProfileDisplayName(profile: Profile) {
28+
const email = getProfileEmail(profile);
29+
const phone = getProfilePhone(profile);
30+
const address = getProfileAddress(profile);
31+
2732
switch (true) {
28-
case profile.type === "email" && profile.details.email !== undefined:
29-
return profile.details.email;
30-
case profile.type === "google" && profile.details.email !== undefined:
31-
return profile.details.email;
32-
case profile.type === "phone" && profile.details.phone !== undefined:
33-
return profile.details.phone;
34-
case profile.details.address !== undefined:
35-
return shortenAddress(profile.details.address, 6);
36-
case (profile.type as string) === "cognito" &&
37-
profile.details.email !== undefined:
38-
return profile.details.email;
33+
case profile.type === "email" && email !== undefined:
34+
return email;
35+
case profile.type === "google" && email !== undefined:
36+
return email;
37+
case profile.type === "phone" && phone !== undefined:
38+
return phone;
39+
case address !== undefined:
40+
return shortenAddress(address, 6);
41+
case (profile.type as string) === "cognito" && email !== undefined:
42+
return email;
3943
case (profile.type as string).toLowerCase() === "custom_auth_endpoint":
4044
return "Custom Profile";
4145
default:
@@ -128,8 +132,9 @@ function LinkedProfile({
128132
enableUnlinking: boolean;
129133
client: ThirdwebClient;
130134
}) {
135+
const profileAddress = getProfileAddress(profile);
131136
const { data: socialProfiles } = useSocialProfiles({
132-
address: profile.details.address,
137+
address: profileAddress,
133138
client,
134139
});
135140
const { mutate: unlinkProfileMutation, isPending } = useUnlinkProfile();
@@ -154,7 +159,7 @@ function LinkedProfile({
154159
}}
155160
width={iconSize.lg}
156161
/>
157-
) : profile.details.address !== undefined ? (
162+
) : profileAddress !== undefined ? (
158163
<Container
159164
style={{
160165
borderRadius: "100%",
@@ -163,7 +168,7 @@ function LinkedProfile({
163168
width: "32px",
164169
}}
165170
>
166-
<Blobbie address={profile.details.address} size={32} />
171+
<Blobbie address={profileAddress} size={32} />
167172
</Container>
168173
) : profile.type === "passkey" ? (
169174
<FingerPrintIcon size={iconSize.lg} />
@@ -202,9 +207,9 @@ function LinkedProfile({
202207
}}
203208
>
204209
{socialProfiles?.find((p) => p.avatar)?.name &&
205-
profile.details.address && (
210+
profileAddress && (
206211
<Text color="secondaryText" size="sm">
207-
{shortenAddress(profile.details.address, 4)}
212+
{shortenAddress(profileAddress, 4)}
208213
</Text>
209214
)}
210215
{enableUnlinking && (

0 commit comments

Comments
 (0)