Skip to content

Commit 747f578

Browse files
Expose social icons
1 parent a0835f7 commit 747f578

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

packages/thirdweb/src/react/web/ui/prebuilt/Wallet/icon.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { render, waitFor } from "~test/react-render.js";
3-
import { WalletIcon, fetchWalletImage } from "./icon.js";
3+
import { SocialIcon, WalletIcon, fetchWalletImage } from "./icon.js";
44
import { WalletProvider } from "./provider.js";
55

66
describe("WalletIcon", () => {
@@ -28,3 +28,12 @@ describe("WalletIcon", () => {
2828
});
2929
});
3030
});
31+
32+
describe("SocialIcon", () => {
33+
it("should render an image", async () => {
34+
const { container } = render(<SocialIcon provider="google" />);
35+
await waitFor(() => {
36+
expect(container.querySelector("img")).not.toBe(null);
37+
});
38+
});
39+
});

packages/thirdweb/src/react/web/ui/prebuilt/Wallet/icon.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import { type UseQueryOptions, useQuery } from "@tanstack/react-query";
44
import type { JSX } from "react";
55
import { getWalletInfo } from "../../../../../wallets/__generated__/getWalletInfo.js";
6+
import type { AuthOption } from "../../../../../wallets/types.js";
67
import type { WalletId } from "../../../../../wallets/wallet-types.js";
8+
import { getSocialIcon } from "../../../../core/utils/walletIcon.js";
79
import { useWalletContext } from "./provider.js";
810

911
export interface WalletIconProps
@@ -20,11 +22,11 @@ export interface WalletIconProps
2022
*/
2123
loadingComponent?: JSX.Element;
2224
/**
23-
* This component will be shown if the icon fails to be retreived
25+
* This component will be shown if the icon fails to be retrieved
2426
* If not passed, the component will return `null`.
2527
*
2628
* You can/should pass a descriptive text/component to this prop, indicating that the
27-
* icon was not fetched succesfully
29+
* icon was not fetched successfully
2830
* @example
2931
* ```tsx
3032
* <WalletIcon fallbackComponent={<span>Failed to load</span>}
@@ -115,6 +117,35 @@ function useWalletIcon(props: {
115117
export async function fetchWalletImage(props: {
116118
id: WalletId;
117119
}) {
118-
const image_src = await getWalletInfo(props.id, true);
119-
return image_src;
120+
return getWalletInfo(props.id, true);
121+
}
122+
123+
interface SocialIconProps
124+
extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src"> {
125+
provider: AuthOption | string;
126+
}
127+
128+
/**
129+
* Social auth provider icon
130+
* @returns an <img /> component with the src set to the svg
131+
*
132+
* @example
133+
* ```tsx
134+
* import { SocialIcon } from "thirdweb/react";
135+
*
136+
* <SocialIcon provider="google" />
137+
* ```
138+
*
139+
* Result: An <img /> component with the src of the icon
140+
* ```html
141+
* <img src="google-icon-svg" />
142+
* ```
143+
*
144+
* @component
145+
* @wallet
146+
* @beta
147+
*/
148+
export function SocialIcon({ provider, ...restProps }: SocialIconProps) {
149+
const src = getSocialIcon(provider);
150+
return <img src={src} {...restProps} alt={restProps.alt} />;
120151
}

0 commit comments

Comments
 (0)