Skip to content

Commit 7d547a4

Browse files
fix: show user info for ecosystem wallets (#4715)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on fixing the display of user information for ecosystem wallets in the Thirdweb application. ### Detailed summary - Updated function name from `getEnclaveUserStatus` to `getUserStatus` in multiple files. - Modified parameters in functions to include `ecosystem` for ecosystem wallets. - Updated caching mechanism for InAppWalletConnector. - Added logic to handle ecosystem wallets in `InAppWalletUserInfo` component. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent c1008a5 commit 7d547a4

File tree

9 files changed

+50
-19
lines changed

9 files changed

+50
-19
lines changed

.changeset/quick-hotels-repair.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+
Fix showing user info for ecosystem wallets

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ import { getLastAuthProvider } from "../../../../react/core/utils/storage.js";
1818
import { isContractDeployed } from "../../../../utils/bytecode/is-contract-deployed.js";
1919
import { formatNumber } from "../../../../utils/formatNumber.js";
2020
import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
21+
import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
22+
import type { Ecosystem } from "../../../../wallets/in-app/web/types.js";
2123
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
2224
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
2325
import {
2426
type AppMetadata,
2527
type SocialAuthOption,
2628
socialAuthOptions,
2729
} from "../../../../wallets/types.js";
28-
import type { WalletId } from "../../../../wallets/wallet-types.js";
30+
import type {
31+
EcosystemWalletId,
32+
WalletId,
33+
} from "../../../../wallets/wallet-types.js";
2934
import {
3035
CustomThemeProvider,
3136
parseTheme,
@@ -53,6 +58,7 @@ import {
5358
import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
5459
import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js";
5560
import { useActiveWalletChain } from "../../../core/hooks/wallets/useActiveWalletChain.js";
61+
import { useAdminWallet } from "../../../core/hooks/wallets/useAdminAccount.js";
5662
import { useDisconnect } from "../../../core/hooks/wallets/useDisconnect.js";
5763
import { useSwitchActiveWalletChain } from "../../../core/hooks/wallets/useSwitchActiveWalletChain.js";
5864
import { SetRootElementContext } from "../../../core/providers/RootElementContext.js";
@@ -1066,6 +1072,7 @@ function InAppWalletUserInfo(props: {
10661072
const { client, locale } = props;
10671073
const account = useActiveAccount();
10681074
const activeWallet = useActiveWallet();
1075+
const adminWallet = useAdminWallet();
10691076
const { data: walletInfo } = useWalletInfo(activeWallet?.id);
10701077
const isSmartWallet = hasSmartAccount(activeWallet);
10711078
const { data: walletName } = useQuery({
@@ -1092,25 +1099,45 @@ function InAppWalletUserInfo(props: {
10921099
const userInfoQuery = useQuery({
10931100
queryKey: ["in-app-wallet-user", client, account?.address],
10941101
queryFn: async () => {
1102+
const isInAppWallet =
1103+
adminWallet &&
1104+
(adminWallet.id === "inApp" || adminWallet.id.startsWith("ecosystem."));
1105+
1106+
if (!isInAppWallet) {
1107+
return null;
1108+
}
1109+
1110+
let ecosystem: Ecosystem | undefined;
1111+
if (isEcosystemWallet(adminWallet)) {
1112+
const ecosystemWallet = adminWallet as Wallet<EcosystemWalletId>;
1113+
const partnerId = ecosystemWallet.getConfig()?.partnerId;
1114+
ecosystem = {
1115+
id: ecosystemWallet.id,
1116+
partnerId,
1117+
};
1118+
}
1119+
10951120
const { getUserEmail, getUserPhoneNumber } = await import(
10961121
"../../../../wallets/in-app/web/lib/auth/index.js"
10971122
);
10981123

10991124
const [email, phone] = await Promise.all([
11001125
getUserEmail({
11011126
client: client,
1127+
ecosystem,
11021128
}),
11031129
getUserPhoneNumber({
11041130
client: client,
1131+
ecosystem,
11051132
}),
11061133
]);
11071134

11081135
return email || phone || null;
11091136
},
1110-
enabled: !isSmartWallet,
1137+
enabled: !!adminWallet,
11111138
});
11121139

1113-
if (isSmartWallet) {
1140+
if (!userInfoQuery.data && isSmartWallet) {
11141141
return <ConnectedToSmartWallet client={client} connectLocale={locale} />;
11151142
}
11161143

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,5 @@ export type GetUser =
243243

244244
export type GetAuthenticatedUserParams = {
245245
client: ThirdwebClient;
246+
ecosystem?: Ecosystem;
246247
};

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import type {
1717
} from "../authentication/types.js";
1818
import type { InAppConnector } from "../interfaces/connector.js";
1919

20-
const connectorCache = new WeakMap<
21-
{ client: ThirdwebClient; ecosystem?: Ecosystem },
22-
InAppConnector
23-
>();
20+
const connectorCache = new Map<string, InAppConnector>();
2421

2522
/**
2623
* @internal
@@ -30,7 +27,7 @@ export async function getOrCreateInAppWalletConnector(
3027
connectorFactory: (client: ThirdwebClient) => Promise<InAppConnector>,
3128
ecosystem?: Ecosystem,
3229
) {
33-
const key = { client, ecosystem };
30+
const key = JSON.stringify({ clientId: client.clientId, ecosystem });
3431
if (connectorCache.has(key)) {
3532
return connectorCache.get(key) as InAppConnector;
3633
}

packages/thirdweb/src/wallets/in-app/web/lib/actions/get-enclave-user-status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Ecosystem } from "../../types.js";
99
*
1010
* @internal
1111
*/
12-
export async function getEnclaveUserStatus({
12+
export async function getUserStatus({
1313
authToken,
1414
client,
1515
ecosystem,

packages/thirdweb/src/wallets/in-app/web/lib/auth/iframe-auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
import type { ClientIdWithQuerierType, Ecosystem } from "../../types.js";
1212
import type { InAppWalletIframeCommunicator } from "../../utils/iFrameCommunication/InAppWalletIframeCommunicator.js";
1313
import { generateWallet } from "../actions/generate-wallet.enclave.js";
14-
import { getEnclaveUserStatus } from "../actions/get-enclave-user-status.js";
14+
import { getUserStatus } from "../actions/get-enclave-user-status.js";
1515
import { BaseLogin } from "./base-login.js";
1616

1717
export type AuthQuerierTypes = {
@@ -111,7 +111,7 @@ export class Auth {
111111
): Promise<AuthLoginReturnType> {
112112
await this.preLogin();
113113

114-
const user = await getEnclaveUserStatus({
114+
const user = await getUserStatus({
115115
authToken: authToken.storedToken.cookieString,
116116
client: this.client,
117117
ecosystem: this.ecosystem,

packages/thirdweb/src/wallets/in-app/web/lib/auth/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ async function getInAppWalletConnector(
5151
export async function getAuthenticatedUser(
5252
options: GetAuthenticatedUserParams,
5353
) {
54-
const { client } = options;
55-
const connector = await getInAppWalletConnector(client);
54+
const { client, ecosystem } = options;
55+
const connector = await getInAppWalletConnector(client, ecosystem);
5656
const user = await connector.getUser();
5757
switch (user.status) {
5858
case UserWalletStatus.LOGGED_IN_WALLET_INITIALIZED: {

packages/thirdweb/src/wallets/in-app/web/lib/enclave-wallet.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
type WalletAddressObjectType,
2121
} from "../../core/authentication/types.js";
2222
import type { Ecosystem } from "../types.js";
23-
import { getEnclaveUserStatus } from "./actions/get-enclave-user-status.js";
23+
import { getUserStatus } from "./actions/get-enclave-user-status.js";
2424
import { signMessage as signEnclaveMessage } from "./actions/sign-message.enclave.js";
2525
import { signTransaction as signEnclaveTransaction } from "./actions/sign-transaction.enclave.js";
2626
import { signTypedData as signEnclaveTypedData } from "./actions/sign-typed-data.enclave.js";
@@ -96,22 +96,23 @@ export class EnclaveWallet implements IWebWallet {
9696
return { status: UserWalletStatus.LOGGED_OUT };
9797
}
9898

99-
const userStatus = await getEnclaveUserStatus({
99+
const userStatus = await getUserStatus({
100100
authToken: token,
101101
client: this.client,
102102
ecosystem: this.ecosystem,
103103
});
104+
104105
if (!userStatus) {
105106
return { status: UserWalletStatus.LOGGED_OUT };
106107
}
107108
const wallet = userStatus.wallets[0];
108109

109110
const authDetails = {
110111
email: userStatus.linkedAccounts.find(
111-
(account) => account.type === "email",
112+
(account) => account.details.email !== undefined,
112113
)?.details.email,
113114
phoneNumber: userStatus.linkedAccounts.find(
114-
(account) => account.type === "phone",
115+
(account) => account.details.phone !== undefined,
115116
)?.details.phone,
116117
userWalletId: userStatus.id || "",
117118
recoveryShareManagement: RecoveryShareManagement.ENCLAVE,

packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
UserWalletStatus,
2121
} from "../../core/authentication/types.js";
2222
import type { InAppConnector } from "../../core/interfaces/connector.js";
23-
import { getEnclaveUserStatus } from "../lib/actions/get-enclave-user-status.js";
23+
import { getUserStatus } from "../lib/actions/get-enclave-user-status.js";
2424
import type { Ecosystem, InAppWalletConstructorType } from "../types.js";
2525
import { InAppWalletIframeCommunicator } from "../utils/iFrameCommunication/InAppWalletIframeCommunicator.js";
2626
import { Auth, type AuthQuerierTypes } from "./auth/iframe-auth.js";
@@ -152,7 +152,7 @@ export class InAppWebConnector implements InAppConnector {
152152
);
153153
}
154154

155-
const user = await getEnclaveUserStatus({
155+
const user = await getUserStatus({
156156
authToken: authToken || (storedAuthToken as string),
157157
client: this.client,
158158
ecosystem: this.ecosystem,

0 commit comments

Comments
 (0)