3
3
import { type UseQueryOptions , useQuery } from "@tanstack/react-query" ;
4
4
import type { JSX } from "react" ;
5
5
import { getWalletInfo } from "../../../../../wallets/__generated__/getWalletInfo.js" ;
6
+ import type { AuthOption } from "../../../../../wallets/types.js" ;
6
7
import type { WalletId } from "../../../../../wallets/wallet-types.js" ;
8
+ import { getSocialIcon } from "../../../../core/utils/walletIcon.js" ;
7
9
import { useWalletContext } from "./provider.js" ;
8
10
9
11
export interface WalletIconProps
@@ -20,11 +22,11 @@ export interface WalletIconProps
20
22
*/
21
23
loadingComponent ?: JSX . Element ;
22
24
/**
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
24
26
* If not passed, the component will return `null`.
25
27
*
26
28
* 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
28
30
* @example
29
31
* ```tsx
30
32
* <WalletIcon fallbackComponent={<span>Failed to load</span>}
@@ -115,6 +117,35 @@ function useWalletIcon(props: {
115
117
export async function fetchWalletImage ( props : {
116
118
id : WalletId ;
117
119
} ) {
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 } /> ;
120
151
}
0 commit comments