Skip to content

Commit

Permalink
feat: add back up secret key page
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Jan 26, 2022
1 parent cc14f74 commit 6e11303
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 136 deletions.
2 changes: 1 addition & 1 deletion public/assets/images/onboarding/secret-key.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions src/app/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,15 @@ export function isEmpty(value: Object) {
return Object.keys(value).length === 0;
}

type ViewMode = 'full' | 'popup' | 'popup-center';
type ViewMode = 'full' | 'popup';

export function getViewMode(): ViewMode {
return document.location.pathname.startsWith('/index.html')
? 'full'
: document.location.pathname.startsWith('/popup.html')
? 'popup'
: 'popup-center';
return document.location.pathname.startsWith('/index.html') ? 'full' : 'popup';
}

export function formatContractId(address: string, name: string) {
return `${address}.${name}`;
}

export const isFullPage = document.location.pathname.startsWith('/index.html');
export const isPopup = !isFullPage;
8 changes: 4 additions & 4 deletions src/app/components/container/container.layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export function ContainerLayout(props: ContainerLayoutProps) {
>
{header || null}
<Flex
as="main"
className="main-content"
flexDirection="column"
flexGrow={1}
className="main-content"
as="main"
pb="loose"
position="relative"
width="100%"
px="loose"
pb="loose"
width="100%"
>
{children}
</Flex>
Expand Down
6 changes: 3 additions & 3 deletions src/app/pages/allow-diagnostics/allow-diagnostics-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC } from 'react';
import { Body, Title } from '@app/components/typography';
import { Box, Button, Flex, color, Stack } from '@stacks/ui';
import { FiCheck } from 'react-icons/fi';
import { InitialPageSelectors } from '@tests/integration/initial-page.selectors';
import { OnboardingSelectors } from '@tests/integration/onboarding.selectors';

