Skip to content

Commit

Permalink
Add React import, update connector type, refactor Button component st…
Browse files Browse the repository at this point in the history
…yling, create Input component with label handling.

- Added React import for Account.tsx
- Updated connector type to 'any' in Account.tsx
- Refactored Button component styling in Button.tsx
- Created Input component with label handling in Input.tsx
  • Loading branch information
Munchies69 committed Jun 20, 2024
1 parent 4e50a18 commit 01c1832
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 179 deletions.
7 changes: 4 additions & 3 deletions packages/moon-react/src/components/Account/Account.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from "react";
import { useMoonSDK } from "../../context";
import { useAccount, useConnect, useSwitchChain } from "wagmi";
import React from "react";

function Account() {
const { address, status } = useAccount();
Expand Down Expand Up @@ -38,7 +39,7 @@ function Account() {
const getBalance = async (wallet: string) => {
// moon connector
console.log(connectors);
const conn = connectors.find((connector) => connector.name === "Moon");
const conn = connectors.find((connector: any) => connector.name === "Moon");
console.log(conn);
setWallet(wallet);
console.log("wallet", wallet);
Expand Down Expand Up @@ -99,7 +100,7 @@ function Account() {

<ul>
<li>
{connectors.map((connector) => (
{connectors.map((connector: any) => (
<button
key={connector.uid}
onClick={() => connect({ connector })}
Expand All @@ -116,7 +117,7 @@ function Account() {
</div>
<ul>
<li>
{chains.map((chain) => (
{chains.map((chain: any) => (
<button
key={chain.id}
onClick={() => switchChain({ chainId: chain.id })}
Expand Down
18 changes: 2 additions & 16 deletions packages/moon-react/src/components/AuthModal/AuthModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import React from "react";
import { useState } from "react";
import { AuthModalConfig } from "../../types";
import { useMoonSDK } from "../../context";
import { useAccount, useConnect, useSignMessage } from "wagmi";
import { useConnectToMoon } from "../../hooks/useConnectToMoon";
import { useWalletConnectors } from "../../hooks/useWalletConnectors";
import WalletConnectorsList from "../WalletConnectorList/WalletConnectorList";

import moonLogoLight from "../../assets/moon-logo-light.png";
import { ModalContent, ModalOverlay } from "../Modal/Modal";
import AuthOptions from "../AuthOptions/AuthOptions";

Expand All @@ -17,18 +12,9 @@ type AuthModalProps = {
};

const AuthModal: React.FC<AuthModalProps> = ({ config, children }) => {
const {
enabled,
socialLogins,
walletConnectEnabled,
anonymousLoginEnabled,
appearance,
theming,
} = config;
const { enabled, appearance } = config;
const [connectWallet, setConnectWallet] = useState(false);
const [showModal, setShowModal] = useState(false);
const { session } = useMoonSDK();
const [selectedTab, setSelectedTab] = useState(0);

if (!enabled) return <>{children}</>;
if (session) return <>{children}</>;
Expand All @@ -40,7 +26,7 @@ const AuthModal: React.FC<AuthModalProps> = ({ config, children }) => {

return (
<>
<ModalOverlay onClick={() => setShowModal(false)} config={config} />
<ModalOverlay onClick={() => {}} config={config} />
<ModalContent config={config}>
{config.appearance.logo?.enabled && (
<img
Expand Down
22 changes: 7 additions & 15 deletions packages/moon-react/src/components/AuthOptions/AuthOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import React from "react";
import {
FaDiscord,
FaTwitter,
FaGithub,
FaWallet,
FaChevronRight,
} from "react-icons/fa";
import { FcGoogle } from "react-icons/fc";
import { FaWallet, FaChevronRight } from "react-icons/fa";
import Button from "../Button/Button";
import SignInAnonymously from "../SignInAnonymously/SignInAnonymously";
import EmailLogin from "../EmailLogin/EmailLogin";
import SocialLogins from "../SocialLogins/SocialLogins";
import { AuthModalConfig, SocialLogins as SocialLoginsType } from "../../types";
import { AuthModalConfig } from "../../types";

interface AuthOptionsProps {
config: AuthModalConfig;
onConnectWallet: any;
}

const AuthOptions = ({
config,
onConnectWallet,
}: AuthOptionsProps) => (
<div className={`p-${config.appearance.modal.padding} justify-center items-center flex flex-col gap-5`}>
<EmailLogin config={config}/>
const AuthOptions = ({ config, onConnectWallet }: AuthOptionsProps) => (
<div
className={`p-${config.appearance.modal.padding} justify-center items-center flex flex-col gap-5`}
>
<EmailLogin config={config} />
<div className="w-full border-b-[1px] border-text-secondary" />
{config.socialLogins && config.socialLogins.length > 0 && (
<div className="w-full overflow-x-scroll h-20 flex gap-4 justify-center scrollbar-hide">
Expand Down
11 changes: 7 additions & 4 deletions packages/moon-react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import { useMoonSDK } from "../..";
import { AuthModalConfig } from "../../types";

interface ButtonProps {
className?: string;
Expand All @@ -23,9 +22,13 @@ function Button({
return (
<button
onClick={handleClick}
className={`w-full relative rounded-${authConfig.appearance.button.borderRadius} flex gap-10 p-2 text-lg bg-[${
authConfig.theming[color]
}] justify-center items-center border-2 border-[${authConfig.theming[color]}] hover:opacity-90 ${className}`}
style={{
backgroundColor: authConfig.theming[color],
color: authConfig.theming.textColor,
borderColor: authConfig.theming[color],
borderRadius: authConfig.appearance.button.borderRadius,
}}
className={`w-full relative flex gap-10 p-2 text-lg justify-center items-center border-2 hover:opacity-90 ${className}`}
>

{children}
Expand Down
78 changes: 35 additions & 43 deletions packages/moon-react/src/components/EmailLogin/EmailLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useMoonSDK } from "../../context";
import { AuthModalConfig } from "../../types";
import Button from "../Button/Button";
import React from "react";
import Input from "../Input/Input";

interface EmailLoginProps {
config: AuthModalConfig;
Expand Down Expand Up @@ -42,55 +43,46 @@ const EmailLogin = ({ config }: EmailLoginProps) => {
setIsLoggingIn(false);
}
};
if (isLoggingIn)
return (
<div className="flex flex-col gap-4 items-center justify-center">
<div className="animate-spin rounded-full h-32 w-32 border-t-2 border-b-2 border-text-primary"></div>
Logging in...
</div>
);

return (
<>
<div className="w-full">
<label
htmlFor="email"
className="block text-sm font-medium leading-6 text-text-secondary"
>
Email
</label>
<div className="relative mt-1 rounded-md shadow-sm">
<input
type="text"
name="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
id="email"
className={`block w-full rounded-${authConfig.appearance.input.borderRadius} border-0 py-1.5 pl-2 pr-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6`}
placeholder={
config?.appearance?.input?.placeholders?.email ||
"eg. [email protected]"
}
/>
</div>
</div>
<div className="w-full">
<label
htmlFor="password"
className="block text-sm font-medium leading-6 text-text-secondary"
>
Password
</label>
<div className="relative mt-1 rounded-md shadow-sm">
<input
type="password"
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
id="password"
className={`block w-full rounded-${authConfig.appearance.input.borderRadius} border-0 py-1.5 pl-2 pr-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6`}
placeholder={
config?.appearance?.input?.placeholders?.password || "******"
}
/>
</div>
</div>
<Input
label="Email"
id="email"
type="text"
name="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
style={{
borderRadius: authConfig.appearance.input.borderRadius || "3px",
}}
placeholder={
config?.appearance?.input?.placeholders?.email ||
"eg. [email protected]"
}
/>
<Input
label="Password"
id="password"
type="password"
name="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder={
config?.appearance?.input?.placeholders?.password || "******"
}
/>
<Button onClick={handleLoginEmail} color="successColor">
Login
</Button>
{error && <div className="text-red-500">{error}</div>}
</>
);
};
Expand Down
31 changes: 31 additions & 0 deletions packages/moon-react/src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { useMoonSDK } from "../..";

type InputProps = {
label: string;
} & React.InputHTMLAttributes<HTMLInputElement>;

function Input({ label, ...rest }: InputProps) {
const { authConfig } = useMoonSDK();
return (
<div className="w-full">
<label
htmlFor={label}
className="block text-sm font-medium leading-6 text-text-secondary"
>
{label}
</label>
<input
id={label}
name={label}
{...rest}
style={{
borderRadius: authConfig.appearance.input.borderRadius || "3px",
}}
className={`block w-full border-0 py-1.5 pl-2 pr-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6`}
/>
</div>
);
}

export default Input;
1 change: 1 addition & 0 deletions packages/moon-react/src/components/Input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Input";
22 changes: 18 additions & 4 deletions packages/moon-react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,36 @@ export const ModalContent = ({ children, config }: ModalProps) => {
!textInside && "mb-4"
} `}
>
<div className={`text-2xl font-bold text-text-primary`}>
<div
style={{ color: config.theming.textColor }}
className={`text-2xl font-bold`}
>
{config.appearance.welcomeMessage?.title}
</div>
<div className={`text-lg text-text-secondary`}>
<div
style={{ color: config.theming.textColorSecondary }}
className={`text-lg`}
>
{config.appearance.welcomeMessage?.subtitle}
</div>
</div>
);

return (
<div className={`bg-[${config.theming.backgroundColor}] justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 z-50 outline-none focus:outline-none`}>
<div
style={{ backgroundColor: config.theming.backgroundColor }}
className={`justify-center items-center flex overflow-x-hidden overflow-y-auto fixed inset-0 z-50 outline-none focus:outline-none`}
>
<div className="relative w-auto my-6 mx-auto flex flex-col justify-center items-center">
{!textInside && title}
<div className="text-white w-full flex items-center justify-center">
<div
className={`relative bg-[${config.theming.backgroundColorSecondary}] rounded-${config.appearance.modal.borderRadius} justify-center items-center w-${config.appearance.modal.width}`}
style={{
backgroundColor: config.theming.backgroundColorSecondary,
width: config.appearance.modal.width,
borderRadius: config.appearance.modal.borderRadius,
}}
className={`relative justify-center items-center`}
>
{textInside && title}
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import getEnvVariables from "../../utils/getEnvVariables";

function Oauth2Button() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FaChevronRight, FaUser } from "react-icons/fa";
import Button from "../Button/Button";
import React from "react";
function SignInAnonymously() {
const { supabase, authConfig } = useMoonSDK();
const { supabase } = useMoonSDK();

const signInAnonymously = async () => {
const auth = await supabase?.auth.signInAnonymously();
Expand Down
Loading

0 comments on commit 01c1832

Please sign in to comment.