Skip to content

Commit

Permalink
[DDW-220] Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaglumac committed Apr 12, 2018
1 parent 041d0c1 commit 9aa0016
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions source/renderer/app/api/ada/lib/v1/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function typedRequest<Response>(
response.on('data', (chunk) => (body += chunk));
// Reject errors
response.on('error', (error) => reject(error));
// Resolve JSON results and handle weird backend behavior
// of "Left" (for errors) and "Right" (for success) properties
// Resolve JSON results and handle backend errors
response.on('end', () => {
try {
const parsedBody = JSON.parse(body);
Expand Down
3 changes: 2 additions & 1 deletion source/renderer/app/api/ada/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type AdaLocalTimeDifference = number;
// ========== V1 API =========

export type AdaV1Assurance = 'normal' | 'strict';
export type AdaV1WalletSyncStateTag = 'restoring' | 'synced';

export type AdaV1WalletSyncState = {
data: ?{
Expand All @@ -123,7 +124,7 @@ export type AdaV1WalletSyncState = {
unit: 'blocksPerSecond',
},
},
tag: 'restoring' | 'synced',
tag: AdaV1WalletSyncStateTag,
};

export type AdaV1Wallet = {
Expand Down
3 changes: 2 additions & 1 deletion source/renderer/app/containers/wallet/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import RestoreNotification from '../../components/notifications/RestoreNotificat
import { buildRoute } from '../../utils/routing';
import { ROUTES } from '../../routes-config';
import type { InjectedContainerProps } from '../../types/injectedPropsType';
import { syncStateTags } from '../../domains/Wallet';

type Props = InjectedContainerProps;

Expand Down Expand Up @@ -43,7 +44,7 @@ export default class Wallet extends Component<Props> {

if (!wallets.active) return <MainLayout><LoadingSpinner /></MainLayout>;

const isRestoreActive = get(wallets.active, 'syncState.tag') === 'restoring';
const isRestoreActive = get(wallets.active, 'syncState.tag') === syncStateTags.RESTORING;
const restoreProgress = get(wallets.active, 'syncState.data.percentage.quantity', 0);
const restoreETA = get(wallets.active, 'syncState.data.estimatedCompletionTime.quantity', 0);

Expand Down
3 changes: 2 additions & 1 deletion source/renderer/app/containers/wallet/WalletSendPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import WalletSendForm from '../../components/wallet/WalletSendForm';
import type { InjectedProps } from '../../types/injectedPropsType';
import globalMessages from '../../i18n/global-messages';
import { DECIMAL_PLACES_IN_ADA, MAX_INTEGER_PLACES_IN_ADA } from '../../config/numbersConfig';
import { syncStateTags } from '../../domains/Wallet';

type Props = InjectedProps;

Expand All @@ -31,7 +32,7 @@ export default class WalletSendPage extends Component<Props> {
// Guard against potential null values
if (!activeWallet) throw new Error('Active wallet required for WalletSendPage.');

const isRestoreActive = get(activeWallet, 'syncState.tag') === 'restoring';
const isRestoreActive = get(activeWallet, 'syncState.tag') === syncStateTags.RESTORING;

return (
<WalletSendForm
Expand Down
3 changes: 2 additions & 1 deletion source/renderer/app/containers/wallet/WalletSummaryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DECIMAL_PLACES_IN_ADA } from '../../config/numbersConfig';
import { ROUTES } from '../../routes-config';
import type { InjectedProps } from '../../types/injectedPropsType';
import resolver from '../../utils/imports';
import { syncStateTags } from '../../domains/Wallet';

const { formattedWalletAmount } = resolver('utils/formatters');

Expand Down Expand Up @@ -52,7 +53,7 @@ export default class WalletSummaryPage extends Component<Props> {
let walletTransactions = null;
const noTransactionsLabel = intl.formatMessage(messages.noTransactions);

const isRestoreActive = get(wallet, 'syncState.tag') === 'restoring';
const isRestoreActive = get(wallet, 'syncState.tag') === syncStateTags.RESTORING;

if (recentTransactionsRequest.isExecutingFirstTime || hasAny || isRestoreActive) {
walletTransactions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import WalletNoTransactions from '../../components/wallet/transactions/WalletNoT
import VerticalFlexContainer from '../../components/layout/VerticalFlexContainer';
import type { InjectedProps } from '../../types/injectedPropsType';
import resolver from '../../utils/imports';
import { syncStateTags } from '../../domains/Wallet';

const { formattedWalletAmount } = resolver('utils/formatters');

Expand Down Expand Up @@ -65,7 +66,7 @@ export default class WalletTransactionsPage extends Component<Props> {
const noTransactionsLabel = intl.formatMessage(messages.noTransactions);
const noTransactionsFoundLabel = intl.formatMessage(messages.noTransactionsFound);

const isRestoreActive = get(activeWallet, 'syncState.tag') === 'restoring';
const isRestoreActive = get(activeWallet, 'syncState.tag') === syncStateTags.RESTORING;

// if (wasSearched || hasAny) {
// transactionSearch = (
Expand Down
8 changes: 7 additions & 1 deletion source/renderer/app/domains/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
import { observable, computed } from 'mobx';
import BigNumber from 'bignumber.js';
import type { AssuranceMode, AssuranceModeOption } from '../types/transactionAssuranceTypes';
import type { AdaV1WalletSyncState } from '../api/ada/types';
import type { AdaV1WalletSyncState, AdaV1WalletSyncStateTag } from '../api/ada/types';
import { assuranceModes, assuranceModeOptions } from '../config/transactionAssuranceConfig';

export const syncStateTags: {
RESTORING: AdaV1WalletSyncStateTag, SYNCED: AdaV1WalletSyncStateTag,
} = {
RESTORING: 'restoring', SYNCED: 'synced',
};

export default class Wallet {

id: string = '';
Expand Down

0 comments on commit 9aa0016

Please sign in to comment.