Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/app-accounts/src/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import React, { useState, useEffect } from 'react';
import styled from 'styled-components';
import { AddressCard, AddressInfo, Button, ChainLock, Forget, Menu, Popup } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';

import Backup from './modals/Backup';
Expand All @@ -22,6 +23,7 @@ interface Props extends I18nProps {
}

function Account ({ address, className, t }: Props): React.ReactElement<Props> {
const api = useApi();
const [genesisHash, setGenesisHash] = useState<string | null>(null);
const [isBackupOpen, setIsBackupOpen] = useState(false);
const [{ isDevelopment, isEditable, isExternal }, setFlags] = useState({ isDevelopment: false, isEditable: false, isExternal: false });
Expand Down Expand Up @@ -135,14 +137,18 @@ function Account ({ address, className, t }: Props): React.ReactElement<Props> {
>
{t('Forget this account')}
</Menu.Item>
<Menu.Divider />
<ChainLock
className='accounts--network-toggle'
genesisHash={genesisHash}
isDisabled={!isEditable || isExternal}
onChange={_onGenesisChange}
preventDefault
/>
{!api.isDevelopment && (
<>
<Menu.Divider />
<ChainLock
className='accounts--network-toggle'
genesisHash={genesisHash}
isDisabled={!isEditable || isExternal}
onChange={_onGenesisChange}
preventDefault
/>
</>
)}
</Menu>
</Popup>
</div>
Expand Down
63 changes: 26 additions & 37 deletions packages/app-accounts/src/modals/Backup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ interface Props extends BareProps {
address: string;
}

interface ButtonsProps {
doBackup: () => void;
isPassValid: boolean;
onClose: () => void;
}

interface ContentProps {
address: string;
doBackup: () => void;
isPassTouched: boolean;
isPassValid: boolean;
onChangePass: (password: string) => void;
password: string;
}

export default function ({ address, onClose }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [password, setPassword] = useState('');
Expand All @@ -25,16 +40,15 @@ export default function ({ address, onClose }: Props): React.ReactElement<Props>
keyring.isPassValid(password) && !backupFailed,
[password, backupFailed]);

function onChangePass (value: string): void {
const _onChangePass = (value: string): void => {
if (!isPassTouched) {
setIsPassTouched(true);
}
setBackupFailed(false);

setBackupFailed(false);
setPassword(value);
}

function doBackup (): void {
};
const _doBackup = (): void => {
try {
const addressKeyring = address && keyring.getPair(address);
const json = addressKeyring && keyring.backupAccount(addressKeyring, password);
Expand All @@ -48,7 +62,7 @@ export default function ({ address, onClose }: Props): React.ReactElement<Props>
}

onClose();
}
};

return (
<Modal
Expand All @@ -59,38 +73,22 @@ export default function ({ address, onClose }: Props): React.ReactElement<Props>
<Modal.Header>{t('Backup account')}</Modal.Header>
<Content
address={address}
doBackup={doBackup}
doBackup={_doBackup}
isPassTouched={isPassTouched}
isPassValid={isPassValid}
password={password}
onChangePass={onChangePass}
onChangePass={_onChangePass}
/>
<Buttons
doBackup={doBackup}
doBackup={_doBackup}
isPassValid={isPassValid}
onClose={onClose}
/>
</Modal>
);
}

interface ContentProps {
address: string;
doBackup: () => void;
isPassTouched: boolean;
isPassValid: boolean;
password: string;
onChangePass: (password: string) => void;
}

function Content ({
address,
doBackup,
isPassTouched,
isPassValid,
password,
onChangePass
}: ContentProps): React.ReactElement<ContentProps> {
function Content ({ address, doBackup, isPassTouched, isPassValid, onChangePass, password }: ContentProps): React.ReactElement<ContentProps> {
const { t } = useTranslation();

return (
Expand All @@ -103,6 +101,7 @@ function Content ({
<p>{t('Save this backup file in a secure location. Additionally, the password associated with this account is needed together with this backup file in order to restore your account.')}</p>
<div>
<Password
autoFocus
help={t('The account password as specified when creating the account. This is used to encrypt the backup file and subsequently decrypt it when restoring the account.')}
isError={isPassTouched && !isPassValid}
label={t('password')}
Expand All @@ -117,17 +116,7 @@ function Content ({
);
}

interface ButtonsProps {
doBackup: () => void;
isPassValid: boolean;
onClose: () => void;
}

function Buttons ({
doBackup,
isPassValid,
onClose
}: ButtonsProps): React.ReactElement<ButtonsProps> {
function Buttons ({ doBackup, isPassValid, onClose }: ButtonsProps): React.ReactElement<ButtonsProps> {
const { t } = useTranslation();

return (
Expand Down
22 changes: 14 additions & 8 deletions packages/app-address-book/src/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { I18nProps } from '@polkadot/react-components/types';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { AddressCard, AddressInfo, Button, ChainLock, Forget, Menu, Popup } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import keyring from '@polkadot/ui-keyring';

import Transfer from '@polkadot/app-accounts/modals/Transfer';
Expand All @@ -26,6 +27,7 @@ const WITH_EXTENDED = { nonce: true };
const isEditable = true;

function Address ({ address, className, t }: Props): React.ReactElement<Props> {
const api = useApi();
const [current, setCurrent] = useState<KeyringAddress | null>(null);
const [genesisHash, setGenesisHash] = useState<string | null>(null);
const [isForgetOpen, setIsForgetOpen] = useState(false);
Expand Down Expand Up @@ -107,14 +109,18 @@ function Address ({ address, className, t }: Props): React.ReactElement<Props> {
>
{t('Forget this address')}
</Menu.Item>
<Menu.Divider />
<ChainLock
className='addresses--network-toggle'
genesisHash={genesisHash}
isDisabled={!isEditable}
onChange={_onGenesisChange}
preventDefault
/>
{!api.isDevelopment && (
<>
<Menu.Divider />
<ChainLock
className='addresses--network-toggle'
genesisHash={genesisHash}
isDisabled={!isEditable}
onChange={_onGenesisChange}
preventDefault
/>
</>
)}
</Menu>
</Popup>
</div>
Expand Down