Skip to content

Commit

Permalink
fix: passphrase modal info
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicvladan committed Sep 27, 2023
1 parent 9a45e4f commit 935a0e1
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/components/Disclosure/Disclosure.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.arrow {
transition: transform 0.3s ease-in-out;
transform: rotate(90deg);
}

.arrowOpen {
transform: rotate(270deg);
}
68 changes: 68 additions & 0 deletions src/components/Disclosure/Disclosure.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
Disclosure as DisclosureComponent,
Transition,
} from '@headlessui/react';

import ArrowRightLight from '@media/UI/arrow-right-light.svg';
import ArrowRightDark from '@media/UI/arrow-right-dark.svg';
import React, { Fragment, useContext } from 'react';
import ThemeContext from '@context/ThemeContext';

import classes from './Disclosure.module.scss';

interface DisclosureProps {
title: string;
children: React.ReactNode;
defaultOpen?: boolean;
buttonClassName?: string;
conentClassName?: string;
}

export default function Disclosure({
title,
children,
defaultOpen,
buttonClassName,
conentClassName,
}: DisclosureProps) {
const { theme } = useContext(ThemeContext);

const getArrowClasses = (open: boolean) =>
`absolute right-4 top-5 ${classes.arrow} ${open ? classes.arrowOpen : ''}`;

return (
<DisclosureComponent defaultOpen={defaultOpen}>
{({ open }) => (
<>
<DisclosureComponent.Button
className={`flex relative w-full justify-between py-2 text-left text-sm font-medium bg-color-shade-white-night dark:bg-color-shade-dark-1-night text-color-accents-purple-black dark:text-color-accents-grey-lavendar text-base py-3 px-8 dark:text-color-shade-light-2-night bg-none text-color-shade-light-3-night rounded ${buttonClassName}`}
>
<span>{title}</span>
{theme === 'light' ? (
<ArrowRightLight className={getArrowClasses(open)} />
) : (
<ArrowRightDark className={getArrowClasses(open)} />
)}
</DisclosureComponent.Button>
<div className="overflow-hidden">
<Transition
as={Fragment}
enter="transition ease-in-out duration-300 transform"
enterFrom="-translate-y-full"
enterTo="translate-y-0"
leave="transition ease-in-out duration-300 transform"
leaveFrom="translate-y-0"
leaveTo="-translate-y-full"
>
<DisclosureComponent.Panel
className={`px-4 pt-4 pb-2 text-sm text-gray-500 ${conentClassName}`}
>
{children}
</DisclosureComponent.Panel>
</Transition>
</div>
</>
)}
</DisclosureComponent>
);
}
18 changes: 16 additions & 2 deletions src/components/Modals/PasswordModal/PasswordModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { FC, useState } from 'react';
import { Modal } from '@components/Modals';
import { Button } from '@components/Buttons';
import FeedbackMessage from '@components/FeedbackMessage/FeedbackMessage';
import Spinner from '@components/Spinner/Spinner';
import AuthenticationInput from '../../Inputs/AuthenticationInput/AuthenticationInput';
import { useForm } from 'react-hook-form';
import { FieldError } from 'react-hook-form/dist/types/errors';
import { MIN_PASSWORD_LENGTH } from '@utils/password';
import { useLocales } from '@context/LocalesContext';
import Disclosure from '@components/Disclosure/Disclosure';
import {
getMetamaskPassphraseExplanation,
setMetamaskPassphraseExplanation,
} from '@utils/localStorage';

interface PasswordModalProps {
showModal: boolean;
Expand All @@ -32,6 +36,7 @@ const PasswordModal: FC<PasswordModalProps> = ({
setLoading(true);
try {
await handleSubmitForm(data.password);
setMetamaskPassphraseExplanation(false);
closeModal();
} catch (e) {
setErrorMessage(intl.get('GENERIC_ERROR', { message: e.message }));
Expand Down Expand Up @@ -68,7 +73,16 @@ const PasswordModal: FC<PasswordModalProps> = ({

<p className="text-sm mb-5">{intl.get('PASSPHRASE_EXPLANATION')}</p>

<p className="text-sm mb-5">{intl.get('PASSPHRASE_EXPLANATION_2')}</p>
<div className="my-5">
<Disclosure
title={intl.get('READ_MORE')}
defaultOpen={!getMetamaskPassphraseExplanation()}
>
<p className="text-sm mb-5">
{intl.get('PASSPHRASE_EXPLANATION_2')}
</p>
</Disclosure>
</div>

<div className="text-center">
<Button
Expand Down
21 changes: 21 additions & 0 deletions src/utils/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum LocalStorageKeys {
NETWORK = 'network',
METAMASK_MIGRATION_DIALOG = 'metamask-migration-dialog',
METAMASK_PASSPHRASE_EXPLANATION_HIDE = 'metamask-migration-explanation-hide',
}

/**
Expand All @@ -17,3 +18,23 @@ export function setDefaultNetwork(network: string): void {
export function getDefaultNetwork(): string | null {
return localStorage.getItem(LocalStorageKeys.NETWORK);
}

/**
* Sets default network to local storage
* @param network Network id
*/
export function setMetamaskPassphraseExplanation(seen: boolean): void {
localStorage.setItem(
LocalStorageKeys.METAMASK_PASSPHRASE_EXPLANATION_HIDE,
String(seen)
);
}

/**
* Gets default network from local storage
*/
export function getMetamaskPassphraseExplanation(): boolean {
return Boolean(
localStorage.getItem(LocalStorageKeys.METAMASK_PASSPHRASE_EXPLANATION_HIDE)
);
}

0 comments on commit 935a0e1

Please sign in to comment.