Skip to content

Commit

Permalink
feat: farcaster login (#3827)
Browse files Browse the repository at this point in the history
### TL;DR

Added Farcaster icon and login support to the thirdweb package.

### What changed?

- Added Farcaster icon to `socialIcons.ts` and `svgs.ts`
- Updated `WalletImage.tsx` to include Farcaster icon.
- Added Farcaster as a supported social login option throughout the codebase.

### How to test?

1. Ensure the Farcaster icon is rendered correctly by using the Farcaster login option.
2. Verify the Farcaster login flow works as expected on both web and native applications.

### Why make this change?

This update adds support for Farcaster as a social login option, enhancing the flexibility and options available to users for authentication.

---

<!-- start pr-codex -->

---

## PR-Codex overview
This PR adds support for the "Farcaster" authentication option in various parts of the application.

### Detailed summary
- Added "Farcaster" as an authentication option
- Updated login and connection flows to include "Farcaster"
- Introduced Farcaster icons for web and native UI components
- Enhanced social auth login paths to support Farcaster

> The following files were skipped due to too many changes: `packages/thirdweb/src/react/core/utils/socialIcons.ts`

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Jul 27, 2024
1 parent 95d90ea commit b0a303d
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 39 deletions.
12 changes: 12 additions & 0 deletions .changeset/spicy-flowers-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"thirdweb": minor
---

Adds SIWF for in-app wallets

```ts
await wallet.connect({
strategy: "farcaster",
client: CLIENT,
});
```
2 changes: 1 addition & 1 deletion apps/playground-web/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export const WALLETS = [
auth: {
options: [
"google",
"facebook",
"discord",
"apple",
"email",
"passkey",
"phone",
"farcaster",
],
mode: "redirect",
},
Expand Down
3 changes: 3 additions & 0 deletions packages/thirdweb/src/react/core/utils/socialIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const twitchIconUri =
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgi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0ZSgtMTgwIDM0IDE0KSIvPjxwYXRoIGZpbGw9IiNmZmMxMDciIGQ9Ik0yNiAyNkg0MlY0MkgyNnoiIHRyYW5zZm9ybT0icm90YXRlKC0xODAgMzQgMzQpIi8+PHBhdGggZmlsbD0iIzAzYTlmNCIgZD0iTTYgMjZIMjJWNDJINnoiIHRyYW5zZm9ybT0icm90YXRlKC0xODAgMTQgMzQpIi8+PC9zdmc+";

Expand Down Expand Up @@ -48,4 +50,5 @@ export const socialIcons = {
apple: appleIconUri,
facebook: facebookIconUri,
discord: discordIconUri,
farcaster: farcasterIconUri,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DISCORD_ICON,
EMAIL_ICON,
FACEBOOK_ICON,
FARCASTER_ICON,
GOOGLE_ICON,
PHONE_ICON,
WALLET_ICON,
Expand Down Expand Up @@ -76,6 +77,8 @@ export function getAuthProviderImage(lastAuthProvider: string | null): string {
return FACEBOOK_ICON;
case "discord":
return DISCORD_ICON;
case "farcaster":
return FARCASTER_ICON;
default:
return WALLET_ICON;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/thirdweb/src/react/native/ui/connect/InAppWalletUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import type {
} from "../../../../wallets/in-app/core/wallet/types.js";
import { preAuthenticate } from "../../../../wallets/in-app/native/auth/index.js";
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
import {
type SocialAuthOption,
socialAuthOptions,
} from "../../../../wallets/types.js";
import type { Theme } from "../../../core/design-system/index.js";
import { setLastAuthProvider } from "../../../core/utils/storage.js";
import { radius, spacing } from "../../design-system/index.js";
Expand All @@ -26,6 +30,7 @@ import {
DISCORD_ICON,
EMAIL_ICON,
FACEBOOK_ICON,
FARCASTER_ICON,
GOOGLE_ICON,
PHONE_ICON,
} from "../icons/svgs.js";
Expand All @@ -44,6 +49,7 @@ const socialIcons = {
facebook: FACEBOOK_ICON,
apple: APPLE_ICON,
discord: DISCORD_ICON,
farcaster: FARCASTER_ICON,
};

type InAppWalletFormUIProps = {
Expand All @@ -62,9 +68,8 @@ export function InAppWalletUI(props: InAppWalletFormUIProps) {
const { wallet, theme } = props;
const config = wallet.getConfig();
const authOptions = config?.auth?.options || defaultAuthOptions;
const socialLogins = authOptions.filter(
(x) =>
x === "google" || x === "apple" || x === "facebook" || x === "discord",
const socialLogins = authOptions.filter((x) =>
socialAuthOptions.includes(x as SocialAuthOption),
) as InAppWalletSocialAuth[];

const [inputMode, setInputMode] = useState<"email" | "phone">("email");
Expand Down
7 changes: 7 additions & 0 deletions packages/thirdweb/src/react/native/ui/icons/svgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const DISCORD_ICON = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink
</g>
</svg>`;

export const FARCASTER_ICON = `<svg width={width} height={height} viewBox="0 0 1000 1000" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="1000" height="1000" rx="200" fill="#855DCD"/>
<path d="M257.778 155.556H742.222V844.444H671.111V528.889H670.414C662.554 441.677 589.258 373.333 500 373.333C410.742 373.333 337.446 441.677 329.586 528.889H328.889V844.444H257.778V155.556Z" fill="white"/>
<path d="M128.889 253.333L157.778 351.111H182.222V746.667C169.949 746.667 160 756.616 160 768.889V795.556H155.556C143.283 795.556 133.333 805.505 133.333 817.778V844.444H382.222V817.778C382.222 805.505 372.273 795.556 360 795.556H355.556V768.889C355.556 756.616 345.606 746.667 333.333 746.667H306.667V253.333H128.889Z" fill="white"/>
<path d="M675.556 746.667C663.283 746.667 653.333 756.616 653.333 768.889V795.556H648.889C636.616 795.556 626.667 805.505 626.667 817.778V844.444H875.556V817.778C875.556 805.505 865.606 795.556 853.333 795.556H848.889V768.889C848.889 756.616 838.94 746.667 826.667 746.667V351.111H851.111L880 253.333H702.222V746.667H675.556Z" fill="white"/>
</svg>`;

export const EMAIL_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13.3335 2.6665H2.66683C1.93045 2.6665 1.3335 3.26346 1.3335 3.99984V11.9998C1.3335 12.7362 1.93045 13.3332 2.66683 13.3332H13.3335C14.0699 13.3332 14.6668 12.7362 14.6668 11.9998V3.99984C14.6668 3.26346 14.0699 2.6665 13.3335 2.6665Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14.6668 4.6665L8.68683 8.4665C8.48101 8.59545 8.24304 8.66384 8.00016 8.66384C7.75728 8.66384 7.51931 8.59545 7.3135 8.4665L1.3335 4.6665" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
Expand Down
4 changes: 4 additions & 0 deletions packages/thirdweb/src/react/web/ui/components/WalletImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
discordIconUri,
emailIcon,
facebookIconUri,
farcasterIconUri,
genericWalletIcon,
googleIconUri,
passkeyIcon,
Expand Down Expand Up @@ -77,6 +78,9 @@ export function WalletImage(props: {
case "discord":
image = discordIconUri;
break;
case "farcaster":
image = farcasterIconUri;
break;

Check warning on line 83 in packages/thirdweb/src/react/web/ui/components/WalletImage.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/components/WalletImage.tsx#L81-L83

Added lines #L81 - L83 were not covered by tests
}
} else {
const mipdImage = getInstalledWalletProviders().find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const ConnectWalletSocialOptions = (
facebook: locale.signInWithFacebook,
apple: locale.signInWithApple,
discord: locale.signInWithDiscord,
farcaster: "Farcaster",

Check warning on line 94 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#L94

Added line #L94 was not covered by tests
};

const { data: ecosystemAuthOptions, isLoading } = useQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ function getOauthLoginPath(
case "apple":
case "facebook":
case "google":
case "farcaster":

Check warning on line 36 in packages/thirdweb/src/react/web/wallets/shared/oauthSignIn.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/wallets/shared/oauthSignIn.ts#L36

Added line #L36 was not covered by tests
case "discord":
return getSocialAuthLoginPath(authOption, client, ecosystem);
return getSocialAuthLoginPath({ authOption, client, ecosystem });

Check warning on line 38 in packages/thirdweb/src/react/web/wallets/shared/oauthSignIn.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/wallets/shared/oauthSignIn.ts#L38

Added line #L38 was not covered by tests
default:
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
import type { SocialAuthOption } from "../../../../wallets/types.js";
import type { Ecosystem } from "../../web/types.js";

export const getSocialAuthLoginPath = (
authOption: SocialAuthOption,
client: ThirdwebClient,
ecosystem?: Ecosystem,
) => {
const baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${authOption}?clientId=${client.clientId}`;
export const getSocialAuthLoginPath = ({
authOption,
client,
ecosystem,
mode = "popup",
}: {
authOption: SocialAuthOption;
client: ThirdwebClient;
ecosystem?: Ecosystem;
mode?: "popup" | "redirect";
}) => {
let baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${authOption}?clientId=${client.clientId}`;

Check warning on line 17 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-L17

Added lines #L7 - L17 were not covered by tests
if (ecosystem?.partnerId) {
return `${baseUrl}&ecosystemId=${ecosystem.id}&ecosystemPartnerId=${ecosystem.partnerId}`;
baseUrl = `${baseUrl}&ecosystemId=${ecosystem.id}&ecosystemPartnerId=${ecosystem.partnerId}`;
} else if (ecosystem) {
baseUrl = `${baseUrl}&ecosystemId=${ecosystem.id}`;

Check warning on line 21 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#L19-L21

Added lines #L19 - L21 were not covered by tests
}
if (ecosystem) {
return `${baseUrl}&ecosystemId=${ecosystem.id}`;

if (mode === "redirect") {
const redirectUrl = new URL(window.location.href);
redirectUrl.searchParams.set("walletId", ecosystem?.id || "inApp");
redirectUrl.searchParams.set("authProvider", authOption);
baseUrl = `${baseUrl}&redirectUrl=${encodeURIComponent(redirectUrl.toString())}`;

Check warning on line 28 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#L23-L28

Added lines #L23 - L28 were not covered by tests
}

Check warning on line 30 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#L30

Added line #L30 was not covered by tests
return baseUrl;
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export enum AuthProvider {
APPLE = "Apple",
PASSKEY = "Passkey",
DISCORD = "Discord",
FARCASTER = "Farcaster",
}

export type OauthOption = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ export async function socialLogin(
auth: OauthOption,
client: ThirdwebClient,
): Promise<AuthStoredTokenWithCookieReturnType> {
const loginUrl = `${getSocialAuthLoginPath(auth.strategy, client)}&redirectUrl=${encodeURIComponent(auth.redirectUrl)}`;
const loginUrl = getSocialAuthLoginPath({
authOption: auth.strategy,
client,
mode: "popup",
});

const result = await WebBrowser.openAuthSessionAsync(
loginUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class InAppNativeConnector implements InAppConnector {
case "google":
case "facebook":
case "discord":
case "farcaster":
case "apple": {
const ExpoLinking = require("expo-linking");
const redirectUrl =
Expand Down
30 changes: 6 additions & 24 deletions packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ThirdwebClient } from "../../../../../client/client.js";
import { getThirdwebBaseUrl } from "../../../../../utils/domains.js";
import type { AuthStoredTokenWithCookieReturnType } from "../../../../../wallets/in-app/core/authentication/type.js";
import type { SocialAuthOption } from "../../../../../wallets/types.js";
import { getSocialAuthLoginPath } from "../../../core/authentication/getLoginPath.js";
import type { Ecosystem } from "../../types.js";
import { DEFAULT_POP_UP_SIZE } from "./constants.js";

Expand All @@ -25,30 +26,15 @@ const closeWindow = ({
}
};

export const getSocialAuthLoginPath = (
authOption: SocialAuthOption,
client: ThirdwebClient,
ecosystem?: Ecosystem,
) => {
const baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${authOption}?clientId=${client.clientId}`;
if (ecosystem?.partnerId) {
return `${baseUrl}&ecosystemId=${ecosystem.id}&ecosystemPartnerId=${ecosystem.partnerId}`;
}
if (ecosystem) {
return `${baseUrl}&ecosystemId=${ecosystem.id}`;
}
return baseUrl;
};

export const loginWithOauthRedirect = (options: {
authOption: SocialAuthOption;
client: ThirdwebClient;
ecosystem?: Ecosystem;
}): void => {
const redirectUrl = new URL(window.location.href);
redirectUrl.searchParams.set("walletId", options.ecosystem?.id || "inApp");
redirectUrl.searchParams.set("authProvider", options.authOption);
const loginUrl = `${getSocialAuthLoginPath(options.authOption, options.client, options.ecosystem)}&redirectUrl=${encodeURIComponent(redirectUrl.toString())}`;
const loginUrl = getSocialAuthLoginPath({
...options,
mode: "redirect",
});

Check warning on line 37 in packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts#L34-L37

Added lines #L34 - L37 were not covered by tests
window.location.href = loginUrl;
};

Expand All @@ -63,11 +49,7 @@ export const loginWithOauth = async (options: {
let isWindowOpenedByFn = false;
if (!win) {
win = window.open(
getSocialAuthLoginPath(
options.authOption,
options.client,
options.ecosystem,
),
getSocialAuthLoginPath({ ...options, mode: "popup" }),

Check warning on line 52 in packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts#L52

Added line #L52 was not covered by tests
`Login to ${options.authOption}`,
DEFAULT_POP_UP_SIZE,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export class InAppWebConnector implements InAppConnector {
case "apple":
case "facebook":
case "google":
case "farcaster":

Check warning on line 225 in packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L225 was not covered by tests
case "discord": {
const authToken = await loginWithOauth({
authOption: strategy,
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 @@ -24,6 +24,7 @@ export const socialAuthOptions = [
"apple",
"facebook",
"discord",
"farcaster",
] as const;
export type SocialAuthOption = (typeof socialAuthOptions)[number];

Expand Down

0 comments on commit b0a303d

Please sign in to comment.