Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fifty-houses-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Enable Sign in with Wallet for ecosystems
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ export function AuthOptionsForm({ ecosystem }: { ecosystem: Ecosystem }) {
className="h-6 w-6"
/>
<p className="text-center font-normal">
{option.slice(0, 1).toUpperCase() + option.slice(1)}
{option === "siwe"
? "Wallet"
: option.slice(0, 1).toUpperCase() +
option.slice(1)}
</p>
<div className="flex-1" />
<FormControl>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const authOptions = [
"email",
"phone",
"passkey",
"siwe",
"guest",
"google",
"facebook",
"x",
Expand All @@ -12,7 +15,6 @@ export const authOptions = [
"apple",
"coinbase",
"line",
"guest",
] as const;

export type Ecosystem = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function usePlaygroundWallets() {
github: false,
coinbase: false,
guest: false,
wallet: false,
});

const [enabledWallets, setEnabledWallets] = useState<WalletRecord>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const getEcosystem = () => {
process.env.NEXT_PUBLIC_IN_APP_WALLET_URL?.endsWith(".thirdweb-dev.com")
) {
// dev ecosystem
return "ecosystem.bonfire-development";
return "ecosystem.catlovers";
}
// prod ecosystem
return "ecosystem.new-age";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { describe, expect, it } from "vitest";
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
import { TEST_ACCOUNT_B } from "../../../test/src/test-wallets.js";
import { getContract } from "../../contract/contract.js";
import { name } from "../common/read/name.js";
import { deployERC1155Contract } from "./deploy-erc1155.js";

// skip this test suite if there is no secret key available to test with
// TODO: remove reliance on secret key during unit tests entirely
const account = TEST_ACCOUNT_B;

describe.runIf(process.env.TW_SECRET_KEY)("deployERC1155", () => {
it("should deploy ERC1155 drop", async () => {
const address = await deployERC1155Contract({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
account: TEST_ACCOUNT_A,
account,
type: "DropERC1155",
params: {
name: "EditionDrop",
Expand All @@ -35,7 +35,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("deployERC1155", () => {
const address = await deployERC1155Contract({
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
account: TEST_ACCOUNT_A,
account,
type: "TokenERC1155",
params: {
name: "Edition",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { describe, expect, it } from "vitest";
import { ANVIL_CHAIN } from "~test/chains.js";
import { TEST_CLIENT } from "~test/test-clients.js";
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
import { TEST_ACCOUNT_C } from "~test/test-wallets.js";
import { isAddress } from "../../utils/address.js";
import { deployPackContract } from "./deploy-pack.js";

const account = TEST_ACCOUNT_C;

describe.runIf(process.env.TW_SECRET_KEY)("deploy-pack contract", () => {
it("should deploy Pack contract", async () => {
const address = await deployPackContract({
account: TEST_ACCOUNT_A,
account,
client: TEST_CLIENT,
chain: ANVIL_CHAIN,
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
done={done}
onBack={goBackToMain || (() => setSelectionData({}))}
locale={props.connectLocale}
isLinking={state.walletLogin.linking}

Check warning on line 132 in packages/thirdweb/src/react/web/wallets/ecosystem/EcosystemWalletConnectUI.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/wallets/ecosystem/EcosystemWalletConnectUI.tsx#L132

Added line #L132 was not covered by tests
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function InAppWalletConnectUI(props: {
done={done}
onBack={goBackToMain || (() => setSelectionData({}))}
locale={props.connectLocale}
isLinking={state.walletLogin.linking}
/>
);
}
Expand Down
30 changes: 20 additions & 10 deletions packages/thirdweb/src/react/web/wallets/in-app/WalletAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
inAppLocale: InAppWalletLocale;
onBack: () => void;
walletConnect: { projectId?: string } | undefined;
isLinking: boolean;
meta?: {
title?: string;
titleIconUrl?: string;
Expand Down Expand Up @@ -61,16 +62,25 @@
setStatus("loading");
walletToConnect.current = walletToLink;
try {
await linkProfile({
client: props.client,
strategy: "wallet",
wallet: walletToLink,
chain: wallet.getChain() || defineChain(1),
ecosystem,
}).catch((e) => {
setError(e.message);
throw e;
});
if (props.isLinking) {
await linkProfile({
client: props.client,
strategy: "wallet",
wallet: walletToLink,
chain: wallet.getChain() || defineChain(1),
ecosystem,
}).catch((e) => {
setError(e.message);
throw e;
});
} else {
await wallet.connect({
client: props.client,
strategy: "wallet",
wallet: walletToLink,
chain: walletToLink.getChain() || defineChain(1),
});
}

Check warning on line 83 in packages/thirdweb/src/react/web/wallets/in-app/WalletAuth.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L65 - L83 were not covered by tests
addConnectedWallet(walletToLink);
done();
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
connectionPromise: Promise<Account | Profile[]>;
};
passkeyLogin?: boolean;
walletLogin?: boolean;
walletLogin?: {
linking: boolean;
};
};

const defaultAuthOptions: AuthOption[] = [
Expand Down Expand Up @@ -186,6 +188,7 @@

const passKeyEnabled = authOptions.includes("passkey");
const guestEnabled = authOptions.includes("guest");
const siweEnabled = authOptions.includes("wallet");

Check warning on line 191 in packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L191 was not covered by tests

const placeholder =
inputMode === "email" ? locale.emailPlaceholder : locale.phonePlaceholder;
Expand Down Expand Up @@ -306,7 +309,9 @@

function handleWalletLogin() {
setData({
walletLogin: true,
walletLogin: {
linking: props.isLinking || false,
},

Check warning on line 314 in packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx#L312-L314

Added lines #L312 - L314 were not covered by tests
});
props.select();
}
Expand Down Expand Up @@ -467,6 +472,18 @@
/>
)}

{/* SIWE login */}
{siweEnabled && (
<WalletTypeRowButton
client={props.client}
icon={getSocialIcon("")}
onClick={() => {
handleWalletLogin();
}}
title={locale.signInWithWallet}
/>

Check warning on line 484 in packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx#L476-L484

Added lines #L476 - L484 were not covered by tests
)}

{/* Guest login */}
{guestEnabled && (
<WalletTypeRowButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export default {
passkey: "Passkey",
linkWallet: "Verknüpfen Sie eine Brieftasche",
loginAsGuest: "Melden Sie sich als Gast an",
signInWithWallet: "Mit Wallet anmelden",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default {
signInWithPhone: "Sign in with phone number",
phoneRequired: "Phone number is required",
passkey: "Passkey",
signInWithWallet: "Sign in with Wallet",
linkWallet: "Link a Wallet",
loginAsGuest: "Continue as guest",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export default {
passkey: "Clave de acceso",
linkWallet: "Vincular una billetera",
loginAsGuest: "Inicia sesión como invitado",
signInWithWallet: "Iniciar sesión con billetera",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export default {
passkey: "Passkey",
linkWallet: "Lier un portefeuille",
loginAsGuest: "Connectez-vous en tant qu'invité",
signInWithWallet: "Se connecter avec portefeuille",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export default {
passkey: "パスキー",
linkWallet: "ウォレットをリンクする",
loginAsGuest: "ゲストとしてログイン",
signInWithWallet: "ウォレットでログイン",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ export default {
passkey: "비밀번호",
linkWallet: "지갑 연결",
loginAsGuest: "게스트로 로그인",
signInWithWallet: "지갑으로 로그인",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export default {
passkey: "Passkey",
linkWallet: "Mag-link ng Wallet",
loginAsGuest: "Mag-login bilang bisita",
signInWithWallet: "Mag-login gamit ang Wallet",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type InAppWalletLocale = {
signInWithApple: string;
signInWithFacebook: string;
signInWithGoogle: string;
signInWithWallet: string;
socialLoginScreen: {
failed: string;
instruction: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ export default {
passkey: "Passkey",
linkWallet: "Link a Wallet",
loginAsGuest: "Đăng nhập với tư cách khách",
signInWithWallet: "Đăng nhập bằng Wallet",
} satisfies InAppWalletLocale;
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@
);
}

// siwe is the auth option in the backend, but we want to use wallet as the auth option in the frontend
if (data.authOptions?.includes("siwe")) {
data.authOptions = data.authOptions.filter((o: string) => o !== "siwe");
data.authOptions.push("wallet");
}

Check warning on line 47 in packages/thirdweb/src/wallets/ecosystem/get-ecosystem-wallet-auth-options.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/ecosystem/get-ecosystem-wallet-auth-options.ts#L44-L47

Added lines #L44 - L47 were not covered by tests

return data ?? null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { type AuthOption, authOptions } from "../../../../wallets/types.js";
import type { Ecosystem } from "../wallet/types.js";

const getLoginOptionRoute = (option: AuthOption | "wallet") => {
if (!authOptions.includes(option as AuthOption) && option !== "wallet") {
const getLoginOptionRoute = (option: AuthOption) => {
if (!authOptions.includes(option as AuthOption)) {

Check warning on line 7 in packages/thirdweb/src/wallets/in-app/core/authentication/getLoginPath.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/in-app/core/authentication/getLoginPath.ts#L7

Added line #L7 was not covered by tests
throw new Error(`Unknown auth option ${option}`);
}
switch (option) {
Expand All @@ -22,7 +22,7 @@
mode = "popup",
redirectUrl,
}: {
authOption: AuthOption | "wallet";
authOption: AuthOption;
client: ThirdwebClient;
ecosystem?: Ecosystem;
mode?: "popup" | "redirect" | "window";
Expand Down Expand Up @@ -60,7 +60,7 @@
client,
ecosystem,
}: {
authOption: AuthOption | "wallet";
authOption: AuthOption;
client: ThirdwebClient;
ecosystem?: Ecosystem;
}): string => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type OAuthRedirectObject = {

// TODO: type this better for each auth provider
export type Profile = {
type: AuthOption | "wallet";
type: AuthOption;
details: {
id?: string;
email?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/thirdweb/src/wallets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const authOptions = [
"email",
"phone",
"passkey",
"wallet",
] as const;
export type AuthOption = (typeof authOptions)[number];

Expand Down