@erikey/react 0.4.25 → 0.4.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui/index.mjs CHANGED
@@ -13738,7 +13738,7 @@ function AuthForm({
13738
13738
  }
13739
13739
 
13740
13740
  // src/ui/components/auth/auth-view.tsx
13741
- import { useContext as useContext28, useEffect as useEffect22, useState as useState14 } from "react";
13741
+ import { useContext as useContext29, useEffect as useEffect23, useState as useState15 } from "react";
13742
13742
 
13743
13743
  // src/ui/components/provider-icons.tsx
13744
13744
  import { jsx as jsx29, jsxs as jsxs18 } from "react/jsx-runtime";
@@ -14724,8 +14724,209 @@ function ProviderButton({
14724
14724
  );
14725
14725
  }
14726
14726
 
14727
+ // src/ui/components/auth/wallet-button.tsx
14728
+ import { useContext as useContext28, useState as useState14, useEffect as useEffect22, useCallback as useCallback8 } from "react";
14729
+
14730
+ // src/ui/lib/wallet.ts
14731
+ function hasInjectedWallet() {
14732
+ return typeof window !== "undefined" && !!window.ethereum;
14733
+ }
14734
+ async function connectWallet() {
14735
+ if (!window.ethereum) {
14736
+ throw new Error("No wallet found. Please install MetaMask or Phantom.");
14737
+ }
14738
+ const accounts = await window.ethereum.request({
14739
+ method: "eth_requestAccounts"
14740
+ });
14741
+ if (!accounts || accounts.length === 0) {
14742
+ throw new Error("No accounts found");
14743
+ }
14744
+ const chainIdHex = await window.ethereum.request({
14745
+ method: "eth_chainId"
14746
+ });
14747
+ const address = toChecksumAddress(accounts[0]);
14748
+ return {
14749
+ address,
14750
+ chainId: parseInt(chainIdHex, 16)
14751
+ };
14752
+ }
14753
+ async function signMessage(message, address) {
14754
+ if (!window.ethereum) {
14755
+ throw new Error("No wallet found");
14756
+ }
14757
+ return window.ethereum.request({
14758
+ method: "personal_sign",
14759
+ params: [message, address]
14760
+ });
14761
+ }
14762
+ function buildSiweMessage(opts) {
14763
+ const issuedAt = opts.issuedAt || (/* @__PURE__ */ new Date()).toISOString();
14764
+ return `${opts.domain} wants you to sign in with your Ethereum account:
14765
+ ${opts.address}
14766
+
14767
+ ${opts.statement}
14768
+
14769
+ URI: ${opts.uri}
14770
+ Version: ${opts.version}
14771
+ Chain ID: ${opts.chainId}
14772
+ Nonce: ${opts.nonce}
14773
+ Issued At: ${issuedAt}`;
14774
+ }
14775
+ function toChecksumAddress(address) {
14776
+ const addr = address.toLowerCase().replace("0x", "");
14777
+ if (address.match(/^0x[0-9a-fA-F]{40}$/)) {
14778
+ if (address !== address.toLowerCase() && address !== address.toUpperCase()) {
14779
+ return address;
14780
+ }
14781
+ }
14782
+ return address;
14783
+ }
14784
+
14785
+ // src/ui/components/auth/wallet-button.tsx
14786
+ import { jsx as jsx36, jsxs as jsxs23 } from "react/jsx-runtime";
14787
+ function WalletButton({
14788
+ classNames,
14789
+ isSubmitting,
14790
+ localization,
14791
+ redirectTo,
14792
+ setIsSubmitting
14793
+ }) {
14794
+ const {
14795
+ authClient,
14796
+ localization: contextLocalization,
14797
+ toast,
14798
+ localizeErrors
14799
+ } = useContext28(AuthUIContext);
14800
+ localization = { ...contextLocalization, ...localization };
14801
+ const { onSuccess } = useOnSuccessTransition({ redirectTo });
14802
+ const [mounted, setMounted] = useState14(false);
14803
+ const [walletAddress, setWalletAddress] = useState14(null);
14804
+ const [chainId, setChainId] = useState14(null);
14805
+ useEffect22(() => {
14806
+ setMounted(true);
14807
+ }, []);
14808
+ const handleWalletAuth = useCallback8(async () => {
14809
+ setIsSubmitting?.(true);
14810
+ try {
14811
+ let address = walletAddress;
14812
+ let chain = chainId;
14813
+ if (!address || !chain) {
14814
+ const connection = await connectWallet();
14815
+ address = connection.address;
14816
+ chain = connection.chainId;
14817
+ setWalletAddress(address);
14818
+ setChainId(chain);
14819
+ }
14820
+ const nonceResult = await authClient.siwe.nonce({
14821
+ walletAddress: address,
14822
+ chainId: chain
14823
+ });
14824
+ if (nonceResult.error) {
14825
+ throw new Error(nonceResult.error.message || "Failed to get nonce");
14826
+ }
14827
+ const nonce = nonceResult.data?.nonce;
14828
+ if (!nonce) {
14829
+ throw new Error("No nonce received from server");
14830
+ }
14831
+ const message = buildSiweMessage({
14832
+ domain: window.location.host,
14833
+ address,
14834
+ statement: "Sign in with Ethereum",
14835
+ uri: window.location.origin,
14836
+ version: "1",
14837
+ chainId: chain,
14838
+ nonce
14839
+ });
14840
+ const signature = await signMessage(message, address);
14841
+ const verifyResult = await authClient.siwe.verify({
14842
+ message,
14843
+ signature,
14844
+ walletAddress: address,
14845
+ chainId: chain
14846
+ });
14847
+ if (verifyResult.error) {
14848
+ throw new Error(verifyResult.error.message || "Verification failed");
14849
+ }
14850
+ onSuccess();
14851
+ } catch (error) {
14852
+ toast({
14853
+ variant: "error",
14854
+ message: getLocalizedError({
14855
+ error,
14856
+ localization,
14857
+ localizeErrors
14858
+ })
14859
+ });
14860
+ setIsSubmitting?.(false);
14861
+ }
14862
+ }, [
14863
+ authClient,
14864
+ walletAddress,
14865
+ chainId,
14866
+ localization,
14867
+ localizeErrors,
14868
+ onSuccess,
14869
+ setIsSubmitting,
14870
+ toast
14871
+ ]);
14872
+ if (!mounted) {
14873
+ return /* @__PURE__ */ jsxs23(
14874
+ Button,
14875
+ {
14876
+ className: cn(
14877
+ "w-full",
14878
+ classNames?.form?.button,
14879
+ classNames?.form?.secondaryButton
14880
+ ),
14881
+ disabled: true,
14882
+ variant: "secondary",
14883
+ children: [
14884
+ /* @__PURE__ */ jsx36(Wallet, { className: "h-4 w-4" }),
14885
+ "Connect Wallet"
14886
+ ]
14887
+ }
14888
+ );
14889
+ }
14890
+ if (!hasInjectedWallet()) {
14891
+ return /* @__PURE__ */ jsxs23(
14892
+ Button,
14893
+ {
14894
+ className: cn(
14895
+ "w-full",
14896
+ classNames?.form?.button,
14897
+ classNames?.form?.secondaryButton
14898
+ ),
14899
+ disabled: true,
14900
+ variant: "secondary",
14901
+ title: "Install MetaMask or Phantom to use wallet sign-in",
14902
+ children: [
14903
+ /* @__PURE__ */ jsx36(Wallet, { className: "h-4 w-4" }),
14904
+ "No Wallet Found"
14905
+ ]
14906
+ }
14907
+ );
14908
+ }
14909
+ return /* @__PURE__ */ jsxs23(
14910
+ Button,
14911
+ {
14912
+ className: cn(
14913
+ "w-full",
14914
+ classNames?.form?.button,
14915
+ classNames?.form?.secondaryButton
14916
+ ),
14917
+ disabled: isSubmitting,
14918
+ variant: "secondary",
14919
+ onClick: handleWalletAuth,
14920
+ children: [
14921
+ /* @__PURE__ */ jsx36(Wallet, { className: "h-4 w-4" }),
14922
+ walletAddress ? `Sign in with ${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "Sign in with Wallet"
14923
+ ]
14924
+ }
14925
+ );
14926
+ }
14927
+
14727
14928
  // src/ui/components/auth/auth-view.tsx
14728
- import { Fragment as Fragment10, jsx as jsx36, jsxs as jsxs23 } from "react/jsx-runtime";
14929
+ import { Fragment as Fragment10, jsx as jsx37, jsxs as jsxs24 } from "react/jsx-runtime";
14729
14930
  function AuthView({
14730
14931
  className,
14731
14932
  classNames,
@@ -14749,12 +14950,13 @@ function AuthView({
14749
14950
  emailOTP,
14750
14951
  oneTap,
14751
14952
  passkey,
14953
+ wallet,
14752
14954
  signUp,
14753
14955
  social,
14754
14956
  genericOAuth,
14755
14957
  viewPaths,
14756
14958
  Link
14757
- } = useContext28(AuthUIContext);
14959
+ } = useContext29(AuthUIContext);
14758
14960
  localization = { ...contextLocalization, ...localization };
14759
14961
  let socialLayout = socialLayoutProp;
14760
14962
  if (socialLayout === "auto") {
@@ -14762,13 +14964,13 @@ function AuthView({
14762
14964
  }
14763
14965
  const path = pathProp ?? pathname?.split("/").pop();
14764
14966
  const view = viewProp || getViewByPath(viewPaths, path) || "SIGN_IN";
14765
- const [isSubmitting, setIsSubmitting] = useState14(false);
14766
- const [providerError, setProviderError] = useState14(null);
14967
+ const [isSubmitting, setIsSubmitting] = useState15(false);
14968
+ const [providerError, setProviderError] = useState15(null);
14767
14969
  const handleSetIsSubmitting = (value) => {
14768
14970
  if (value) setProviderError(null);
14769
14971
  setIsSubmitting(value);
14770
14972
  };
14771
- useEffect22(() => {
14973
+ useEffect23(() => {
14772
14974
  const handlePageHide = () => setIsSubmitting(false);
14773
14975
  window.addEventListener("pagehide", handlePageHide);
14774
14976
  return () => {
@@ -14776,12 +14978,12 @@ function AuthView({
14776
14978
  window.removeEventListener("pagehide", handlePageHide);
14777
14979
  };
14778
14980
  }, []);
14779
- if (view === "CALLBACK") return /* @__PURE__ */ jsx36(AuthCallback, { redirectTo });
14780
- if (view === "SIGN_OUT") return /* @__PURE__ */ jsx36(SignOut, { redirectTo });
14981
+ if (view === "CALLBACK") return /* @__PURE__ */ jsx37(AuthCallback, { redirectTo });
14982
+ if (view === "SIGN_OUT") return /* @__PURE__ */ jsx37(SignOut, { redirectTo });
14781
14983
  const description = !credentials && !magicLink && !emailOTP ? localization.DISABLED_CREDENTIALS_DESCRIPTION : localization[`${view}_DESCRIPTION`];
14782
- return /* @__PURE__ */ jsxs23(Card, { className: cn("w-full max-w-sm", className, classNames?.base), children: [
14783
- /* @__PURE__ */ jsx36(CardHeader, { className: classNames?.header, children: cardHeader ? cardHeader : /* @__PURE__ */ jsxs23(Fragment10, { children: [
14784
- /* @__PURE__ */ jsx36(
14984
+ return /* @__PURE__ */ jsxs24(Card, { className: cn("w-full max-w-sm", className, classNames?.base), children: [
14985
+ /* @__PURE__ */ jsx37(CardHeader, { className: classNames?.header, children: cardHeader ? cardHeader : /* @__PURE__ */ jsxs24(Fragment10, { children: [
14986
+ /* @__PURE__ */ jsx37(
14785
14987
  CardTitle,
14786
14988
  {
14787
14989
  className: cn(
@@ -14791,7 +14993,7 @@ function AuthView({
14791
14993
  children: localization[view]
14792
14994
  }
14793
14995
  ),
14794
- description && /* @__PURE__ */ jsx36(
14996
+ description && /* @__PURE__ */ jsx37(
14795
14997
  CardDescription,
14796
14998
  {
14797
14999
  className: cn(
@@ -14802,18 +15004,18 @@ function AuthView({
14802
15004
  }
14803
15005
  )
14804
15006
  ] }) }),
14805
- /* @__PURE__ */ jsxs23(CardContent, { className: cn("grid gap-6", classNames?.content), children: [
15007
+ /* @__PURE__ */ jsxs24(CardContent, { className: cn("grid gap-6", classNames?.content), children: [
14806
15008
  oneTap && ["SIGN_IN", "SIGN_UP", "MAGIC_LINK", "EMAIL_OTP"].includes(
14807
15009
  view
14808
- ) && /* @__PURE__ */ jsx36(
15010
+ ) && /* @__PURE__ */ jsx37(
14809
15011
  OneTap,
14810
15012
  {
14811
15013
  localization,
14812
15014
  redirectTo
14813
15015
  }
14814
15016
  ),
14815
- (credentials || magicLink || emailOTP) && /* @__PURE__ */ jsxs23("div", { className: "grid gap-4", children: [
14816
- /* @__PURE__ */ jsx36(
15017
+ (credentials || magicLink || emailOTP) && /* @__PURE__ */ jsxs24("div", { className: "grid gap-4", children: [
15018
+ /* @__PURE__ */ jsx37(
14817
15019
  AuthForm,
14818
15020
  {
14819
15021
  classNames: classNames?.form,
@@ -14832,7 +15034,7 @@ function AuthView({
14832
15034
  "SIGN_IN",
14833
15035
  "MAGIC_LINK",
14834
15036
  "EMAIL_OTP"
14835
- ].includes(view) || emailOTP && view === "EMAIL_OTP") && /* @__PURE__ */ jsx36(
15037
+ ].includes(view) || emailOTP && view === "EMAIL_OTP") && /* @__PURE__ */ jsx37(
14836
15038
  MagicLinkButton,
14837
15039
  {
14838
15040
  classNames,
@@ -14849,7 +15051,7 @@ function AuthView({
14849
15051
  "EMAIL_OTP"
14850
15052
  ].includes(view) || magicLink && ["SIGN_IN", "MAGIC_LINK"].includes(
14851
15053
  view
14852
- )) && /* @__PURE__ */ jsx36(
15054
+ )) && /* @__PURE__ */ jsx37(
14853
15055
  EmailOTPButton,
14854
15056
  {
14855
15057
  classNames,
@@ -14859,8 +15061,8 @@ function AuthView({
14859
15061
  }
14860
15062
  )
14861
15063
  ] }),
14862
- view !== "RESET_PASSWORD" && view !== "EMAIL_VERIFICATION" && (social?.providers?.length || genericOAuth?.providers?.length || view === "SIGN_IN" && passkey) && /* @__PURE__ */ jsxs23(Fragment10, { children: [
14863
- (credentials || magicLink || emailOTP) && /* @__PURE__ */ jsxs23(
15064
+ view !== "RESET_PASSWORD" && view !== "EMAIL_VERIFICATION" && (social?.providers?.length || genericOAuth?.providers?.length || view === "SIGN_IN" && passkey) && /* @__PURE__ */ jsxs24(Fragment10, { children: [
15065
+ (credentials || magicLink || emailOTP) && /* @__PURE__ */ jsxs24(
14864
15066
  "div",
14865
15067
  {
14866
15068
  className: cn(
@@ -14868,7 +15070,7 @@ function AuthView({
14868
15070
  classNames?.continueWith
14869
15071
  ),
14870
15072
  children: [
14871
- /* @__PURE__ */ jsx36(
15073
+ /* @__PURE__ */ jsx37(
14872
15074
  Separator,
14873
15075
  {
14874
15076
  className: cn(
@@ -14877,8 +15079,8 @@ function AuthView({
14877
15079
  )
14878
15080
  }
14879
15081
  ),
14880
- /* @__PURE__ */ jsx36("span", { className: "flex-shrink-0 text-muted-foreground text-sm", children: localization.OR_CONTINUE_WITH }),
14881
- /* @__PURE__ */ jsx36(
15082
+ /* @__PURE__ */ jsx37("span", { className: "flex-shrink-0 text-muted-foreground text-sm", children: localization.OR_CONTINUE_WITH }),
15083
+ /* @__PURE__ */ jsx37(
14882
15084
  Separator,
14883
15085
  {
14884
15086
  className: cn(
@@ -14890,8 +15092,8 @@ function AuthView({
14890
15092
  ]
14891
15093
  }
14892
15094
  ),
14893
- /* @__PURE__ */ jsxs23("div", { className: "grid gap-4", children: [
14894
- (social?.providers?.length || genericOAuth?.providers?.length) && /* @__PURE__ */ jsxs23(
15095
+ /* @__PURE__ */ jsxs24("div", { className: "grid gap-4", children: [
15096
+ (social?.providers?.length || genericOAuth?.providers?.length) && /* @__PURE__ */ jsxs24(
14895
15097
  "div",
14896
15098
  {
14897
15099
  className: cn(
@@ -14906,7 +15108,7 @@ function AuthView({
14906
15108
  (socialProvider2) => socialProvider2.provider === provider
14907
15109
  );
14908
15110
  if (!socialProvider) return null;
14909
- return /* @__PURE__ */ jsx36(
15111
+ return /* @__PURE__ */ jsx37(
14910
15112
  ProviderButton,
14911
15113
  {
14912
15114
  classNames,
@@ -14923,7 +15125,7 @@ function AuthView({
14923
15125
  );
14924
15126
  }),
14925
15127
  genericOAuth?.providers?.map(
14926
- (provider) => /* @__PURE__ */ jsx36(
15128
+ (provider) => /* @__PURE__ */ jsx37(
14927
15129
  ProviderButton,
14928
15130
  {
14929
15131
  classNames,
@@ -14943,7 +15145,7 @@ function AuthView({
14943
15145
  ]
14944
15146
  }
14945
15147
  ),
14946
- providerError && /* @__PURE__ */ jsx36("div", { className: "rounded-md bg-destructive/10 p-3 text-sm text-destructive", children: providerError }),
15148
+ providerError && /* @__PURE__ */ jsx37("div", { className: "rounded-md bg-destructive/10 p-3 text-sm text-destructive", children: providerError }),
14947
15149
  passkey && [
14948
15150
  "SIGN_IN",
14949
15151
  "MAGIC_LINK",
@@ -14951,7 +15153,7 @@ function AuthView({
14951
15153
  "RECOVER_ACCOUNT",
14952
15154
  "TWO_FACTOR",
14953
15155
  "FORGOT_PASSWORD"
14954
- ].includes(view) && /* @__PURE__ */ jsx36(
15156
+ ].includes(view) && /* @__PURE__ */ jsx37(
14955
15157
  PasskeyButton,
14956
15158
  {
14957
15159
  classNames,
@@ -14960,12 +15162,27 @@ function AuthView({
14960
15162
  redirectTo,
14961
15163
  setIsSubmitting: handleSetIsSubmitting
14962
15164
  }
15165
+ ),
15166
+ wallet && [
15167
+ "SIGN_IN",
15168
+ "SIGN_UP",
15169
+ "MAGIC_LINK",
15170
+ "EMAIL_OTP"
15171
+ ].includes(view) && /* @__PURE__ */ jsx37(
15172
+ WalletButton,
15173
+ {
15174
+ classNames,
15175
+ isSubmitting,
15176
+ localization,
15177
+ redirectTo,
15178
+ setIsSubmitting: handleSetIsSubmitting
15179
+ }
14963
15180
  )
14964
15181
  ] })
14965
15182
  ] })
14966
15183
  ] }),
14967
- cardFooter && /* @__PURE__ */ jsx36(CardFooter, { className: classNames?.footer, children: cardFooter }),
14968
- credentials && signUp && /* @__PURE__ */ jsxs23(
15184
+ cardFooter && /* @__PURE__ */ jsx37(CardFooter, { className: classNames?.footer, children: cardFooter }),
15185
+ credentials && signUp && /* @__PURE__ */ jsxs24(
14969
15186
  CardFooter,
14970
15187
  {
14971
15188
  className: cn(
@@ -14973,8 +15190,8 @@ function AuthView({
14973
15190
  classNames?.footer
14974
15191
  ),
14975
15192
  children: [
14976
- view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP" ? localization.DONT_HAVE_AN_ACCOUNT : view === "SIGN_UP" ? localization.ALREADY_HAVE_AN_ACCOUNT : /* @__PURE__ */ jsx36(ArrowLeft, { className: "size-3" }),
14977
- view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP" || view === "SIGN_UP" ? /* @__PURE__ */ jsx36(
15193
+ view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP" ? localization.DONT_HAVE_AN_ACCOUNT : view === "SIGN_UP" ? localization.ALREADY_HAVE_AN_ACCOUNT : /* @__PURE__ */ jsx37(ArrowLeft, { className: "size-3" }),
15194
+ view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP" || view === "SIGN_UP" ? /* @__PURE__ */ jsx37(
14978
15195
  Link,
14979
15196
  {
14980
15197
  className: cn(
@@ -14982,7 +15199,7 @@ function AuthView({
14982
15199
  classNames?.footerLink
14983
15200
  ),
14984
15201
  href: `${basePath}/${viewPaths[view === "SIGN_IN" || view === "MAGIC_LINK" || view === "EMAIL_OTP" ? "SIGN_UP" : "SIGN_IN"]}${isHydrated ? window.location.search : ""}`,
14985
- children: /* @__PURE__ */ jsx36(
15202
+ children: /* @__PURE__ */ jsx37(
14986
15203
  Button,
14987
15204
  {
14988
15205
  variant: "link",
@@ -14995,7 +15212,7 @@ function AuthView({
14995
15212
  }
14996
15213
  )
14997
15214
  }
14998
- ) : /* @__PURE__ */ jsx36(
15215
+ ) : /* @__PURE__ */ jsx37(
14999
15216
  Button,
15000
15217
  {
15001
15218
  variant: "link",
@@ -15014,207 +15231,6 @@ function AuthView({
15014
15231
  ] });
15015
15232
  }
15016
15233
 
15017
- // src/ui/components/auth/wallet-button.tsx
15018
- import { useContext as useContext29, useState as useState15, useEffect as useEffect23, useCallback as useCallback8 } from "react";
15019
-
15020
- // src/ui/lib/wallet.ts
15021
- function hasInjectedWallet() {
15022
- return typeof window !== "undefined" && !!window.ethereum;
15023
- }
15024
- async function connectWallet() {
15025
- if (!window.ethereum) {
15026
- throw new Error("No wallet found. Please install MetaMask or Phantom.");
15027
- }
15028
- const accounts = await window.ethereum.request({
15029
- method: "eth_requestAccounts"
15030
- });
15031
- if (!accounts || accounts.length === 0) {
15032
- throw new Error("No accounts found");
15033
- }
15034
- const chainIdHex = await window.ethereum.request({
15035
- method: "eth_chainId"
15036
- });
15037
- const address = toChecksumAddress(accounts[0]);
15038
- return {
15039
- address,
15040
- chainId: parseInt(chainIdHex, 16)
15041
- };
15042
- }
15043
- async function signMessage(message, address) {
15044
- if (!window.ethereum) {
15045
- throw new Error("No wallet found");
15046
- }
15047
- return window.ethereum.request({
15048
- method: "personal_sign",
15049
- params: [message, address]
15050
- });
15051
- }
15052
- function buildSiweMessage(opts) {
15053
- const issuedAt = opts.issuedAt || (/* @__PURE__ */ new Date()).toISOString();
15054
- return `${opts.domain} wants you to sign in with your Ethereum account:
15055
- ${opts.address}
15056
-
15057
- ${opts.statement}
15058
-
15059
- URI: ${opts.uri}
15060
- Version: ${opts.version}
15061
- Chain ID: ${opts.chainId}
15062
- Nonce: ${opts.nonce}
15063
- Issued At: ${issuedAt}`;
15064
- }
15065
- function toChecksumAddress(address) {
15066
- const addr = address.toLowerCase().replace("0x", "");
15067
- if (address.match(/^0x[0-9a-fA-F]{40}$/)) {
15068
- if (address !== address.toLowerCase() && address !== address.toUpperCase()) {
15069
- return address;
15070
- }
15071
- }
15072
- return address;
15073
- }
15074
-
15075
- // src/ui/components/auth/wallet-button.tsx
15076
- import { jsx as jsx37, jsxs as jsxs24 } from "react/jsx-runtime";
15077
- function WalletButton({
15078
- classNames,
15079
- isSubmitting,
15080
- localization,
15081
- redirectTo,
15082
- setIsSubmitting
15083
- }) {
15084
- const {
15085
- authClient,
15086
- localization: contextLocalization,
15087
- toast,
15088
- localizeErrors
15089
- } = useContext29(AuthUIContext);
15090
- localization = { ...contextLocalization, ...localization };
15091
- const { onSuccess } = useOnSuccessTransition({ redirectTo });
15092
- const [mounted, setMounted] = useState15(false);
15093
- const [walletAddress, setWalletAddress] = useState15(null);
15094
- const [chainId, setChainId] = useState15(null);
15095
- useEffect23(() => {
15096
- setMounted(true);
15097
- }, []);
15098
- const handleWalletAuth = useCallback8(async () => {
15099
- setIsSubmitting?.(true);
15100
- try {
15101
- let address = walletAddress;
15102
- let chain = chainId;
15103
- if (!address || !chain) {
15104
- const connection = await connectWallet();
15105
- address = connection.address;
15106
- chain = connection.chainId;
15107
- setWalletAddress(address);
15108
- setChainId(chain);
15109
- }
15110
- const nonceResult = await authClient.siwe.nonce({
15111
- walletAddress: address,
15112
- chainId: chain
15113
- });
15114
- if (nonceResult.error) {
15115
- throw new Error(nonceResult.error.message || "Failed to get nonce");
15116
- }
15117
- const nonce = nonceResult.data?.nonce;
15118
- if (!nonce) {
15119
- throw new Error("No nonce received from server");
15120
- }
15121
- const message = buildSiweMessage({
15122
- domain: window.location.host,
15123
- address,
15124
- statement: "Sign in with Ethereum",
15125
- uri: window.location.origin,
15126
- version: "1",
15127
- chainId: chain,
15128
- nonce
15129
- });
15130
- const signature = await signMessage(message, address);
15131
- const verifyResult = await authClient.siwe.verify({
15132
- message,
15133
- signature,
15134
- walletAddress: address,
15135
- chainId: chain
15136
- });
15137
- if (verifyResult.error) {
15138
- throw new Error(verifyResult.error.message || "Verification failed");
15139
- }
15140
- onSuccess();
15141
- } catch (error) {
15142
- toast({
15143
- variant: "error",
15144
- message: getLocalizedError({
15145
- error,
15146
- localization,
15147
- localizeErrors
15148
- })
15149
- });
15150
- setIsSubmitting?.(false);
15151
- }
15152
- }, [
15153
- authClient,
15154
- walletAddress,
15155
- chainId,
15156
- localization,
15157
- localizeErrors,
15158
- onSuccess,
15159
- setIsSubmitting,
15160
- toast
15161
- ]);
15162
- if (!mounted) {
15163
- return /* @__PURE__ */ jsxs24(
15164
- Button,
15165
- {
15166
- className: cn(
15167
- "w-full",
15168
- classNames?.form?.button,
15169
- classNames?.form?.secondaryButton
15170
- ),
15171
- disabled: true,
15172
- variant: "secondary",
15173
- children: [
15174
- /* @__PURE__ */ jsx37(Wallet, { className: "h-4 w-4" }),
15175
- "Connect Wallet"
15176
- ]
15177
- }
15178
- );
15179
- }
15180
- if (!hasInjectedWallet()) {
15181
- return /* @__PURE__ */ jsxs24(
15182
- Button,
15183
- {
15184
- className: cn(
15185
- "w-full",
15186
- classNames?.form?.button,
15187
- classNames?.form?.secondaryButton
15188
- ),
15189
- disabled: true,
15190
- variant: "secondary",
15191
- title: "Install MetaMask or Phantom to use wallet sign-in",
15192
- children: [
15193
- /* @__PURE__ */ jsx37(Wallet, { className: "h-4 w-4" }),
15194
- "No Wallet Found"
15195
- ]
15196
- }
15197
- );
15198
- }
15199
- return /* @__PURE__ */ jsxs24(
15200
- Button,
15201
- {
15202
- className: cn(
15203
- "w-full",
15204
- classNames?.form?.button,
15205
- classNames?.form?.secondaryButton
15206
- ),
15207
- disabled: isSubmitting,
15208
- variant: "secondary",
15209
- onClick: handleWalletAuth,
15210
- children: [
15211
- /* @__PURE__ */ jsx37(Wallet, { className: "h-4 w-4" }),
15212
- walletAddress ? `Sign in with ${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "Sign in with Wallet"
15213
- ]
15214
- }
15215
- );
15216
- }
15217
-
15218
15234
  // src/ui/components/auth-loading.tsx
15219
15235
  import { useContext as useContext30 } from "react";
15220
15236
  function AuthLoading({ children }) {