Skip to content

Commit 9962b81

Browse files
committed
refactor: clean up ecosystem parsing
1 parent 2d92af0 commit 9962b81

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -908,22 +908,12 @@ function DetailsModal(props: {
908908
/>
909909
);
910910
} else if (screen === "linked-profiles") {
911-
let ecosystem: Ecosystem | undefined;
912-
if (activeWallet && isEcosystemWallet(activeWallet)) {
913-
const ecosystemWallet = activeWallet as Wallet<EcosystemWalletId>;
914-
const partnerId = ecosystemWallet.getConfig()?.partnerId;
915-
ecosystem = {
916-
id: ecosystemWallet.id,
917-
partnerId,
918-
};
919-
}
920911
content = (
921912
<LinkedProfilesScreen
922913
onBack={() => setScreen("manage-wallet")}
923914
client={client}
924915
locale={locale}
925916
setScreen={setScreen}
926-
ecosystem={ecosystem}
927917
/>
928918
);
929919
} else if (screen === "link-profile") {

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
import { Cross2Icon } from "@radix-ui/react-icons";
33
import { useMutation, useQueryClient } from "@tanstack/react-query";
44
import type { ThirdwebClient } from "../../../../../client/client.js";
5+
import { useActiveWallet } from "../../../../../react/core/hooks/wallets/useActiveWallet.js";
56
import { shortenAddress } from "../../../../../utils/address.js";
7+
import { isEcosystemWallet } from "../../../../../wallets/ecosystem/is-ecosystem-wallet.js";
68
import type { Profile } from "../../../../../wallets/in-app/core/authentication/types.js";
79
import type { Ecosystem } from "../../../../../wallets/in-app/core/wallet/types.js";
810
import { unlinkProfile } from "../../../../../wallets/in-app/web/lib/auth/index.js";
11+
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
12+
import type { EcosystemWalletId } from "../../../../../wallets/wallet-types.js";
913
import { fontSize, iconSize } from "../../../../core/design-system/index.js";
1014
import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js";
1115
import { getSocialIcon } from "../../../../core/utils/walletIcon.js";
@@ -51,7 +55,6 @@ export function LinkedProfilesScreen(props: {
5155
setScreen: (screen: WalletDetailsModalScreen) => void;
5256
locale: ConnectLocale;
5357
client: ThirdwebClient;
54-
ecosystem?: Ecosystem;
5558
}) {
5659
const { data: connectedProfiles, isLoading } = useProfiles({
5760
client: props.client,
@@ -122,20 +125,34 @@ function LinkedProfile({
122125
profile,
123126
enableUnlinking,
124127
client,
125-
ecosystem,
126128
}: {
127129
profile: Profile;
128130
enableUnlinking: boolean;
129131
client: ThirdwebClient;
130-
ecosystem?: Ecosystem;
131132
}) {
133+
const activeWallet = useActiveWallet();
132134
const { data: socialProfiles } = useSocialProfiles({
133135
client,
134136
address: profile.details.address,
135137
});
136138
const queryClient = useQueryClient();
137139
const { mutate: unlinkProfileMutation, isPending } = useMutation({
138140
mutationFn: async () => {
141+
let ecosystem: Ecosystem | undefined;
142+
143+
if (!activeWallet) {
144+
throw new Error("No active wallet found");
145+
}
146+
147+
if (isEcosystemWallet(activeWallet)) {
148+
const ecosystemWallet = activeWallet as Wallet<EcosystemWalletId>;
149+
const partnerId = ecosystemWallet.getConfig()?.partnerId;
150+
ecosystem = {
151+
id: ecosystemWallet.id,
152+
partnerId,
153+
};
154+
}
155+
139156
await unlinkProfile({
140157
client,
141158
ecosystem,

0 commit comments

Comments
 (0)