Skip to content

Commit

Permalink
[DDW-893] Flow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thedanheller committed Sep 12, 2019
1 parent fb84801 commit 0b01e03
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 40 deletions.
1 change: 0 additions & 1 deletion source/common/types/paper-wallet-request.types.js
Expand Up @@ -6,7 +6,6 @@ export type GeneratePaperWalletParams = {
isMainnet: boolean, isMainnet: boolean,
buildLabel: string, buildLabel: string,
timestamp: string, timestamp: string,
createdAt: Date,
messages: { messages: {
walletAddressLabel: string, walletAddressLabel: string,
recoveryPhraseLabel: string, recoveryPhraseLabel: string,
Expand Down
Expand Up @@ -10,7 +10,7 @@ type Props = {
activeItem: string, activeItem: string,
isActiveScreen: Function, isActiveScreen: Function,
onWalletNavItemClick: Function, onWalletNavItemClick: Function,
hasNotification: boolean, hasNotification?: boolean,
}; };


@observer @observer
Expand Down
Expand Up @@ -54,7 +54,7 @@ type Props = {
activeItem: string, activeItem: string,
isActiveNavItem: Function, isActiveNavItem: Function,
onNavItemClick: Function, onNavItemClick: Function,
hasNotification: boolean, hasNotification?: boolean,
}; };


@observer @observer
Expand Down
Expand Up @@ -85,14 +85,16 @@ export const messages = defineMessages({
}); });


type Props = { type Props = {
mnemonicsConfirmationDate: Date,
walletCreationDate: Date, walletCreationDate: Date,
openDialogAction: Function, openDialogAction: Function,
isDialogOpen: Function, isDialogOpen: Function,
walletRecoveryPhraseStep1Container: Node, walletRecoveryPhraseStep1Container: Node,
walletRecoveryPhraseStep2Container: Node, walletRecoveryPhraseStep2Container: Node,
walletRecoveryPhraseStep3Container: Node, walletRecoveryPhraseStep3Container: Node,
walletRecoveryPhraseStep4Container: Node, walletRecoveryPhraseStep4Container: Node,
mnemonicsConfirmationDate: ?Date,
mnemonicsConfirmationStatus: string,
mnemonicsConfirmationStatusType: string,
}; };


@observer @observer
Expand Down Expand Up @@ -135,24 +137,32 @@ export default class WalletRecoveryPhrase extends Component<Props> {
} }


