diff --git a/apiClient/client.ts b/apiClient/client.ts index 2bbeb75a..a826b4c6 100644 --- a/apiClient/client.ts +++ b/apiClient/client.ts @@ -12,6 +12,11 @@ import { LoginEvent, } from './types' import { LocalError } from './errors' +import { + UNABLE_TO_LOGIN, + ENDPOINT_UNAVAILABLE, + NOT_ISOMORPHIC, +} from 'constants/errors' // Environment variables set in Vercel config. const SERVER_API_URL = process.env.API_URL @@ -142,7 +147,7 @@ export async function getMetricsConfig(): Promise< /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ export async function login(email: string): Promise { if (typeof window === 'undefined' || !magic) { - return new LocalError('Only runnable in the browser', 500) + return new LocalError('Only runnable in the browser', NOT_ISOMORPHIC) } try { await magic.auth.loginWithMagicLink({ @@ -161,7 +166,7 @@ export async function login(email: string): Promise { return { statusCode: 200, loaded: true } } } catch (e) { - return new LocalError(e.message, 500) + return new LocalError(e.message, UNABLE_TO_LOGIN) } } @@ -177,13 +182,13 @@ export async function getUserDetails( }) return data.json() } catch (e) { - return new LocalError(e.message, 500) + return new LocalError(e.message, ENDPOINT_UNAVAILABLE) } } export async function tokenLogin(): Promise { if (typeof window === 'undefined' || !magic) { - return new LocalError('Only runnable in the browser', 500) + return new LocalError('Only runnable in the browser', NOT_ISOMORPHIC) } try { const token = await magic.auth.loginWithCredential() @@ -195,6 +200,6 @@ export async function tokenLogin(): Promise { }) return res.json() } catch (e) { - return new LocalError(e.message, 500) + return new LocalError(e.message, ENDPOINT_UNAVAILABLE) } } diff --git a/components/FooterCTA/index.tsx b/components/FooterCTA/index.tsx index 3e1edae0..e54d72b8 100644 --- a/components/FooterCTA/index.tsx +++ b/components/FooterCTA/index.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx' -import Router from 'next/router' +import Link from 'next/link' import Intertubes from 'components/About/ImageIntertubes' import { RawButton } from 'components/Button' @@ -21,23 +21,24 @@ export function TubesCTA({ cta, goTo, buttonText }: TubesCTAProps) {
{cta} - Router.push(goTo)} - className={clsx( - 'm-auto', - 'mt-8', - 'mb-16', - 'max-w-[240px]', - 'text-lg', - 'px-4', - 'py-3', - 'md:text-xl', - 'md:py-5', - 'md:px-4' - )} - > - {buttonText} - + + + {buttonText} + + ) diff --git a/components/Navbar/Flyout.tsx b/components/Navbar/Flyout.tsx index 210216d6..b63c17f5 100644 --- a/components/Navbar/Flyout.tsx +++ b/components/Navbar/Flyout.tsx @@ -1,5 +1,6 @@ import Logo from 'components/Logo' import Close from 'components/icons/Close' +import { LoginContext } from 'hooks/useLogin' import NavbarLinks from './Links' export type NavbarFlyoutProps = { @@ -9,6 +10,7 @@ export type NavbarFlyoutProps = { testnetClicked: () => unknown companyVisible: boolean testnetVisible: boolean + loginContext: LoginContext } export function NavbarFlyout({ @@ -18,12 +20,14 @@ export function NavbarFlyout({ testnetClicked, companyVisible, testnetVisible, + loginContext, }: NavbarFlyoutProps) { const navbarLinksProps = { companyClicked, testnetClicked, companyVisible, testnetVisible, + loginContext, } return (
unknown testnetHovered?: () => unknown testnetVisible?: boolean + loginContext: LoginContext } export function NavbarLinks({ @@ -28,6 +31,7 @@ export function NavbarLinks({ testnetClicked, testnetHovered, testnetVisible = false, + loginContext, }: NavbarLinksProps) { const itemPadding = [`px-2`, `lg:px-3.5`, `3xl:px-5`] const cc = clsx([className, ...itemPadding]) @@ -60,7 +64,7 @@ export function NavbarLinks({ > {testnetVisible && } - + ) } diff --git a/components/Navbar/LoginButton.tsx b/components/Navbar/LoginButton.tsx index f38a150f..bf61300b 100644 --- a/components/Navbar/LoginButton.tsx +++ b/components/Navbar/LoginButton.tsx @@ -1,7 +1,7 @@ import { useState, ReactNode, MouseEventHandler } from 'react' import Link from 'next/link' import clsx from 'clsx' -import { LoginContext } from 'contexts/LoginContext' +import { LoginContext } from 'hooks/useLogin' import ChevronDown from './ChevronDown' import { ApiUserMetadata } from 'apiClient/types' @@ -142,52 +142,49 @@ const UserButton = ({ id, graffiti, visible }: ApiUserMetadataUI) => (
) -export const LoginButton = () => { +type LoginProps = { + loginContext: LoginContext +} +export const LoginButton = ({ loginContext }: LoginProps) => { const [$visible, $setVisible] = useState(false) const set = (x: boolean) => () => $setVisible(x) const on = set(true) const off = set(false) + const { checkLoggedIn, metadata } = loginContext + const isLoggedIn = checkLoggedIn() + // eslint-disable-next-line + const meta = metadata as any return ( - - {({ checkLoggedIn, metadata }) => { - const isLoggedIn = checkLoggedIn() - // eslint-disable-next-line - const meta = metadata as any - const hasGraffiti = metadata && !!metadata.graffiti - return ( - - {isLoggedIn && hasGraffiti ? ( - - ) : ( - - )} - - ) - }} - + + {isLoggedIn ? ( + + ) : ( + + )} + ) } export default LoginButton diff --git a/components/Navbar/index.tsx b/components/Navbar/index.tsx index b05cc8f5..128abe5a 100644 --- a/components/Navbar/index.tsx +++ b/components/Navbar/index.tsx @@ -4,6 +4,7 @@ import clsx from 'clsx' import Logo from 'components/Logo' import Menu from 'components/icons/Menu' import { useNav, NavState } from 'hooks/useNav' +import { LoginContext } from 'hooks/useLogin' import NavbarLinks from './Links' import NavbarFlyout from './Flyout' @@ -13,11 +14,13 @@ import Link from 'next/link' type NavbarProps = { className?: string fill?: string + loginContext: LoginContext } function Navbar({ fill = 'white', className = 'bg-black text-white', + loginContext, }: NavbarProps) { const { $flyoutVisible, @@ -40,6 +43,7 @@ function Navbar({ testnetClicked: toggleNavTestnet, testnetHovered: enterNavTestnet, testnetVisible, + loginContext, } return (