Skip to content

Commit 99fa2da

Browse files
authored
Adds custom logo to social login modal (#3034)
1 parent 001449d commit 99fa2da

File tree

7 files changed

+110
-6
lines changed

7 files changed

+110
-6
lines changed

.changeset/new-games-prove.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Adds the ability to set a custom logo for the social login modal
6+
7+
```ts
8+
import { inAppWallet } from "thirdweb/wallets";
9+
const wallet = inAppWallet({
10+
metadata: {
11+
image: {
12+
src: "https://example.com/logo.png",
13+
alt: "My logo",
14+
width: 100,
15+
height: 100,
16+
},
17+
},
18+
});
19+
```

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { TOS } from "./Modal/TOS.js";
3232
import { PoweredByThirdweb } from "./PoweredByTW.js";
3333
import { WalletButton, WalletEntryButton } from "./WalletEntryButton.js";
3434
import { WalletTypeRowButton } from "./WalletTypeRowButton.js";
35+
import { compactModalMaxHeight } from "./constants.js";
3536
import { genericWalletIcon } from "./icons/dataUris.js";
3637

3738
const InAppWalletSelectionUI = /* @__PURE__ */ lazy(
@@ -311,7 +312,13 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
311312
// social login + More than 1 eoa wallets
312313
if (eoaWallets.length > 1) {
313314
bottomSection = (
314-
<Container flex="column" gap="sm">
315+
<Container
316+
flex="column"
317+
style={{ position: "relative" }}
318+
gap="sm"
319+
>
320+
<GradientDiv />
321+
315322
<Container px="lg" flex="column" gap="md">
316323
{connectAWallet}
317324
{continueAsGuest}
@@ -386,7 +393,8 @@ const WalletSelectorInner: React.FC<WalletSelectorProps> = (props) => {
386393
animate="fadein"
387394
fullHeight
388395
style={{
389-
maxHeight: connectModal.size === "compact" ? "550px" : undefined,
396+
maxHeight:
397+
connectModal.size === "compact" ? compactModalMaxHeight : undefined,
390398
}}
391399
>
392400
{/* Header */}
@@ -604,3 +612,17 @@ const WalletList = /* @__PURE__ */ StyledUl({
604612
marginBottom: 0,
605613
paddingBottom: spacing.lg,
606614
});
615+
616+
const GradientDiv = /* @__PURE__ */ StyledDiv(() => {
617+
const theme = useCustomTheme();
618+
theme.colors.modalBg;
619+
return {
620+
height: spacing.lg,
621+
position: "absolute",
622+
top: `-${spacing.lg}`,
623+
left: 0,
624+
width: "100%",
625+
background: `linear-gradient(to bottom, transparent 0%, ${theme.colors.modalBg} 80%)`,
626+
pointerEvents: "none",
627+
};
628+
});

packages/thirdweb/src/react/web/ui/ConnectWallet/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const modalMaxWidthWide = `${wideModalWidth}px`;
1212
export const wideModalScreenThreshold = wideModalWidth + 40;
1313

1414
export const wideModalMaxHeight = "570px";
15-
export const compactModalMaxHeight = "650px";
15+
export const compactModalMaxHeight = "660px";
1616

1717
export const defaultTheme = "dark";
1818

packages/thirdweb/src/react/web/ui/components/Img.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useState } from "react";
33
import type { ThirdwebClient } from "../../../../client/client.js";
44
import { resolveScheme } from "../../../../utils/ipfs.js";
55
import { Skeleton } from "./Skeleton.js";
6+
import { Container } from "./basic.js";
67

78
// Note: Must not use useConnectUI here
89

@@ -28,7 +29,11 @@ export const Img: React.FC<{
2829
const heightPx = `${props.height || props.width}px`;
2930

3031
if (propSrc === undefined) {
31-
return <Skeleton width={widthPx} height={heightPx} />;
32+
return (
33+
<Container style={{ margin: "auto" }}>
34+
<Skeleton width={widthPx} height={heightPx} />
35+
</Container>
36+
);
3237
}
3338

3439
const getSrc = () => {
@@ -51,9 +56,14 @@ export const Img: React.FC<{
5156
display: "inline-flex",
5257
flexShrink: 0,
5358
alignItems: "center",
59+
justifyItems: "center",
5460
}}
5561
>
56-
{!isLoaded && <Skeleton width={widthPx} height={heightPx} />}
62+
{!isLoaded && (
63+
<Container style={{ margin: "auto" }}>
64+
<Skeleton width={widthPx} height={heightPx} />
65+
</Container>
66+
)}
5767
<img
5868
onLoad={() => {
5969
setIsLoaded(true);
@@ -66,6 +76,7 @@ export const Img: React.FC<{
6676
loading={props.loading}
6777
decoding="async"
6878
style={{
79+
display: isLoaded ? "block" : "none",
6980
objectFit: "contain",
7081
height: !isLoaded
7182
? 0

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ export const InAppWalletFormUI = (props: InAppWalletFormUIProps) => {
152152

153153
const showOnlyIcons = socialLogins.length > 1;
154154

155+
if (
156+
config?.metadata?.image &&
157+
(!config.metadata.image.height || !config.metadata.image.width)
158+
) {
159+
console.warn(
160+
"Image is not properly configured. Please set height and width.",
161+
config.metadata.image,
162+
);
163+
}
164+
155165
return (
156166
<Container
157167
flex="column"
@@ -160,6 +170,25 @@ export const InAppWalletFormUI = (props: InAppWalletFormUIProps) => {
160170
position: "relative",
161171
}}
162172
>
173+
{config?.metadata?.image && (
174+
<Img
175+
loading="eager"
176+
client={client}
177+
style={{
178+
maxHeight: "100px",
179+
maxWidth: "300px",
180+
margin: "auto",
181+
}}
182+
src={config.metadata.image.src}
183+
alt={config.metadata.image.alt}
184+
width={Math.min(config.metadata.image.width ?? 300, 300)?.toString()}
185+
height={Math.min(
186+
config.metadata.image.height ?? 100,
187+
100,
188+
)?.toString()}
189+
/>
190+
)}
191+
163192
{/* Social Login */}
164193
{hasSocialLogins && (
165194
<Container
@@ -320,7 +349,7 @@ export function InAppWalletFormUIScreen(props: InAppWalletFormUIProps) {
320349
{isCompact ? (
321350
<>
322351
<ModalHeader onBack={onBack} title={locale.title} />
323-
<Spacer y="xl" />
352+
<Spacer y="sm" />
324353
</>
325354
) : null}
326355

packages/thirdweb/src/wallets/create-wallet.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,21 @@ export function smartWallet(
420420
* },
421421
* });
422422
* ```
423+
*
424+
* Specify a logo for your login page
425+
* ```ts
426+
* import { inAppWallet } from "thirdweb/wallets";
427+
* const wallet = inAppWallet({
428+
* metadata: {
429+
* image: {
430+
* src: "https://example.com/logo.png",
431+
* alt: "My logo",
432+
* width: 100,
433+
* height: 100,
434+
* },
435+
* },
436+
* });
437+
* ```
423438
* @wallet
424439
*/
425440
export function inAppWallet(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ export type InAppWalletCreationOptions =
3232
auth?: {
3333
options: InAppWalletAuth[];
3434
};
35+
metadata?: {
36+
image?: {
37+
src: string;
38+
width?: number;
39+
height?: number;
40+
alt?: string;
41+
};
42+
};
3543
smartAccount?: SmartWalletOptions;
3644
}
3745
| undefined;

0 commit comments

Comments
 (0)