get recoveryPhraseStatus() { get recoveryPhraseStatus() {
const { mnemonicsConfirmationDate, walletCreationDate } = this.props; const {
const dateToCheck = mnemonicsConfirmationDate || walletCreationDate; walletCreationDate,
const daysSinceDate = moment().diff(moment(dateToCheck), 'days'); mnemonicsConfirmationDate,
let status = 'ok'; mnemonicsConfirmationStatus,
if (daysSinceDate > MNEMONICS_CHECKING_NOTIFICATION) mnemonicsConfirmationStatusType,
status = 'notification'; } = this.props;
else if (daysSinceDate > MNEMONICS_CHECKING_WARNING) status = 'warning';
const type = mnemonicsConfirmationDate ? 'alreadyChecked' : 'neverChecked'; const statuses = this.statuses[mnemonicsConfirmationStatusType];
const statuses = this.statuses[type]; const { icon, message } = statuses[mnemonicsConfirmationStatus];
const { icon, message } = statuses[status];
const timeAgo = moment(mnemonicsConfirmationDate).fromNow(); const timeAgo = moment(mnemonicsConfirmationDate).fromNow();
const timeUntilWarning = 'few months, more or less'; const fromNowToWarning = moment().add(MNEMONICS_CHECKING_WARNING, 'days');
const timeUntilNotification = 'couple of days, more or less'; const fromNowToNotification = moment().add(
MNEMONICS_CHECKING_NOTIFICATION,
'days'
);
const timeUntilWarning = moment(walletCreationDate).diff(
fromNowToWarning,
'days'
);
const timeUntilNotification = moment(walletCreationDate).diff(
fromNowToNotification,
'days'
);
return { return {
icon, icon,
message, message,
type,
status,
timeAgo, timeAgo,
timeUntilWarning, timeUntilWarning,
timeUntilNotification, timeUntilNotification,
Expand All @@ -168,19 +178,19 @@ export default class WalletRecoveryPhrase extends Component<Props> {
walletRecoveryPhraseStep2Container, walletRecoveryPhraseStep2Container,
walletRecoveryPhraseStep3Container, walletRecoveryPhraseStep3Container,
walletRecoveryPhraseStep4Container, walletRecoveryPhraseStep4Container,
mnemonicsConfirmationStatus,
} = this.props; } = this.props;
const { const {
icon, icon,
message, message,
status,
timeAgo, timeAgo,
timeUntilWarning, timeUntilWarning,
timeUntilNotification, timeUntilNotification,
} = this.recoveryPhraseStatus; } = this.recoveryPhraseStatus;


const validationStatusStyles = classnames([ const validationStatusStyles = classnames([
styles.validationStatus, styles.validationStatus,
styles[`validationStatus${capitalize(status)}`], styles[`validationStatus${capitalize(mnemonicsConfirmationStatus)}`],
]); ]);


return ( return (
Expand Down
Expand Up @@ -54,7 +54,7 @@ export default class WalletRecoveryPhraseStep1 extends Component<Props, State> {
safetyAgreement: false, safetyAgreement: false,
}; };


onToggleSafetyAgreement = checked => { onToggleSafetyAgreement = (checked: boolean) => {
this.setState({ this.setState({
safetyAgreement: checked, safetyAgreement: checked,
}); });
Expand Down
Expand Up @@ -53,7 +53,7 @@ export default class WalletRecoveryPhraseStep1 extends Component<Props, State> {
safetyAgreement: false, safetyAgreement: false,
}; };


onToggleSafetyAgreement = checked => { onToggleSafetyAgreement = (checked: boolean) => {
this.setState({ this.setState({
safetyAgreement: checked, safetyAgreement: checked,
}); });
Expand Down
Expand Up @@ -79,7 +79,9 @@ type Props = {
walletRecoveryPhraseStep2Container: Node, walletRecoveryPhraseStep2Container: Node,
walletRecoveryPhraseStep3Container: Node, walletRecoveryPhraseStep3Container: Node,
walletRecoveryPhraseStep4Container: Node, walletRecoveryPhraseStep4Container: Node,
mnemonicsConfirmationDate?: Date, mnemonicsConfirmationDate: ?Date,
mnemonicsConfirmationStatus: string,
mnemonicsConfirmationStatusType: string,
}; };


@observer @observer
Expand Down Expand Up @@ -127,6 +129,8 @@ export default class WalletSettings extends Component<Props> {
walletRecoveryPhraseStep3Container, walletRecoveryPhraseStep3Container,
walletRecoveryPhraseStep4Container, walletRecoveryPhraseStep4Container,
mnemonicsConfirmationDate, mnemonicsConfirmationDate,
mnemonicsConfirmationStatus,
mnemonicsConfirmationStatusType,
} = this.props; } = this.props;


const assuranceLevelOptions = assuranceLevels.map(assurance => ({ const assuranceLevelOptions = assuranceLevels.map(assurance => ({
Expand Down Expand Up @@ -188,6 +192,8 @@ export default class WalletSettings extends Component<Props> {


<WalletRecoveryPhrase <WalletRecoveryPhrase
mnemonicsConfirmationDate={mnemonicsConfirmationDate} mnemonicsConfirmationDate={mnemonicsConfirmationDate}
mnemonicsConfirmationStatus={mnemonicsConfirmationStatus}
mnemonicsConfirmationStatusType={mnemonicsConfirmationStatusType}
walletCreationDate={walletCreationDate} walletCreationDate={walletCreationDate}
openDialogAction={openDialogAction} openDialogAction={openDialogAction}
isDialogOpen={isDialogOpen} isDialogOpen={isDialogOpen}
Expand Down
3 changes: 2 additions & 1 deletion source/renderer/app/containers/wallet/Wallet.js
Expand Up @@ -73,8 +73,9 @@ export default class Wallet extends Component<Props> {
0 0
); );
const hasNotification = const hasNotification =
wallets.active &&
wallets.active.mnemonicsConfirmationStatus === wallets.active.mnemonicsConfirmationStatus ===
WalletStatuses.NOTIFICATION; WalletStatuses.NOTIFICATION;


return ( return (
<MainLayout> <MainLayout>
Expand Down
5 changes: 4 additions & 1 deletion source/renderer/app/containers/wallet/WalletSettingsPage.js
Expand Up @@ -4,7 +4,6 @@ import { observer, inject } from 'mobx-react';
import WalletSettings from '../../components/wallet/settings/WalletSettings'; import WalletSettings from '../../components/wallet/settings/WalletSettings';
import type { InjectedProps } from '../../types/injectedPropsType'; import type { InjectedProps } from '../../types/injectedPropsType';
import { isValidWalletName } from '../../utils/validations'; import { isValidWalletName } from '../../utils/validations';
// import { getWalletLocalData } from '../../utils/walletLocalStorage.js';
import ChangeSpendingPasswordDialogContainer from './dialogs/settings/ChangeSpendingPasswordDialogContainer'; import ChangeSpendingPasswordDialogContainer from './dialogs/settings/ChangeSpendingPasswordDialogContainer';
import DeleteWalletDialogContainer from './dialogs/settings/DeleteWalletDialogContainer'; import DeleteWalletDialogContainer from './dialogs/settings/DeleteWalletDialogContainer';
import ExportWalletToFileDialogContainer from './dialogs/settings/ExportWalletToFileDialogContainer'; import ExportWalletToFileDialogContainer from './dialogs/settings/ExportWalletToFileDialogContainer';
Expand Down Expand Up @@ -54,6 +53,10 @@ export default class WalletSettingsPage extends Component<Props> {
isSpendingPasswordSet={activeWallet.hasPassword} isSpendingPasswordSet={activeWallet.hasPassword}
spendingPasswordUpdateDate={activeWallet.passwordUpdateDate} spendingPasswordUpdateDate={activeWallet.passwordUpdateDate}
mnemonicsConfirmationDate={activeWallet.mnemonicsConfirmationDate} mnemonicsConfirmationDate={activeWallet.mnemonicsConfirmationDate}
mnemonicsConfirmationStatus={activeWallet.mnemonicsConfirmationStatus}
mnemonicsConfirmationStatusType={
activeWallet.mnemonicsConfirmationStatusType
}
isDialogOpen={uiDialogs.isOpen} isDialogOpen={uiDialogs.isOpen}
walletId={activeWallet.id} walletId={activeWallet.id}
walletName={activeWallet.name} walletName={activeWallet.name}
Expand Down
Expand Up @@ -21,10 +21,10 @@ export default class WalletRecoveryPhraseStep2Container extends Component<Props>
updateWalletLocalData = () => { updateWalletLocalData = () => {
const { wallets } = this.props.stores; const { wallets } = this.props.stores;
const activeWallet = wallets.active; const activeWallet = wallets.active;
activeWallet.updateWalletLocalData(); if (activeWallet) activeWallet.updateWalletLocalData();
}; };


handleVerify = successful => { handleVerify = (successful: boolean) => {
const dialog = successful const dialog = successful
? WalletRecoveryPhraseStep3Dialog ? WalletRecoveryPhraseStep3Dialog
: WalletRecoveryPhraseStep4Dialog; : WalletRecoveryPhraseStep4Dialog;
Expand Down
7 changes: 5 additions & 2 deletions source/renderer/app/domains/Wallet.js
Expand Up @@ -73,6 +73,9 @@ export type WalletProps = {
isDelegated?: boolean, isDelegated?: boolean,
delegatedStakePool?: StakePool, delegatedStakePool?: StakePool,
createdAt: Date, createdAt: Date,
mnemonicsConfirmationDate: ?Date,
mnemonicsConfirmationStatus: string,
mnemonicsConfirmationStatusType: string,
}; };


export default class Wallet { export default class Wallet {
Expand Down Expand Up @@ -109,8 +112,8 @@ export default class Wallet {
}; };


getWalletStatus = (mnemonicsConfirmationDate: ?Date) => { getWalletStatus = (mnemonicsConfirmationDate: ?Date) => {
const { walletCreationDate } = this; const { createdAt } = this;
const dateToCheck = mnemonicsConfirmationDate || walletCreationDate; const dateToCheck = mnemonicsConfirmationDate || createdAt;
const daysSinceDate = moment().diff(moment(dateToCheck), 'days'); const daysSinceDate = moment().diff(moment(dateToCheck), 'days');
let status = WalletStatuses.OK; let status = WalletStatuses.OK;
if (daysSinceDate > MNEMONICS_CHECKING_NOTIFICATION) if (daysSinceDate > MNEMONICS_CHECKING_NOTIFICATION)
Expand Down
3 changes: 1 addition & 2 deletions source/renderer/app/utils/walletLocalStorage.js
Expand Up @@ -15,7 +15,7 @@ const storageKeys = {


export type WalletLocalData = { export type WalletLocalData = {
id: string, id: string,
mnemonicsConfirmationDate: ?Date, mnemonicsConfirmationDate?: ?Date,
}; };


export const getWalletLocalData = ( export const getWalletLocalData = (
Expand Down Expand Up @@ -51,7 +51,6 @@ export const setWalletLocalData = (


export const updateWalletLocalData = (updatedWalletData: { export const updateWalletLocalData = (updatedWalletData: {
id: string, id: string,
mnemonicsConfirmationDate: Date,
}): Promise<void> => }): Promise<void> =>
new Promise(async (resolve, reject) => { new Promise(async (resolve, reject) => {
const walletId = updatedWalletData.id; const walletId = updatedWalletData.id;
Expand Down
3 changes: 3 additions & 0 deletions storybook/stories/Sidebar.stories.js
Expand Up @@ -19,20 +19,23 @@ const sidebarMenus = observable({
info: '100 ADA', info: '100 ADA',
isConnected: true, isConnected: true,
isLegacy: false, isLegacy: false,
mnemonicsConfirmationStatus: 'ok',
}, },
{ {
id: '2', id: '2',
title: 'Second', title: 'Second',
info: '200 ADA', info: '200 ADA',
isConnected: true, isConnected: true,
isLegacy: false, isLegacy: false,
mnemonicsConfirmationStatus: 'ok',
}, },
{ {
id: '3', id: '3',
title: 'Third', title: 'Third',
info: '300 ADA', info: '300 ADA',
isConnected: true, isConnected: true,
isLegacy: false, isLegacy: false,
mnemonicsConfirmationStatus: 'ok',
}, },
], ],
activeWalletId: '1', activeWalletId: '1',
Expand Down
16 changes: 16 additions & 0 deletions storybook/stories/SidebarWalletsMenu.stories.js
Expand Up @@ -36,6 +36,10 @@ storiesOf('SidebarWalletsMenu', module)
isRestoreActive: false, isRestoreActive: false,
restoreProgress: 0, restoreProgress: 0,
isLegacy: false, isLegacy: false,
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}, },
{ {
id: '2', id: '2',
Expand All @@ -45,6 +49,10 @@ storiesOf('SidebarWalletsMenu', module)
isRestoreActive: false, isRestoreActive: false,
restoreProgress: 0, restoreProgress: 0,
isLegacy: false, isLegacy: false,
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}, },
{ {
id: '3', id: '3',
Expand All @@ -54,6 +62,10 @@ storiesOf('SidebarWalletsMenu', module)
isRestoreActive: false, isRestoreActive: false,
restoreProgress: 0, restoreProgress: 0,
isLegacy: false, isLegacy: false,
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}, },
{ {
id: '4', id: '4',
Expand All @@ -63,6 +75,10 @@ storiesOf('SidebarWalletsMenu', module)
isRestoreActive: false, isRestoreActive: false,
restoreProgress: 0, restoreProgress: 0,
isLegacy: false, isLegacy: false,
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}, },
]} ]}
isActiveWallet={id => id === '2'} isActiveWallet={id => id === '2'}
Expand Down
12 changes: 12 additions & 0 deletions storybook/stories/Staking-DelegationCenter.stories.js
Expand Up @@ -29,6 +29,10 @@ const wallets = [
inactiveStakePercentage: 24, inactiveStakePercentage: 24,
isDelegated: true, isDelegated: true,
delegatedStakePool: STAKE_POOLS[0], delegatedStakePool: STAKE_POOLS[0],
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}), }),
new Wallet({ new Wallet({
id: 'wallet2', id: 'wallet2',
Expand All @@ -41,6 +45,10 @@ const wallets = [
inactiveStakePercentage: 35, inactiveStakePercentage: 35,
isDelegated: true, isDelegated: true,
delegatedStakePool: STAKE_POOLS[1], delegatedStakePool: STAKE_POOLS[1],
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}), }),
new Wallet({ new Wallet({
id: 'wallet3', id: 'wallet3',
Expand All @@ -52,6 +60,10 @@ const wallets = [
isLegacy: false, isLegacy: false,
inactiveStakePercentage: 0, inactiveStakePercentage: 0,
isDelegated: false, isDelegated: false,
createdAt: new Date(),
mnemonicsConfirmationDate: new Date(),
mnemonicsConfirmationStatus: 'ok',
mnemonicsConfirmationStatusType: 'neverChecked',
}), }),
]; ];


Expand Down
34 changes: 25 additions & 9 deletions storybook/stories/WalletScreens-Settings.stories.js
Expand Up @@ -73,11 +73,8 @@ const getWalletDates = (type: string, status: string) => {
.subtract(MNEMONICS_CHECKING_NOTIFICATION + 10, 'days') .subtract(MNEMONICS_CHECKING_NOTIFICATION + 10, 'days')
.toDate(); .toDate();


let walletCreationDate; const mnemonicsConfirmationDate = date;
let mnemonicsConfirmationDate; const walletCreationDate = date;

if (type === 'alreadyChecked') mnemonicsConfirmationDate = date;
else walletCreationDate = date;


return { return {
mnemonicsConfirmationDate, mnemonicsConfirmationDate,
Expand Down Expand Up @@ -248,12 +245,31 @@ export default () => {
onClose={action('Export Wallet - onClose')} onClose={action('Export Wallet - onClose')}
/> />
} }
walletRecoveryPhraseStep1Container={<WalletRecoveryPhraseStep1Dialog />} walletRecoveryPhraseStep1Container={
walletRecoveryPhraseStep2Container={<WalletRecoveryPhraseStep2Dialog />} <WalletRecoveryPhraseStep1Dialog
walletRecoveryPhraseStep3Container={<WalletRecoveryPhraseStep3Dialog />} onClose={action('onClose')}
walletRecoveryPhraseStep4Container={<WalletRecoveryPhraseStep4Dialog />} onContinue={action('onContinue')}
/>
}
walletRecoveryPhraseStep2Container={
<WalletRecoveryPhraseStep2Dialog
onClose={action('onClose')}
onVerify={action('onVerify')}
/>
}
walletRecoveryPhraseStep3Container={
<WalletRecoveryPhraseStep3Dialog onClose={action('onClose')} />
}
walletRecoveryPhraseStep4Container={
<WalletRecoveryPhraseStep4Dialog
onClose={action('onClose')}
onVerifyAgain={action('onVerifyAgain')}
/>
}
walletCreationDate={walletCreationDate} walletCreationDate={walletCreationDate}
mnemonicsConfirmationDate={mnemonicsConfirmationDate} mnemonicsConfirmationDate={mnemonicsConfirmationDate}
mnemonicsConfirmationStatus={status}
mnemonicsConfirmationStatusType={type}
/> />
); );
}; };
1 change: 1 addition & 0 deletions storybook/stories/support/StoryLayout.js
Expand Up @@ -113,6 +113,7 @@ export default class StoryLayout extends Component<Props> {
isRestoreActive: get(wallet, 'syncState.tag', 'synced') === 'restoring', isRestoreActive: get(wallet, 'syncState.tag', 'synced') === 'restoring',
restoreProgress: get(wallet, 'syncState.data.percentage.quantity', 0), restoreProgress: get(wallet, 'syncState.data.percentage.quantity', 0),
isLegacy: wallet.isLegacy, isLegacy: wallet.isLegacy,
mnemonicsConfirmationStatus: wallet.mnemonicsConfirmationStatus,
})); }));


getSidebarMenus = ( getSidebarMenus = (
Expand Down

0 comments on commit 0b01e03

Please sign in to comment.