-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement session management and login flow
- Loading branch information
1 parent
718638a
commit 373f573
Showing
9 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { useCurrentAccount } from "@umami/state"; | ||
import { useHandleSession } from "@umami/state"; | ||
|
||
import { Layout } from "../../Layout"; | ||
import { SessionLogin } from "../../views/SessionLogin/SessionLogin"; | ||
import { Welcome } from "../../views/Welcome"; | ||
import { BeaconProvider } from "../beacon"; | ||
import { WalletConnectProvider } from "../WalletConnect/WalletConnectProvider"; | ||
|
||
export const App = () => { | ||
const currentAccount = useCurrentAccount(); | ||
const { isSessionActive, isOnboarded } = useHandleSession(); | ||
|
||
return currentAccount ? ( | ||
<BeaconProvider> | ||
<WalletConnectProvider> | ||
<Layout /> | ||
</WalletConnectProvider> | ||
</BeaconProvider> | ||
) : ( | ||
<Welcome /> | ||
); | ||
if (!isOnboarded()) { | ||
return <Welcome />; | ||
} else if (!isSessionActive) { | ||
return <SessionLogin />; | ||
} else { | ||
return ( | ||
<BeaconProvider> | ||
<WalletConnectProvider> | ||
<Layout /> | ||
</WalletConnectProvider> | ||
</BeaconProvider> | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Button, Center, Flex, type FlexProps, Heading, Icon, Text } from "@chakra-ui/react"; | ||
import { type FieldValues, FormProvider, useForm } from "react-hook-form"; | ||
|
||
import { LogoLightIcon, TezosLogoIcon } from "../../assets/icons"; | ||
import { PasswordInput } from "../../components/PasswordInput"; | ||
import { useColor } from "../../styles/useColor"; | ||
|
||
export const SessionLogin = () => { | ||
const color = useColor(); | ||
|
||
const form = useForm({ | ||
defaultValues: { | ||
password: "", | ||
}, | ||
mode: "onBlur", | ||
}); | ||
|
||
const onSubmit = (data: FieldValues) => { | ||
console.log(data); | ||
}; | ||
|
||
return ( | ||
<FormProvider {...form}> | ||
<Flex alignItems={{ base: "end", md: "center" }} justifyContent="center" height="100vh"> | ||
<Flex | ||
alignItems="center" | ||
alignContent="start" | ||
flexDirection="column" | ||
gap="36px" | ||
width={{ base: "full", md: "510px" }} | ||
padding={{ base: "36px", md: "36px 42px" }} | ||
color={color("700")} | ||
fontSize="14px" | ||
border="1px solid" | ||
borderColor={color("100")} | ||
borderTopRadius="30px" | ||
borderBottomRadius={{ base: 0, md: "30px" }} | ||
backgroundColor={color("white")} | ||
> | ||
<Flex alignItems="center" justifyContent="end" flexDirection="column" gridArea="header"> | ||
<Icon as={LogoLightIcon} width="42px" height="42px" /> | ||
<Heading marginTop="18px" color={color("900")} size={{ base: "2xl", md: "3xl" }}> | ||
Welcome back! | ||
</Heading> | ||
<Text marginTop="6px" color={color("600")} size={{ base: "md", md: "lg" }}> | ||
You need to sign back in to use your wallet. | ||
</Text> | ||
</Flex> | ||
<PasswordInput inputName="password" /> | ||
<Button width="full" onClick={form.handleSubmit(onSubmit)} size="lg" variant="primary"> | ||
Unlock | ||
</Button> | ||
<Logo alignSelf="end" gridArea="tezos-logo" /> | ||
</Flex> | ||
</Flex> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
const Logo = (props: FlexProps) => ( | ||
<Center gap="10px" width="full" {...props}> | ||
<Text color="gray.400" size="sm"> | ||
Powered by | ||
</Text> | ||
<Icon as={TezosLogoIcon} width="auto" height={{ base: "24px", md: "36px" }} color="gray.400" /> | ||
</Center> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./SessionLogin"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
export const sessionSlice = createSlice({ | ||
name: "session", | ||
initialState: { | ||
hasSession: false, | ||
}, | ||
reducers: { | ||
setHasSession: (state, action) => { | ||
state.hasSession = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setHasSession } = sessionSlice.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters