Skip to content

Commit 09cf826

Browse files
fix: improve wallet linking for ecosystems
1 parent ccff347 commit 09cf826

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

.changeset/large-snails-unite.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 linking wallets for ecosystems

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Suspense, useRef, useState } from "react";
22
import { defineChain } from "../../../../chains/utils.js";
33
import type { ThirdwebClient } from "../../../../client/client.js";
4+
import { isEcosystemWallet } from "../../../../wallets/ecosystem/is-ecosystem-wallet.js";
45
import { linkProfile } from "../../../../wallets/in-app/web/lib/auth/index.js";
56
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
67
import type { EcosystemWalletId } from "../../../../wallets/wallet-types.js";
@@ -43,6 +44,12 @@ export function WalletAuth(props: {
4344
);
4445
const [error, setError] = useState<string | undefined>();
4546
const [showAll, setShowAll] = useState<boolean>(false);
47+
const ecosystem = isEcosystemWallet(wallet)
48+
? {
49+
id: wallet.id,
50+
partnerId: wallet.getConfig()?.partnerId,
51+
}
52+
: undefined;
4653

4754
const back = () => {
4855
setStatus("selecting");
@@ -59,6 +66,7 @@ export function WalletAuth(props: {
5966
strategy: "wallet",
6067
wallet: walletToLink,
6168
chain: wallet.getChain() || defineChain(1),
69+
ecosystem,
6270
}).catch((e) => {
6371
setError(e.message);
6472
throw e;

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export const ConnectWalletSocialOptions = (
262262
closeOpenedWindow: (openedWindow: Window) => {
263263
openedWindow.close();
264264
},
265+
ecosystem: ecosystemInfo,
265266
};
266267

267268
const connectPromise = (() => {

packages/thirdweb/src/react/web/wallets/shared/OTPLoginUI.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2+
import { useCallback, useEffect, useRef, useState } from "react";
33
import type { Chain } from "../../../../chains/types.js";
44
import type { ThirdwebClient } from "../../../../client/client.js";
55
import { webLocalStorage } from "../../../../utils/storage/webStorage.js";
@@ -9,7 +9,6 @@ import {
99
preAuthenticate,
1010
} from "../../../../wallets/in-app/web/lib/auth/index.js";
1111
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
12-
import type { EcosystemWalletId } from "../../../../wallets/wallet-types.js";
1312
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
1413
import { fontSize } from "../../../core/design-system/index.js";
1514
import { setLastAuthProvider } from "../../../core/utils/storage.js";
@@ -54,7 +53,12 @@ export function OTPLoginUI(props: {
5453
const [verifyStatus, setVerifyStatus] = useState<VerificationStatus>("idle");
5554
const [error, setError] = useState<string | undefined>();
5655
const [accountStatus, setAccountStatus] = useState<AccountStatus>("sending");
57-
const isEcosystem = useMemo(() => isEcosystemWallet(wallet.id), [wallet.id]);
56+
const ecosystem = isEcosystemWallet(wallet)
57+
? {
58+
id: wallet.id,
59+
partnerId: wallet.getConfig()?.partnerId,
60+
}
61+
: undefined;
5862

5963
const [screen] = useState<ScreenToShow>("base");
6064

@@ -66,27 +70,15 @@ export function OTPLoginUI(props: {
6670
try {
6771
if ("email" in userInfo) {
6872
await preAuthenticate({
69-
ecosystem: isEcosystem
70-
? {
71-
id: wallet.id as EcosystemWalletId,
72-
partnerId: (wallet as Wallet<EcosystemWalletId>).getConfig()
73-
?.partnerId,
74-
}
75-
: undefined,
73+
ecosystem,
7674
email: userInfo.email,
7775
strategy: "email",
7876
client: props.client,
7977
});
8078
setAccountStatus("sent");
8179
} else if ("phone" in userInfo) {
8280
await preAuthenticate({
83-
ecosystem: isEcosystem
84-
? {
85-
id: wallet.id as EcosystemWalletId,
86-
partnerId: (wallet as Wallet<EcosystemWalletId>).getConfig()
87-
?.partnerId,
88-
}
89-
: undefined,
81+
ecosystem,
9082
phoneNumber: userInfo.phone,
9183
strategy: "phone",
9284
client: props.client,
@@ -100,7 +92,7 @@ export function OTPLoginUI(props: {
10092
setVerifyStatus("idle");
10193
setAccountStatus("error");
10294
}
103-
}, [props.client, userInfo, wallet, isEcosystem]);
95+
}, [props.client, userInfo, ecosystem]);
10496

10597
async function connect(otp: string) {
10698
if ("email" in userInfo) {
@@ -133,13 +125,15 @@ export function OTPLoginUI(props: {
133125
strategy: "email",
134126
email: userInfo.email,
135127
verificationCode: otp,
128+
ecosystem,
136129
});
137130
} else if ("phone" in userInfo) {
138131
await linkProfile({
139132
client: props.client,
140133
strategy: "phone",
141134
phoneNumber: userInfo.phone,
142135
verificationCode: otp,
136+
ecosystem,
143137
});
144138
}
145139
}

packages/thirdweb/src/react/web/wallets/shared/PassKeyLogin.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ function SignupScreen(props: {
211211
const { wallet, done, client, chain } = props;
212212
const [error, setError] = useState<string | undefined>();
213213
const [status, setStatus] = useState<"loading" | "error">("loading");
214+
const ecosystem = isEcosystemWallet(wallet)
215+
? {
216+
id: wallet.id,
217+
partnerId: wallet.getConfig()?.partnerId,
218+
}
219+
: undefined;
214220

215221
async function signup() {
216222
setStatus("loading");
@@ -220,6 +226,7 @@ function SignupScreen(props: {
220226
client,
221227
strategy: "passkey",
222228
type: "sign-up",
229+
ecosystem,
223230
});
224231
} else {
225232
await wallet.connect({

packages/thirdweb/src/react/web/wallets/shared/SocialLogin.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ export function SocialLogin(props: {
3939
const ewLocale = props.locale;
4040
const locale = ewLocale.socialLoginScreen;
4141
const themeObj = useCustomTheme();
42+
const ecosystem = isEcosystemWallet(props.wallet)
43+
? {
44+
id: props.wallet.id,
45+
partnerId: props.wallet.getConfig()?.partnerId,
46+
}
47+
: undefined;
4248

4349
const [authError, setAuthError] = useState<string | undefined>(undefined);
4450
const { done, wallet } = props;
@@ -62,12 +68,7 @@ export function SocialLogin(props: {
6268
return loginWithOauthRedirect({
6369
authOption: props.socialAuth,
6470
client: props.client,
65-
ecosystem: isEcosystemWallet(wallet)
66-
? {
67-
id: wallet.id,
68-
partnerId: wallet.getConfig()?.partnerId,
69-
}
70-
: undefined,
71+
ecosystem,
7172
redirectUrl: walletConfig?.auth?.redirectUrl,
7273
mode: walletConfig?.auth?.mode,
7374
});
@@ -78,12 +79,7 @@ export function SocialLogin(props: {
7879
authOption: props.socialAuth,
7980
themeObj,
8081
client: props.client,
81-
ecosystem: isEcosystemWallet(wallet)
82-
? {
83-
id: wallet.id,
84-
partnerId: wallet.getConfig()?.partnerId,
85-
}
86-
: undefined,
82+
ecosystem,
8783
});
8884

8985
if (!socialWindow) {
@@ -99,6 +95,7 @@ export function SocialLogin(props: {
9995
closeOpenedWindow: (openedWindow) => {
10096
openedWindow.close();
10197
},
98+
ecosystem,
10299
}).catch((e) => {
103100
setAuthError(e.message);
104101
throw e;

0 commit comments

Comments
 (0)