Skip to content
Permalink
Browse files

[DDW-893] Move wallet status logic

  • Loading branch information...
daniloprates committed Sep 12, 2019
1 parent 24d3cf1 commit 4481fe53ef92dd1c06946381417a5e0f786596f0
@@ -17,6 +17,7 @@ type Props = {
isRestoreActive?: boolean,
restoreProgress?: number,
isLegacy: boolean,
mnemonicsConfirmationStatus: string,
};

@observer
@@ -31,13 +32,15 @@ export default class SidebarWalletMenuItem extends Component<Props> {
isRestoreActive,
restoreProgress,
isLegacy,
mnemonicsConfirmationStatus,
} = this.props;

const componentStyles = classNames([
styles.component,
active ? styles.active : null,
isLegacy ? styles.legacyItem : null,
className,
styles[`mnemonicsConfirmationStatus-${mnemonicsConfirmationStatus}`],
]);

return (
@@ -68,6 +68,7 @@ export default class SidebarWalletsMenu extends Component<Props> {
isRestoreActive={wallet.isRestoreActive}
restoreProgress={wallet.restoreProgress}
isLegacy={wallet.isLegacy}
mnemonicsConfirmationStatus={wallet.mnemonicsConfirmationStatus}
/>
))}
</Scrollbars>
@@ -63,3 +63,17 @@
cursor: default;
}
}

.mnemonicsConfirmationStatus-notification {
background: red;
&:after {
background: red;
border-radius: 50%;
content: '';
display: block;
height: 10px;
position: absolute;
right: 10px;
width: 10px;
}
}
@@ -2,6 +2,11 @@
import { pick } from 'lodash';
import { observable, computed, action, runInAction } from 'mobx';
import BigNumber from 'bignumber.js';
import moment from 'moment';
import {
MNEMONICS_CHECKING_NOTIFICATION,
MNEMONICS_CHECKING_WARNING,
} from '../config/walletsConfig';
import {
getWalletLocalData,
updateWalletLocalData,
@@ -44,6 +49,17 @@ const WalletAssuranceModes: {
},
};

export const WalletStatuses = {
OK: 'ok',
WARNING: 'warning',
NOTIFICATION: 'notification',
};

export const WalletStatusesType = {
NEVER_CHECKED: 'neverChecked',
ALREADY_CHECKED: 'alreadyChecked',
};

export type WalletProps = {
id: string,
name: string,
@@ -73,6 +89,8 @@ export default class Wallet {
@observable delegatedStakePool: ?StakePool;
@observable createdAt: Date;
@observable mnemonicsConfirmationDate: ?Date;
@observable mnemonicsConfirmationStatus: string;
@observable mnemonicsConfirmationStatusType: string;

constructor(data: WalletProps) {
Object.assign(this, data);
@@ -82,15 +100,35 @@ export default class Wallet {
getWalletLocalData = async () => {
const { id } = this;
const { mnemonicsConfirmationDate } = await getWalletLocalData(id);
const { status, type } = this.getWalletStatus(mnemonicsConfirmationDate);
runInAction('set mnemonicsConfirmationDate', () => {
this.mnemonicsConfirmationDate = mnemonicsConfirmationDate;
this.mnemonicsConfirmationStatus = status;
this.mnemonicsConfirmationStatusType = type;
});
};

getWalletStatus = (mnemonicsConfirmationDate: ?Date) => {
const { walletCreationDate } = this;
const dateToCheck = mnemonicsConfirmationDate || walletCreationDate;
const daysSinceDate = moment().diff(moment(dateToCheck), 'days');
let status = WalletStatuses.OK;
if (daysSinceDate > MNEMONICS_CHECKING_NOTIFICATION)
status = WalletStatuses.NOTIFICATION;
else if (daysSinceDate > MNEMONICS_CHECKING_WARNING)
status = WalletStatuses.WARNING;
const type = mnemonicsConfirmationDate
? WalletStatusesType.ALREADY_CHECKED
: WalletStatusesType.NEVER_CHECKED;
return { status, type };
};

@action updateWalletLocalData = async () => {
const { id } = this;
const mnemonicsConfirmationDate = new Date();
this.mnemonicsConfirmationDate = mnemonicsConfirmationDate;
this.mnemonicsConfirmationStatus = WalletStatuses.OK;
this.mnemonicsConfirmationStatusType = WalletStatusesType.ALREADY_CHECKED;
await updateWalletLocalData({
id,
mnemonicsConfirmationDate,
@@ -37,6 +37,10 @@ export default class SidebarStore extends Store {
get(w, 'syncState.tag') === WalletSyncStateTags.RESTORING,
restoreProgress: get(w, 'syncState.data.percentage.quantity', 0),
isLegacy: w.isLegacy,
mnemonicsConfirmationDate: w.mnemonicsConfirmationDate,
mnemonicsConfirmationStatus: w.mnemonicsConfirmationStatus,
mnemonicsConfirmationStatusType: w.mnemonicsConfirmationStatusType,
blah: true,
}));
}

@@ -7,4 +7,5 @@ export type SidebarWalletType = {
isRestoreActive?: boolean,
restoreProgress?: number,
isLegacy: boolean,
mnemonicsConfirmationStatus: string,
};

0 comments on commit 4481fe5

Please sign in to comment.
You can’t perform that action at this time.