interface ReasonToAllowDiagnosticsProps {
text: string;
Expand All @@ -27,7 +27,7 @@ export function AllowDiagnosticsLayout(props: AllowDiagnosticsLayoutProps) {
const { onUserAllowDiagnostics, onUserDenyDiagnosticsPermissions } = props;

return (
<Stack spacing="extra-loose" flexGrow={1} justifyContent="center">
<Stack flexGrow={1} justifyContent="center" maxWidth="440px" spacing="extra-loose">
<Title as="h1" fontWeight={500} textAlign="center">
Help us improve
</Title>
Expand All @@ -46,7 +46,7 @@ export function AllowDiagnosticsLayout(props: AllowDiagnosticsLayoutProps) {
type="button"
size="lg"
mode="primary"
data-testid={InitialPageSelectors.AnalyticsAllow}
data-testid={OnboardingSelectors.AnalyticsAllow}
onClick={() => onUserAllowDiagnostics()}
mr="base-tight"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,108 @@
import { Button, Stack } from '@stacks/ui';
import { cx } from '@emotion/css';
import { FiEyeOff, FiLock, FiRotateCcw } from 'react-icons/fi';
import { Box, Button, color, Flex, Stack } from '@stacks/ui';

import { Text, Title } from '@app/components/typography';
import { Caption, Text, Title } from '@app/components/typography';
import { Link } from '@app/components/link';
import { getViewMode } from '@app/common/utils';
import { isFullPage, isPopup } from '@app/common/utils';
import KeyIllustrationFull from '@assets/images/onboarding/key-illustration-full.svg';
import KeyIllustrationPopup from '@assets/images/onboarding/key-illustration-popup.svg';
import SecretKey from '@assets/images/onboarding/secret-key.svg';
import { useRouteHeader } from '@app/common/hooks/use-route-header';
import { Header } from '@app/components/header';

interface BackUpSecretKeyLayoutProps {}
import {
fullPageContentText,
fullPageTitle,
popupContentText,
popupTitle,
} from './back-up-secret-key.styles';

interface BackUpSecretKeyLayoutProps {
hasCopied: boolean;
onBackedUpSecretKey(): void;
onCopyToClipboard(): void;
secretKey: string | undefined;
}
export function BackUpSecretKeyLayout(props: BackUpSecretKeyLayoutProps): JSX.Element {
const mode = getViewMode();
const { hasCopied, onBackedUpSecretKey, onCopyToClipboard, secretKey } = props;
useRouteHeader(<Header hideActions />);

return (
<>Placeholder</>
// <Stack className="welcome-page" isInline={mode === 'full'} width="100%">
// <Stack className="content-image" flexGrow={1}>
// <img src={ExploreStacksLarge} className="image-large" />
// <img src={ExploreStacksSmall} className="image-small" />
// </Stack>
// <Stack className="content-text" flexGrow={1} justifyContent="center">
// <Stack width="100%" textAlign="left" alignItems="start">
// <Title className="title" fontWeight={500}>
// Explore the world of Stacks
// </Title>
// <Text className="text">
// Hiro Wallet connects you to Stacks apps while keeping your account, data, and crypto
// secure. Create your Stacks account to get started.
// </Text>
// </Stack>
// <Stack spacing="loose" textAlign="left" {...props}>
// <Button
// borderRadius="10px"
// data-testid={InitialPageSelectors.SignUp}
// height="48px"
// isLoading={isGeneratingWallet}
// onClick={onStartOnboarding}
// width="198px"
// >
// Create Stacks Account
// </Button>
// <Link data-testid={InitialPageSelectors.SignIn} fontSize="14px" onClick={onRestoreWallet}>
// I already have an account
// </Link>
// </Stack>
// </Stack>
// </Stack>
<Stack isInline={isFullPage} width="100%">
<Flex
className={cx({ [fullPageContentText]: isFullPage }, { [popupContentText]: isPopup })}
flexGrow={1}
justifyContent="center"
>
<Stack maxWidth="440px" spacing="loose">
<img src={SecretKey} width="135px" />
<Title
className={cx({ [fullPageTitle]: isFullPage }, { [popupTitle]: isPopup })}
fontWeight={500}
>
Back up your Secret Key
</Title>
<Text>
Here’s your Secret Key: 24 words that generated your Stacks account. You’ll need it to
access your account on a new device, in a different wallet, or in case you lose your
password — so back it up somewhere safe.
</Text>
<Stack alignItems="center" isInline>
<Box as={FiRotateCcw} color={color('text-caption')} size="12px" />
<Caption>Your Secret Key gives access to your account</Caption>
</Stack>
<Stack alignItems="center" isInline>
<Box as={FiEyeOff} color={color('text-caption')} size="12px" />
<Caption>Never share your Secret Key</Caption>
</Stack>
<Stack alignItems="center" isInline>
<Box as={FiLock} color={color('text-caption')} size="12px" />
<Caption>Put it somewhere private and secure</Caption>
</Stack>
<Stack alignItems={isFullPage ? 'center' : 'start'} isInline={isFullPage} spacing="loose">
<Button
borderRadius="10px"
height="48px"
mr="24px !important"
onClick={onBackedUpSecretKey}
width="198px"
>
I've backed it up
</Button>
<Stack isInline alignItems="center">
<Caption mr="4px !important">Or</Caption>
<Link fontSize="14px" onClick={() => {}}>
back it up later
</Link>
</Stack>
</Stack>
</Stack>
</Flex>
<Flex
className={cx({ [fullPageContentText]: isFullPage }, { [popupContentText]: isPopup })}
flexGrow={1}
justifyContent="center"
>
<Box
border="1px solid"
borderColor={color('border')}
borderRadius="16px"
height="484px"
width="432px"
>
<Stack alignItems="center" pt="80px" spacing="loose">
{isFullPage ? <img src={KeyIllustrationFull} /> : <img src={KeyIllustrationPopup} />}
<Title fontSize="20px">Your Secret Key</Title>
<Text px="loose" textAlign="center">
{secretKey}
</Text>
<Link fontSize="14px" onClick={!hasCopied ? onCopyToClipboard : undefined}>
{!hasCopied ? 'Copy to clipboard' : 'Copied!'}
</Link>
</Stack>
</Box>
</Flex>
</Stack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { css } from '@emotion/css';

export const fullPageContentText = css`
align-items: center;
`;

export const fullPageTitle = css`
font-size: 48px;
line-height: 60px;
`;

export const popupContentText = css`
margin-top: 16px;
`;

export const popupTitle = css`
font-size: 32px;
line-height: 44px;
margin-bottom: 16px !important;
width: 264px;
`;
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
import { memo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useClipboard } from '@stacks/ui';

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { useWallet } from '@app/common/hooks/use-wallet';
import { RouteUrls } from '@shared/route-urls';

import { BackUpSecretKeyLayout } from './back-up-secret-key.layout';

export const BackUpSecretKeyPage = memo(() => {
return <BackUpSecretKeyLayout />;
const { secretKey } = useWallet();
const { onCopy, hasCopied } = useClipboard(secretKey || '');
const navigate = useNavigate();

const analytics = useAnalytics();

const copyToClipboard = () => {
void analytics.track('copy_secret_key_to_clipboard');
onCopy();
};

return (
<BackUpSecretKeyLayout
hasCopied={hasCopied}
onBackedUpSecretKey={() => navigate(RouteUrls.SetPassword)}
onCopyToClipboard={copyToClipboard}
secretKey={secretKey}
/>
);
});
48 changes: 23 additions & 25 deletions src/app/pages/onboarding/welcome/welcome.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,66 @@
import { css, cx } from '@emotion/css';
import { Button, Stack } from '@stacks/ui';
import { cx } from '@emotion/css';
import { Flex, Button, Stack } from '@stacks/ui';

import { Text, Title } from '@app/components/typography';
import { Link } from '@app/components/link';
import WelcomeStacksFull from '@assets/images/onboarding/welcome-full.svg';
import WelcomeStacksPopup from '@assets/images/onboarding/welcome-popup.svg';
import { InitialPageSelectors } from '@tests/integration/initial-page.selectors';
import { getViewMode } from '@app/common/utils';
import { isFullPage, isPopup } from '@app/common/utils';
import { OnboardingSelectors } from '@tests/integration/onboarding.selectors';

import {
fullPageContentImage,
fullPageContentText,
fullPageTitle,
popupTitle,
} from './welcome.styles';
import { fullPageContentText, fullPageTitle, popupContentText, popupTitle } from './welcome.styles';
interface WelcomeLayoutProps {
isGeneratingWallet: boolean;
onStartOnboarding(): void;
onRestoreWallet(): void;
}
export function WelcomeLayout(props: WelcomeLayoutProps): JSX.Element {
const { isGeneratingWallet, onStartOnboarding, onRestoreWallet } = props;
const mode = getViewMode();
const isFullPage = mode === 'full';
const isPopup = mode === 'popup';

return (
<Stack isInline={isFullPage} width="100%">
<Stack className={cx({ [fullPageContentImage]: isFullPage })} flexGrow={1}>
{isFullPage ? <img src={WelcomeStacksFull} /> : <img src={WelcomeStacksPopup} />}
</Stack>
<Stack
className={cx({ [fullPageContentText]: isFullPage })}
<Flex flexGrow={1} justifyContent="center" order={isFullPage ? 1 : 0}>
{isFullPage ? (
<img src={WelcomeStacksFull} />
) : (
<img src={WelcomeStacksPopup} width="394px" />
)}
</Flex>
<Flex
className={cx({ [fullPageContentText]: isFullPage }, { [popupContentText]: isPopup })}
flexGrow={1}
justifyContent="center"
>
<Stack width="100%" textAlign="left" alignItems="start">
<Stack maxWidth="500px" spacing="loose">
<Title
className={cx({ [fullPageTitle]: isFullPage }, { [popupTitle]: isPopup })}
fontWeight={500}
>
Explore the world of Stacks
</Title>
<Text className="text">
<Text>
Hiro Wallet connects you to Stacks apps while keeping your account, data, and crypto
secure. Create your Stacks account to get started.
</Text>
</Stack>
<Stack spacing="loose" textAlign="left" {...props}>
<Button
borderRadius="10px"
data-testid={InitialPageSelectors.SignUp}
data-testid={OnboardingSelectors.SignUpBtn}
height="48px"
isLoading={isGeneratingWallet}
onClick={onStartOnboarding}
width="198px"
>
Create Stacks Account
</Button>
<Link data-testid={InitialPageSelectors.SignIn} fontSize="14px" onClick={onRestoreWallet}>
<Link
data-testid={OnboardingSelectors.SignInLink}
fontSize="14px"
onClick={onRestoreWallet}
>
I already have an account
</Link>
</Stack>
</Stack>
</Flex>
</Stack>
);
}

0 comments on commit 6e11303

Please sign in to comment.