Skip to content

Commit

Permalink
Merge pull request PolkaGate#1443 from PolkaGate/hideNumbersBeforLogin
Browse files Browse the repository at this point in the history
add hide numbers on login page
  • Loading branch information
Nick-1979 authored Jul 29, 2024
2 parents b75c02e + e642b0b commit 64a061d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
26 changes: 13 additions & 13 deletions packages/extension-polkagate/src/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

import { Box, Grid, Theme, useTheme } from '@mui/material';
import type { Theme} from '@mui/material';

import { Box, Grid, useTheme } from '@mui/material';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import { blake2AsHex } from '@polkadot/util-crypto';
Expand All @@ -26,18 +27,17 @@ interface Props {
children?: React.ReactNode;
}


export type LoginInfo = {
export interface LoginInfo {
status: 'noLogin' | 'mayBeLater' | 'justSet' | 'set' | 'forgot' | 'reset';
lastLoginTime?: number;
hashedPassword?: string;
addressesToForget?: string[];
}

export const updateStorage = async (label: string, newInfo: unknown) => {
export const updateStorage = async (label: string, newInfo: object) => {
try {
// Retrieve the previous value
const previousData = await getStorage(label);
const previousData = await getStorage(label) as object;

// Update the previous data with the new data
const updatedData = { ...previousData, ...newInfo } as unknown;
Expand All @@ -47,26 +47,26 @@ export const updateStorage = async (label: string, newInfo: unknown) => {

return true;
} catch (error) {
console.error('Error while updating data');
console.error('Error while updating data', error);

return false;
}
};

export const getStorage = (label: string, parse = false) => {
export const getStorage = (label: string, parse = false): Promise<object | string> => {
return new Promise((resolve, reject) => {
chrome.storage.local.get([label], (result) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(parse ? JSON.parse((result[label] || '{}') as string) : result[label]);
resolve(parse ? JSON.parse((result[label] || '{}') as string) as object : result[label] as object);
}
});
});
};

export const watchStorage = (label: string, setChanges: ((value: any) => void), parse = false) => {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
chrome.storage.onChanged.addListener(function (changes, areaName) {
if (areaName === 'local' && label in changes) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down Expand Up @@ -111,7 +111,7 @@ const FlyingLogo = ({ theme }: { theme: Theme }) => (
/>
);

export default function Loading({ children }: Props): React.ReactElement<Props> {
export default function Loading ({ children }: Props): React.ReactElement<Props> {
const theme = useTheme();
const manifest = useManifest();

Expand Down Expand Up @@ -251,7 +251,7 @@ export default function Loading({ children }: Props): React.ReactElement<Props>
{isFlying && isPopupOpenedByExtension
? <FlyingLogo theme={theme} />
: <>
{[STEPS.ASK_TO_SET_PASSWORD, STEPS.SHOW_LOGIN].includes(step) && (isPopupOpenedByExtension || isExtensionLocked) &&
{ step !== undefined && [STEPS.ASK_TO_SET_PASSWORD, STEPS.SHOW_LOGIN].includes(step) && (isPopupOpenedByExtension || isExtensionLocked) &&
<Grid container item justifyContent='center' mt='33px' my='35px'>
<StillLogo theme={theme} />
</Grid>
Expand All @@ -269,7 +269,7 @@ export default function Loading({ children }: Props): React.ReactElement<Props>
setStep={setStep}
/>
}
{[STEPS.SHOW_LOGIN].includes(step) &&
{step !== undefined && [STEPS.SHOW_LOGIN].includes(step) &&
<Login
isPasswordError={isPasswordError}
onPassChange={onPassChange}
Expand Down
6 changes: 6 additions & 0 deletions packages/extension-polkagate/src/popup/home/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface News {
}

export const news: News[] = [
{
version: '0.6.9',
notes: [
'Hide Numbers on Login Page. Add an option to hide numbers on the login page before logging in.'
]
},
{
version: '0.6.8',
notes: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
// SPDX-License-Identifier: Apache-2.0
// @ts-nocheck

/* eslint-disable react/jsx-max-props-per-line */

import { Grid, Typography, useTheme } from '@mui/material';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { openOrFocusTab } from '@polkadot/extension-polkagate/src/fullscreen/accountDetails/components/CommonTasks';

import { Password, PButton, WrongPasswordAlert } from '../../components';
import { HideIcon, Password, PButton, ShowIcon, WrongPasswordAlert } from '../../components';
import { useIsExtensionPopup, useTranslation } from '../../hooks';
import { STEPS } from './constants';

Expand All @@ -25,6 +24,8 @@ function Login({ isPasswordError, onPassChange, onUnlock, setStep }: Props): Rea
const theme = useTheme();
const isPopup = useIsExtensionPopup();

const [hideNumbers, setHideNumbers] = useState<boolean>();

const onForgotPassword = useCallback((): void => {
if (isPopup) {
return setStep(STEPS.SHOW_DELETE_ACCOUNT_CONFIRMATION);
Expand All @@ -34,9 +35,29 @@ function Login({ isPasswordError, onPassChange, onUnlock, setStep }: Props): Rea
openOrFocusTab('/forgot-password', true);
}, [isPopup, setStep]);

useEffect(() => {
const isHide = window.localStorage.getItem('hide_numbers');

isHide === 'false' || isHide === null ? setHideNumbers(false) : setHideNumbers(true);
}, [setHideNumbers]);

const onHideClick = useCallback(() => {
setHideNumbers && setHideNumbers(!hideNumbers);
window.localStorage.setItem('hide_numbers', hideNumbers ? 'false' : 'true');
}, [hideNumbers, setHideNumbers]);

return (
<>
<Grid container sx={{ my: '10px' }}>
<Grid alignItems='center' direction='column' item onClick={onHideClick} sx={{ cursor: 'pointer', display: 'flex', position: 'absolute', pt: '3px', right: '35px', top: '15px', opacity: 0.5, '&:hover': { opacity: 1 } }}>
{hideNumbers
? <ShowIcon />
: <HideIcon />
}
<Typography sx={{ color: 'secondary.light', fontSize: '12px', fontWeight: 500 }}>
{hideNumbers ? t('Show numbers') : t('Hide numbers')}
</Typography>
</Grid>
{isPasswordError &&
<WrongPasswordAlert bgcolor={theme.palette.mode === 'dark' ? 'black' : 'white'} />
}
Expand Down

0 comments on commit 64a061d

Please sign in to comment.