|
| 1 | +"use client"; |
| 2 | +import type { ThirdwebClient } from "../../../../client/client.js"; |
| 3 | +import type { Wallet } from "../../../../wallets/interfaces/wallet.js"; |
| 4 | +import type { AuthOption } from "../../../../wallets/types.js"; |
| 5 | +import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js"; |
| 6 | +import { |
| 7 | + iconSize, |
| 8 | + radius, |
| 9 | + spacing, |
| 10 | +} from "../../../core/design-system/index.js"; |
| 11 | +import { socialIcons } from "../../../core/utils/walletIcon.js"; |
| 12 | +import { defaultAuthOptions } from "../../wallets/shared/ConnectWalletSocialOptions.js"; |
| 13 | +import { Img } from "../components/Img.js"; |
| 14 | +import { EmailIcon } from "./icons/EmailIcon.js"; |
| 15 | +import { FingerPrintIcon } from "./icons/FingerPrintIcon.js"; |
| 16 | +import { GuestIcon } from "./icons/GuestIcon.js"; |
| 17 | +import { PhoneIcon } from "./icons/PhoneIcon.js"; |
| 18 | + |
| 19 | +export function InAppWalletIcon(props: { |
| 20 | + client: ThirdwebClient; |
| 21 | + wallet: Wallet<"inApp">; |
| 22 | +}) { |
| 23 | + const enabledAuthMethods = ( |
| 24 | + props.wallet.getConfig()?.auth?.options || defaultAuthOptions |
| 25 | + ).sort((a, b) => { |
| 26 | + if (a in socialIcons && !(b in socialIcons)) { |
| 27 | + return -1; |
| 28 | + } |
| 29 | + if (!(a in socialIcons) && b in socialIcons) { |
| 30 | + return 1; |
| 31 | + } |
| 32 | + return 0; |
| 33 | + }); |
| 34 | + const theme = useCustomTheme(); |
| 35 | + |
| 36 | + const firstMethod = enabledAuthMethods[0]; |
| 37 | + const secondMethod = enabledAuthMethods[1]; |
| 38 | + const thirdMethod = enabledAuthMethods[2]; |
| 39 | + const fourthMethod = enabledAuthMethods[3]; |
| 40 | + |
| 41 | + const offset = "3.5px"; |
| 42 | + const offset2 = "6px"; |
| 43 | + const smallIconSize = "20"; |
| 44 | + const extraIconSize = "12"; |
| 45 | + |
| 46 | + if (firstMethod && secondMethod) { |
| 47 | + return ( |
| 48 | + <div |
| 49 | + style={{ |
| 50 | + width: `${iconSize.xl}px`, |
| 51 | + height: `${iconSize.xl}px`, |
| 52 | + position: "relative", |
| 53 | + gap: spacing["3xs"], |
| 54 | + border: `1px solid ${theme.colors.borderColor}`, |
| 55 | + borderRadius: radius.md, |
| 56 | + backgroundColor: theme.colors.tertiaryBg, |
| 57 | + }} |
| 58 | + > |
| 59 | + <div |
| 60 | + style={{ |
| 61 | + position: "absolute", |
| 62 | + top: offset, |
| 63 | + left: offset, |
| 64 | + display: "flex", |
| 65 | + }} |
| 66 | + > |
| 67 | + <AuthOptionIcon |
| 68 | + authOption={firstMethod} |
| 69 | + client={props.client} |
| 70 | + size={smallIconSize} |
| 71 | + /> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div |
| 75 | + style={{ |
| 76 | + position: "absolute", |
| 77 | + bottom: offset, |
| 78 | + right: offset, |
| 79 | + display: "flex", |
| 80 | + }} |
| 81 | + > |
| 82 | + <AuthOptionIcon |
| 83 | + authOption={secondMethod} |
| 84 | + client={props.client} |
| 85 | + size={smallIconSize} |
| 86 | + /> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div> |
| 90 | + {thirdMethod && ( |
| 91 | + <div |
| 92 | + style={{ |
| 93 | + position: "absolute", |
| 94 | + top: offset2, |
| 95 | + right: offset2, |
| 96 | + display: "flex", |
| 97 | + }} |
| 98 | + > |
| 99 | + <AuthOptionIcon |
| 100 | + authOption={thirdMethod} |
| 101 | + client={props.client} |
| 102 | + size={extraIconSize} |
| 103 | + /> |
| 104 | + </div> |
| 105 | + )} |
| 106 | + |
| 107 | + {fourthMethod && ( |
| 108 | + <div |
| 109 | + style={{ |
| 110 | + position: "absolute", |
| 111 | + bottom: offset2, |
| 112 | + left: offset2, |
| 113 | + display: "flex", |
| 114 | + }} |
| 115 | + > |
| 116 | + <AuthOptionIcon |
| 117 | + authOption={fourthMethod} |
| 118 | + client={props.client} |
| 119 | + size={extraIconSize} |
| 120 | + /> |
| 121 | + </div> |
| 122 | + )} |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + ); |
| 126 | + } |
| 127 | + |
| 128 | + if (firstMethod) { |
| 129 | + return ( |
| 130 | + <div |
| 131 | + style={{ |
| 132 | + width: `${iconSize.xl}px`, |
| 133 | + height: `${iconSize.xl}px`, |
| 134 | + display: "flex", |
| 135 | + justifyContent: "center", |
| 136 | + alignItems: "center", |
| 137 | + border: `1px solid ${theme.colors.borderColor}`, |
| 138 | + borderRadius: radius.md, |
| 139 | + backgroundColor: theme.colors.tertiaryBg, |
| 140 | + }} |
| 141 | + > |
| 142 | + <AuthOptionIcon |
| 143 | + authOption={firstMethod} |
| 144 | + client={props.client} |
| 145 | + key={firstMethod} |
| 146 | + size={iconSize.lg} |
| 147 | + /> |
| 148 | + </div> |
| 149 | + ); |
| 150 | + } |
| 151 | + |
| 152 | + return null; |
| 153 | +} |
| 154 | + |
| 155 | +function AuthOptionIcon(props: { |
| 156 | + authOption: AuthOption; |
| 157 | + client: ThirdwebClient; |
| 158 | + size: string; |
| 159 | +}) { |
| 160 | + const theme = useCustomTheme(); |
| 161 | + if (props.authOption in socialIcons) { |
| 162 | + const icon = socialIcons[props.authOption as keyof typeof socialIcons]; |
| 163 | + return ( |
| 164 | + <Img |
| 165 | + src={icon} |
| 166 | + width={props.size} |
| 167 | + height={props.size} |
| 168 | + client={props.client} |
| 169 | + /> |
| 170 | + ); |
| 171 | + } |
| 172 | + |
| 173 | + if (props.authOption === "phone") { |
| 174 | + return <PhoneIcon size={props.size} color={theme.colors.secondaryText} />; |
| 175 | + } |
| 176 | + |
| 177 | + if (props.authOption === "email") { |
| 178 | + return <EmailIcon size={props.size} color={theme.colors.secondaryText} />; |
| 179 | + } |
| 180 | + |
| 181 | + if (props.authOption === "passkey") { |
| 182 | + return ( |
| 183 | + <FingerPrintIcon size={props.size} color={theme.colors.secondaryText} /> |
| 184 | + ); |
| 185 | + } |
| 186 | + |
| 187 | + if (props.authOption === "guest") { |
| 188 | + return <GuestIcon size={props.size} color={theme.colors.secondaryText} />; |
| 189 | + } |
| 190 | + |
| 191 | + return null; |
| 192 | +} |
0 commit comments