From fc37a7f5136694d648d7948acaae5a362d6c6474 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 10 Sep 2018 23:35:34 -0700 Subject: [PATCH 01/29] [DDW-321] Removes depreciated types --- source/renderer/app/api/ada/types.js | 249 ++++++++++++--------------- 1 file changed, 110 insertions(+), 139 deletions(-) diff --git a/source/renderer/app/api/ada/types.js b/source/renderer/app/api/ada/types.js index 856db77a38..77c564fc73 100644 --- a/source/renderer/app/api/ada/types.js +++ b/source/renderer/app/api/ada/types.js @@ -1,6 +1,7 @@ // @flow -// ========= General Types ========== +// ========= General ========== + export type RequestConfig = { port: number, ca: Uint8Array, @@ -8,10 +9,23 @@ export type RequestConfig = { key: Uint8Array, }; -// ========= Response Types ========= -export type AdaAssurance = 'CWANormal' | 'CWAStrict'; -export type AdaAssuranceV1 = 'normal' | 'strict'; -export type AdaTransactionCondition = 'CPtxApplying' | 'CPtxInBlocks' | 'CPtxWontApply' | 'CPtxNotTracked'; +export type ResponseBaseV1 = { + status: ResponseStatus, + meta: Pagination +}; + +export type ResponseStatus = 'success' | 'fail' | 'error'; + +export type Pagination = { + pagination: { + totalPages: number, + page: number, + perPage: number, + totalEntries: number + } +}; + +// ========= Responses ========= export type AdaWalletRecoveryPhraseResponse = Array; export type AdaWalletCertificateAdditionalMnemonicsResponse = Array; export type AdaWalletCertificateRecoveryPhraseResponse = Array; @@ -20,67 +34,52 @@ export type GetWalletCertificateAdditionalMnemonicsResponse = Array; export type GetWalletCertificateRecoveryPhraseResponse = Array; export type GetWalletRecoveryPhraseFromCertificateResponse = Array; -export type NodeInfo = { - syncProgress: { - quantity: number, - unit: 'percent' - }, - blockchainHeight: { - quantity: number, - unit: 'blocks' - }, - localBlockchainHeight: { - quantity: number, - unit: 'blocks' - }, - localTimeInformation: { - differenceFromNtpServer: { - quantity: number, - unit: 'microseconds' - } +// ========= Transactions ========= + +export type AdaTransactions = Array; +export type AdaTransaction = { + amount: number, + confirmations: number, + creationTime: string, + direction: 'outgoing' | 'incoming', + id: string, + type: 'local' | 'foreign', + inputs: Array, + outputs: Array, + status: { + tag: 'applying' | 'inNewestBlocks' | 'persisted' | 'wontApply' | 'creating', + data: {}, }, - subscriptionStatus: any }; -export type NodeUpdate = { - applicationName: string, - version: number +export type PaymentDistribution = { + address: string, + amount: number }; -export type NodeSettings = { - slotDuration: { - quantity: number, - unit: ?'milliseconds' - }, - softwareInfo: { - version: number, - applicationName: string - }, - projectVersion: string, - gitRevision: string -}; +export type TxnAssuranceLevel = 'low' | 'medium' | 'high'; +export type TransactionState = 'pending' | 'failed' | 'ok'; -export type AdaWalletInitData = { - operation: 'create' | 'restore', - backupPhrase: [string], - assuranceLevel: AdaAssuranceV1, - name: string, - spendingPassword: ?string, +export type AdaTransactionFee = { + estimatedAmount: number, + ...ResponseBaseV1 }; -export type AdaAmount = { - getCCoin: number, +export type AdaTransactionParams = { + data: { + source: { + accountIndex: number, + walletId: string, + }, + destinations: Array, + groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', + spendingPassword: ?string + }, }; -export type AdaTransactionTag = 'CTIn' | 'CTOut'; - -export type AdaAddress = { - id: string, - used: boolean, - changeAddress: boolean -}; +export type AdaTxFeeParams = AdaTransactionParams; -export type AdaAddresses = Array; +// ========= Accounts ========= export type AdaAccount = { amount: number, @@ -92,29 +91,38 @@ export type AdaAccount = { export type AdaAccounts = Array; -export type AdaTransactionInputOutput = [ - [string, AdaAmount], -]; +// ========= Addresses ========= + +export type AdaAddress = { + id: string, + used: boolean, + changeAddress: boolean +}; + +export type AdaAddresses = Array; + +// ========= Wallets ========= export type AdaWallet = { - createdAt: Date, - syncState: AdaV1WalletSyncState, + createdAt: string, + syncState: WalletSyncState, balance: number, hasSpendingPassword: boolean, - assuranceLevel: AdaAssuranceV1, + assuranceLevel: WalletAssuranceLevel, name: string, id: string, - spendingPasswordLastUpdate: Date, + spendingPasswordLastUpdate: string, }; export type AdaWallets = Array; -// ========== V1 API ========= +export type WalletAssuranceLevel = 'normal' | 'strict'; + +export type WalletAssuranceMode = { low: number, medium: number }; -export type AdaV1Assurance = 'normal' | 'strict'; -export type AdaV1WalletSyncStateTag = 'restoring' | 'synced'; +export type SyncStateTag = 'restoring' | 'synced'; -export type AdaV1WalletSyncState = { +export type WalletSyncState = { data: ?{ estimatedCompletionTime: { quantity: number, @@ -129,78 +137,57 @@ export type AdaV1WalletSyncState = { unit: 'blocksPerSecond', }, }, - tag: AdaV1WalletSyncStateTag, + tag: SyncStateTag, }; -export type AdaV1Wallet = { - assuranceLevel: AdaV1Assurance, - balance: number, - createdAt: string, - hasSpendingPassword: boolean, - id: string, +export type AdaWalletInitData = { + operation: 'create' | 'restore', + backupPhrase: [string], + assuranceLevel: WalletAssuranceLevel, name: string, - spendingPasswordLastUpdate: string, - syncState: AdaV1WalletSyncState, + spendingPassword: ?string, }; -export type AdaV1Wallets = Array; +// ========= Node ========= -export const AdaV1AssuranceOptions: { - NORMAL: AdaV1Assurance, STRICT: AdaV1Assurance, -} = { - NORMAL: 'normal', STRICT: 'strict', -}; - -export type AdaTransactions = Array; -export type AdaTransaction = { - amount: number, - confirmations: number, - creationTime: string, - direction: 'outgoing' | 'incoming', - id: string, - type: 'local' | 'foreign', - inputs: AdaTransactionInputOutputV1, - outputs: AdaTransactionInputOutputV1, - status: { - tag: 'applying' | 'inNewestBlocks' | 'persisted' | 'wontApply' | 'creating', - data: {}, +export type NodeInfo = { + syncProgress: { + quantity: number, + unit: 'percent' }, -}; - -export type AdaTransactionInputOutputV1 = [ - { - address: string, - amount: number, + blockchainHeight: { + quantity: number, + unit: 'blocks' }, -]; - -export type AdaTransactionFee = { - estimatedAmount: number, - status: 'success', - meta: { - pagination: {} + localBlockchainHeight: { + quantity: number, + unit: 'blocks' }, + localTimeInformation: { + differenceFromNtpServer: { + quantity: number, + unit: 'microseconds' + } + }, + subscriptionStatus: any }; -export type AdaTransactionParams = { - data: { - source: { - accountIndex: number, - walletId: string, - }, - destinations: [ - { - address: string, - amount: number, - }, - ], - groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', - spendingPassword: ?string +export type NodeSettings = { + slotDuration: { + quantity: number, + unit: ?'milliseconds' }, + softwareInfo: NodeSoftware, + projectVersion: string, + gitRevision: string }; -export type AdaTxFeeParams = AdaTransactionParams; +export type NodeSoftware = { + applicationName: string, + version: number +}; +// ========== V1 API ========= export type RedeemAdaParams = { redemptionCode: string, mnemonic: ?Array, @@ -213,19 +200,3 @@ export type RedeemPaperVendedAdaParams = { mnemonic: Array, ...RedeemAdaParams }; - -export type Pagination = { - pagination: { - totalPages: number, - page: number, - perPage: number, - totalEntries: number - } -}; - -export type ResponseStatus = 'success' | 'fail' | 'error'; - -export type ResponseBaseV1 = { - status: ResponseStatus, - meta: Pagination -}; From 28a7df545d6a949a42b33bb4722ccf52324cf420 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 10 Sep 2018 23:36:53 -0700 Subject: [PATCH 02/29] [DDW-321] Pulls wallet constants containing types into Wallet.js domain --- source/renderer/app/containers/wallet/Wallet.js | 4 ++-- source/renderer/app/containers/wallet/WalletSendPage.js | 4 ++-- source/renderer/app/containers/wallet/WalletSummaryPage.js | 4 ++-- .../renderer/app/containers/wallet/WalletTransactionsPage.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/renderer/app/containers/wallet/Wallet.js b/source/renderer/app/containers/wallet/Wallet.js index e5bea72e87..8cbe79e923 100644 --- a/source/renderer/app/containers/wallet/Wallet.js +++ b/source/renderer/app/containers/wallet/Wallet.js @@ -11,7 +11,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'; +import { WalletSyncStateTags } from '../../domains/Wallet'; import environment from '../../../../common/environment'; import AntivirusRestaurationSlowdownNotification from '../../components/notifications/AntivirusRestaurationSlowdownNotification'; @@ -58,7 +58,7 @@ export default class Wallet extends Component { if (!wallets.active) return ; - const isRestoreActive = get(wallets.active, 'syncState.tag') === syncStateTags.RESTORING; + const isRestoreActive = get(wallets.active, 'syncState.tag') === WalletSyncStateTags.RESTORING; const restoreProgress = get(wallets.active, 'syncState.data.percentage.quantity', 0); const restoreETA = get(wallets.active, 'syncState.data.estimatedCompletionTime.quantity', 0); diff --git a/source/renderer/app/containers/wallet/WalletSendPage.js b/source/renderer/app/containers/wallet/WalletSendPage.js index cce6710440..7205fa3bb9 100755 --- a/source/renderer/app/containers/wallet/WalletSendPage.js +++ b/source/renderer/app/containers/wallet/WalletSendPage.js @@ -7,7 +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'; +import { WalletSyncStateTags } from '../../domains/Wallet'; type Props = InjectedProps; @@ -32,7 +32,7 @@ export default class WalletSendPage extends Component { // Guard against potential null values if (!activeWallet) throw new Error('Active wallet required for WalletSendPage.'); - const isRestoreActive = get(activeWallet, 'syncState.tag') === syncStateTags.RESTORING; + const isRestoreActive = get(activeWallet, 'syncState.tag') === WalletSyncStateTags.RESTORING; return ( { let walletTransactions = null; const noTransactionsLabel = intl.formatMessage(messages.noTransactions); - const isRestoreActive = get(wallet, 'syncState.tag') === syncStateTags.RESTORING; + const isRestoreActive = get(wallet, 'syncState.tag') === WalletSyncStateTags.RESTORING; if (recentTransactionsRequest.isExecutingFirstTime || hasAny || isRestoreActive) { walletTransactions = ( diff --git a/source/renderer/app/containers/wallet/WalletTransactionsPage.js b/source/renderer/app/containers/wallet/WalletTransactionsPage.js index b0468a2975..d0310f879d 100755 --- a/source/renderer/app/containers/wallet/WalletTransactionsPage.js +++ b/source/renderer/app/containers/wallet/WalletTransactionsPage.js @@ -9,7 +9,7 @@ import WalletNoTransactions from '../../components/wallet/transactions/WalletNoT import VerticalFlexContainer from '../../components/layout/VerticalFlexContainer'; import type { InjectedProps } from '../../types/injectedPropsType'; import { formattedWalletAmount } from '../../utils/formatters'; -import { syncStateTags } from '../../domains/Wallet'; +import { WalletSyncStateTags } from '../../domains/Wallet'; export const messages = defineMessages({ noTransactions: { @@ -64,7 +64,7 @@ export default class WalletTransactionsPage extends Component { const noTransactionsLabel = intl.formatMessage(messages.noTransactions); const noTransactionsFoundLabel = intl.formatMessage(messages.noTransactionsFound); - const isRestoreActive = get(activeWallet, 'syncState.tag') === syncStateTags.RESTORING; + const isRestoreActive = get(activeWallet, 'syncState.tag') === WalletSyncStateTags.RESTORING; // if (wasSearched || hasAny) { // transactionSearch = ( From 1089432f36cce0e50f1076af07bc7ae30f97fba6 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 10 Sep 2018 23:37:37 -0700 Subject: [PATCH 03/29] [DDW-321] Pulls wallet constants containing types into Wallet.js domain --- source/renderer/app/domains/Wallet.js | 50 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/source/renderer/app/domains/Wallet.js b/source/renderer/app/domains/Wallet.js index b09e88eb68..4d31685319 100644 --- a/source/renderer/app/domains/Wallet.js +++ b/source/renderer/app/domains/Wallet.js @@ -2,37 +2,53 @@ import { observable, computed } from 'mobx'; import BigNumber from 'bignumber.js'; import type { - AssuranceMode, - AssuranceModeOptionV1, - AssuranceModeOptionV0 -} from '../types/transactionAssuranceTypes'; -import { assuranceModeOptionsV1, assuranceModes } from '../types/transactionAssuranceTypes'; -import type { AdaV1WalletSyncState, AdaV1WalletSyncStateTag } from '../api/ada/types'; - -export const syncStateTags: { - RESTORING: AdaV1WalletSyncStateTag, SYNCED: AdaV1WalletSyncStateTag, + WalletAssuranceLevel, + WalletAssuranceMode, + WalletSyncState, + SyncStateTag +} from '../api/ada/types'; + +export const WalletAssuranceModeOptions: { + NORMAL: WalletAssuranceLevel, STRICT: WalletAssuranceLevel, +} = { + NORMAL: 'normal', STRICT: 'strict', +}; + +export const WalletSyncStateTags: { + RESTORING: SyncStateTag, SYNCED: SyncStateTag, } = { RESTORING: 'restoring', SYNCED: 'synced', }; +const WalletAssuranceModes: { NORMAL: WalletAssuranceMode, STRICT: WalletAssuranceMode } = { + NORMAL: { + low: 3, + medium: 9, + }, + STRICT: { + low: 5, + medium: 15, + } +}; + export default class Wallet { id: string = ''; @observable name: string = ''; @observable amount: BigNumber; - @observable assurance: AssuranceModeOptionV1 | AssuranceModeOptionV0; + @observable assurance: WalletAssuranceLevel; @observable hasPassword: boolean; @observable passwordUpdateDate: ?Date; - @observable syncState: ?AdaV1WalletSyncState; + @observable syncState: ?WalletSyncState; constructor(data: { id: string, name: string, amount: BigNumber, - assurance: AssuranceModeOptionV1 | AssuranceModeOptionV0, + assurance: WalletAssuranceLevel, hasPassword: boolean, passwordUpdateDate: ?Date, - syncState?: AdaV1WalletSyncState, + syncState?: WalletSyncState, }) { Object.assign(this, data); } @@ -41,11 +57,11 @@ export default class Wallet { return this.amount > 0; } - @computed get assuranceMode(): AssuranceMode { + @computed get assuranceMode(): WalletAssuranceMode { switch (this.assurance) { - case assuranceModeOptionsV1.NORMAL: return assuranceModes.NORMAL; - case assuranceModeOptionsV1.STRICT: return assuranceModes.STRICT; - default: return assuranceModes.NORMAL; + case WalletAssuranceModeOptions.NORMAL: return WalletAssuranceModes.NORMAL; + case WalletAssuranceModeOptions.STRICT: return WalletAssuranceModes.STRICT; + default: return WalletAssuranceModes.NORMAL; } } From 0e1b9bc56f74aed8458b0b75b0511dc09a25dc14 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 10 Sep 2018 23:39:13 -0700 Subject: [PATCH 04/29] [DDW-321] Pulls transactions constants containing types into WalletTransactions.js domain --- .../wallet/transactions/Transaction.js | 16 ++++--- .../transactions/WalletTransactionsList.js | 4 +- .../renderer/app/domains/WalletTransaction.js | 18 +++++--- .../app/types/transactionAssuranceTypes.js | 46 ------------------- 4 files changed, 23 insertions(+), 61 deletions(-) delete mode 100644 source/renderer/app/types/transactionAssuranceTypes.js diff --git a/source/renderer/app/components/wallet/transactions/Transaction.js b/source/renderer/app/components/wallet/transactions/Transaction.js index b5042fa20f..c32f9b3f28 100644 --- a/source/renderer/app/components/wallet/transactions/Transaction.js +++ b/source/renderer/app/components/wallet/transactions/Transaction.js @@ -7,10 +7,14 @@ import styles from './Transaction.scss'; import TransactionTypeIcon from './TransactionTypeIcon'; import adaSymbol from '../../../assets/images/ada-symbol.inline.svg'; import arrow from '../../../assets/images/collapse-arrow.inline.svg'; -import WalletTransaction, { transactionStates, transactionTypes } from '../../../domains/WalletTransaction'; -import { assuranceLevels } from '../../../types/transactionAssuranceTypes'; +import WalletTransaction, +{ + TxnAssuranceLevelOptions, + transactionStates, + transactionTypes +} from '../../../domains/WalletTransaction'; import { environmentSpecificMessages } from '../../../i18n/global-messages'; -import type { TransactionState } from '../../../domains/WalletTransaction'; +import type { TransactionState } from '../../../api/ada/types'; import environment from '../../../../../common/environment'; import { getNetworkExplorerUrl } from '../../../utils/network'; @@ -88,17 +92,17 @@ const messages = defineMessages({ }); const assuranceLevelTranslations = defineMessages({ - [assuranceLevels.LOW]: { + [TxnAssuranceLevelOptions.LOW]: { id: 'wallet.transaction.assuranceLevel.low', defaultMessage: '!!!low', description: 'Transaction assurance level "low".', }, - [assuranceLevels.MEDIUM]: { + [TxnAssuranceLevelOptions.MEDIUM]: { id: 'wallet.transaction.assuranceLevel.medium', defaultMessage: '!!!medium', description: 'Transaction assurance level "medium".', }, - [assuranceLevels.HIGH]: { + [TxnAssuranceLevelOptions.HIGH]: { id: 'wallet.transaction.assuranceLevel.high', defaultMessage: '!!!high', description: 'Transaction assurance level "high".', diff --git a/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js b/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js index 94ad8276af..54e4eb4478 100644 --- a/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js +++ b/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js @@ -10,7 +10,7 @@ import styles from './WalletTransactionsList.scss'; import Transaction from './Transaction'; import WalletTransaction from '../../../domains/WalletTransaction'; import LoadingSpinner from '../../widgets/LoadingSpinner'; -import type { AssuranceMode } from '../../../types/transactionAssuranceTypes'; +import type { WalletAssuranceMode } from '../../../api/ada/types'; const messages = defineMessages({ today: { @@ -42,7 +42,7 @@ type Props = { isLoadingTransactions: boolean, isRestoreActive?: boolean, hasMoreToLoad: boolean, - assuranceMode: AssuranceMode, + assuranceMode: WalletAssuranceMode, walletId: string, formattedWalletAmount: Function, showMoreTransactionsButton?: boolean, diff --git a/source/renderer/app/domains/WalletTransaction.js b/source/renderer/app/domains/WalletTransaction.js index ae711063a2..51d1512801 100644 --- a/source/renderer/app/domains/WalletTransaction.js +++ b/source/renderer/app/domains/WalletTransaction.js @@ -1,10 +1,8 @@ // @flow import { observable } from 'mobx'; import BigNumber from 'bignumber.js'; -import type { AssuranceMode, AssuranceLevel } from '../types/transactionAssuranceTypes'; -import { assuranceLevels } from '../types/transactionAssuranceTypes'; +import type { WalletAssuranceMode, TxnAssuranceLevel, TransactionState } from '../api/ada/types'; -export type TransactionState = 'pending' | 'failed' | 'ok'; export type TrasactionAddresses = { from: Array, to: Array }; export type TransactionType = 'card' | 'expend' | 'income' | 'exchange'; @@ -14,6 +12,12 @@ export const transactionStates: { PENDING: 'pending', FAILED: 'failed', OK: 'ok', }; +export const TxnAssuranceLevelOptions: { + LOW: TxnAssuranceLevel, MEDIUM: TxnAssuranceLevel, HIGH: TxnAssuranceLevel, +} = { + LOW: 'low', MEDIUM: 'medium', HIGH: 'high', +}; + export const transactionTypes: { CARD: TransactionType, EXPEND: TransactionType, @@ -52,13 +56,13 @@ export default class WalletTransaction { Object.assign(this, data); } - getAssuranceLevelForMode(mode: AssuranceMode): AssuranceLevel { + getAssuranceLevelForMode(mode: WalletAssuranceMode): TxnAssuranceLevel { if (this.numberOfConfirmations < mode.low) { - return assuranceLevels.LOW; + return TxnAssuranceLevelOptions.LOW; } else if (this.numberOfConfirmations < mode.medium) { - return assuranceLevels.MEDIUM; + return TxnAssuranceLevelOptions.MEDIUM; } - return assuranceLevels.HIGH; + return TxnAssuranceLevelOptions.HIGH; } } diff --git a/source/renderer/app/types/transactionAssuranceTypes.js b/source/renderer/app/types/transactionAssuranceTypes.js deleted file mode 100644 index a1bcc16719..0000000000 --- a/source/renderer/app/types/transactionAssuranceTypes.js +++ /dev/null @@ -1,46 +0,0 @@ -// @flow - -// V0 types ------------------------------------------------------------ - -// TODO Remove after v1 implementation is complete -export type AssuranceModeOptionV0 = 'CWANormal' | 'CWAStrict'; - -// TODO Remove after v1 implementation is complete -export const assuranceModeOptionsV0: { - NORMAL: AssuranceModeOptionV0, STRICT: AssuranceModeOptionV0, -} = { - NORMAL: 'CWANormal', STRICT: 'CWAStrict', -}; - -// V1 types ------------------------------------------------------------ - -export type AssuranceModeOptionV1 = 'normal' | 'strict'; - -export const assuranceModeOptionsV1: { - NORMAL: AssuranceModeOptionV1, STRICT: AssuranceModeOptionV1, -} = { - NORMAL: 'normal', STRICT: 'strict', -}; - -// common assurance types ---------------------------------------------- - -export type AssuranceMode = { low: number, medium: number }; - -export type AssuranceLevel = 'low' | 'medium' | 'high'; - -export const assuranceModes: { NORMAL: AssuranceMode, STRICT: AssuranceMode } = { - NORMAL: { - low: 3, - medium: 9, - }, - STRICT: { - low: 5, - medium: 15, - } -}; - -export const assuranceLevels: { - LOW: AssuranceLevel, MEDIUM: AssuranceLevel, HIGH: AssuranceLevel, -} = { - LOW: 'low', MEDIUM: 'medium', HIGH: 'high', -}; From 7d4e0da5ddf73f5b2f1095900e22f58c6ee4f6f3 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 10 Sep 2018 23:39:51 -0700 Subject: [PATCH 05/29] [DDW-321] Replaces old type names with new ones --- .../support/helpers/notifications-helpers.js | 4 ++-- .../app/api/ada/changeAdaWalletPassphrase.js | 4 ++-- source/renderer/app/api/ada/getAdaWallets.js | 4 ++-- source/renderer/app/api/ada/index.js | 22 +++++++++---------- .../renderer/app/api/ada/updateAdaWallet.js | 6 ++--- source/renderer/app/api/common.js | 4 ++-- source/renderer/app/stores/SidebarStore.js | 4 ++-- .../app/stores/WalletSettingsStore.js | 6 ++--- .../app/stores/ada/NodeUpdateStore.js | 4 ++-- storybook/stories/WalletScreens.stories.js | 8 +++---- storybook/stories/support/StoryProvider.js | 6 ++--- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/features/support/helpers/notifications-helpers.js b/features/support/helpers/notifications-helpers.js index 3034d82e1a..d13b3d7f9e 100644 --- a/features/support/helpers/notifications-helpers.js +++ b/features/support/helpers/notifications-helpers.js @@ -1,9 +1,9 @@ -import { syncStateTags } from '../../../source/renderer/app/domains/Wallet'; +import { WalletSyncStateTags } from '../../../source/renderer/app/domains/Wallet'; export const isActiveWalletBeingRestored = async (client) => { const result = await client.execute((expectedSyncTag) => ( daedalus.stores.ada.wallets.active.syncState.tag === expectedSyncTag - ), syncStateTags.RESTORING); + ), WalletSyncStateTags.RESTORING); return result.value; }; diff --git a/source/renderer/app/api/ada/changeAdaWalletPassphrase.js b/source/renderer/app/api/ada/changeAdaWalletPassphrase.js index 5285f3180b..ba95b085d4 100644 --- a/source/renderer/app/api/ada/changeAdaWalletPassphrase.js +++ b/source/renderer/app/api/ada/changeAdaWalletPassphrase.js @@ -1,5 +1,5 @@ // @flow -import type { AdaV1Wallet, RequestConfig } from './types'; +import type { AdaWallet, RequestConfig } from './types'; import { request } from './lib/v1/request'; import { encryptPassphrase } from './lib/encryptPassphrase'; @@ -12,7 +12,7 @@ export type ChangeAdaWalletPassphraseParams = { export const changeAdaWalletPassphrase = ( config: RequestConfig, { walletId, oldPassword, newPassword }: ChangeAdaWalletPassphraseParams -): Promise => { +): Promise => { const encryptedOldPassphrase = oldPassword ? encryptPassphrase(oldPassword) : ''; const encryptedNewPassphrase = newPassword ? encryptPassphrase(newPassword) : ''; return request({ diff --git a/source/renderer/app/api/ada/getAdaWallets.js b/source/renderer/app/api/ada/getAdaWallets.js index 7c057e7b76..8bb0327d9d 100644 --- a/source/renderer/app/api/ada/getAdaWallets.js +++ b/source/renderer/app/api/ada/getAdaWallets.js @@ -1,11 +1,11 @@ // @flow -import type { AdaV1Wallets, RequestConfig } from './types'; +import type { AdaWallets, RequestConfig } from './types'; import { request } from './lib/v1/request'; import { MAX_ADA_WALLETS_COUNT } from '../../config/numbersConfig'; export const getAdaWallets = ( config: RequestConfig -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'GET', diff --git a/source/renderer/app/api/ada/index.js b/source/renderer/app/api/ada/index.js index 28c8f7b1d1..835c9354a9 100644 --- a/source/renderer/app/api/ada/index.js +++ b/source/renderer/app/api/ada/index.js @@ -4,7 +4,7 @@ import { action } from 'mobx'; import { ipcRenderer } from 'electron'; import BigNumber from 'bignumber.js'; import { Logger, stringifyData, stringifyError } from '../../../../common/logging'; -import { unixTimestampToDate, utcStringToDate } from './lib/utils'; +import { utcStringToDate } from './lib/utils'; import { encryptPassphrase } from './lib/encryptPassphrase'; import Wallet from '../../domains/Wallet'; import WalletTransaction, { transactionTypes } from '../../domains/WalletTransaction'; @@ -48,11 +48,11 @@ import type { AdaTransactions, AdaTransactionFee, AdaWallet, - AdaV1Wallet, - AdaV1Wallets, + AdaWallets, AdaWalletRecoveryPhraseResponse, AdaWalletCertificateAdditionalMnemonicsResponse, AdaWalletCertificateRecoveryPhraseResponse, + WalletAssuranceLevel, GetWalletCertificateAdditionalMnemonicsResponse, GetWalletCertificateRecoveryPhraseResponse, GetWalletRecoveryPhraseFromCertificateResponse, @@ -60,8 +60,7 @@ import type { RedeemPaperVendedAdaParams, RequestConfig, NodeInfo, - NodeUpdate, - AdaV1Assurance, + NodeSoftware, } from './types'; import type { CreateWalletRequest, @@ -129,7 +128,7 @@ export type CreateAddressRequest = { }; export type UpdateWalletRequest = { walletId: string, - assuranceLevel: AdaV1Assurance, + assuranceLevel: WalletAssuranceLevel, name: string }; export type ImportWalletFromKeyRequest = { @@ -202,7 +201,7 @@ export default class AdaApi { getWallets = async (): Promise => { Logger.debug('AdaApi::getWallets called'); try { - const response: AdaV1Wallets = await getAdaWallets(this.config); + const response: AdaWallets = await getAdaWallets(this.config); Logger.debug('AdaApi::getWallets success: ' + stringifyData(response)); return response.map(data => _createWalletFromServerV1Data(data)); } catch (error) { @@ -238,6 +237,7 @@ export default class AdaApi { const { walletId, skip, limit } = request; const accounts: AdaAccounts = await getAdaWalletAccounts(this.config, { walletId }); + const accountIndex = accounts[0].index; const page = skip === 0 ? 1 : (skip / limit) + 1; const perPage = limit > 50 ? 50 : limit; @@ -606,7 +606,7 @@ export default class AdaApi { } } - nextUpdate = async (): Promise => { + nextUpdate = async (): Promise => { Logger.debug('AdaApi::nextUpdate called'); try { const nodeUpdate = await nextAdaUpdate(this.config); @@ -666,7 +666,7 @@ export default class AdaApi { Logger.debug('AdaApi::updateWallet called: ' + stringifyData(request)); const { walletId, assuranceLevel, name } = request; try { - const wallet: AdaV1Wallet = await updateAdaWallet( + const wallet: AdaWallet = await updateAdaWallet( this.config, { walletId, assuranceLevel, name } ); Logger.debug('AdaApi::updateWallet success: ' + stringifyData(wallet)); @@ -755,7 +755,7 @@ const _createWalletFromServerData = action( name: data.name, assurance: data.assuranceLevel, hasPassword: data.hasSpendingPassword, - passwordUpdateDate: unixTimestampToDate(data.spendingPasswordLastUpdate), + passwordUpdateDate: new Date(`${data.spendingPasswordLastUpdate}Z`), }) ) ); @@ -805,7 +805,7 @@ const _createTransactionFeeFromServerData = action( // ========== V1 API ========= const _createWalletFromServerV1Data = action( - 'AdaApi::_createWalletFromServerV1Data', (data: AdaV1Wallet) => { + 'AdaApi::_createWalletFromServerV1Data', (data: AdaWallet) => { const { id, balance, name, assuranceLevel, hasSpendingPassword, spendingPasswordLastUpdate, diff --git a/source/renderer/app/api/ada/updateAdaWallet.js b/source/renderer/app/api/ada/updateAdaWallet.js index f4f9b60311..90a96dca55 100644 --- a/source/renderer/app/api/ada/updateAdaWallet.js +++ b/source/renderer/app/api/ada/updateAdaWallet.js @@ -1,17 +1,17 @@ // @flow -import type { AdaV1Wallet, AdaV1Assurance, RequestConfig } from './types'; +import type { AdaWallet, WalletAssuranceLevel, RequestConfig } from './types'; import { request } from './lib/v1/request'; export type UpdateAdaWalletParams = { walletId: string, - assuranceLevel: AdaV1Assurance, + assuranceLevel: WalletAssuranceLevel, name: string }; export const updateAdaWallet = ( config: RequestConfig, { walletId, assuranceLevel, name }: UpdateAdaWalletParams -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'PUT', diff --git a/source/renderer/app/api/common.js b/source/renderer/app/api/common.js index eb7062287c..a026b3dcec 100644 --- a/source/renderer/app/api/common.js +++ b/source/renderer/app/api/common.js @@ -1,7 +1,7 @@ import { defineMessages } from 'react-intl'; import LocalizableError from '../i18n/LocalizableError'; import { WalletTransaction, Wallet } from '../domains/WalletTransaction'; -import type { AdaV1Wallet, ResponseBaseV1 } from './ada/types'; +import type { AdaWallet, ResponseBaseV1 } from './ada/types'; import globalMessages from '../i18n/global-messages'; const messages = defineMessages({ @@ -80,7 +80,7 @@ export type GetWalletsResponse = Array; export type GetWalletRecoveryPhraseResponse = Array; export type RestoreWalletResponse = Wallet; export type UpdateWalletResponse = { - data: AdaV1Wallet, + data: AdaWallet, ...ResponseBaseV1 }; export type UpdateWalletPasswordResponse = boolean; diff --git a/source/renderer/app/stores/SidebarStore.js b/source/renderer/app/stores/SidebarStore.js index 3cfcc4f4c5..027c1cf8e0 100644 --- a/source/renderer/app/stores/SidebarStore.js +++ b/source/renderer/app/stores/SidebarStore.js @@ -5,7 +5,7 @@ import { ipcRenderer } from 'electron'; import Store from './lib/Store'; import environment from '../../../common/environment'; import { sidebarConfig } from '../config/sidebarConfig'; -import { syncStateTags } from '../domains/Wallet'; +import { WalletSyncStateTags } from '../domains/Wallet'; import { GO_TO_ADA_REDEMPTION_SCREEN_CHANNEL } from '../../../common/ipc-api/go-to-ada-redemption-screen'; import { formattedWalletAmount } from '../utils/formatters'; import type { SidebarWalletType } from '../types/sidebarTypes'; @@ -44,7 +44,7 @@ export default class SidebarStore extends Store { title: w.name, info: formattedWalletAmount(w.amount), isConnected: networkStatus.isConnected, - isRestoreActive: get(w, 'syncState.tag') === syncStateTags.RESTORING, + isRestoreActive: get(w, 'syncState.tag') === WalletSyncStateTags.RESTORING, restoreProgress: get(w, 'syncState.data.percentage.quantity', 0), })); } diff --git a/source/renderer/app/stores/WalletSettingsStore.js b/source/renderer/app/stores/WalletSettingsStore.js index 3109374e2a..055512f3a3 100644 --- a/source/renderer/app/stores/WalletSettingsStore.js +++ b/source/renderer/app/stores/WalletSettingsStore.js @@ -2,13 +2,13 @@ import { observable, action } from 'mobx'; import Store from './lib/Store'; import globalMessages from '../i18n/global-messages'; -import { assuranceModeOptionsV1 } from '../types/transactionAssuranceTypes'; +import { WalletAssuranceModeOptions } from '../domains/Wallet'; export default class WalletSettingsStore extends Store { WALLET_ASSURANCE_LEVEL_OPTIONS = [ - { value: assuranceModeOptionsV1.NORMAL, label: globalMessages.assuranceLevelNormal }, - { value: assuranceModeOptionsV1.STRICT, label: globalMessages.assuranceLevelStrict }, + { value: WalletAssuranceModeOptions.NORMAL, label: globalMessages.assuranceLevelNormal }, + { value: WalletAssuranceModeOptions.STRICT, label: globalMessages.assuranceLevelStrict }, ]; @observable walletFieldBeingEdited = null; diff --git a/source/renderer/app/stores/ada/NodeUpdateStore.js b/source/renderer/app/stores/ada/NodeUpdateStore.js index fac9e5fa1f..8f1e05bdb2 100644 --- a/source/renderer/app/stores/ada/NodeUpdateStore.js +++ b/source/renderer/app/stores/ada/NodeUpdateStore.js @@ -2,7 +2,7 @@ import { observable, action, runInAction } from 'mobx'; import Store from '../lib/Store'; import Request from '../lib/LocalizedRequest'; -import type { NodeUpdate } from '../../api/ada/types'; +import type { NodeSoftware } from '../../api/ada/types'; import type { PostponeUpdateResponse, ApplyUpdateResponse } from '../../api/ada/index'; import { NODE_UPDATE_POLL_INTERVAL } from '../../config/timingConfig'; @@ -16,7 +16,7 @@ export default class NodeUpdateStore extends Store { // REQUESTS /* eslint-disable max-len */ - @observable nextUpdateRequest: Request = new Request(this.api.ada.nextUpdate); + @observable nextUpdateRequest: Request = new Request(this.api.ada.nextUpdate); @observable postponeUpdateRequest: Request = new Request(this.api.ada.postponeUpdate); @observable applyUpdateRequest: Request = new Request(this.api.ada.applyUpdate); /* eslint-disable max-len */ diff --git a/storybook/stories/WalletScreens.stories.js b/storybook/stories/WalletScreens.stories.js index 3a122fd1ca..bed54132df 100644 --- a/storybook/stories/WalletScreens.stories.js +++ b/storybook/stories/WalletScreens.stories.js @@ -23,7 +23,7 @@ import WalletSendForm from '../../source/renderer/app/components/wallet/WalletSe import WalletReceive from '../../source/renderer/app/components/wallet/WalletReceive'; import WalletTransactionsList from '../../source/renderer/app/components/wallet/transactions/WalletTransactionsList'; import WalletSettings from '../../source/renderer/app/components/wallet/WalletSettings'; -import { assuranceModeOptionsV1 } from '../../source/renderer/app/types/transactionAssuranceTypes'; +import { WalletAssuranceModeOptions } from '../../source/renderer/app/domains/Wallet'; import ChangeWalletPasswordDialog from '../../source/renderer/app/components/wallet/settings/ChangeWalletPasswordDialog'; import DeleteWalletConfirmationDialog from '../../source/renderer/app/components/wallet/settings/DeleteWalletConfirmationDialog'; import ExportWalletToFileDialog from '../../source/renderer/app/components/wallet/settings/ExportWalletToFileDialog'; @@ -142,7 +142,7 @@ storiesOf('WalletScreens', module) activeField={null} assuranceLevels={[ { - value: assuranceModeOptionsV1.NORMAL, + value: WalletAssuranceModeOptions.NORMAL, label: { id: 'global.assuranceLevel.normal', defaultMessage: '!!!Normal', @@ -150,7 +150,7 @@ storiesOf('WalletScreens', module) } }, { - value: assuranceModeOptionsV1.STRICT, + value: WalletAssuranceModeOptions.STRICT, label: { id: 'global.assuranceLevel.strict', defaultMessage: '!!!Strict', @@ -179,7 +179,7 @@ storiesOf('WalletScreens', module) onStartEditing={() => {}} onStopEditing={() => {}} openDialogAction={() => {}} - walletAssurance={assuranceModeOptionsV1.NORMAL} + walletAssurance={WalletAssuranceModeOptions.NORMAL} walletName={text('Wallet Name', 'Wallet Name')} walletPasswordUpdateDate={moment().subtract(1, 'month').toDate()} changeWalletPasswordDialog={ diff --git a/storybook/stories/support/StoryProvider.js b/storybook/stories/support/StoryProvider.js index 41b668afc8..f706ec5cb2 100644 --- a/storybook/stories/support/StoryProvider.js +++ b/storybook/stories/support/StoryProvider.js @@ -6,7 +6,7 @@ import { observable, computed, runInAction } from 'mobx'; import BigNumber from 'bignumber.js'; import moment from 'moment'; import actions from '../../../source/renderer/app/actions'; -import { assuranceModeOptionsV1 } from '../../../source/renderer/app/types/transactionAssuranceTypes.js'; +import { WalletAssuranceModeOptions } from '../../../source/renderer/app/domains/Wallet'; type Props = { children: Node, @@ -17,7 +17,7 @@ const WALLETS = [ id: '0', name: 'No Password', amount: new BigNumber(66.998), - assurance: assuranceModeOptionsV1.NORMAL, + assurance: WalletAssuranceModeOptions.NORMAL, hasPassword: false, passwordUpdateDate: new Date() }, @@ -25,7 +25,7 @@ const WALLETS = [ id: '1', name: 'With Password', amount: new BigNumber(0), - assurance: assuranceModeOptionsV1.NORMAL, + assurance: WalletAssuranceModeOptions.NORMAL, hasPassword: true, passwordUpdateDate: moment().subtract(1, 'month').toDate() } From d27be0ce91a2e0fc3700836615c262b845795501 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Wed, 12 Sep 2018 00:58:09 -0700 Subject: [PATCH 06/29] [DDW-321] Implements new API file structure. Renames requests. --- source/renderer/app/api/accounts/errors.js | 0 .../requests/getAccounts.js} | 8 +- source/renderer/app/api/accounts/types.js | 0 .../api/ada/getAdaAccountRecoveryPhrase.js | 7 - source/renderer/app/api/ada/getAdaAccounts.js | 18 --- .../app/api/ada/getAdaAddressHistory.js | 22 --- source/renderer/app/api/ada/getAdaHistory.js | 23 --- .../app/api/ada/getAdaHistoryByAccount.js | 21 --- ...AdaWalletCertificateAdditionalMnemonics.js | 9 -- .../getAdaWalletCertificateRecoveryPhrase.js | 14 -- ...tAdaWalletRecoveryPhraseFromCertificate.js | 14 -- .../app/api/ada/lib/encryptPassphrase.js | 9 -- source/renderer/app/api/ada/lib/utils.js | 5 - source/renderer/app/api/ada/newAdaAccount.js | 31 ---- source/renderer/app/api/addresses/errors.js | 0 .../requests/createAddress.js} | 8 +- .../requests/getAddress.js} | 8 +- source/renderer/app/api/addresses/types.js | 0 .../renderer/app/api/{ada/index.js => api.js} | 133 +++++++++--------- source/renderer/app/api/common/errors.js | 0 .../requests/sendBugReport.js} | 10 +- source/renderer/app/api/common/types.js | 0 source/renderer/app/api/{ada => }/errors.js | 0 source/renderer/app/api/index.js | 4 +- source/renderer/app/api/lib/utils.js | 6 - source/renderer/app/api/nodes/errors.js | 0 .../requests/applyNodeUpdate.js} | 4 +- .../requests/getNextNodeUpdate.js} | 4 +- .../{ada => nodes/requests}/getNodeInfo.js | 2 +- .../requests/postponeNodeUpdate.js} | 4 +- source/renderer/app/api/nodes/types.js | 0 .../renderer/app/api/transactions/errors.js | 0 .../requests/createTransaction.js} | 4 +- .../requests/getTransactionFee.js} | 4 +- .../requests/getTransactionHistory.js} | 8 +- .../requests}/redeemAda.js | 2 +- .../requests}/redeemAdaPaperVend.js | 2 +- source/renderer/app/api/transactions/types.js | 0 source/renderer/app/api/{ada => }/types.js | 0 source/renderer/app/api/utils/index.js | 22 +++ .../index.js => utils/localStorage.js} | 0 source/renderer/app/api/utils/mnemonics.js | 32 +++++ .../api/{ada/mocks => utils}/patchAdaApi.js | 4 +- .../app/api/{lib => utils}/reportRequest.js | 0 .../app/api/{ada/lib/v1 => utils}/request.js | 3 +- .../lib/request.js => utils/requestV0.js} | 3 +- source/renderer/app/api/wallets/errors.js | 0 .../requests/changeSpendingPassword.js} | 10 +- .../requests/createWallet.js} | 8 +- .../requests/deleteWallet.js} | 8 +- .../requests/exportWalletAsJSON.js} | 8 +- .../requests/getWallets.js} | 4 +- .../requests/importWalletAsJSON.js} | 4 +- .../requests/importWalletAsKey.js} | 8 +- .../requests/resetWalletState.js} | 4 +- .../requests/restoreWallet.js} | 8 +- .../requests/updateWallet.js} | 8 +- source/renderer/app/api/wallets/types.js | 0 .../app/stores/ada/AdaRedemptionStore.js | 2 +- 59 files changed, 197 insertions(+), 323 deletions(-) create mode 100644 source/renderer/app/api/accounts/errors.js rename source/renderer/app/api/{ada/getAdaWalletAccounts.js => accounts/requests/getAccounts.js} (62%) create mode 100644 source/renderer/app/api/accounts/types.js delete mode 100644 source/renderer/app/api/ada/getAdaAccountRecoveryPhrase.js delete mode 100644 source/renderer/app/api/ada/getAdaAccounts.js delete mode 100644 source/renderer/app/api/ada/getAdaAddressHistory.js delete mode 100644 source/renderer/app/api/ada/getAdaHistory.js delete mode 100644 source/renderer/app/api/ada/getAdaHistoryByAccount.js delete mode 100644 source/renderer/app/api/ada/getAdaWalletCertificateAdditionalMnemonics.js delete mode 100644 source/renderer/app/api/ada/getAdaWalletCertificateRecoveryPhrase.js delete mode 100644 source/renderer/app/api/ada/getAdaWalletRecoveryPhraseFromCertificate.js delete mode 100644 source/renderer/app/api/ada/lib/encryptPassphrase.js delete mode 100644 source/renderer/app/api/ada/lib/utils.js delete mode 100644 source/renderer/app/api/ada/newAdaAccount.js create mode 100644 source/renderer/app/api/addresses/errors.js rename source/renderer/app/api/{ada/newAdaWalletAddress.js => addresses/requests/createAddress.js} (64%) rename source/renderer/app/api/{ada/getAdaAddress.js => addresses/requests/getAddress.js} (69%) create mode 100644 source/renderer/app/api/addresses/types.js rename source/renderer/app/api/{ada/index.js => api.js} (86%) create mode 100644 source/renderer/app/api/common/errors.js rename source/renderer/app/api/{ada/sendAdaBugReport.js => common/requests/sendBugReport.js} (81%) create mode 100644 source/renderer/app/api/common/types.js rename source/renderer/app/api/{ada => }/errors.js (100%) delete mode 100644 source/renderer/app/api/lib/utils.js create mode 100644 source/renderer/app/api/nodes/errors.js rename source/renderer/app/api/{ada/applyAdaUpdate.js => nodes/requests/applyNodeUpdate.js} (73%) rename source/renderer/app/api/{ada/nextAdaUpdate.js => nodes/requests/getNextNodeUpdate.js} (72%) rename source/renderer/app/api/{ada => nodes/requests}/getNodeInfo.js (84%) rename source/renderer/app/api/{ada/postponeAdaUpdate.js => nodes/requests/postponeNodeUpdate.js} (73%) create mode 100644 source/renderer/app/api/nodes/types.js create mode 100644 source/renderer/app/api/transactions/errors.js rename source/renderer/app/api/{ada/newAdaPayment.js => transactions/requests/createTransaction.js} (79%) rename source/renderer/app/api/{ada/adaTxFee.js => transactions/requests/getTransactionFee.js} (79%) rename source/renderer/app/api/{ada/getAdaHistoryByWallet.js => transactions/requests/getTransactionHistory.js} (70%) rename source/renderer/app/api/{ada => transactions/requests}/redeemAda.js (88%) rename source/renderer/app/api/{ada => transactions/requests}/redeemAdaPaperVend.js (89%) create mode 100644 source/renderer/app/api/transactions/types.js rename source/renderer/app/api/{ada => }/types.js (100%) create mode 100644 source/renderer/app/api/utils/index.js rename source/renderer/app/api/{localStorage/index.js => utils/localStorage.js} (100%) create mode 100644 source/renderer/app/api/utils/mnemonics.js rename source/renderer/app/api/{ada/mocks => utils}/patchAdaApi.js (95%) rename source/renderer/app/api/{lib => utils}/reportRequest.js (100%) rename source/renderer/app/api/{ada/lib/v1 => utils}/request.js (97%) rename source/renderer/app/api/{ada/lib/request.js => utils/requestV0.js} (96%) create mode 100644 source/renderer/app/api/wallets/errors.js rename source/renderer/app/api/{ada/changeAdaWalletPassphrase.js => wallets/requests/changeSpendingPassword.js} (67%) rename source/renderer/app/api/{ada/newAdaWallet.js => wallets/requests/createWallet.js} (66%) rename source/renderer/app/api/{ada/deleteAdaWallet.js => wallets/requests/deleteWallet.js} (61%) rename source/renderer/app/api/{ada/exportAdaBackupJSON.js => wallets/requests/exportWalletAsJSON.js} (61%) rename source/renderer/app/api/{ada/getAdaWallets.js => wallets/requests/getWallets.js} (84%) rename source/renderer/app/api/{ada/importAdaBackupJSON.js => wallets/requests/importWalletAsJSON.js} (75%) rename source/renderer/app/api/{ada/importAdaWallet.js => wallets/requests/importWalletAsKey.js} (66%) rename source/renderer/app/api/{ada/adaTestReset.js => wallets/requests/resetWalletState.js} (74%) rename source/renderer/app/api/{ada/restoreAdaWallet.js => wallets/requests/restoreWallet.js} (65%) rename source/renderer/app/api/{ada/updateAdaWallet.js => wallets/requests/updateWallet.js} (68%) create mode 100644 source/renderer/app/api/wallets/types.js diff --git a/source/renderer/app/api/accounts/errors.js b/source/renderer/app/api/accounts/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/getAdaWalletAccounts.js b/source/renderer/app/api/accounts/requests/getAccounts.js similarity index 62% rename from source/renderer/app/api/ada/getAdaWalletAccounts.js rename to source/renderer/app/api/accounts/requests/getAccounts.js index efc89e1485..81f5d1e524 100644 --- a/source/renderer/app/api/ada/getAdaWalletAccounts.js +++ b/source/renderer/app/api/accounts/requests/getAccounts.js @@ -1,14 +1,14 @@ // @flow import type { AdaAccounts, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type GetAdaWalletAccountsParams = { +export type GetAccountsParams = { walletId: string, }; -export const getAdaWalletAccounts = ( +export const getAccounts = ( config: RequestConfig, - { walletId }: GetAdaWalletAccountsParams + { walletId }: GetAccountsParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/accounts/types.js b/source/renderer/app/api/accounts/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/getAdaAccountRecoveryPhrase.js b/source/renderer/app/api/ada/getAdaAccountRecoveryPhrase.js deleted file mode 100644 index 00be1e1d40..0000000000 --- a/source/renderer/app/api/ada/getAdaAccountRecoveryPhrase.js +++ /dev/null @@ -1,7 +0,0 @@ -// @flow -import type { AdaWalletRecoveryPhraseResponse } from './types'; -import { generateMnemonic } from '../../utils/crypto'; - -export const getAdaAccountRecoveryPhrase = (): AdaWalletRecoveryPhraseResponse => ( - generateMnemonic().split(' ') -); diff --git a/source/renderer/app/api/ada/getAdaAccounts.js b/source/renderer/app/api/ada/getAdaAccounts.js deleted file mode 100644 index 296ca4efdb..0000000000 --- a/source/renderer/app/api/ada/getAdaAccounts.js +++ /dev/null @@ -1,18 +0,0 @@ -// @flow -import type { AdaAccounts, RequestConfig } from './types'; -import { request } from './lib/request'; - -export type GetAdaAccountsParams = { - ca: Uint8Array, -}; - -export const getAdaAccounts = ( - config: RequestConfig -): Promise => ( - request({ - hostname: 'localhost', - method: 'GET', - path: '/api/accounts', - ...config, - }) -); diff --git a/source/renderer/app/api/ada/getAdaAddressHistory.js b/source/renderer/app/api/ada/getAdaAddressHistory.js deleted file mode 100644 index 49a5531eae..0000000000 --- a/source/renderer/app/api/ada/getAdaAddressHistory.js +++ /dev/null @@ -1,22 +0,0 @@ -// @flow -import type { AdaTransactions, RequestConfig } from './types'; -import { request } from './lib/request'; - -export type GetAdaAddressHistoryParams = { - accountId: string, - address: string, - skip: number, - limit: number, -}; - -export const getAdaAddressHistory = ( - config: RequestConfig, - { accountId, address, skip, limit }: GetAdaAddressHistoryParams -): Promise => ( - request({ - hostname: 'localhost', - method: 'GET', - path: '/api/txs/histories', - ...config, - }, { accountId, address, skip, limit }) -); diff --git a/source/renderer/app/api/ada/getAdaHistory.js b/source/renderer/app/api/ada/getAdaHistory.js deleted file mode 100644 index 7c4c07c6c6..0000000000 --- a/source/renderer/app/api/ada/getAdaHistory.js +++ /dev/null @@ -1,23 +0,0 @@ -// @flow -import type { AdaTransactions, RequestConfig } from './types'; -import { request } from './lib/request'; - -export type GetAdaHistoryParams = { - walletId: ?string, - accountId: ?string, - address: ?string, - skip: number, - limit: number, -}; - -export const getAdaHistory = ( - config: RequestConfig, - { walletId, accountId, address, skip, limit }: GetAdaHistoryParams -): Promise => ( - request({ - hostname: 'localhost', - method: 'GET', - path: '/api/txs/histories', - ...config, - }, { walletId, accountId, address, skip, limit }) -); diff --git a/source/renderer/app/api/ada/getAdaHistoryByAccount.js b/source/renderer/app/api/ada/getAdaHistoryByAccount.js deleted file mode 100644 index afdb7fb502..0000000000 --- a/source/renderer/app/api/ada/getAdaHistoryByAccount.js +++ /dev/null @@ -1,21 +0,0 @@ -// @flow -import type { AdaTransactions, RequestConfig } from './types'; -import { request } from './lib/request'; - -export type GetAdaHistoryByAccountParams = { - accountId: string, - skip: number, - limit: number, -}; - -export const getAdaHistoryByAccount = ( - config: RequestConfig, - { accountId, skip, limit }: GetAdaHistoryByAccountParams -): Promise => ( - request({ - hostname: 'localhost', - method: 'GET', - path: '/api/txs/histories', - ...config, - }, { accountId, skip, limit }) -); diff --git a/source/renderer/app/api/ada/getAdaWalletCertificateAdditionalMnemonics.js b/source/renderer/app/api/ada/getAdaWalletCertificateAdditionalMnemonics.js deleted file mode 100644 index 365fe98fcf..0000000000 --- a/source/renderer/app/api/ada/getAdaWalletCertificateAdditionalMnemonics.js +++ /dev/null @@ -1,9 +0,0 @@ -// @flow -import type { AdaWalletCertificateAdditionalMnemonicsResponse } from './types'; -import { generateMnemonic } from '../../utils/crypto'; -import { PAPER_WALLET_WRITTEN_WORDS_COUNT } from '../../config/cryptoConfig'; - -// eslint-disable-next-line -export const getAdaWalletCertificateAdditionalMnemonics = (): AdaWalletCertificateAdditionalMnemonicsResponse => ( - generateMnemonic(PAPER_WALLET_WRITTEN_WORDS_COUNT).split(' ') -); diff --git a/source/renderer/app/api/ada/getAdaWalletCertificateRecoveryPhrase.js b/source/renderer/app/api/ada/getAdaWalletCertificateRecoveryPhrase.js deleted file mode 100644 index 460c1dae8d..0000000000 --- a/source/renderer/app/api/ada/getAdaWalletCertificateRecoveryPhrase.js +++ /dev/null @@ -1,14 +0,0 @@ -// @flow -import type { AdaWalletCertificateRecoveryPhraseResponse } from './types'; -import { scramblePaperWalletMnemonic } from '../../utils/crypto'; - -export type GetAdaWalletCertificateRecoveryPhraseParams = { - passphrase: string, - scrambledInput: string, -}; - -export const getAdaWalletCertificateRecoveryPhrase = ( - { passphrase, scrambledInput }: GetAdaWalletCertificateRecoveryPhraseParams -): AdaWalletCertificateRecoveryPhraseResponse => ( - scramblePaperWalletMnemonic(passphrase, scrambledInput) -); diff --git a/source/renderer/app/api/ada/getAdaWalletRecoveryPhraseFromCertificate.js b/source/renderer/app/api/ada/getAdaWalletRecoveryPhraseFromCertificate.js deleted file mode 100644 index afde8cf1c9..0000000000 --- a/source/renderer/app/api/ada/getAdaWalletRecoveryPhraseFromCertificate.js +++ /dev/null @@ -1,14 +0,0 @@ -// @flow -import type { AdaWalletRecoveryPhraseFromCertificateResponse } from './types'; -import { unscramblePaperWalletMnemonic } from '../../utils/crypto'; - -export type GetAdaWalletRecoveryPhraseFromCertificateParams = { - passphrase: string, // 9-word mnemonic - scrambledInput: string, // 18-word scrambled mnemonic -}; - -export const getAdaWalletRecoveryPhraseFromCertificate = ( - { passphrase, scrambledInput }: GetAdaWalletRecoveryPhraseFromCertificateParams -): AdaWalletRecoveryPhraseFromCertificateResponse => ( - unscramblePaperWalletMnemonic(passphrase, scrambledInput) -); diff --git a/source/renderer/app/api/ada/lib/encryptPassphrase.js b/source/renderer/app/api/ada/lib/encryptPassphrase.js deleted file mode 100644 index dd7f296ddc..0000000000 --- a/source/renderer/app/api/ada/lib/encryptPassphrase.js +++ /dev/null @@ -1,9 +0,0 @@ -// @flow -import blakejs from 'blakejs'; - -const bytesToB16 = (bytes) => Buffer.from(bytes).toString('hex'); -const blake2b = (data) => blakejs.blake2b(data, null, 32); - -export const encryptPassphrase = (passphrase: ?string) => ( - bytesToB16(blake2b(passphrase)) -); diff --git a/source/renderer/app/api/ada/lib/utils.js b/source/renderer/app/api/ada/lib/utils.js deleted file mode 100644 index c2693fc717..0000000000 --- a/source/renderer/app/api/ada/lib/utils.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow -import moment from 'moment'; - -export const unixTimestampToDate = (timestamp: number) => new Date(timestamp * 1000); -export const utcStringToDate = (createDate: string) => moment.utc(createDate).toDate(); diff --git a/source/renderer/app/api/ada/newAdaAccount.js b/source/renderer/app/api/ada/newAdaAccount.js deleted file mode 100644 index b41d8c5a4a..0000000000 --- a/source/renderer/app/api/ada/newAdaAccount.js +++ /dev/null @@ -1,31 +0,0 @@ -// @flow -import type { AdaAccount, RequestConfig } from './types'; -import { request } from './lib/request'; - -export type NewAdaAccountQueryParams = { - passphrase: ?string, -}; - -export type NewAdaAccountRawBodyParams = { - accountInitData: { - caInitMeta: { - caName: string, - }, - caInitWId: string, - } -}; - -export const newAdaAccount = ( - config: RequestConfig, - pathParams: {}, - queryParams: NewAdaAccountQueryParams, - rawBodyParams: NewAdaAccountRawBodyParams, -): Promise => { - const { accountInitData } = rawBodyParams; - return request({ - hostname: 'localhost', - method: 'POST', - path: '/api/accounts', - ...config, - }, queryParams, accountInitData); -}; diff --git a/source/renderer/app/api/addresses/errors.js b/source/renderer/app/api/addresses/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/newAdaWalletAddress.js b/source/renderer/app/api/addresses/requests/createAddress.js similarity index 64% rename from source/renderer/app/api/ada/newAdaWalletAddress.js rename to source/renderer/app/api/addresses/requests/createAddress.js index 86816080c6..172d55ff04 100644 --- a/source/renderer/app/api/ada/newAdaWalletAddress.js +++ b/source/renderer/app/api/addresses/requests/createAddress.js @@ -1,16 +1,16 @@ // @flow import type { AdaAddress, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type NewAdaWalletAddressParams = { +export type CreateAddressParams = { spendingPassword?: string, accountIndex: number, walletId: string, }; -export const newAdaWalletAddress = ( +export const createAddress = ( config: RequestConfig, - { spendingPassword, accountIndex, walletId }: NewAdaWalletAddressParams + { spendingPassword, accountIndex, walletId }: CreateAddressParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/getAdaAddress.js b/source/renderer/app/api/addresses/requests/getAddress.js similarity index 69% rename from source/renderer/app/api/ada/getAdaAddress.js rename to source/renderer/app/api/addresses/requests/getAddress.js index 22d2f13480..b588b532ff 100644 --- a/source/renderer/app/api/ada/getAdaAddress.js +++ b/source/renderer/app/api/addresses/requests/getAddress.js @@ -1,14 +1,14 @@ // @flow import type { AdaAddress, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type GetAdaAddressParams = { +export type GetAddressParams = { address: string, }; -export const getAdaAddress = ( +export const getAddress = ( config: RequestConfig, - { address }: GetAdaAddressParams + { address }: GetAddressParams ): Promise => { const encodedAddress = encodeURIComponent(address); return request({ diff --git a/source/renderer/app/api/addresses/types.js b/source/renderer/app/api/addresses/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/index.js b/source/renderer/app/api/api.js similarity index 86% rename from source/renderer/app/api/ada/index.js rename to source/renderer/app/api/api.js index 4b83de6775..2ec78798b0 100644 --- a/source/renderer/app/api/ada/index.js +++ b/source/renderer/app/api/api.js @@ -3,43 +3,45 @@ import { split, get } from 'lodash'; import { action } from 'mobx'; import { ipcRenderer } from 'electron'; import BigNumber from 'bignumber.js'; -import { Logger, stringifyData, stringifyError } from '../../../../common/logging'; -import { utcStringToDate } from './lib/utils'; -import { encryptPassphrase } from './lib/encryptPassphrase'; -import Wallet from '../../domains/Wallet'; -import WalletTransaction, { transactionTypes } from '../../domains/WalletTransaction'; -import WalletAddress from '../../domains/WalletAddress'; -import { isValidMnemonic } from '../../../../common/decrypt'; -import { isValidRedemptionKey, isValidPaperVendRedemptionKey } from '../../../../common/redemption-key-validation'; -import { LOVELACES_PER_ADA, MAX_TRANSACTIONS_PER_PAGE } from '../../config/numbersConfig'; -import patchAdaApi from './mocks/patchAdaApi'; -import { getAdaWallets } from './getAdaWallets'; -import { changeAdaWalletPassphrase } from './changeAdaWalletPassphrase'; -import { deleteAdaWallet } from './deleteAdaWallet'; -import { newAdaWallet } from './newAdaWallet'; -import { newAdaWalletAddress } from './newAdaWalletAddress'; -import { restoreAdaWallet } from './restoreAdaWallet'; -import { updateAdaWallet } from './updateAdaWallet'; -import { exportAdaBackupJSON } from './exportAdaBackupJSON'; -import { importAdaBackupJSON } from './importAdaBackupJSON'; -import { importAdaWallet } from './importAdaWallet'; -import { getAdaWalletAccounts } from './getAdaWalletAccounts'; -import { getAdaAddress } from './getAdaAddress'; -import { adaTxFee } from './adaTxFee'; -import { newAdaPayment } from './newAdaPayment'; -import { redeemAda } from './redeemAda'; -import { redeemAdaPaperVend } from './redeemAdaPaperVend'; -import { nextAdaUpdate } from './nextAdaUpdate'; -import { postponeAdaUpdate } from './postponeAdaUpdate'; -import { applyAdaUpdate } from './applyAdaUpdate'; -import { adaTestReset } from './adaTestReset'; -import { getAdaHistoryByWallet } from './getAdaHistoryByWallet'; -import { getAdaAccountRecoveryPhrase } from './getAdaAccountRecoveryPhrase'; -import { getAdaWalletCertificateAdditionalMnemonics } from './getAdaWalletCertificateAdditionalMnemonics'; -import { getAdaWalletCertificateRecoveryPhrase } from './getAdaWalletCertificateRecoveryPhrase'; -import { getAdaWalletRecoveryPhraseFromCertificate } from './getAdaWalletRecoveryPhraseFromCertificate'; -import { getNodeInfo } from './getNodeInfo'; -import { sendAdaBugReport } from './sendAdaBugReport'; +import { Logger, stringifyData, stringifyError } from '../../../common/logging'; +import patchAdaApi from './utils/patchAdaApi'; +import Wallet from '../domains/Wallet'; +import WalletTransaction, { transactionTypes } from '../domains/WalletTransaction'; +import WalletAddress from '../domains/WalletAddress'; +import { isValidMnemonic } from '../../../common/decrypt'; +import { isValidRedemptionKey, isValidPaperVendRedemptionKey } from '../../../common/redemption-key-validation'; +import { LOVELACES_PER_ADA, MAX_TRANSACTIONS_PER_PAGE } from '../config/numbersConfig'; +import { getAccounts } from './accounts/requests/getAccounts'; +import { getAddress } from './addresses/requests/getAddress'; +import { createAddress } from './addresses/requests/createAddress'; +import { resetWalletState } from './wallets/requests/resetWalletState'; +import { sendBugReport } from './common/requests/sendBugReport'; +import { applyNodeUpdate } from './nodes/requests/applyNodeUpdate'; +import { getNodeInfo } from './nodes/requests/getNodeInfo'; +import { getNextNodeUpdate } from './nodes/requests/getNextNodeUpdate'; +import { postponeNodeUpdate } from './nodes/requests/postponeNodeUpdate'; +import { getTransactionFee } from './transactions/requests/getTransactionFee'; +import { getTransactionHistory } from './transactions/requests/getTransactionHistory'; +import { createTransaction } from './transactions/requests/createTransaction'; +import { redeemAda } from './transactions/requests/redeemAda'; +import { redeemAdaPaperVend } from './transactions/requests/redeemAdaPaperVend'; +import { changeSpendingPassword } from './wallets/requests/changeSpendingPassword'; +import { deleteWallet } from './wallets/requests/deleteWallet'; +import { exportWalletAsJSON } from './wallets/requests/exportWalletAsJSON'; +import { importWalletAsJSON } from './wallets/requests/importWalletAsJSON'; +import { getWallets } from './wallets/requests/getWallets'; +import { importWalletAsKey } from './wallets/requests/importWalletAsKey'; +import { createWallet } from './wallets/requests/createWallet'; +import { restoreWallet } from './wallets/requests/restoreWallet'; +import { updateWallet } from './wallets/requests/updateWallet'; +import { utcStringToDate, encryptPassphrase } from './utils'; +import { + unscrambleMnemonics, + scrambleMnemonics, + generateAccountMnemonics, + generateAdditionalMnemonics +} from './utils/mnemonics'; + import type { AdaAddress, AdaAddresses, @@ -49,7 +51,6 @@ import type { AdaTransactionFee, AdaWallet, AdaWallets, - AdaWalletRecoveryPhraseResponse, AdaWalletCertificateAdditionalMnemonicsResponse, AdaWalletCertificateRecoveryPhraseResponse, WalletAssuranceLevel, @@ -200,7 +201,7 @@ export default class AdaApi { getWallets = async (): Promise => { Logger.debug('AdaApi::getWallets called'); try { - const response: AdaWallets = await getAdaWallets(this.config); + const response: AdaWallets = await getWallets(this.config); Logger.debug('AdaApi::getWallets success: ' + stringifyData(response)); return response.map(data => _createWalletFromServerV1Data(data)); } catch (error) { @@ -213,7 +214,7 @@ export default class AdaApi { Logger.debug('AdaApi::getAddresses called: ' + stringifyData(request)); const { walletId } = request; try { - const accounts: AdaAccounts = await getAdaWalletAccounts(this.config, { walletId }); + const accounts: AdaAccounts = await getAccounts(this.config, { walletId }); Logger.debug('AdaApi::getAddresses success: ' + stringifyData(accounts)); if (!accounts || !accounts.length) { @@ -234,7 +235,7 @@ export default class AdaApi { getTransactions = async (request: GetTransactionsRequest): Promise => { Logger.debug('AdaApi::searchHistory called: ' + stringifyData(request)); const { walletId, skip, limit } = request; - const accounts: AdaAccounts = await getAdaWalletAccounts(this.config, { walletId }); + const accounts: AdaAccounts = await getAccounts(this.config, { walletId }); let perPage = limit; if (limit === null || limit > MAX_TRANSACTIONS_PER_PAGE) { @@ -255,7 +256,7 @@ export default class AdaApi { const { data: history, meta - }: AdaTransactions = await getAdaHistoryByWallet(this.config, params); + }: AdaTransactions = await getTransactionHistory(this.config, params); const { totalPages } = meta.pagination; const hasMultiplePages = (totalPages > 1 && limit > MAX_TRANSACTIONS_PER_PAGE); @@ -266,7 +267,7 @@ export default class AdaApi { for (page; (hasNextPage() && shouldLoadNextPage()); page++) { const { data: pageHistory } = - await getAdaHistoryByWallet(this.config, Object.assign(params, { page })); + await getTransactionHistory(this.config, Object.assign(params, { page })); history.push(...pageHistory); } if (limit !== null) history.splice(limit); @@ -296,7 +297,7 @@ export default class AdaApi { name, spendingPassword: passwordString ? encryptPassphrase(passwordString) : null, }; - const wallet: AdaWallet = await newAdaWallet(this.config, { walletInitData }); + const wallet: AdaWallet = await createWallet(this.config, { walletInitData }); Logger.debug('AdaApi::createWallet success'); return _createWalletFromServerV1Data(wallet); } catch (error) { @@ -309,7 +310,7 @@ export default class AdaApi { Logger.debug('AdaApi::deleteWallet called: ' + stringifyData(request)); try { const { walletId } = request; - const response = await deleteAdaWallet(this.config, { walletId }); + const response = await deleteWallet(this.config, { walletId }); Logger.debug('AdaApi::deleteWallet success: ' + stringifyData(response)); return true; } catch (error) { @@ -339,7 +340,7 @@ export default class AdaApi { groupingPolicy: 'OptimizeForSecurity', spendingPassword, }; - const response: AdaTransaction = await newAdaPayment(this.config, { data }); + const response: AdaTransaction = await createTransaction(this.config, { data }); Logger.debug('AdaApi::createTransaction success: ' + stringifyData(response)); return _createTransactionFromServerDataV1(response); } catch (error) { @@ -381,7 +382,7 @@ export default class AdaApi { groupingPolicy: 'OptimizeForSecurity', spendingPassword, }; - const response: adaTxFee = await adaTxFee(this.config, { data }); + const response: AdaTransactionFee = await getTransactionFee(this.config, { data }); Logger.debug('AdaApi::calculateTransactionFee success: ' + stringifyData(response)); return _createTransactionFeeFromServerData(response); } catch (error) { @@ -402,7 +403,7 @@ export default class AdaApi { const { spendingPassword: passwordString, accountIndex, walletId } = request; const spendingPassword = passwordString ? encryptPassphrase(passwordString) : ''; try { - const address: AdaAddress = await newAdaWalletAddress( + const address: AdaAddress = await createAddress( this.config, { spendingPassword, accountIndex, walletId } ); Logger.debug('AdaApi::createAddress success: ' + stringifyData(address)); @@ -419,7 +420,7 @@ export default class AdaApi { async isValidAddress(address: string): Promise { Logger.debug('AdaApi::isValidAdaAddress called'); try { - const response: AdaAddress = await getAdaAddress(this.config, { address }); + const response: AdaAddress = await getAddress(this.config, { address }); Logger.debug(`AdaApi::isValidAdaAddress success: ${stringifyData(response)}`); return true; } catch (error) { @@ -449,8 +450,8 @@ export default class AdaApi { getWalletRecoveryPhrase(): Promise { Logger.debug('AdaApi::getWalletRecoveryPhrase called'); try { - const response: Promise = new Promise( - (resolve) => resolve(getAdaAccountRecoveryPhrase()) + const response: Promise> = new Promise( + (resolve) => resolve(generateAccountMnemonics()) ); Logger.debug('AdaApi::getWalletRecoveryPhrase success'); return response; @@ -465,7 +466,7 @@ export default class AdaApi { Logger.debug('AdaApi::getWalletCertificateAdditionalMnemonics called'); try { const response: Promise = new Promise( - (resolve) => resolve(getAdaWalletCertificateAdditionalMnemonics()) + (resolve) => resolve(generateAdditionalMnemonics()) ); Logger.debug('AdaApi::getWalletCertificateAdditionalMnemonics success'); return response; @@ -482,7 +483,7 @@ export default class AdaApi { const { passphrase, input } = request; try { const response: Promise = new Promise( - (resolve) => resolve(getAdaWalletCertificateRecoveryPhrase({ + (resolve) => resolve(scrambleMnemonics({ passphrase, scrambledInput: input, })) @@ -501,7 +502,7 @@ export default class AdaApi { Logger.debug('AdaApi::getWalletRecoveryPhraseFromCertificate called'); const { passphrase, scrambledInput } = request; try { - const response = getAdaWalletRecoveryPhraseFromCertificate({ passphrase, scrambledInput }); + const response = unscrambleMnemonics({ passphrase, scrambledInput }); Logger.debug('AdaApi::getWalletRecoveryPhraseFromCertificate success'); return Promise.resolve(response); } catch (error) { @@ -524,7 +525,7 @@ export default class AdaApi { }; try { - const wallet: AdaWallet = await restoreAdaWallet(this.config, { walletInitData }); + const wallet: AdaWallet = await restoreWallet(this.config, { walletInitData }); Logger.debug('AdaApi::restoreWallet success'); return _createWalletFromServerData(wallet); } catch (error) { @@ -547,7 +548,7 @@ export default class AdaApi { ): Promise => { Logger.debug('AdaApi::importWalletFromKey called'); try { - const importedWallet: AdaWallet = await importAdaWallet(this.config, request); + const importedWallet: AdaWallet = await importWalletAsKey(this.config, request); Logger.debug('AdaApi::importWalletFromKey success'); return _createWalletFromServerData(importedWallet); } catch (error) { @@ -567,9 +568,9 @@ export default class AdaApi { const isKeyFile = filePath.split('.').pop().toLowerCase() === 'key'; try { const importedWallet: AdaWallet = isKeyFile ? ( - await importAdaWallet(this.config, request) + await importWalletAsKey(this.config, request) ) : ( - await importAdaBackupJSON(this.config, filePath) + await importWalletAsJSON(this.config, filePath) ); Logger.debug('AdaApi::importWalletFromFile success'); return _createWalletFromServerData(importedWallet); @@ -617,7 +618,7 @@ export default class AdaApi { async sendBugReport(requestFormData: SendBugReportRequest): Promise { Logger.debug('AdaApi::sendBugReport called: ' + stringifyData(requestFormData)); try { - await sendAdaBugReport({ requestFormData }); + await sendBugReport({ requestFormData }); Logger.debug('AdaApi::sendBugReport success'); return true; } catch (error) { @@ -629,7 +630,7 @@ export default class AdaApi { nextUpdate = async (): Promise => { Logger.debug('AdaApi::nextUpdate called'); try { - const nodeUpdate = await nextAdaUpdate(this.config); + const nodeUpdate = await getNextNodeUpdate(this.config); if (nodeUpdate && nodeUpdate.version) { Logger.debug('AdaApi::nextUpdate success: ' + stringifyData(nodeUpdate)); return nodeUpdate; @@ -645,7 +646,7 @@ export default class AdaApi { postponeUpdate = async (): PostponeUpdateResponse => { Logger.debug('AdaApi::postponeUpdate called'); try { - const response: Promise = await postponeAdaUpdate(this.config); + const response: Promise = await postponeNodeUpdate(this.config); Logger.debug('AdaApi::postponeUpdate success: ' + stringifyData(response)); } catch (error) { Logger.error('AdaApi::postponeUpdate error: ' + stringifyError(error)); @@ -656,7 +657,7 @@ export default class AdaApi { applyUpdate = async (): ApplyUpdateResponse => { Logger.debug('AdaApi::applyUpdate called'); try { - const response: Promise = await applyAdaUpdate(this.config); + const response: Promise = await applyNodeUpdate(this.config); Logger.debug('AdaApi::applyUpdate success: ' + stringifyData(response)); ipcRenderer.send('kill-process'); } catch (error) { @@ -669,7 +670,7 @@ export default class AdaApi { Logger.debug('AdaApi::updateWallet called: ' + stringifyData(request)); const { walletId, assuranceLevel, name } = request; try { - const wallet: AdaWallet = await updateAdaWallet( + const wallet: AdaWallet = await updateWallet( this.config, { walletId, assuranceLevel, name } ); Logger.debug('AdaApi::updateWallet success: ' + stringifyData(wallet)); @@ -686,7 +687,7 @@ export default class AdaApi { Logger.debug('AdaApi::updateWalletPassword called'); const { walletId, oldPassword, newPassword } = request; try { - await changeAdaWalletPassphrase(this.config, { walletId, oldPassword, newPassword }); + await changeSpendingPassword(this.config, { walletId, oldPassword, newPassword }); Logger.debug('AdaApi::updateWalletPassword success'); return true; } catch (error) { @@ -704,7 +705,7 @@ export default class AdaApi { const { walletId, filePath } = request; Logger.debug('AdaApi::exportWalletToFile called'); try { - const response: Promise<[]> = await exportAdaBackupJSON(this.config, { + const response: Promise<[]> = await exportWalletAsJSON(this.config, { walletId, filePath }); @@ -719,7 +720,7 @@ export default class AdaApi { testReset = async (): Promise => { Logger.debug('AdaApi::testReset called'); try { - const response: Promise = await adaTestReset(this.config); + const response: Promise = await resetWalletState(this.config); Logger.debug('AdaApi::testReset success: ' + stringifyData(response)); return response; } catch (error) { diff --git a/source/renderer/app/api/common/errors.js b/source/renderer/app/api/common/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/sendAdaBugReport.js b/source/renderer/app/api/common/requests/sendBugReport.js similarity index 81% rename from source/renderer/app/api/ada/sendAdaBugReport.js rename to source/renderer/app/api/common/requests/sendBugReport.js index dd987504a3..58a385e03c 100644 --- a/source/renderer/app/api/ada/sendAdaBugReport.js +++ b/source/renderer/app/api/common/requests/sendBugReport.js @@ -1,10 +1,10 @@ // @flow import moment from 'moment'; import url from 'url'; -import { request } from '../lib/reportRequest'; -import environment from '../../../../common/environment'; +import { request } from '../../utils/reportRequest'; +import environment from '../../../../../common/environment'; -export type SendAdaBugReportRequestParams = { +export type SendBugReportParams = { requestFormData: { email: string, subject: string, @@ -13,8 +13,8 @@ export type SendAdaBugReportRequestParams = { }, }; -export const sendAdaBugReport = ( - { requestFormData }: SendAdaBugReportRequestParams +export const sendBugReport = ( + { requestFormData }: SendBugReportParams ) => { const { email, subject, problem, compressedLogsFile } = requestFormData; const { version, os, API_VERSION, NETWORK, build, getInstallerVersion, REPORT_URL } = environment; diff --git a/source/renderer/app/api/common/types.js b/source/renderer/app/api/common/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/errors.js b/source/renderer/app/api/errors.js similarity index 100% rename from source/renderer/app/api/ada/errors.js rename to source/renderer/app/api/errors.js diff --git a/source/renderer/app/api/index.js b/source/renderer/app/api/index.js index 94ccc108e3..ef4e401c90 100644 --- a/source/renderer/app/api/index.js +++ b/source/renderer/app/api/index.js @@ -1,7 +1,7 @@ // @flow import { remote } from 'electron'; -import AdaApi from './ada/index'; -import LocalStorageApi from './localStorage/index'; +import AdaApi from './api'; +import LocalStorageApi from './utils/localStorage'; import environment from '../../../common/environment'; export type Api = { diff --git a/source/renderer/app/api/lib/utils.js b/source/renderer/app/api/lib/utils.js deleted file mode 100644 index 8a4d5ab73c..0000000000 --- a/source/renderer/app/api/lib/utils.js +++ /dev/null @@ -1,6 +0,0 @@ -// @flow - -// 'TextEncoder' is used to measure correct length of UTF-8 strings -export const getContentLength = (content: string) => ( - (new TextEncoder()).encode(content).length -); diff --git a/source/renderer/app/api/nodes/errors.js b/source/renderer/app/api/nodes/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/applyAdaUpdate.js b/source/renderer/app/api/nodes/requests/applyNodeUpdate.js similarity index 73% rename from source/renderer/app/api/ada/applyAdaUpdate.js rename to source/renderer/app/api/nodes/requests/applyNodeUpdate.js index 82d678c65a..38e2f62b19 100644 --- a/source/renderer/app/api/ada/applyAdaUpdate.js +++ b/source/renderer/app/api/nodes/requests/applyNodeUpdate.js @@ -1,8 +1,8 @@ // @flow -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import type { RequestConfig } from './types'; -export const applyAdaUpdate = ( +export const applyNodeUpdate = ( config: RequestConfig, ): Promise => ( request({ diff --git a/source/renderer/app/api/ada/nextAdaUpdate.js b/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js similarity index 72% rename from source/renderer/app/api/ada/nextAdaUpdate.js rename to source/renderer/app/api/nodes/requests/getNextNodeUpdate.js index 5723ab367d..4bf8097e0e 100644 --- a/source/renderer/app/api/ada/nextAdaUpdate.js +++ b/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js @@ -1,8 +1,8 @@ // @flow -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import type { RequestConfig } from './types'; -export const nextAdaUpdate = ( +export const getNextNodeUpdate = ( config: RequestConfig ): Promise => ( request({ diff --git a/source/renderer/app/api/ada/getNodeInfo.js b/source/renderer/app/api/nodes/requests/getNodeInfo.js similarity index 84% rename from source/renderer/app/api/ada/getNodeInfo.js rename to source/renderer/app/api/nodes/requests/getNodeInfo.js index 1c99e4919f..8c38368f74 100644 --- a/source/renderer/app/api/ada/getNodeInfo.js +++ b/source/renderer/app/api/nodes/requests/getNodeInfo.js @@ -1,6 +1,6 @@ // @flow import type { NodeInfo, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; export const getNodeInfo = ( config: RequestConfig diff --git a/source/renderer/app/api/ada/postponeAdaUpdate.js b/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js similarity index 73% rename from source/renderer/app/api/ada/postponeAdaUpdate.js rename to source/renderer/app/api/nodes/requests/postponeNodeUpdate.js index 268f84a11d..20c16c7a6a 100644 --- a/source/renderer/app/api/ada/postponeAdaUpdate.js +++ b/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js @@ -1,8 +1,8 @@ // @flow -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import type { RequestConfig } from './types'; -export const postponeAdaUpdate = ( +export const postponeNodeUpdate = ( config: RequestConfig ): Promise => ( request({ diff --git a/source/renderer/app/api/nodes/types.js b/source/renderer/app/api/nodes/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/transactions/errors.js b/source/renderer/app/api/transactions/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/newAdaPayment.js b/source/renderer/app/api/transactions/requests/createTransaction.js similarity index 79% rename from source/renderer/app/api/ada/newAdaPayment.js rename to source/renderer/app/api/transactions/requests/createTransaction.js index 6919e087b0..28cebd60ee 100644 --- a/source/renderer/app/api/ada/newAdaPayment.js +++ b/source/renderer/app/api/transactions/requests/createTransaction.js @@ -1,8 +1,8 @@ // @flow import type { AdaTransaction, AdaTransactionParams, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export const newAdaPayment = ( +export const createTransaction = ( config: RequestConfig, { data }: AdaTransactionParams ): Promise => ( diff --git a/source/renderer/app/api/ada/adaTxFee.js b/source/renderer/app/api/transactions/requests/getTransactionFee.js similarity index 79% rename from source/renderer/app/api/ada/adaTxFee.js rename to source/renderer/app/api/transactions/requests/getTransactionFee.js index 010efd1676..98b2387f03 100644 --- a/source/renderer/app/api/ada/adaTxFee.js +++ b/source/renderer/app/api/transactions/requests/getTransactionFee.js @@ -1,8 +1,8 @@ // @flow import type { AdaTransactionFee, AdaTxFeeParams, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export const adaTxFee = ( +export const getTransactionFee = ( config: RequestConfig, { data }: AdaTxFeeParams ): Promise => ( diff --git a/source/renderer/app/api/ada/getAdaHistoryByWallet.js b/source/renderer/app/api/transactions/requests/getTransactionHistory.js similarity index 70% rename from source/renderer/app/api/ada/getAdaHistoryByWallet.js rename to source/renderer/app/api/transactions/requests/getTransactionHistory.js index 2c6e20f64b..9537634c0d 100644 --- a/source/renderer/app/api/ada/getAdaHistoryByWallet.js +++ b/source/renderer/app/api/transactions/requests/getTransactionHistory.js @@ -1,8 +1,8 @@ // @flow import type { AdaTransactions, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type GetAdaHistoryByWalletParams = { +export type GetTxnHistoryParams = { wallet_id: string, page: number, per_page: number, @@ -14,9 +14,9 @@ const requestOptions = { returnMeta: true, }; -export const getAdaHistoryByWallet = ( +export const getTransactionHistory = ( config: RequestConfig, - { ...requestParams }: GetAdaHistoryByWalletParams + { ...requestParams }: GetTxnHistoryParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/redeemAda.js b/source/renderer/app/api/transactions/requests/redeemAda.js similarity index 88% rename from source/renderer/app/api/ada/redeemAda.js rename to source/renderer/app/api/transactions/requests/redeemAda.js index 4afae88cd4..215f52237c 100644 --- a/source/renderer/app/api/ada/redeemAda.js +++ b/source/renderer/app/api/transactions/requests/redeemAda.js @@ -1,6 +1,6 @@ // @flow import type { RequestConfig, RedeemAdaParams, AdaTransaction } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; export const redeemAda = ( config: RequestConfig, diff --git a/source/renderer/app/api/ada/redeemAdaPaperVend.js b/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js similarity index 89% rename from source/renderer/app/api/ada/redeemAdaPaperVend.js rename to source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js index 94a7a9e551..41cf766f17 100644 --- a/source/renderer/app/api/ada/redeemAdaPaperVend.js +++ b/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js @@ -1,6 +1,6 @@ // @flow import type { RequestConfig, RedeemPaperVendedAdaParams, AdaTransaction } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; export const redeemAdaPaperVend = ( config: RequestConfig, diff --git a/source/renderer/app/api/transactions/types.js b/source/renderer/app/api/transactions/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/types.js b/source/renderer/app/api/types.js similarity index 100% rename from source/renderer/app/api/ada/types.js rename to source/renderer/app/api/types.js diff --git a/source/renderer/app/api/utils/index.js b/source/renderer/app/api/utils/index.js new file mode 100644 index 0000000000..ed65451640 --- /dev/null +++ b/source/renderer/app/api/utils/index.js @@ -0,0 +1,22 @@ +// @flow +import moment from 'moment'; +import blakejs from 'blakejs'; + +// time utils +export const unixTimestampToDate = (timestamp: number) => new Date(timestamp * 1000); +export const utcStringToDate = (createDate: string) => moment.utc(createDate).toDate(); + + +// passphrase utils +const bytesToB16 = (bytes) => Buffer.from(bytes).toString('hex'); +const blake2b = (data) => blakejs.blake2b(data, null, 32); + +export const encryptPassphrase = (passphrase: ?string) => ( + bytesToB16(blake2b(passphrase)) +); + +// string utils +export const getContentLength = (content: string) => ( + // 'TextEncoder' is used to measure correct length of UTF-8 strings + (new TextEncoder()).encode(content).length +); diff --git a/source/renderer/app/api/localStorage/index.js b/source/renderer/app/api/utils/localStorage.js similarity index 100% rename from source/renderer/app/api/localStorage/index.js rename to source/renderer/app/api/utils/localStorage.js diff --git a/source/renderer/app/api/utils/mnemonics.js b/source/renderer/app/api/utils/mnemonics.js new file mode 100644 index 0000000000..a3bf0dd5c8 --- /dev/null +++ b/source/renderer/app/api/utils/mnemonics.js @@ -0,0 +1,32 @@ +import { + unscramblePaperWalletMnemonic, + scramblePaperWalletMnemonic, + generateMnemonic +} from '../../utils/crypto'; +import { PAPER_WALLET_WRITTEN_WORDS_COUNT } from '../../config/cryptoConfig'; + +type MnemonicsParams = { + passphrase: string, // 9-word mnemonic + scrambledInput: string, // 18-word scrambled mnemonic +}; + +export const unscrambleMnemonics = ( + { passphrase, scrambledInput }: MnemonicsParams +): Array => ( + unscramblePaperWalletMnemonic(passphrase, scrambledInput) +); + +export const scrambleMnemonics = ( + { passphrase, scrambledInput }: MnemonicsParams +): Array => ( + scramblePaperWalletMnemonic(passphrase, scrambledInput) +); + +export const generateAccountMnemonics = (): Array => ( + generateMnemonic().split(' ') +); + +// eslint-disable-next-line +export const generateAdditionalMnemonics = (): Array => ( + generateMnemonic(PAPER_WALLET_WRITTEN_WORDS_COUNT).split(' ') +); diff --git a/source/renderer/app/api/ada/mocks/patchAdaApi.js b/source/renderer/app/api/utils/patchAdaApi.js similarity index 95% rename from source/renderer/app/api/ada/mocks/patchAdaApi.js rename to source/renderer/app/api/utils/patchAdaApi.js index 375acd0173..ac4b6ca25d 100644 --- a/source/renderer/app/api/ada/mocks/patchAdaApi.js +++ b/source/renderer/app/api/utils/patchAdaApi.js @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; -import { Logger } from '../../../../../common/logging'; +import { Logger } from '../../../../common/logging'; import { RedeemAdaError } from '../errors'; -import AdaApi from '../index'; +import AdaApi from '../api'; import type { RedeemAdaParams, RedeemPaperVendedAdaParams diff --git a/source/renderer/app/api/lib/reportRequest.js b/source/renderer/app/api/utils/reportRequest.js similarity index 100% rename from source/renderer/app/api/lib/reportRequest.js rename to source/renderer/app/api/utils/reportRequest.js diff --git a/source/renderer/app/api/ada/lib/v1/request.js b/source/renderer/app/api/utils/request.js similarity index 97% rename from source/renderer/app/api/ada/lib/v1/request.js rename to source/renderer/app/api/utils/request.js index 7a23275104..e89e99fe66 100644 --- a/source/renderer/app/api/ada/lib/v1/request.js +++ b/source/renderer/app/api/utils/request.js @@ -2,8 +2,7 @@ import https from 'https'; import { size, has, get, omit } from 'lodash'; import querystring from 'querystring'; -import { encryptPassphrase } from '../encryptPassphrase'; -import { getContentLength } from '../../../lib/utils'; +import { encryptPassphrase, getContentLength } from './'; export type RequestOptions = { hostname: string, diff --git a/source/renderer/app/api/ada/lib/request.js b/source/renderer/app/api/utils/requestV0.js similarity index 96% rename from source/renderer/app/api/ada/lib/request.js rename to source/renderer/app/api/utils/requestV0.js index 21c6e1010c..928b7524fc 100644 --- a/source/renderer/app/api/ada/lib/request.js +++ b/source/renderer/app/api/utils/requestV0.js @@ -2,8 +2,7 @@ import https from 'https'; import { size, has, get, omit } from 'lodash'; import querystring from 'querystring'; -import { encryptPassphrase } from './encryptPassphrase'; -import { getContentLength } from '../../lib/utils'; +import { encryptPassphrase, getContentLength } from './'; export type RequestOptions = { hostname: string, diff --git a/source/renderer/app/api/wallets/errors.js b/source/renderer/app/api/wallets/errors.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/api/ada/changeAdaWalletPassphrase.js b/source/renderer/app/api/wallets/requests/changeSpendingPassword.js similarity index 67% rename from source/renderer/app/api/ada/changeAdaWalletPassphrase.js rename to source/renderer/app/api/wallets/requests/changeSpendingPassword.js index ba95b085d4..02775300a7 100644 --- a/source/renderer/app/api/ada/changeAdaWalletPassphrase.js +++ b/source/renderer/app/api/wallets/requests/changeSpendingPassword.js @@ -1,17 +1,17 @@ // @flow import type { AdaWallet, RequestConfig } from './types'; -import { request } from './lib/v1/request'; -import { encryptPassphrase } from './lib/encryptPassphrase'; +import { encryptPassphrase } from '../../utils'; +import { request } from '../../utils/request'; -export type ChangeAdaWalletPassphraseParams = { +export type ChangeSpendingPasswordParams = { walletId: string, oldPassword?: string, newPassword: string, }; -export const changeAdaWalletPassphrase = ( +export const changeSpendingPassword = ( config: RequestConfig, - { walletId, oldPassword, newPassword }: ChangeAdaWalletPassphraseParams + { walletId, oldPassword, newPassword }: ChangeSpendingPasswordParams ): Promise => { const encryptedOldPassphrase = oldPassword ? encryptPassphrase(oldPassword) : ''; const encryptedNewPassphrase = newPassword ? encryptPassphrase(newPassword) : ''; diff --git a/source/renderer/app/api/ada/newAdaWallet.js b/source/renderer/app/api/wallets/requests/createWallet.js similarity index 66% rename from source/renderer/app/api/ada/newAdaWallet.js rename to source/renderer/app/api/wallets/requests/createWallet.js index 4db5e74d32..e32e3e20b4 100644 --- a/source/renderer/app/api/ada/newAdaWallet.js +++ b/source/renderer/app/api/wallets/requests/createWallet.js @@ -1,14 +1,14 @@ // @flow import type { AdaWallet, AdaWalletInitData, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type NewAdaWalletParams = { +export type CreateWalletParams = { walletInitData: AdaWalletInitData }; -export const newAdaWallet = ( +export const createWallet = ( config: RequestConfig, - { walletInitData }: NewAdaWalletParams + { walletInitData }: CreateWalletParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/deleteAdaWallet.js b/source/renderer/app/api/wallets/requests/deleteWallet.js similarity index 61% rename from source/renderer/app/api/ada/deleteAdaWallet.js rename to source/renderer/app/api/wallets/requests/deleteWallet.js index acc61c12f2..dec478c184 100644 --- a/source/renderer/app/api/ada/deleteAdaWallet.js +++ b/source/renderer/app/api/wallets/requests/deleteWallet.js @@ -1,14 +1,14 @@ // @flow -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import type { RequestConfig } from './types'; -export type DeleteAdaWalletParams = { +export type DeleteWalletParams = { walletId: string, }; -export const deleteAdaWallet = ( +export const deleteWallet = ( config: RequestConfig, - { walletId }: DeleteAdaWalletParams + { walletId }: DeleteWalletParams ): Promise<*> => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/exportAdaBackupJSON.js b/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js similarity index 61% rename from source/renderer/app/api/ada/exportAdaBackupJSON.js rename to source/renderer/app/api/wallets/requests/exportWalletAsJSON.js index 79f866cfc0..f308a4a6ec 100644 --- a/source/renderer/app/api/ada/exportAdaBackupJSON.js +++ b/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js @@ -1,15 +1,15 @@ // @flow -import { request } from './lib/request'; +import { request } from '../../utils/requestV0'; import type { RequestConfig } from './types'; -export type ExportAdaBackupJSONParams = { +export type ExportWalletAsJSONParams = { walletId: string, filePath: string, }; -export const exportAdaBackupJSON = ( +export const exportWalletAsJSON = ( config: RequestConfig, - { walletId, filePath }: ExportAdaBackupJSONParams, + { walletId, filePath }: ExportWalletAsJSONParams, ): Promise<[]> => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/getAdaWallets.js b/source/renderer/app/api/wallets/requests/getWallets.js similarity index 84% rename from source/renderer/app/api/ada/getAdaWallets.js rename to source/renderer/app/api/wallets/requests/getWallets.js index 8bb0327d9d..50fb04d61f 100644 --- a/source/renderer/app/api/ada/getAdaWallets.js +++ b/source/renderer/app/api/wallets/requests/getWallets.js @@ -1,9 +1,9 @@ // @flow import type { AdaWallets, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import { MAX_ADA_WALLETS_COUNT } from '../../config/numbersConfig'; -export const getAdaWallets = ( +export const getWallets = ( config: RequestConfig ): Promise => ( request({ diff --git a/source/renderer/app/api/ada/importAdaBackupJSON.js b/source/renderer/app/api/wallets/requests/importWalletAsJSON.js similarity index 75% rename from source/renderer/app/api/ada/importAdaBackupJSON.js rename to source/renderer/app/api/wallets/requests/importWalletAsJSON.js index 574fe07044..f2ebeda03a 100644 --- a/source/renderer/app/api/ada/importAdaBackupJSON.js +++ b/source/renderer/app/api/wallets/requests/importWalletAsJSON.js @@ -1,8 +1,8 @@ // @flow import type { AdaWallet, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/requestV0'; -export const importAdaBackupJSON = ( +export const importWalletAsJSON = ( config: RequestConfig, filePath: string, ): Promise => ( diff --git a/source/renderer/app/api/ada/importAdaWallet.js b/source/renderer/app/api/wallets/requests/importWalletAsKey.js similarity index 66% rename from source/renderer/app/api/ada/importAdaWallet.js rename to source/renderer/app/api/wallets/requests/importWalletAsKey.js index 19d8e0d02d..07f3d68e4c 100644 --- a/source/renderer/app/api/ada/importAdaWallet.js +++ b/source/renderer/app/api/wallets/requests/importWalletAsKey.js @@ -1,15 +1,15 @@ // @flow import type { AdaWallet, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type ImportAdaWalletParams = { +export type ImportWalletAsKey = { filePath: string, spendingPassword: ?string, }; -export const importAdaWallet = ( +export const importWalletAsKey = ( config: RequestConfig, - walletImportData: ImportAdaWalletParams + walletImportData: ImportWalletAsKey ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/adaTestReset.js b/source/renderer/app/api/wallets/requests/resetWalletState.js similarity index 74% rename from source/renderer/app/api/ada/adaTestReset.js rename to source/renderer/app/api/wallets/requests/resetWalletState.js index 8e2e7f9a07..07d3bd74ad 100644 --- a/source/renderer/app/api/ada/adaTestReset.js +++ b/source/renderer/app/api/wallets/requests/resetWalletState.js @@ -1,8 +1,8 @@ // @flow -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; import type { RequestConfig } from './types'; -export const adaTestReset = ( +export const resetWalletState = ( config: RequestConfig ): Promise => ( request({ diff --git a/source/renderer/app/api/ada/restoreAdaWallet.js b/source/renderer/app/api/wallets/requests/restoreWallet.js similarity index 65% rename from source/renderer/app/api/ada/restoreAdaWallet.js rename to source/renderer/app/api/wallets/requests/restoreWallet.js index 2ab0da3cc0..ecee146f25 100644 --- a/source/renderer/app/api/ada/restoreAdaWallet.js +++ b/source/renderer/app/api/wallets/requests/restoreWallet.js @@ -1,14 +1,14 @@ // @flow import type { AdaWallet, AdaWalletInitData, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type RestoreAdaWalletParams = { +export type RestoreWalletParams = { walletInitData: AdaWalletInitData }; -export const restoreAdaWallet = ( +export const restoreWallet = ( config: RequestConfig, - { walletInitData }: RestoreAdaWalletParams + { walletInitData }: RestoreWalletParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/ada/updateAdaWallet.js b/source/renderer/app/api/wallets/requests/updateWallet.js similarity index 68% rename from source/renderer/app/api/ada/updateAdaWallet.js rename to source/renderer/app/api/wallets/requests/updateWallet.js index 90a96dca55..4f7dac5661 100644 --- a/source/renderer/app/api/ada/updateAdaWallet.js +++ b/source/renderer/app/api/wallets/requests/updateWallet.js @@ -1,16 +1,16 @@ // @flow import type { AdaWallet, WalletAssuranceLevel, RequestConfig } from './types'; -import { request } from './lib/v1/request'; +import { request } from '../../utils/request'; -export type UpdateAdaWalletParams = { +export type UpdateWalletParams = { walletId: string, assuranceLevel: WalletAssuranceLevel, name: string }; -export const updateAdaWallet = ( +export const updateWallet = ( config: RequestConfig, - { walletId, assuranceLevel, name }: UpdateAdaWalletParams + { walletId, assuranceLevel, name }: UpdateWalletParams ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/wallets/types.js b/source/renderer/app/api/wallets/types.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/source/renderer/app/stores/ada/AdaRedemptionStore.js b/source/renderer/app/stores/ada/AdaRedemptionStore.js index 7405f846fe..211c7cafe3 100644 --- a/source/renderer/app/stores/ada/AdaRedemptionStore.js +++ b/source/renderer/app/stores/ada/AdaRedemptionStore.js @@ -6,7 +6,7 @@ import BigNumber from 'bignumber.js'; import Store from '../lib/Store'; import Request from '../lib/LocalizedRequest'; import { Logger } from '../../../../common/logging'; -import { encryptPassphrase } from '../../api/ada/lib/encryptPassphrase'; +import { encryptPassphrase } from '../../api/utils'; import { matchRoute } from '../../utils/routing'; import { PARSE_REDEMPTION_CODE } from '../../../../common/ipc-api'; import { From 874eac4b9a132d540391d6410e7cfd3c7ee0ea61 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Wed, 12 Sep 2018 02:03:19 -0700 Subject: [PATCH 07/29] [DDW-321] Moves common and wallet errors into their respective files --- source/renderer/app/api/common/errors.js | 57 +++++++++++++++++++++++ source/renderer/app/api/wallets/errors.js | 19 ++++++++ 2 files changed, 76 insertions(+) diff --git a/source/renderer/app/api/common/errors.js b/source/renderer/app/api/common/errors.js index e69de29bb2..8f34c0fbaf 100644 --- a/source/renderer/app/api/common/errors.js +++ b/source/renderer/app/api/common/errors.js @@ -0,0 +1,57 @@ +import { defineMessages } from 'react-intl'; +import LocalizableError from '../../i18n/LocalizableError'; +import globalMessages from '../../i18n/global-messages'; + +const messages = defineMessages({ + genericApiError: { + id: 'api.errors.GenericApiError', + defaultMessage: '!!!An error occurred, please try again later.', + description: 'Generic error message.' + }, + incorrectWalletPasswordError: { + id: 'api.errors.IncorrectPasswordError', + defaultMessage: '!!!Incorrect wallet password.', + description: '"Incorrect wallet password." error message.' + }, + reportRequestError: { + id: 'api.errors.ReportRequestError', + defaultMessage: '!!!There was a problem sending the support request.', + description: '"There was a problem sending the support request." error message' + }, +}); + +export class GenericApiError extends LocalizableError { + constructor() { + super({ + id: messages.genericApiError.id, + defaultMessage: messages.genericApiError.defaultMessage, + }); + } +} + +export class IncorrectWalletPasswordError extends LocalizableError { + constructor() { + super({ + id: messages.incorrectWalletPasswordError.id, + defaultMessage: messages.incorrectWalletPasswordError.defaultMessage, + }); + } +} + +export class ReportRequestError extends LocalizableError { + constructor() { + super({ + id: messages.reportRequestError.id, + defaultMessage: messages.reportRequestError.defaultMessage, + }); + } +} + +export class InvalidMnemonicError extends LocalizableError { + constructor() { + super({ + id: globalMessages.invalidMnemonic.id, + defaultMessage: globalMessages.invalidMnemonic.defaultMessage, + }); + } +} diff --git a/source/renderer/app/api/wallets/errors.js b/source/renderer/app/api/wallets/errors.js index e69de29bb2..2eaa789f18 100644 --- a/source/renderer/app/api/wallets/errors.js +++ b/source/renderer/app/api/wallets/errors.js @@ -0,0 +1,19 @@ +import { defineMessages } from 'react-intl'; +import LocalizableError from '../../i18n/LocalizableError'; + +const messages = defineMessages({ + walletAlreadyRestoredError: { + id: 'api.errors.WalletAlreadyRestoredError', + defaultMessage: '!!!Wallet you are trying to restore already exists.', + description: '"Wallet you are trying to restore already exists." error message.' + }, +}); + +export class WalletAlreadyRestoredError extends LocalizableError { + constructor() { + super({ + id: messages.walletAlreadyRestoredError.id, + defaultMessage: messages.walletAlreadyRestoredError.defaultMessage, + }); + } +} From 540b78070805b98dc8064a318a593a2ac1503bf0 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Wed, 12 Sep 2018 02:04:03 -0700 Subject: [PATCH 08/29] [DDW-321] Moves types in respective files. Deletes redundant type definitions. --- source/renderer/app/api/accounts/types.js | 9 + source/renderer/app/api/addresses/types.js | 7 + source/renderer/app/api/api.js | 45 ++-- source/renderer/app/api/common.js | 135 ------------ source/renderer/app/api/common/types.js | 29 +++ source/renderer/app/api/nodes/types.js | 44 ++++ .../api/transactions/requests/redeemAda.js | 11 +- .../requests/redeemAdaPaperVend.js | 9 +- source/renderer/app/api/transactions/types.js | 63 ++++++ source/renderer/app/api/types.js | 206 ------------------ source/renderer/app/api/wallets/types.js | 68 ++++++ .../renderer/app/domains/WalletTransaction.js | 2 +- source/renderer/app/stores/WalletStore.js | 3 +- .../app/stores/ada/AdaWalletSettingsStore.js | 6 +- .../app/stores/ada/AdaWalletsStore.js | 38 ++-- 15 files changed, 272 insertions(+), 403 deletions(-) delete mode 100644 source/renderer/app/api/common.js delete mode 100644 source/renderer/app/api/types.js diff --git a/source/renderer/app/api/accounts/types.js b/source/renderer/app/api/accounts/types.js index e69de29bb2..9bb3cff9b9 100644 --- a/source/renderer/app/api/accounts/types.js +++ b/source/renderer/app/api/accounts/types.js @@ -0,0 +1,9 @@ +export type AdaAccount = { + amount: number, + addresses: AdaAddresses, + name: string, + walletId: string, + index: number +}; + +export type AdaAccounts = Array; diff --git a/source/renderer/app/api/addresses/types.js b/source/renderer/app/api/addresses/types.js index e69de29bb2..af817623d9 100644 --- a/source/renderer/app/api/addresses/types.js +++ b/source/renderer/app/api/addresses/types.js @@ -0,0 +1,7 @@ +export type AdaAddress = { + id: string, + used: boolean, + changeAddress: boolean +}; + +export type AdaAddresses = Array; diff --git a/source/renderer/app/api/api.js b/source/renderer/app/api/api.js index 2ec78798b0..b67873de19 100644 --- a/source/renderer/app/api/api.js +++ b/source/renderer/app/api/api.js @@ -51,12 +51,7 @@ import type { AdaTransactionFee, AdaWallet, AdaWallets, - AdaWalletCertificateAdditionalMnemonicsResponse, - AdaWalletCertificateRecoveryPhraseResponse, WalletAssuranceLevel, - GetWalletCertificateAdditionalMnemonicsResponse, - GetWalletCertificateRecoveryPhraseResponse, - GetWalletRecoveryPhraseFromCertificateResponse, RedeemAdaParams, RedeemPaperVendedAdaParams, RequestConfig, @@ -65,23 +60,13 @@ import type { } from './types'; import type { CreateWalletRequest, - CreateWalletResponse, - CreateTransactionResponse, DeleteWalletRequest, - DeleteWalletResponse, GetNetworkStatusResponse, GetTransactionsRequest, GetTransactionsResponse, - GetWalletRecoveryPhraseResponse, - GetWalletsResponse, - IsValidAddressResponse, RestoreWalletRequest, - RestoreWalletResponse, SendBugReportRequest, - SendBugReportResponse, - UpdateWalletResponse, UpdateWalletPasswordRequest, - UpdateWalletPasswordResponse, } from '../common'; import { GenericApiError, @@ -198,7 +183,7 @@ export default class AdaApi { this.config = config; } - getWallets = async (): Promise => { + getWallets = async (): Promise> => { Logger.debug('AdaApi::getWallets called'); try { const response: AdaWallets = await getWallets(this.config); @@ -285,7 +270,7 @@ export default class AdaApi { } }; - createWallet = async (request: CreateWalletRequest): Promise => { + createWallet = async (request: CreateWalletRequest): Promise => { Logger.debug('AdaApi::createWallet called'); const { name, mnemonic, spendingPassword: passwordString } = request; const assuranceLevel = 'normal'; @@ -306,7 +291,7 @@ export default class AdaApi { } }; - deleteWallet = async (request: DeleteWalletRequest): Promise => { + deleteWallet = async (request: DeleteWalletRequest): Promise => { Logger.debug('AdaApi::deleteWallet called: ' + stringifyData(request)); try { const { walletId } = request; @@ -321,7 +306,7 @@ export default class AdaApi { createTransaction = async ( request: CreateTransactionRequest - ): Promise => { + ): Promise => { Logger.debug('AdaApi::createTransaction called'); const { accountIndex, walletId, address, amount, spendingPassword: passwordString } = request; const spendingPassword = passwordString ? encryptPassphrase(passwordString) : ''; @@ -417,7 +402,7 @@ export default class AdaApi { } }; - async isValidAddress(address: string): Promise { + async isValidAddress(address: string): Promise { Logger.debug('AdaApi::isValidAdaAddress called'); try { const response: AdaAddress = await getAddress(this.config, { address }); @@ -447,7 +432,7 @@ export default class AdaApi { mnemonic.split(' ').length === ADA_CERTIFICATE_MNEMONIC_LENGHT ); - getWalletRecoveryPhrase(): Promise { + getWalletRecoveryPhrase(): Promise> { Logger.debug('AdaApi::getWalletRecoveryPhrase called'); try { const response: Promise> = new Promise( @@ -462,10 +447,10 @@ export default class AdaApi { } // eslint-disable-next-line max-len - getWalletCertificateAdditionalMnemonics(): Promise { + getWalletCertificateAdditionalMnemonics(): Promise> { Logger.debug('AdaApi::getWalletCertificateAdditionalMnemonics called'); try { - const response: Promise = new Promise( + const response: Promise> = new Promise( (resolve) => resolve(generateAdditionalMnemonics()) ); Logger.debug('AdaApi::getWalletCertificateAdditionalMnemonics success'); @@ -478,11 +463,11 @@ export default class AdaApi { getWalletCertificateRecoveryPhrase( request: GetWalletCertificateRecoveryPhraseRequest - ): Promise { + ): Promise> { Logger.debug('AdaApi::getWalletCertificateRecoveryPhrase called'); const { passphrase, input } = request; try { - const response: Promise = new Promise( + const response: Promise> = new Promise( (resolve) => resolve(scrambleMnemonics({ passphrase, scrambledInput: input, @@ -498,7 +483,7 @@ export default class AdaApi { getWalletRecoveryPhraseFromCertificate( request: GetWalletRecoveryPhraseFromCertificateRequest - ): Promise { + ): Promise> { Logger.debug('AdaApi::getWalletRecoveryPhraseFromCertificate called'); const { passphrase, scrambledInput } = request; try { @@ -511,7 +496,7 @@ export default class AdaApi { } } - restoreWallet = async (request: RestoreWalletRequest): Promise => { + restoreWallet = async (request: RestoreWalletRequest): Promise => { Logger.debug('AdaApi::restoreWallet called'); const { recoveryPhrase, walletName, walletPassword: passwordString } = request; const assuranceLevel = 'normal'; @@ -615,7 +600,7 @@ export default class AdaApi { } } - async sendBugReport(requestFormData: SendBugReportRequest): Promise { + async sendBugReport(requestFormData: SendBugReportRequest): Promise<*> { Logger.debug('AdaApi::sendBugReport called: ' + stringifyData(requestFormData)); try { await sendBugReport({ requestFormData }); @@ -666,7 +651,7 @@ export default class AdaApi { } }; - updateWallet = async (request: UpdateWalletRequest): Promise => { + updateWallet = async (request: UpdateWalletRequest): Promise => { Logger.debug('AdaApi::updateWallet called: ' + stringifyData(request)); const { walletId, assuranceLevel, name } = request; try { @@ -683,7 +668,7 @@ export default class AdaApi { updateWalletPassword = async ( request: UpdateWalletPasswordRequest - ): Promise => { + ): Promise => { Logger.debug('AdaApi::updateWalletPassword called'); const { walletId, oldPassword, newPassword } = request; try { diff --git a/source/renderer/app/api/common.js b/source/renderer/app/api/common.js deleted file mode 100644 index 21264e33ec..0000000000 --- a/source/renderer/app/api/common.js +++ /dev/null @@ -1,135 +0,0 @@ -import { defineMessages } from 'react-intl'; -import LocalizableError from '../i18n/LocalizableError'; -import { WalletTransaction, Wallet } from '../domains/WalletTransaction'; -import type { AdaWallet, ResponseBaseV1 } from './ada/types'; -import globalMessages from '../i18n/global-messages'; - -const messages = defineMessages({ - genericApiError: { - id: 'api.errors.GenericApiError', - defaultMessage: '!!!An error occurred, please try again later.', - description: 'Generic error message.' - }, - incorrectWalletPasswordError: { - id: 'api.errors.IncorrectPasswordError', - defaultMessage: '!!!Incorrect wallet password.', - description: '"Incorrect wallet password." error message.' - }, - walletAlreadyRestoredError: { - id: 'api.errors.WalletAlreadyRestoredError', - defaultMessage: '!!!Wallet you are trying to restore already exists.', - description: '"Wallet you are trying to restore already exists." error message.' - }, - reportRequestError: { - id: 'api.errors.ReportRequestError', - defaultMessage: '!!!There was a problem sending the support request.', - description: '"There was a problem sending the support request." error message' - }, -}); - -export class GenericApiError extends LocalizableError { - constructor() { - super({ - id: messages.genericApiError.id, - defaultMessage: messages.genericApiError.defaultMessage, - }); - } -} - -export class IncorrectWalletPasswordError extends LocalizableError { - constructor() { - super({ - id: messages.incorrectWalletPasswordError.id, - defaultMessage: messages.incorrectWalletPasswordError.defaultMessage, - }); - } -} - -export class WalletAlreadyRestoredError extends LocalizableError { - constructor() { - super({ - id: messages.walletAlreadyRestoredError.id, - defaultMessage: messages.walletAlreadyRestoredError.defaultMessage, - }); - } -} - -export class ReportRequestError extends LocalizableError { - constructor() { - super({ - id: messages.reportRequestError.id, - defaultMessage: messages.reportRequestError.defaultMessage, - }); - } -} - -export class InvalidMnemonicError extends LocalizableError { - constructor() { - super({ - id: globalMessages.invalidMnemonic.id, - defaultMessage: globalMessages.invalidMnemonic.defaultMessage, - }); - } -} - -export type CreateTransactionResponse = WalletTransaction; -export type CreateWalletResponse = Wallet; -export type DeleteWalletResponse = boolean; -export type GetWalletsResponse = Array; -export type GetWalletRecoveryPhraseResponse = Array; -export type RestoreWalletResponse = Wallet; -export type UpdateWalletResponse = { - data: AdaWallet, - ...ResponseBaseV1 -}; -export type UpdateWalletPasswordResponse = boolean; -export type IsValidAddressResponse = boolean; - -export type CreateWalletRequest = { - name: string, - mnemonic: string, - spendingPassword: ?string, -}; - -export type UpdateWalletPasswordRequest = { - walletId: string, - oldPassword?: string, - newPassword: ?string, -}; - -export type DeleteWalletRequest = { - walletId: string, -}; - -export type RestoreWalletRequest = { - recoveryPhrase: string, - walletName: string, - walletPassword: ?string, -}; - -export type GetNetworkStatusResponse = { - subscriptionStatus: Object, - syncProgress: number, - blockchainHeight: number, - localBlockchainHeight: number -}; - -export type GetTransactionsRequest = { - walletId: string, - searchTerm: string, - skip: number, - limit: number, -}; - -export type GetTransactionsResponse = { - transactions: Array, - total: number, -}; - -export type SendBugReportRequest = { - email: string, - subject: string, - problem: string, - logs: Array, -}; -export type SendBugReportResponse = any; diff --git a/source/renderer/app/api/common/types.js b/source/renderer/app/api/common/types.js index e69de29bb2..220bae40dc 100644 --- a/source/renderer/app/api/common/types.js +++ b/source/renderer/app/api/common/types.js @@ -0,0 +1,29 @@ +export type RequestConfig = { + port: number, + ca: Uint8Array, + cert: Uint8Array, + key: Uint8Array, +}; + +export type ResponseBase = { + status: ResponseStatus, + meta: Pagination +}; + +export type ResponseStatus = 'success' | 'fail' | 'error'; + +export type Pagination = { + pagination: { + totalPages: number, + page: number, + perPage: number, + totalEntries: number + } +}; + +export type SendBugReportRequest = { + email: string, + subject: string, + problem: string, + logs: Array, +}; diff --git a/source/renderer/app/api/nodes/types.js b/source/renderer/app/api/nodes/types.js index e69de29bb2..6467d65c01 100644 --- a/source/renderer/app/api/nodes/types.js +++ b/source/renderer/app/api/nodes/types.js @@ -0,0 +1,44 @@ +export type NodeInfo = { + syncProgress: { + quantity: number, + unit: 'percent' + }, + blockchainHeight: ?{ + quantity: number, + unit: ?'blocks' + }, + localBlockchainHeight: { + quantity: number, + unit: ?'blocks' + }, + localTimeInformation: { + differenceFromNtpServer: ?{ + quantity: number, + unit: ?'microseconds' + } + }, + subscriptionStatus: Object +}; + +export type NodeSettings = { + slotDuration: { + quantity: number, + unit: ?'milliseconds' + }, + softwareInfo: NodeSoftware, + projectVersion: string, + gitRevision: string +}; + +export type NodeSoftware = { + applicationName: string, + version: number +}; + +// I/O Node Types +export type GetNetworkStatusResponse = { + subscriptionStatus: Object, + syncProgress: number, + blockchainHeight: number, + localBlockchainHeight: number +}; diff --git a/source/renderer/app/api/transactions/requests/redeemAda.js b/source/renderer/app/api/transactions/requests/redeemAda.js index 215f52237c..a6ad49c8f7 100644 --- a/source/renderer/app/api/transactions/requests/redeemAda.js +++ b/source/renderer/app/api/transactions/requests/redeemAda.js @@ -1,7 +1,16 @@ // @flow -import type { RequestConfig, RedeemAdaParams, AdaTransaction } from './types'; +// import RequestConfig +import type { AdaTransaction } from '../types'; import { request } from '../../utils/request'; +export type RedeemAdaParams = { + redemptionCode: string, + mnemonic: ?Array, + spendingPassword: string, + walletId: string, + accountIndex: number +}; + export const redeemAda = ( config: RequestConfig, redemptionParams: RedeemAdaParams diff --git a/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js b/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js index 41cf766f17..a5bda90ab3 100644 --- a/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js +++ b/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js @@ -1,7 +1,14 @@ // @flow -import type { RequestConfig, RedeemPaperVendedAdaParams, AdaTransaction } from './types'; +// import RequestConfig +import type { AdaTransaction } from '../types'; +import type { RedeemAdaParams } from './redeemAda'; import { request } from '../../utils/request'; +export type RedeemPaperVendedAdaParams = { + mnemonic: Array, + ...RedeemAdaParams +}; + export const redeemAdaPaperVend = ( config: RequestConfig, redemptionParams: RedeemPaperVendedAdaParams diff --git a/source/renderer/app/api/transactions/types.js b/source/renderer/app/api/transactions/types.js index e69de29bb2..dc957b2738 100644 --- a/source/renderer/app/api/transactions/types.js +++ b/source/renderer/app/api/transactions/types.js @@ -0,0 +1,63 @@ +// @flow +import WalletTransaction from '../../domains/WalletTransaction'; +import type { ResponseBase } from '../common/types'; + +export type AdaTransactions = { + data: Array, + ...ResponseBase +}; + +export type AdaTransaction = { + amount: number, + confirmations: number, + creationTime: string, + direction: 'outgoing' | 'incoming', + id: string, + type: 'local' | 'foreign', + inputs: Array, + outputs: Array, + status: { + tag: 'applying' | 'inNewestBlocks' | 'persisted' | 'wontApply' | 'creating', + data: {}, + }, +}; + +export type PaymentDistribution = { + address: string, + amount: number +}; + +export type TxnAssuranceLevel = 'low' | 'medium' | 'high'; +export type TransactionState = 'pending' | 'failed' | 'ok'; + +export type AdaTransactionFee = { + estimatedAmount: number, + ...ResponseBase +}; + +export type AdaTransactionParams = { + data: { + source: { + accountIndex: number, + walletId: string, + }, + destinations: Array, + groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', + spendingPassword: ?string + }, +}; + +export type AdaTxFeeParams = AdaTransactionParams; + +// I/O Transaction Types +export type GetTransactionsRequest = { + walletId: string, + searchTerm: string, + skip: number, + limit: number, +}; + +export type GetTransactionsResponse = { + transactions: Array, + total: number, +}; diff --git a/source/renderer/app/api/types.js b/source/renderer/app/api/types.js deleted file mode 100644 index 1b9915094a..0000000000 --- a/source/renderer/app/api/types.js +++ /dev/null @@ -1,206 +0,0 @@ -// @flow - -// ========= General ========== - -export type RequestConfig = { - port: number, - ca: Uint8Array, - cert: Uint8Array, - key: Uint8Array, -}; - -export type ResponseBaseV1 = { - status: ResponseStatus, - meta: Pagination -}; - -export type ResponseStatus = 'success' | 'fail' | 'error'; - -export type Pagination = { - pagination: { - totalPages: number, - page: number, - perPage: number, - totalEntries: number - } -}; - -// ========= Responses ========= -export type AdaWalletRecoveryPhraseResponse = Array; -export type AdaWalletCertificateAdditionalMnemonicsResponse = Array; -export type AdaWalletCertificateRecoveryPhraseResponse = Array; -export type AdaWalletRecoveryPhraseFromCertificateResponse = Array; -export type GetWalletCertificateAdditionalMnemonicsResponse = Array; -export type GetWalletCertificateRecoveryPhraseResponse = Array; -export type GetWalletRecoveryPhraseFromCertificateResponse = Array; - -// ========= Transactions ========= -export type AdaTransactions = { - data: Array, - status: ResponseStatus, - meta: Pagination, -}; - -export type AdaTransaction = { - amount: number, - confirmations: number, - creationTime: string, - direction: 'outgoing' | 'incoming', - id: string, - type: 'local' | 'foreign', - inputs: Array, - outputs: Array, - status: { - tag: 'applying' | 'inNewestBlocks' | 'persisted' | 'wontApply' | 'creating', - data: {}, - }, -}; - -export type PaymentDistribution = { - address: string, - amount: number -}; - -export type TxnAssuranceLevel = 'low' | 'medium' | 'high'; -export type TransactionState = 'pending' | 'failed' | 'ok'; - -export type AdaTransactionFee = { - estimatedAmount: number, - ...ResponseBaseV1 -}; - -export type AdaTransactionParams = { - data: { - source: { - accountIndex: number, - walletId: string, - }, - destinations: Array, - groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', - spendingPassword: ?string - }, -}; - -export type AdaTxFeeParams = AdaTransactionParams; - -// ========= Accounts ========= - -export type AdaAccount = { - amount: number, - addresses: AdaAddresses, - name: string, - walletId: string, - index: number -}; - -export type AdaAccounts = Array; - -// ========= Addresses ========= - -export type AdaAddress = { - id: string, - used: boolean, - changeAddress: boolean -}; - -export type AdaAddresses = Array; - -// ========= Wallets ========= - -export type AdaWallet = { - createdAt: string, - syncState: WalletSyncState, - balance: number, - hasSpendingPassword: boolean, - assuranceLevel: WalletAssuranceLevel, - name: string, - id: string, - spendingPasswordLastUpdate: string, -}; - -export type AdaWallets = Array; - -export type WalletAssuranceLevel = 'normal' | 'strict'; - -export type WalletAssuranceMode = { low: number, medium: number }; - -export type SyncStateTag = 'restoring' | 'synced'; - -export type WalletSyncState = { - data: ?{ - estimatedCompletionTime: { - quantity: number, - unit: 'milliseconds', - }, - percentage: { - quantity: number, - unit: 'percent', - }, - throughput: { - quantity: number, - unit: 'blocksPerSecond', - }, - }, - tag: SyncStateTag, -}; - -export type AdaWalletInitData = { - operation: 'create' | 'restore', - backupPhrase: [string], - assuranceLevel: WalletAssuranceLevel, - name: string, - spendingPassword: ?string, -}; - -// ========= Node ========= - -export type NodeInfo = { - syncProgress: { - quantity: number, - unit: 'percent' - }, - blockchainHeight: ?{ - quantity: number, - unit: ?'blocks' - }, - localBlockchainHeight: { - quantity: number, - unit: ?'blocks' - }, - localTimeInformation: { - differenceFromNtpServer: ?{ - quantity: number, - unit: ?'microseconds' - } - }, - subscriptionStatus: Object -}; - -export type NodeSettings = { - slotDuration: { - quantity: number, - unit: ?'milliseconds' - }, - softwareInfo: NodeSoftware, - projectVersion: string, - gitRevision: string -}; - -export type NodeSoftware = { - applicationName: string, - version: number -}; - -// ========== V1 API ========= -export type RedeemAdaParams = { - redemptionCode: string, - mnemonic: ?Array, - spendingPassword: string, - walletId: string, - accountIndex: number -}; - -export type RedeemPaperVendedAdaParams = { - mnemonic: Array, - ...RedeemAdaParams -}; diff --git a/source/renderer/app/api/wallets/types.js b/source/renderer/app/api/wallets/types.js index e69de29bb2..cec03660db 100644 --- a/source/renderer/app/api/wallets/types.js +++ b/source/renderer/app/api/wallets/types.js @@ -0,0 +1,68 @@ +// @flow +export type AdaWallet = { + createdAt: string, + syncState: WalletSyncState, + balance: number, + hasSpendingPassword: boolean, + assuranceLevel: WalletAssuranceLevel, + name: string, + id: string, + spendingPasswordLastUpdate: string, +}; + +export type AdaWallets = Array; + +export type WalletAssuranceLevel = 'normal' | 'strict'; + +export type WalletAssuranceMode = { low: number, medium: number }; + +export type SyncStateTag = 'restoring' | 'synced'; + +export type WalletSyncState = { + data: ?{ + estimatedCompletionTime: { + quantity: number, + unit: 'milliseconds', + }, + percentage: { + quantity: number, + unit: 'percent', + }, + throughput: { + quantity: number, + unit: 'blocksPerSecond', + }, + }, + tag: SyncStateTag, +}; + +// I/O Wallet types +export type AdaWalletInitData = { + operation: 'create' | 'restore', + backupPhrase: [string], + assuranceLevel: WalletAssuranceLevel, + name: string, + spendingPassword: ?string, +}; + +export type CreateWalletRequest = { + name: string, + mnemonic: string, + spendingPassword: ?string, +}; + +export type UpdateWalletPasswordRequest = { + walletId: string, + oldPassword?: string, + newPassword: ?string, +}; + +export type DeleteWalletRequest = { + walletId: string, +}; + +export type RestoreWalletRequest = { + recoveryPhrase: string, + walletName: string, + walletPassword: ?string, +}; diff --git a/source/renderer/app/domains/WalletTransaction.js b/source/renderer/app/domains/WalletTransaction.js index 51d1512801..3846247c07 100644 --- a/source/renderer/app/domains/WalletTransaction.js +++ b/source/renderer/app/domains/WalletTransaction.js @@ -1,7 +1,7 @@ // @flow import { observable } from 'mobx'; import BigNumber from 'bignumber.js'; -import type { WalletAssuranceMode, TxnAssuranceLevel, TransactionState } from '../api/ada/types'; +import type { WalletAssuranceMode, TxnAssuranceLevel, TransactionState } from '../api/transactions/types'; export type TrasactionAddresses = { from: Array, to: Array }; export type TransactionType = 'card' | 'expend' | 'income' | 'exchange'; diff --git a/source/renderer/app/stores/WalletStore.js b/source/renderer/app/stores/WalletStore.js index 31ed08d242..0c6e5a41f0 100644 --- a/source/renderer/app/stores/WalletStore.js +++ b/source/renderer/app/stores/WalletStore.js @@ -6,7 +6,6 @@ import Wallet from '../domains/Wallet'; import Request from './lib/LocalizedRequest'; import { buildRoute, matchRoute } from '../utils/routing'; import { ROUTES } from '../routes-config'; -import type { GetWalletRecoveryPhraseResponse } from '../api/common'; import environment from '../../../common/environment'; /** @@ -49,7 +48,7 @@ export default class WalletsStore extends Store { }) => { Object.assign(this._newWalletDetails, params); try { - const recoveryPhrase: ?GetWalletRecoveryPhraseResponse = await ( + const recoveryPhrase: ?Array = await ( this.getWalletRecoveryPhraseRequest.execute().promise ); if (recoveryPhrase != null) { diff --git a/source/renderer/app/stores/ada/AdaWalletSettingsStore.js b/source/renderer/app/stores/ada/AdaWalletSettingsStore.js index fa304d0b7a..354361c265 100644 --- a/source/renderer/app/stores/ada/AdaWalletSettingsStore.js +++ b/source/renderer/app/stores/ada/AdaWalletSettingsStore.js @@ -2,16 +2,16 @@ import { observable, action } from 'mobx'; import { findIndex, merge } from 'lodash'; import WalletSettingsStore from '../WalletSettingsStore'; +import Wallet from '../../domains/Wallet'; import Request from '../lib/LocalizedRequest'; import type { WalletExportToFileParams } from '../../actions/ada/wallet-settings-actions'; import type { ExportWalletToFileResponse } from '../../api/ada/index'; -import type { UpdateWalletPasswordResponse, UpdateWalletResponse } from '../../api/common'; export default class EtcWalletSettingsStore extends WalletSettingsStore { /* eslint-disable max-len */ - @observable updateWalletRequest: Request = new Request(this.api.ada.updateWallet); - @observable updateWalletPasswordRequest: Request = new Request(this.api.ada.updateWalletPassword); + @observable updateWalletRequest: Request = new Request(this.api.ada.updateWallet); + @observable updateWalletPasswordRequest: Request = new Request(this.api.ada.updateWalletPassword); @observable exportWalletToFileRequest: Request = new Request(this.api.ada.exportWalletToFile); /* eslint-enable max-len */ diff --git a/source/renderer/app/stores/ada/AdaWalletsStore.js b/source/renderer/app/stores/ada/AdaWalletsStore.js index 3face1cd4b..5b93f0d79a 100644 --- a/source/renderer/app/stores/ada/AdaWalletsStore.js +++ b/source/renderer/app/stores/ada/AdaWalletsStore.js @@ -3,6 +3,7 @@ import { observable, action, computed, runInAction } from 'mobx'; import { get, chunk, find } from 'lodash'; import WalletStore from '../WalletStore'; import Wallet from '../../domains/Wallet'; +import WalletTransaction from '../../domains/WalletTransaction'; import { MAX_ADA_WALLETS_COUNT } from '../../config/numbersConfig'; import { matchRoute, buildRoute } from '../../utils/routing'; import { i18nContext } from '../../utils/i18nContext'; @@ -13,33 +14,22 @@ import { downloadPaperWalletCertificate } from '../../utils/paperWalletPdfGenera import type { walletExportTypeChoices } from '../../types/walletExportTypes'; import type { WalletImportFromFileParams } from '../../actions/ada/wallets-actions'; import type { ImportWalletFromFileResponse } from '../../api/ada/index'; -import type { - CreateTransactionResponse, CreateWalletResponse, DeleteWalletResponse, - GetWalletsResponse, RestoreWalletResponse, - GetWalletRecoveryPhraseResponse, -} from '../../api/common'; -import type { - GetWalletCertificateAdditionalMnemonicsResponse, - GetWalletCertificateRecoveryPhraseResponse, - GetWalletRecoveryPhraseFromCertificateResponse, -} from '../../api/ada/types'; - export default class AdaWalletsStore extends WalletStore { // REQUESTS /* eslint-disable max-len */ - @observable walletsRequest: Request = new Request(this.api.ada.getWallets); + @observable walletsRequest: Request> = new Request(this.api.ada.getWallets); @observable importFromFileRequest: Request = new Request(this.api.ada.importWalletFromFile); - @observable createWalletRequest: Request = new Request(this.api.ada.createWallet); + @observable createWalletRequest: Request = new Request(this.api.ada.createWallet); @observable getWalletAddressesRequest: Request = new Request(this.api.ada.getAddresses); - @observable deleteWalletRequest: Request = new Request(this.api.ada.deleteWallet); - @observable sendMoneyRequest: Request = new Request(this.api.ada.createTransaction); - @observable getWalletRecoveryPhraseRequest: Request = new Request(this.api.ada.getWalletRecoveryPhrase); - @observable getWalletCertificateAdditionalMnemonicsRequest: Request = new Request(this.api.ada.getWalletCertificateAdditionalMnemonics); - @observable getWalletCertificateRecoveryPhraseRequest: Request = new Request(this.api.ada.getWalletCertificateRecoveryPhrase); - @observable getWalletRecoveryPhraseFromCertificateRequest: Request = new Request(this.api.ada.getWalletRecoveryPhraseFromCertificate); - @observable restoreRequest: Request = new Request(this.api.ada.restoreWallet); + @observable deleteWalletRequest: Request = new Request(this.api.ada.deleteWallet); + @observable sendMoneyRequest: Request = new Request(this.api.ada.createTransaction); + @observable getWalletRecoveryPhraseRequest: Request> = new Request(this.api.ada.getWalletRecoveryPhrase); + @observable getWalletCertificateAdditionalMnemonicsRequest: Request> = new Request(this.api.ada.getWalletCertificateAdditionalMnemonics); + @observable getWalletCertificateRecoveryPhraseRequest: Request> = new Request(this.api.ada.getWalletCertificateRecoveryPhrase); + @observable getWalletRecoveryPhraseFromCertificateRequest: Request> = new Request(this.api.ada.getWalletRecoveryPhraseFromCertificate); + @observable restoreRequest: Request = new Request(this.api.ada.restoreWallet); /* eslint-enable max-len */ @observable walletExportType: walletExportTypeChoices = 'paperWallet'; @@ -201,7 +191,7 @@ export default class AdaWalletsStore extends WalletStore { const spendingPassword = mnemonicToSeedHex(certificatePassword.join(' ')); // Unscramble 18-word wallet certificate mnemonic to 12-word mnemonic - const unscrambledRecoveryPhrase: GetWalletRecoveryPhraseFromCertificateResponse = await ( + const unscrambledRecoveryPhrase: Array = await ( this.getWalletRecoveryPhraseFromCertificateRequest.execute({ passphrase: spendingPassword, scrambledInput: scrambledInput.join(' '), @@ -281,12 +271,12 @@ export default class AdaWalletsStore extends WalletStore { this._updateCertificateCreationState(true); // Generate wallet recovery phrase - const recoveryPhrase: GetWalletRecoveryPhraseResponse = await ( + const recoveryPhrase: Array = await ( this.getWalletRecoveryPhraseRequest.execute().promise ); // Generate 9-words (additional) mnemonic - const additionalMnemonicWords: GetWalletCertificateAdditionalMnemonicsResponse = await ( + const additionalMnemonicWords: Array = await ( this.getWalletCertificateAdditionalMnemonicsRequest.execute().promise ); this.additionalMnemonicWords = additionalMnemonicWords.join(' '); @@ -296,7 +286,7 @@ export default class AdaWalletsStore extends WalletStore { this.walletCertificatePassword = spendingPassword; // Generate paper wallet scrambled mnemonic - const walletCertificateRecoveryPhrase: GetWalletCertificateRecoveryPhraseResponse = await ( + const walletCertificateRecoveryPhrase: Array = await ( this.getWalletCertificateRecoveryPhraseRequest.execute({ passphrase: spendingPassword, input: recoveryPhrase.join(' '), From aa76938dc9ae5785eb505cd377997284c40430f3 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Wed, 12 Sep 2018 23:42:05 -0700 Subject: [PATCH 09/29] [DDW-321] Fixes incorrect spelling of a constant --- .../wallet/ada-redemption/AdaRedemptionForm.js | 12 ++++++------ source/renderer/app/config/cryptoConfig.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/renderer/app/components/wallet/ada-redemption/AdaRedemptionForm.js b/source/renderer/app/components/wallet/ada-redemption/AdaRedemptionForm.js index 8b55794083..6008174c4e 100644 --- a/source/renderer/app/components/wallet/ada-redemption/AdaRedemptionForm.js +++ b/source/renderer/app/components/wallet/ada-redemption/AdaRedemptionForm.js @@ -23,7 +23,7 @@ import { InvalidMnemonicError, InvalidEmailError, FieldRequiredError } from '../ import globalMessages from '../../../i18n/global-messages'; import styles from './AdaRedemptionForm.scss'; import { FORM_VALIDATION_DEBOUNCE_WAIT } from '../../../config/timingConfig'; -import { ADA_REDEMPTION_PASSPHRASE_LENGHT } from '../../../config/cryptoConfig'; +import { ADA_REDEMPTION_PASSPHRASE_LENGTH } from '../../../config/cryptoConfig'; import { ADA_REDEMPTION_TYPES } from '../../../types/redemptionTypes'; import type { RedemptionTypeChoices } from '../../../types/redemptionTypes'; import { submitOnEnter } from '../../../utils/form'; @@ -244,7 +244,7 @@ export default class AdaRedemptionForm extends Component { passPhrase: { label: this.context.intl.formatMessage(messages.passphraseLabel), placeholder: this.context.intl.formatMessage(messages.passphraseHint, { - length: ADA_REDEMPTION_PASSPHRASE_LENGHT + length: ADA_REDEMPTION_PASSPHRASE_LENGTH }), value: [], validators: [({ field }) => { @@ -472,18 +472,18 @@ export default class AdaRedemptionForm extends Component { switch (redemptionType) { case ADA_REDEMPTION_TYPES.REGULAR: instructionMessage = messages.instructionsRegular; - instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGHT }; + instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGTH }; break; case ADA_REDEMPTION_TYPES.FORCE_VENDED: instructionMessage = messages.instructionsForceVended; break; case ADA_REDEMPTION_TYPES.PAPER_VENDED: instructionMessage = messages.instructionsPaperVended; - instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGHT }; + instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGTH }; break; case ADA_REDEMPTION_TYPES.RECOVERY_REGULAR: instructionMessage = messages.instructionsRecoveryRegular; - instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGHT }; + instructionValues = { adaRedemptionPassphraseLength: ADA_REDEMPTION_PASSPHRASE_LENGTH }; break; case ADA_REDEMPTION_TYPES.RECOVERY_FORCE_VENDED: instructionMessage = messages.instructionsRecoveryForceVended; @@ -600,7 +600,7 @@ export default class AdaRedemptionForm extends Component { Date: Wed, 12 Sep 2018 23:44:49 -0700 Subject: [PATCH 10/29] [DDW-321] Adds flow to config files --- source/renderer/app/config/cryptoConfig.js | 1 + source/renderer/app/config/formattingConfig.js | 1 + source/renderer/app/config/numbersConfig.js | 1 + source/renderer/app/config/timingConfig.js | 1 + source/renderer/app/config/urlsConfig.js | 1 + 5 files changed, 5 insertions(+) diff --git a/source/renderer/app/config/cryptoConfig.js b/source/renderer/app/config/cryptoConfig.js index 610bcfc51a..21ba1c90f1 100644 --- a/source/renderer/app/config/cryptoConfig.js +++ b/source/renderer/app/config/cryptoConfig.js @@ -1,3 +1,4 @@ +// @flow // Cryptographic constants go here export const WALLET_RECOVERY_PHRASE_WORD_COUNT = 12; export const ADA_REDEMPTION_PASSPHRASE_LENGTH = 9; diff --git a/source/renderer/app/config/formattingConfig.js b/source/renderer/app/config/formattingConfig.js index 5cc0950c82..504fea4a38 100644 --- a/source/renderer/app/config/formattingConfig.js +++ b/source/renderer/app/config/formattingConfig.js @@ -1,2 +1,3 @@ +// @flow // Defines how many chars of the copied wallet address are shown in the notication export const ADDRESS_COPY_NOTIFICATION_ELLIPSIS = 8; diff --git a/source/renderer/app/config/numbersConfig.js b/source/renderer/app/config/numbersConfig.js index be3d39b6c8..45ba924514 100644 --- a/source/renderer/app/config/numbersConfig.js +++ b/source/renderer/app/config/numbersConfig.js @@ -1,3 +1,4 @@ +// @flow import BigNumber from 'bignumber.js'; // ADA diff --git a/source/renderer/app/config/timingConfig.js b/source/renderer/app/config/timingConfig.js index c876d0b6fb..e3b22e741d 100644 --- a/source/renderer/app/config/timingConfig.js +++ b/source/renderer/app/config/timingConfig.js @@ -1,3 +1,4 @@ +// @flow // All configuration values for timeouts / intervals should go here export const REPORT_ISSUE_TIME_TRIGGER = 5 * 60; // 5 minutes | unit: seconds export const ADDRESS_COPY_NOTIFICATION_DURATION = 10; // unit: seconds diff --git a/source/renderer/app/config/urlsConfig.js b/source/renderer/app/config/urlsConfig.js index 65ed4e5e3b..f169c2bd7e 100644 --- a/source/renderer/app/config/urlsConfig.js +++ b/source/renderer/app/config/urlsConfig.js @@ -1,3 +1,4 @@ +// @flow export const MAINNET_EXPLORER_URL = 'https://cardanoexplorer.com'; export const STAGING_EXPLORER_URL = 'http://cardano-explorer.awstest.iohkdev.io'; export const TESTNET_EXPLORER_URL = 'http://cardano-explorer.cardano-testnet.iohkdev.io'; From 38bb6f7e68fb3698a553e297760bbbda8b058051 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:05:39 -0700 Subject: [PATCH 11/29] [DDW-321] Moves redemption-key-validation.js to /api/utils --- .../{common => renderer/app/utils}/redemption-key-validation.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/{common => renderer/app/utils}/redemption-key-validation.js (100%) diff --git a/source/common/redemption-key-validation.js b/source/renderer/app/utils/redemption-key-validation.js similarity index 100% rename from source/common/redemption-key-validation.js rename to source/renderer/app/utils/redemption-key-validation.js From 9234a6962ccda2c3e777774aa89778992e8c95bc Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:09:31 -0700 Subject: [PATCH 12/29] [DDW-321] Moves commented out API helper methods to api/utils --- source/renderer/app/api/utils/apiHelpers.js | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 source/renderer/app/api/utils/apiHelpers.js diff --git a/source/renderer/app/api/utils/apiHelpers.js b/source/renderer/app/api/utils/apiHelpers.js new file mode 100644 index 0000000000..23025016ff --- /dev/null +++ b/source/renderer/app/api/utils/apiHelpers.js @@ -0,0 +1,22 @@ +// @flow +import { ApiMethodNotYetImplementedError } from '../common/errors'; + +export const notYetImplemented = async () => ( + new Promise((resolve, reject) => { + reject(new ApiMethodNotYetImplementedError()); + }) +); + +// helper code for testing async APIs +export const testAsync = async (apiMethod: Function) => { + const result = await apiMethod(); + console.log(`testAsync result: ${result}`); + return result; +}; + +// helper code for testing sync APIs +export const testSync = (apiMethod: Function) => { + const result = apiMethod(); + console.log(`testSync result: ${result}`); + return result; +}; From b86844fbbd4b35cd546643b602d1a7c898bcbc0c Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:10:38 -0700 Subject: [PATCH 13/29] [DDW-321] Renames paper vended ada redemption request file --- .../{redeemAdaPaperVend.js => redeemPaperVendedAda.js} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename source/renderer/app/api/transactions/requests/{redeemAdaPaperVend.js => redeemPaperVendedAda.js} (71%) diff --git a/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js b/source/renderer/app/api/transactions/requests/redeemPaperVendedAda.js similarity index 71% rename from source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js rename to source/renderer/app/api/transactions/requests/redeemPaperVendedAda.js index a5bda90ab3..1612f14410 100644 --- a/source/renderer/app/api/transactions/requests/redeemAdaPaperVend.js +++ b/source/renderer/app/api/transactions/requests/redeemPaperVendedAda.js @@ -1,6 +1,6 @@ // @flow -// import RequestConfig -import type { AdaTransaction } from '../types'; +import type { RequestConfig } from '../../common/types'; +import type { Transaction } from '../types'; import type { RedeemAdaParams } from './redeemAda'; import { request } from '../../utils/request'; @@ -9,10 +9,10 @@ export type RedeemPaperVendedAdaParams = { ...RedeemAdaParams }; -export const redeemAdaPaperVend = ( +export const redeemPaperVendedAda = ( config: RequestConfig, redemptionParams: RedeemPaperVendedAdaParams -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'POST', From 163131b8cc17e40e159dfb432e61c155ec3cd45b Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:15:14 -0700 Subject: [PATCH 14/29] [DDW-321] Separates API errors into sub-directories by category --- source/renderer/app/api/common/errors.js | 14 ++ source/renderer/app/api/errors.js | 131 ------------------ .../renderer/app/api/transactions/errors.js | 89 ++++++++++++ source/renderer/app/api/wallets/errors.js | 28 ++++ 4 files changed, 131 insertions(+), 131 deletions(-) delete mode 100644 source/renderer/app/api/errors.js diff --git a/source/renderer/app/api/common/errors.js b/source/renderer/app/api/common/errors.js index 8f34c0fbaf..a18a1c6d0c 100644 --- a/source/renderer/app/api/common/errors.js +++ b/source/renderer/app/api/common/errors.js @@ -18,6 +18,11 @@ const messages = defineMessages({ defaultMessage: '!!!There was a problem sending the support request.', description: '"There was a problem sending the support request." error message' }, + apiMethodNotYetImplementedError: { + id: 'api.errors.ApiMethodNotYetImplementedError', + defaultMessage: '!!!This API method is not yet implemented.', + description: '"This API method is not yet implemented." error message.' + }, }); export class GenericApiError extends LocalizableError { @@ -55,3 +60,12 @@ export class InvalidMnemonicError extends LocalizableError { }); } } + +export class ApiMethodNotYetImplementedError extends LocalizableError { + constructor() { + super({ + id: messages.apiMethodNotYetImplementedError.id, + defaultMessage: messages.apiMethodNotYetImplementedError.defaultMessage, + }); + } +} diff --git a/source/renderer/app/api/errors.js b/source/renderer/app/api/errors.js deleted file mode 100644 index e1a29dba36..0000000000 --- a/source/renderer/app/api/errors.js +++ /dev/null @@ -1,131 +0,0 @@ -import { defineMessages } from 'react-intl'; -import LocalizableError from '../../i18n/LocalizableError'; - -const messages = defineMessages({ - apiMethodNotYetImplementedError: { - id: 'api.errors.ApiMethodNotYetImplementedError', - defaultMessage: '!!!This API method is not yet implemented.', - description: '"This API method is not yet implemented." error message.' - }, - walletAlreadyImportedError: { - id: 'api.errors.WalletAlreadyImportedError', - defaultMessage: '!!!Wallet you are trying to import already exists.', - description: '"Wallet you are trying to import already exists." error message.' - }, - redeemAdaError: { - id: 'api.errors.RedeemAdaError', - defaultMessage: '!!!Your ADA could not be redeemed correctly.', - description: '"Your ADA could not be redeemed correctly." error message.' - }, - walletFileImportError: { - id: 'api.errors.WalletFileImportError', - defaultMessage: '!!!Wallet could not be imported, please make sure you are providing a correct file.', - description: '"Wallet could not be imported, please make sure you are providing a correct file." error message.' - }, - notEnoughMoneyToSendError: { - id: 'api.errors.NotEnoughMoneyToSendError', - defaultMessage: '!!!Not enough money to make this transaction.', - description: '"Not enough money to make this transaction." error message.' - }, - notAllowedToSendMoneyToSameAddressError: { - id: 'api.errors.NotAllowedToSendMoneyToSameAddressError', - defaultMessage: '!!!It\'s not allowed to send money to the same address you are sending from. Make sure you have enough addresses with money in this account or send to a different address.', - description: '"It\'s not allowed to send money to the same address you are sending from." error message.' - }, - notAllowedToSendMoneyToRedeemAddressError: { - id: 'api.errors.NotAllowedToSendMoneyToRedeemAddressError', - defaultMessage: '!!!It is not allowed to send money to Ada redemption address.', - description: '"It is not allowed to send money to Ada redemption address." error message.' - }, - allFundsAlreadyAtReceiverAddressError: { - id: 'api.errors.AllFundsAlreadyAtReceiverAddressError', - defaultMessage: '!!!All your funds are already at the address you are trying send money to.', - description: '"All your funds are already at the address you are trying send money to." error message.' - }, - notEnoughFundsForTransactionFeesError: { - id: 'api.errors.NotEnoughFundsForTransactionFeesError', - defaultMessage: '!!!Not enough Ada for fees. Try sending a smaller amount.', - description: '"Not enough Ada for fees. Try sending a smaller amount." error message' - }, -}); - -export class ApiMethodNotYetImplementedError extends LocalizableError { - constructor() { - super({ - id: messages.apiMethodNotYetImplementedError.id, - defaultMessage: messages.apiMethodNotYetImplementedError.defaultMessage, - }); - } -} - -export class WalletAlreadyImportedError extends LocalizableError { - constructor() { - super({ - id: messages.walletAlreadyImportedError.id, - defaultMessage: messages.walletAlreadyImportedError.defaultMessage, - }); - } -} - -export class RedeemAdaError extends LocalizableError { - constructor() { - super({ - id: messages.redeemAdaError.id, - defaultMessage: messages.redeemAdaError.defaultMessage, - }); - } -} - -export class WalletFileImportError extends LocalizableError { - constructor() { - super({ - id: messages.walletFileImportError.id, - defaultMessage: messages.walletFileImportError.defaultMessage, - }); - } -} - -export class NotEnoughMoneyToSendError extends LocalizableError { - constructor() { - super({ - id: messages.notEnoughMoneyToSendError.id, - defaultMessage: messages.notEnoughMoneyToSendError.defaultMessage, - }); - } -} - -export class NotAllowedToSendMoneyToSameAddressError extends LocalizableError { - constructor() { - super({ - id: messages.notAllowedToSendMoneyToSameAddressError.id, - defaultMessage: messages.notAllowedToSendMoneyToSameAddressError.defaultMessage, - }); - } -} - -export class NotAllowedToSendMoneyToRedeemAddressError extends LocalizableError { - constructor() { - super({ - id: messages.notAllowedToSendMoneyToRedeemAddressError.id, - defaultMessage: messages.notAllowedToSendMoneyToRedeemAddressError.defaultMessage, - }); - } -} - -export class AllFundsAlreadyAtReceiverAddressError extends LocalizableError { - constructor() { - super({ - id: messages.allFundsAlreadyAtReceiverAddressError.id, - defaultMessage: messages.allFundsAlreadyAtReceiverAddressError.defaultMessage, - }); - } -} - -export class NotEnoughFundsForTransactionFeesError extends LocalizableError { - constructor() { - super({ - id: messages.notEnoughFundsForTransactionFeesError.id, - defaultMessage: messages.notEnoughFundsForTransactionFeesError.defaultMessage, - }); - } -} diff --git a/source/renderer/app/api/transactions/errors.js b/source/renderer/app/api/transactions/errors.js index e69de29bb2..5041ac9921 100644 --- a/source/renderer/app/api/transactions/errors.js +++ b/source/renderer/app/api/transactions/errors.js @@ -0,0 +1,89 @@ +import { defineMessages } from 'react-intl'; +import LocalizableError from '../../i18n/LocalizableError'; + +const messages = defineMessages({ + notAllowedToSendMoneyToSameAddressError: { + id: 'api.errors.NotAllowedToSendMoneyToSameAddressError', + defaultMessage: '!!!It\'s not allowed to send money to the same address you are sending from. Make sure you have enough addresses with money in this account or send to a different address.', + description: '"It\'s not allowed to send money to the same address you are sending from." error message.' + }, + notAllowedToSendMoneyToRedeemAddressError: { + id: 'api.errors.NotAllowedToSendMoneyToRedeemAddressError', + defaultMessage: '!!!It is not allowed to send money to Ada redemption address.', + description: '"It is not allowed to send money to Ada redemption address." error message.' + }, + notEnoughMoneyToSendError: { + id: 'api.errors.NotEnoughMoneyToSendError', + defaultMessage: '!!!Not enough money to make this transaction.', + description: '"Not enough money to make this transaction." error message.' + }, + redeemAdaError: { + id: 'api.errors.RedeemAdaError', + defaultMessage: '!!!Your ADA could not be redeemed correctly.', + description: '"Your ADA could not be redeemed correctly." error message.' + }, + allFundsAlreadyAtReceiverAddressError: { + id: 'api.errors.AllFundsAlreadyAtReceiverAddressError', + defaultMessage: '!!!All your funds are already at the address you are trying send money to.', + description: '"All your funds are already at the address you are trying send money to." error message.' + }, + notEnoughFundsForTransactionFeesError: { + id: 'api.errors.NotEnoughFundsForTransactionFeesError', + defaultMessage: '!!!Not enough Ada for fees. Try sending a smaller amount.', + description: '"Not enough Ada for fees. Try sending a smaller amount." error message' + }, +}); + +export class NotAllowedToSendMoneyToSameAddressError extends LocalizableError { + constructor() { + super({ + id: messages.notAllowedToSendMoneyToSameAddressError.id, + defaultMessage: messages.notAllowedToSendMoneyToSameAddressError.defaultMessage, + }); + } +} + +export class NotAllowedToSendMoneyToRedeemAddressError extends LocalizableError { + constructor() { + super({ + id: messages.notAllowedToSendMoneyToRedeemAddressError.id, + defaultMessage: messages.notAllowedToSendMoneyToRedeemAddressError.defaultMessage, + }); + } +} + +export class NotEnoughMoneyToSendError extends LocalizableError { + constructor() { + super({ + id: messages.notEnoughMoneyToSendError.id, + defaultMessage: messages.notEnoughMoneyToSendError.defaultMessage, + }); + } +} + +export class RedeemAdaError extends LocalizableError { + constructor() { + super({ + id: messages.redeemAdaError.id, + defaultMessage: messages.redeemAdaError.defaultMessage, + }); + } +} + +export class AllFundsAlreadyAtReceiverAddressError extends LocalizableError { + constructor() { + super({ + id: messages.allFundsAlreadyAtReceiverAddressError.id, + defaultMessage: messages.allFundsAlreadyAtReceiverAddressError.defaultMessage, + }); + } +} + +export class NotEnoughFundsForTransactionFeesError extends LocalizableError { + constructor() { + super({ + id: messages.notEnoughFundsForTransactionFeesError.id, + defaultMessage: messages.notEnoughFundsForTransactionFeesError.defaultMessage, + }); + } +} diff --git a/source/renderer/app/api/wallets/errors.js b/source/renderer/app/api/wallets/errors.js index 2eaa789f18..b22f5501fc 100644 --- a/source/renderer/app/api/wallets/errors.js +++ b/source/renderer/app/api/wallets/errors.js @@ -7,6 +7,16 @@ const messages = defineMessages({ defaultMessage: '!!!Wallet you are trying to restore already exists.', description: '"Wallet you are trying to restore already exists." error message.' }, + walletAlreadyImportedError: { + id: 'api.errors.WalletAlreadyImportedError', + defaultMessage: '!!!Wallet you are trying to import already exists.', + description: '"Wallet you are trying to import already exists." error message.' + }, + walletFileImportError: { + id: 'api.errors.WalletFileImportError', + defaultMessage: '!!!Wallet could not be imported, please make sure you are providing a correct file.', + description: '"Wallet could not be imported, please make sure you are providing a correct file." error message.' + }, }); export class WalletAlreadyRestoredError extends LocalizableError { @@ -17,3 +27,21 @@ export class WalletAlreadyRestoredError extends LocalizableError { }); } } + +export class WalletAlreadyImportedError extends LocalizableError { + constructor() { + super({ + id: messages.walletAlreadyImportedError.id, + defaultMessage: messages.walletAlreadyImportedError.defaultMessage, + }); + } +} + +export class WalletFileImportError extends LocalizableError { + constructor() { + super({ + id: messages.walletFileImportError.id, + defaultMessage: messages.walletFileImportError.defaultMessage, + }); + } +} From 30dc394be42dc4e250e9242f86384697de18c489 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:17:45 -0700 Subject: [PATCH 15/29] [DDW-321] Separates API types into sub-directories by category --- source/renderer/app/api/accounts/types.js | 9 ++-- source/renderer/app/api/addresses/types.js | 21 +++++++++- source/renderer/app/api/nodes/types.js | 3 +- source/renderer/app/api/transactions/types.js | 34 +++++++-------- source/renderer/app/api/wallets/types.js | 42 +++++++++++++++---- 5 files changed, 76 insertions(+), 33 deletions(-) diff --git a/source/renderer/app/api/accounts/types.js b/source/renderer/app/api/accounts/types.js index 9bb3cff9b9..d2036c5a3a 100644 --- a/source/renderer/app/api/accounts/types.js +++ b/source/renderer/app/api/accounts/types.js @@ -1,9 +1,12 @@ -export type AdaAccount = { +// @flow +import type { Addresses } from '../addresses/types'; + +export type Account = { amount: number, - addresses: AdaAddresses, + addresses: Addresses, name: string, walletId: string, index: number }; -export type AdaAccounts = Array; +export type Accounts = Array; diff --git a/source/renderer/app/api/addresses/types.js b/source/renderer/app/api/addresses/types.js index af817623d9..ecbdb20ca2 100644 --- a/source/renderer/app/api/addresses/types.js +++ b/source/renderer/app/api/addresses/types.js @@ -1,7 +1,24 @@ -export type AdaAddress = { +// @flow +export type Address = { id: string, used: boolean, changeAddress: boolean }; -export type AdaAddresses = Array; +export type Addresses = Array
; + +// req/res Address types +export type GetAddressesResponse = { + accountIndex: ?number, + addresses: Addresses, +}; + +export type GetAddressesRequest = { + walletId: string, +}; + +export type CreateAddressRequest = { + spendingPassword?: string, + accountIndex: number, + walletId: string, +}; diff --git a/source/renderer/app/api/nodes/types.js b/source/renderer/app/api/nodes/types.js index 6467d65c01..afed2d758b 100644 --- a/source/renderer/app/api/nodes/types.js +++ b/source/renderer/app/api/nodes/types.js @@ -1,3 +1,4 @@ +// @flow export type NodeInfo = { syncProgress: { quantity: number, @@ -35,7 +36,7 @@ export type NodeSoftware = { version: number }; -// I/O Node Types +// req/res Node Types export type GetNetworkStatusResponse = { subscriptionStatus: Object, syncProgress: number, diff --git a/source/renderer/app/api/transactions/types.js b/source/renderer/app/api/transactions/types.js index dc957b2738..257f05f058 100644 --- a/source/renderer/app/api/transactions/types.js +++ b/source/renderer/app/api/transactions/types.js @@ -2,12 +2,12 @@ import WalletTransaction from '../../domains/WalletTransaction'; import type { ResponseBase } from '../common/types'; -export type AdaTransactions = { - data: Array, +export type Transactions = { + data: Array, ...ResponseBase }; -export type AdaTransaction = { +export type Transaction = { amount: number, confirmations: number, creationTime: string, @@ -28,28 +28,18 @@ export type PaymentDistribution = { }; export type TxnAssuranceLevel = 'low' | 'medium' | 'high'; + export type TransactionState = 'pending' | 'failed' | 'ok'; -export type AdaTransactionFee = { +export type TransactionFee = { estimatedAmount: number, ...ResponseBase }; -export type AdaTransactionParams = { - data: { - source: { - accountIndex: number, - walletId: string, - }, - destinations: Array, - groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', - spendingPassword: ?string - }, -}; +export type TrasactionAddresses = { from: Array, to: Array }; +export type TransactionType = 'card' | 'expend' | 'income' | 'exchange'; -export type AdaTxFeeParams = AdaTransactionParams; - -// I/O Transaction Types +// req/res Transaction Types export type GetTransactionsRequest = { walletId: string, searchTerm: string, @@ -57,6 +47,14 @@ export type GetTransactionsRequest = { limit: number, }; +export type TransactionRequest = { + accountIndex: number, + walletId: string, + address: string, + amount: number, + spendingPassword?: ?string, +}; + export type GetTransactionsResponse = { transactions: Array, total: number, diff --git a/source/renderer/app/api/wallets/types.js b/source/renderer/app/api/wallets/types.js index cec03660db..784d1f54f8 100644 --- a/source/renderer/app/api/wallets/types.js +++ b/source/renderer/app/api/wallets/types.js @@ -36,15 +36,7 @@ export type WalletSyncState = { tag: SyncStateTag, }; -// I/O Wallet types -export type AdaWalletInitData = { - operation: 'create' | 'restore', - backupPhrase: [string], - assuranceLevel: WalletAssuranceLevel, - name: string, - spendingPassword: ?string, -}; - +// req/res Wallet types export type CreateWalletRequest = { name: string, mnemonic: string, @@ -66,3 +58,35 @@ export type RestoreWalletRequest = { walletName: string, walletPassword: ?string, }; + +export type UpdateWalletRequest = { + walletId: string, + assuranceLevel: WalletAssuranceLevel, + name: string +}; +export type ImportWalletFromKeyRequest = { + filePath: string, + spendingPassword: ?string, +}; + +export type ImportWalletFromFileRequest = { + filePath: string, + spendingPassword: ?string, + walletName: ?string, +}; + +export type ExportWalletToFileRequest = { + walletId: string, + filePath: string, + password: ?string +}; + +export type GetWalletCertificateRecoveryPhraseRequest = { + passphrase: string, + input: string, +}; + +export type GetWalletRecoveryPhraseFromCertificateRequest = { + passphrase: string, + scrambledInput: string, +}; From 0d227e757931919d024a93cd41fad2367eefc63c Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:19:51 -0700 Subject: [PATCH 16/29] [DDW-321] Separates Accounts requests into its own sub-directory --- source/renderer/app/api/accounts/requests/getAccounts.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/renderer/app/api/accounts/requests/getAccounts.js b/source/renderer/app/api/accounts/requests/getAccounts.js index 81f5d1e524..e6f7180f9e 100644 --- a/source/renderer/app/api/accounts/requests/getAccounts.js +++ b/source/renderer/app/api/accounts/requests/getAccounts.js @@ -1,5 +1,6 @@ // @flow -import type { AdaAccounts, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { Accounts } from '../types'; import { request } from '../../utils/request'; export type GetAccountsParams = { @@ -9,7 +10,7 @@ export type GetAccountsParams = { export const getAccounts = ( config: RequestConfig, { walletId }: GetAccountsParams -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'GET', From 1865c67c1c1fe8c0ea4336dc24eb5db202ef50cd Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:20:40 -0700 Subject: [PATCH 17/29] [DDW-321] Separates Addresses requests into their own sub-directory --- source/renderer/app/api/addresses/requests/createAddress.js | 5 +++-- source/renderer/app/api/addresses/requests/getAddress.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/renderer/app/api/addresses/requests/createAddress.js b/source/renderer/app/api/addresses/requests/createAddress.js index 172d55ff04..ef9e1ec83c 100644 --- a/source/renderer/app/api/addresses/requests/createAddress.js +++ b/source/renderer/app/api/addresses/requests/createAddress.js @@ -1,5 +1,6 @@ // @flow -import type { AdaAddress, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { Address } from '../types'; import { request } from '../../utils/request'; export type CreateAddressParams = { @@ -11,7 +12,7 @@ export type CreateAddressParams = { export const createAddress = ( config: RequestConfig, { spendingPassword, accountIndex, walletId }: CreateAddressParams -): Promise => ( +): Promise
=> ( request({ hostname: 'localhost', method: 'POST', diff --git a/source/renderer/app/api/addresses/requests/getAddress.js b/source/renderer/app/api/addresses/requests/getAddress.js index b588b532ff..5831c55a0f 100644 --- a/source/renderer/app/api/addresses/requests/getAddress.js +++ b/source/renderer/app/api/addresses/requests/getAddress.js @@ -1,5 +1,6 @@ // @flow -import type { AdaAddress, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { Address } from '../types'; import { request } from '../../utils/request'; export type GetAddressParams = { @@ -9,7 +10,7 @@ export type GetAddressParams = { export const getAddress = ( config: RequestConfig, { address }: GetAddressParams -): Promise => { +): Promise
=> { const encodedAddress = encodeURIComponent(address); return request({ hostname: 'localhost', From 9eb48c0eb5a7dffe3e592f3306a8411e9092d4ab Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:21:11 -0700 Subject: [PATCH 18/29] [DDW-321] Separates Nodes requests into their own sub-directory --- source/renderer/app/api/nodes/requests/applyNodeUpdate.js | 2 +- source/renderer/app/api/nodes/requests/getNextNodeUpdate.js | 2 +- source/renderer/app/api/nodes/requests/getNodeInfo.js | 3 ++- source/renderer/app/api/nodes/requests/postponeNodeUpdate.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/source/renderer/app/api/nodes/requests/applyNodeUpdate.js b/source/renderer/app/api/nodes/requests/applyNodeUpdate.js index 38e2f62b19..bdc1f1154f 100644 --- a/source/renderer/app/api/nodes/requests/applyNodeUpdate.js +++ b/source/renderer/app/api/nodes/requests/applyNodeUpdate.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/request'; -import type { RequestConfig } from './types'; export const applyNodeUpdate = ( config: RequestConfig, diff --git a/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js b/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js index 4bf8097e0e..04e45e97ca 100644 --- a/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js +++ b/source/renderer/app/api/nodes/requests/getNextNodeUpdate.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/request'; -import type { RequestConfig } from './types'; export const getNextNodeUpdate = ( config: RequestConfig diff --git a/source/renderer/app/api/nodes/requests/getNodeInfo.js b/source/renderer/app/api/nodes/requests/getNodeInfo.js index 8c38368f74..600d13e6ae 100644 --- a/source/renderer/app/api/nodes/requests/getNodeInfo.js +++ b/source/renderer/app/api/nodes/requests/getNodeInfo.js @@ -1,5 +1,6 @@ // @flow -import type { NodeInfo, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { NodeInfo } from '../types'; import { request } from '../../utils/request'; export const getNodeInfo = ( diff --git a/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js b/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js index 20c16c7a6a..3254082265 100644 --- a/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js +++ b/source/renderer/app/api/nodes/requests/postponeNodeUpdate.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/request'; -import type { RequestConfig } from './types'; export const postponeNodeUpdate = ( config: RequestConfig From 4ccd7b778c30bb75975d63b269219daf674c51bd Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:21:45 -0700 Subject: [PATCH 19/29] [DDW-321] Separates Transactions requests into their own sub-directory --- .../requests/createTransaction.js | 19 ++++++++++++++++--- .../requests/getTransactionFee.js | 8 +++++--- .../requests/getTransactionHistory.js | 5 +++-- .../api/transactions/requests/redeemAda.js | 6 +++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/source/renderer/app/api/transactions/requests/createTransaction.js b/source/renderer/app/api/transactions/requests/createTransaction.js index 28cebd60ee..85eb1b86a8 100644 --- a/source/renderer/app/api/transactions/requests/createTransaction.js +++ b/source/renderer/app/api/transactions/requests/createTransaction.js @@ -1,11 +1,24 @@ // @flow -import type { AdaTransaction, AdaTransactionParams, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { Transaction, PaymentDistribution } from '../types'; import { request } from '../../utils/request'; +export type TransactionParams = { + data: { + source: { + accountIndex: number, + walletId: string, + }, + destinations: Array, + groupingPolicy: ?'OptimizeForSecurity' | 'OptimizeForSize', + spendingPassword: ?string + }, +}; + export const createTransaction = ( config: RequestConfig, - { data }: AdaTransactionParams -): Promise => ( + { data }: TransactionParams +): Promise => ( request({ hostname: 'localhost', method: 'POST', diff --git a/source/renderer/app/api/transactions/requests/getTransactionFee.js b/source/renderer/app/api/transactions/requests/getTransactionFee.js index 98b2387f03..c43c2ee764 100644 --- a/source/renderer/app/api/transactions/requests/getTransactionFee.js +++ b/source/renderer/app/api/transactions/requests/getTransactionFee.js @@ -1,11 +1,13 @@ // @flow -import type { AdaTransactionFee, AdaTxFeeParams, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { TransactionParams } from './createTransaction'; +import type { TransactionFee } from '../types'; import { request } from '../../utils/request'; export const getTransactionFee = ( config: RequestConfig, - { data }: AdaTxFeeParams -): Promise => ( + { data }: TransactionParams +): Promise => ( request({ hostname: 'localhost', method: 'POST', diff --git a/source/renderer/app/api/transactions/requests/getTransactionHistory.js b/source/renderer/app/api/transactions/requests/getTransactionHistory.js index 9537634c0d..0aa093b4a9 100644 --- a/source/renderer/app/api/transactions/requests/getTransactionHistory.js +++ b/source/renderer/app/api/transactions/requests/getTransactionHistory.js @@ -1,5 +1,6 @@ // @flow -import type { AdaTransactions, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { Transactions } from '../types'; import { request } from '../../utils/request'; export type GetTxnHistoryParams = { @@ -17,7 +18,7 @@ const requestOptions = { export const getTransactionHistory = ( config: RequestConfig, { ...requestParams }: GetTxnHistoryParams -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'GET', diff --git a/source/renderer/app/api/transactions/requests/redeemAda.js b/source/renderer/app/api/transactions/requests/redeemAda.js index a6ad49c8f7..8fa25fa442 100644 --- a/source/renderer/app/api/transactions/requests/redeemAda.js +++ b/source/renderer/app/api/transactions/requests/redeemAda.js @@ -1,6 +1,6 @@ // @flow -// import RequestConfig -import type { AdaTransaction } from '../types'; +import type { RequestConfig } from '../../common/types'; +import type { Transaction } from '../types'; import { request } from '../../utils/request'; export type RedeemAdaParams = { @@ -14,7 +14,7 @@ export type RedeemAdaParams = { export const redeemAda = ( config: RequestConfig, redemptionParams: RedeemAdaParams -): Promise => ( +): Promise => ( request({ hostname: 'localhost', method: 'POST', From 16a012b8f0f220713ff181bb8827541b37a3fe0d Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:22:16 -0700 Subject: [PATCH 20/29] [DDW-321] Separates Wallets requests into their own sub-directory --- .../api/wallets/requests/changeSpendingPassword.js | 7 ++++--- .../app/api/wallets/requests/createWallet.js | 13 +++++++++---- .../app/api/wallets/requests/deleteWallet.js | 2 +- .../app/api/wallets/requests/exportWalletAsJSON.js | 2 +- .../renderer/app/api/wallets/requests/getWallets.js | 5 +++-- .../app/api/wallets/requests/importWalletAsJSON.js | 3 ++- .../app/api/wallets/requests/importWalletAsKey.js | 3 ++- .../app/api/wallets/requests/resetWalletState.js | 2 +- .../app/api/wallets/requests/restoreWallet.js | 10 ++++------ .../app/api/wallets/requests/updateWallet.js | 3 ++- 10 files changed, 29 insertions(+), 21 deletions(-) diff --git a/source/renderer/app/api/wallets/requests/changeSpendingPassword.js b/source/renderer/app/api/wallets/requests/changeSpendingPassword.js index 02775300a7..507b6d0422 100644 --- a/source/renderer/app/api/wallets/requests/changeSpendingPassword.js +++ b/source/renderer/app/api/wallets/requests/changeSpendingPassword.js @@ -1,12 +1,13 @@ // @flow -import type { AdaWallet, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallet } from '../types'; import { encryptPassphrase } from '../../utils'; import { request } from '../../utils/request'; export type ChangeSpendingPasswordParams = { walletId: string, - oldPassword?: string, - newPassword: string, + oldPassword: ?string, + newPassword: ?string, }; export const changeSpendingPassword = ( diff --git a/source/renderer/app/api/wallets/requests/createWallet.js b/source/renderer/app/api/wallets/requests/createWallet.js index e32e3e20b4..91f47dc07e 100644 --- a/source/renderer/app/api/wallets/requests/createWallet.js +++ b/source/renderer/app/api/wallets/requests/createWallet.js @@ -1,14 +1,19 @@ // @flow -import type { AdaWallet, AdaWalletInitData, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallet, WalletAssuranceLevel } from '../types'; import { request } from '../../utils/request'; -export type CreateWalletParams = { - walletInitData: AdaWalletInitData +export type WalletInitData = { + operation: 'create' | 'restore', + backupPhrase: [string], + assuranceLevel: WalletAssuranceLevel, + name: string, + spendingPassword: ?string, }; export const createWallet = ( config: RequestConfig, - { walletInitData }: CreateWalletParams + { walletInitData }: { walletInitData: WalletInitData } ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/wallets/requests/deleteWallet.js b/source/renderer/app/api/wallets/requests/deleteWallet.js index dec478c184..3c9a53f7fd 100644 --- a/source/renderer/app/api/wallets/requests/deleteWallet.js +++ b/source/renderer/app/api/wallets/requests/deleteWallet.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/request'; -import type { RequestConfig } from './types'; export type DeleteWalletParams = { walletId: string, diff --git a/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js b/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js index f308a4a6ec..d5f6ec5bbe 100644 --- a/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js +++ b/source/renderer/app/api/wallets/requests/exportWalletAsJSON.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/requestV0'; -import type { RequestConfig } from './types'; export type ExportWalletAsJSONParams = { walletId: string, diff --git a/source/renderer/app/api/wallets/requests/getWallets.js b/source/renderer/app/api/wallets/requests/getWallets.js index 50fb04d61f..4031584a80 100644 --- a/source/renderer/app/api/wallets/requests/getWallets.js +++ b/source/renderer/app/api/wallets/requests/getWallets.js @@ -1,7 +1,8 @@ // @flow -import type { AdaWallets, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallets } from '../types'; import { request } from '../../utils/request'; -import { MAX_ADA_WALLETS_COUNT } from '../../config/numbersConfig'; +import { MAX_ADA_WALLETS_COUNT } from '../../../config/numbersConfig'; export const getWallets = ( config: RequestConfig diff --git a/source/renderer/app/api/wallets/requests/importWalletAsJSON.js b/source/renderer/app/api/wallets/requests/importWalletAsJSON.js index f2ebeda03a..66434b765a 100644 --- a/source/renderer/app/api/wallets/requests/importWalletAsJSON.js +++ b/source/renderer/app/api/wallets/requests/importWalletAsJSON.js @@ -1,5 +1,6 @@ // @flow -import type { AdaWallet, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallet } from '../types'; import { request } from '../../utils/requestV0'; export const importWalletAsJSON = ( diff --git a/source/renderer/app/api/wallets/requests/importWalletAsKey.js b/source/renderer/app/api/wallets/requests/importWalletAsKey.js index 07f3d68e4c..2d02961dff 100644 --- a/source/renderer/app/api/wallets/requests/importWalletAsKey.js +++ b/source/renderer/app/api/wallets/requests/importWalletAsKey.js @@ -1,5 +1,6 @@ // @flow -import type { AdaWallet, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallet } from '../types'; import { request } from '../../utils/request'; export type ImportWalletAsKey = { diff --git a/source/renderer/app/api/wallets/requests/resetWalletState.js b/source/renderer/app/api/wallets/requests/resetWalletState.js index 07d3bd74ad..49627115a8 100644 --- a/source/renderer/app/api/wallets/requests/resetWalletState.js +++ b/source/renderer/app/api/wallets/requests/resetWalletState.js @@ -1,6 +1,6 @@ // @flow +import type { RequestConfig } from '../../common/types'; import { request } from '../../utils/request'; -import type { RequestConfig } from './types'; export const resetWalletState = ( config: RequestConfig diff --git a/source/renderer/app/api/wallets/requests/restoreWallet.js b/source/renderer/app/api/wallets/requests/restoreWallet.js index ecee146f25..462e553f02 100644 --- a/source/renderer/app/api/wallets/requests/restoreWallet.js +++ b/source/renderer/app/api/wallets/requests/restoreWallet.js @@ -1,14 +1,12 @@ // @flow -import type { AdaWallet, AdaWalletInitData, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { WalletInitData } from './createWallet'; +import type { AdaWallet } from '../types'; import { request } from '../../utils/request'; -export type RestoreWalletParams = { - walletInitData: AdaWalletInitData -}; - export const restoreWallet = ( config: RequestConfig, - { walletInitData }: RestoreWalletParams + { walletInitData }: { walletInitData: WalletInitData } ): Promise => ( request({ hostname: 'localhost', diff --git a/source/renderer/app/api/wallets/requests/updateWallet.js b/source/renderer/app/api/wallets/requests/updateWallet.js index 4f7dac5661..34fbd67039 100644 --- a/source/renderer/app/api/wallets/requests/updateWallet.js +++ b/source/renderer/app/api/wallets/requests/updateWallet.js @@ -1,5 +1,6 @@ // @flow -import type { AdaWallet, WalletAssuranceLevel, RequestConfig } from './types'; +import type { RequestConfig } from '../../common/types'; +import type { AdaWallet, WalletAssuranceLevel } from '../types'; import { request } from '../../utils/request'; export type UpdateWalletParams = { From 3bf54412683ade579d1f75f6237559cdba392178 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:28:42 -0700 Subject: [PATCH 21/29] [DDW-321] Updates name of flow types in patchAdaApi.js --- source/renderer/app/api/utils/patchAdaApi.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/renderer/app/api/utils/patchAdaApi.js b/source/renderer/app/api/utils/patchAdaApi.js index ac4b6ca25d..4bd4caf4a4 100644 --- a/source/renderer/app/api/utils/patchAdaApi.js +++ b/source/renderer/app/api/utils/patchAdaApi.js @@ -1,11 +1,9 @@ import BigNumber from 'bignumber.js'; -import { Logger } from '../../../../common/logging'; -import { RedeemAdaError } from '../errors'; import AdaApi from '../api'; -import type { - RedeemAdaParams, - RedeemPaperVendedAdaParams -} from '../types'; +import { Logger } from '../../../../common/logging'; +import { RedeemAdaError } from '../transactions/errors'; +import type { RedeemAdaParams } from '../transactions/requests/redeemAda'; +import type { RedeemPaperVendedAdaParams } from '../transactions/requests/redeemPaperVendedAda'; // ========== LOGGING ========= From 43f4ae497def6245003e650f19001615f41b5154 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:29:30 -0700 Subject: [PATCH 22/29] [DDW-321] Updates name of flow types in components --- source/renderer/app/components/wallet/WalletReceive.js | 4 ++-- .../app/components/wallet/transactions/Transaction.js | 2 +- .../components/wallet/transactions/WalletTransactionsList.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/renderer/app/components/wallet/WalletReceive.js b/source/renderer/app/components/wallet/WalletReceive.js index a565d18a81..02721f3727 100644 --- a/source/renderer/app/components/wallet/WalletReceive.js +++ b/source/renderer/app/components/wallet/WalletReceive.js @@ -14,7 +14,7 @@ import ReactToolboxMobxForm from '../../utils/ReactToolboxMobxForm'; import BorderedBox from '../widgets/BorderedBox'; import TinySwitch from '../widgets/forms/TinySwitch'; import iconCopy from '../../assets/images/clipboard-ic.inline.svg'; -import type { AdaAddress } from '../../api/ada/types'; +import type { Addresses } from '../../api/addresses/types'; import globalMessages from '../../i18n/global-messages'; import LocalizableError from '../../i18n/LocalizableError'; import styles from './WalletReceive.scss'; @@ -62,7 +62,7 @@ messages.fieldIsRequired = globalMessages.fieldIsRequired; type Props = { walletAddress: string, isWalletAddressUsed: boolean, - walletAddresses: Array, + walletAddresses: Addresses, onGenerateAddress: Function, onCopyAddress: Function, isSidebarExpanded: boolean, diff --git a/source/renderer/app/components/wallet/transactions/Transaction.js b/source/renderer/app/components/wallet/transactions/Transaction.js index c32f9b3f28..8249848a5e 100644 --- a/source/renderer/app/components/wallet/transactions/Transaction.js +++ b/source/renderer/app/components/wallet/transactions/Transaction.js @@ -14,7 +14,7 @@ import WalletTransaction, transactionTypes } from '../../../domains/WalletTransaction'; import { environmentSpecificMessages } from '../../../i18n/global-messages'; -import type { TransactionState } from '../../../api/ada/types'; +import type { TransactionState } from '../../../api/transactions/types'; import environment from '../../../../../common/environment'; import { getNetworkExplorerUrl } from '../../../utils/network'; diff --git a/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js b/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js index 54e4eb4478..35eaa00471 100644 --- a/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js +++ b/source/renderer/app/components/wallet/transactions/WalletTransactionsList.js @@ -10,7 +10,7 @@ import styles from './WalletTransactionsList.scss'; import Transaction from './Transaction'; import WalletTransaction from '../../../domains/WalletTransaction'; import LoadingSpinner from '../../widgets/LoadingSpinner'; -import type { WalletAssuranceMode } from '../../../api/ada/types'; +import type { WalletAssuranceMode } from '../../../api/wallets/types'; const messages = defineMessages({ today: { From 5eb9aa10b2d1dbc9b8b205b7ea6dd058fde35cd6 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:30:04 -0700 Subject: [PATCH 23/29] [DDW-321] Updates name of flow types in domains --- source/renderer/app/domains/Wallet.js | 2 +- source/renderer/app/domains/WalletTransaction.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/renderer/app/domains/Wallet.js b/source/renderer/app/domains/Wallet.js index 4d31685319..ba2b95fdad 100644 --- a/source/renderer/app/domains/Wallet.js +++ b/source/renderer/app/domains/Wallet.js @@ -6,7 +6,7 @@ import type { WalletAssuranceMode, WalletSyncState, SyncStateTag -} from '../api/ada/types'; +} from '../api/wallets/types'; export const WalletAssuranceModeOptions: { NORMAL: WalletAssuranceLevel, STRICT: WalletAssuranceLevel, diff --git a/source/renderer/app/domains/WalletTransaction.js b/source/renderer/app/domains/WalletTransaction.js index 3846247c07..7a6a6e1209 100644 --- a/source/renderer/app/domains/WalletTransaction.js +++ b/source/renderer/app/domains/WalletTransaction.js @@ -1,10 +1,13 @@ // @flow import { observable } from 'mobx'; import BigNumber from 'bignumber.js'; -import type { WalletAssuranceMode, TxnAssuranceLevel, TransactionState } from '../api/transactions/types'; - -export type TrasactionAddresses = { from: Array, to: Array }; -export type TransactionType = 'card' | 'expend' | 'income' | 'exchange'; +import type { WalletAssuranceMode } from '../api/wallets/types'; +import type { + TxnAssuranceLevel, + TransactionState, + TrasactionAddresses, + TransactionType +} from '../api/transactions/types'; export const transactionStates: { PENDING: TransactionState, FAILED: TransactionState, OK: TransactionState, From cde2038cb51320c28d89eb250e2ecd7b9e72f8c4 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:30:26 -0700 Subject: [PATCH 24/29] [DDW-321] Updates name of flow types in stores --- source/renderer/app/stores/NetworkStatusStore.js | 2 +- source/renderer/app/stores/TransactionsStore.js | 2 +- .../renderer/app/stores/ada/AdaRedemptionStore.js | 13 +++++++------ .../app/stores/ada/AdaWalletSettingsStore.js | 3 +-- source/renderer/app/stores/ada/AdaWalletsStore.js | 3 +-- source/renderer/app/stores/ada/AddressesStore.js | 13 ++++++------- source/renderer/app/stores/ada/NodeUpdateStore.js | 7 +++---- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/source/renderer/app/stores/NetworkStatusStore.js b/source/renderer/app/stores/NetworkStatusStore.js index 18f4cb4a07..033d0f82a3 100644 --- a/source/renderer/app/stores/NetworkStatusStore.js +++ b/source/renderer/app/stores/NetworkStatusStore.js @@ -4,7 +4,7 @@ import moment from 'moment'; import Store from './lib/Store'; import Request from './lib/LocalizedRequest'; import { Logger } from '../../../common/logging'; -import type { GetNetworkStatusResponse } from '../api/common'; +import type { GetNetworkStatusResponse } from '../api/nodes/types'; // To avoid slow reconnecting on store reset, we cache the most important props let cachedState = null; diff --git a/source/renderer/app/stores/TransactionsStore.js b/source/renderer/app/stores/TransactionsStore.js index b8a9ebfa7f..04978ae750 100644 --- a/source/renderer/app/stores/TransactionsStore.js +++ b/source/renderer/app/stores/TransactionsStore.js @@ -4,7 +4,7 @@ import _ from 'lodash'; import Store from './lib/Store'; import CachedRequest from './lib/LocalizedCachedRequest'; import WalletTransaction from '../domains/WalletTransaction'; -import type { GetTransactionsResponse } from '../api/common'; +import type { GetTransactionsResponse } from '../api/transactions/types'; import environment from '../../../common/environment'; export type TransactionSearchOptionsStruct = { diff --git a/source/renderer/app/stores/ada/AdaRedemptionStore.js b/source/renderer/app/stores/ada/AdaRedemptionStore.js index 211c7cafe3..01e7c7d7db 100644 --- a/source/renderer/app/stores/ada/AdaRedemptionStore.js +++ b/source/renderer/app/stores/ada/AdaRedemptionStore.js @@ -2,9 +2,9 @@ import { action, computed, observable, runInAction } from 'mobx'; import { ipcRenderer } from 'electron'; import { isString } from 'lodash'; -import BigNumber from 'bignumber.js'; import Store from '../lib/Store'; import Request from '../lib/LocalizedRequest'; +import WalletTransaction from '../../domains/WalletTransaction'; import { Logger } from '../../../../common/logging'; import { encryptPassphrase } from '../../api/utils'; import { matchRoute } from '../../utils/routing'; @@ -19,7 +19,8 @@ import LocalizableError from '../../i18n/LocalizableError'; import { ROUTES } from '../../routes-config'; import type { RedemptionTypeChoices } from '../../types/redemptionTypes'; import { ADA_REDEMPTION_TYPES } from '../../types/redemptionTypes'; -import type { AdaTransaction, RedeemAdaParams, RedeemPaperVendedAdaParams } from '../../api/ada/types'; +import type { RedeemAdaParams } from '../../api/transactions/requests/redeemAda'; +import type { RedeemPaperVendedAdaParams } from '../../api/transactions/requests/redeemPaperVendedAda'; export default class AdaRedemptionStore extends Store { @@ -219,11 +220,11 @@ export default class AdaRedemptionStore extends Store { redemptionCode, spendingPassword: spendingPassword && encryptPassphrase(spendingPassword) }) - .then(action((transaction: AdaTransaction) => { + .then(action((transaction: WalletTransaction) => { this._reset(); this.actions.ada.adaRedemption.adaSuccessfullyRedeemed.trigger({ walletId, - amount: new BigNumber(transaction.amount).toFormat(DECIMAL_PLACES_IN_ADA), + amount: transaction.amount.toFormat(DECIMAL_PLACES_IN_ADA) }); })) .catch(action((error) => { @@ -242,7 +243,7 @@ export default class AdaRedemptionStore extends Store { if (!accountIndex) throw new Error('Active account required before redeeming Ada.'); try { - const transaction: AdaTransaction = await this.redeemPaperVendedAdaRequest.execute({ + const transaction: WalletTransaction = await this.redeemPaperVendedAdaRequest.execute({ mnemonics: this.passPhrase && this.passPhrase.split(' '), accountIndex, redemptionCode: shieldedRedemptionKey, @@ -251,7 +252,7 @@ export default class AdaRedemptionStore extends Store { this._reset(); this.actions.ada.adaRedemption.adaSuccessfullyRedeemed.trigger({ walletId, - amount: new BigNumber(transaction.amount).toFormat(DECIMAL_PLACES_IN_ADA), + amount: transaction.amount.toFormat(DECIMAL_PLACES_IN_ADA) }); } catch (error) { runInAction(() => this.error = error); diff --git a/source/renderer/app/stores/ada/AdaWalletSettingsStore.js b/source/renderer/app/stores/ada/AdaWalletSettingsStore.js index 354361c265..9205992799 100644 --- a/source/renderer/app/stores/ada/AdaWalletSettingsStore.js +++ b/source/renderer/app/stores/ada/AdaWalletSettingsStore.js @@ -5,14 +5,13 @@ import WalletSettingsStore from '../WalletSettingsStore'; import Wallet from '../../domains/Wallet'; import Request from '../lib/LocalizedRequest'; import type { WalletExportToFileParams } from '../../actions/ada/wallet-settings-actions'; -import type { ExportWalletToFileResponse } from '../../api/ada/index'; export default class EtcWalletSettingsStore extends WalletSettingsStore { /* eslint-disable max-len */ @observable updateWalletRequest: Request = new Request(this.api.ada.updateWallet); @observable updateWalletPasswordRequest: Request = new Request(this.api.ada.updateWalletPassword); - @observable exportWalletToFileRequest: Request = new Request(this.api.ada.exportWalletToFile); + @observable exportWalletToFileRequest: Request> = new Request(this.api.ada.exportWalletToFile); /* eslint-enable max-len */ setup() { diff --git a/source/renderer/app/stores/ada/AdaWalletsStore.js b/source/renderer/app/stores/ada/AdaWalletsStore.js index 5b93f0d79a..12b67671f9 100644 --- a/source/renderer/app/stores/ada/AdaWalletsStore.js +++ b/source/renderer/app/stores/ada/AdaWalletsStore.js @@ -13,14 +13,13 @@ import { mnemonicToSeedHex } from '../../utils/crypto'; import { downloadPaperWalletCertificate } from '../../utils/paperWalletPdfGenerator'; import type { walletExportTypeChoices } from '../../types/walletExportTypes'; import type { WalletImportFromFileParams } from '../../actions/ada/wallets-actions'; -import type { ImportWalletFromFileResponse } from '../../api/ada/index'; export default class AdaWalletsStore extends WalletStore { // REQUESTS /* eslint-disable max-len */ @observable walletsRequest: Request> = new Request(this.api.ada.getWallets); - @observable importFromFileRequest: Request = new Request(this.api.ada.importWalletFromFile); + @observable importFromFileRequest: Request = new Request(this.api.ada.importWalletFromFile); @observable createWalletRequest: Request = new Request(this.api.ada.createWallet); @observable getWalletAddressesRequest: Request = new Request(this.api.ada.getAddresses); @observable deleteWalletRequest: Request = new Request(this.api.ada.deleteWallet); diff --git a/source/renderer/app/stores/ada/AddressesStore.js b/source/renderer/app/stores/ada/AddressesStore.js index 5c97955b73..d1047d358e 100644 --- a/source/renderer/app/stores/ada/AddressesStore.js +++ b/source/renderer/app/stores/ada/AddressesStore.js @@ -4,13 +4,12 @@ import { observable, computed, action, runInAction } from 'mobx'; import Store from '../lib/Store'; import CachedRequest from '../lib/LocalizedCachedRequest'; import Request from '../lib/LocalizedRequest'; -import type { AdaAddress } from '../../api/ada/types'; +import type { Address, Addresses, GetAddressesResponse } from '../../api/addresses/types'; import LocalizableError from '../../i18n/LocalizableError'; -import type { GetAddressesResponse, CreateAddressResponse } from '../../api/ada/index'; export default class AddressesStore extends Store { - @observable lastGeneratedAddress: ?AdaAddress = null; + @observable lastGeneratedAddress: ?Address = null; @observable addressesRequests: Array<{ walletId: string, allRequest: CachedRequest @@ -19,7 +18,7 @@ export default class AddressesStore extends Store { // REQUESTS /* eslint-disable max-len */ - @observable createAddressRequest: Request = new Request(this.api.ada.createAddress); + @observable createAddressRequest: Request
= new Request(this.api.ada.createAddress); /* eslint-disable max-len */ setup() { @@ -33,7 +32,7 @@ export default class AddressesStore extends Store { const { walletId, spendingPassword } = params; const accountIndex = await this.getAccountIndexByWalletId(walletId); - const address: ?CreateAddressResponse = await this.createAddressRequest.execute({ + const address: ?Address = await this.createAddressRequest.execute({ accountIndex, spendingPassword, walletId }).promise; @@ -49,7 +48,7 @@ export default class AddressesStore extends Store { } }; - @computed get all(): Array { + @computed get all(): Addresses { const wallet = this.stores.ada.wallets.active; if (!wallet) return []; const result = this._getAddressesAllRequest(wallet.id).result; @@ -63,7 +62,7 @@ export default class AddressesStore extends Store { return result ? result.addresses.length > 0 : false; } - @computed get active(): ?AdaAddress { + @computed get active(): ?Address { if (this.lastGeneratedAddress) return this.lastGeneratedAddress; const wallet = this.stores.ada.wallets.active; if (!wallet) return; diff --git a/source/renderer/app/stores/ada/NodeUpdateStore.js b/source/renderer/app/stores/ada/NodeUpdateStore.js index 8f1e05bdb2..dd17991e4f 100644 --- a/source/renderer/app/stores/ada/NodeUpdateStore.js +++ b/source/renderer/app/stores/ada/NodeUpdateStore.js @@ -2,8 +2,7 @@ import { observable, action, runInAction } from 'mobx'; import Store from '../lib/Store'; import Request from '../lib/LocalizedRequest'; -import type { NodeSoftware } from '../../api/ada/types'; -import type { PostponeUpdateResponse, ApplyUpdateResponse } from '../../api/ada/index'; +import type { NodeSoftware } from '../../api/nodes/types'; import { NODE_UPDATE_POLL_INTERVAL } from '../../config/timingConfig'; export default class NodeUpdateStore extends Store { @@ -17,8 +16,8 @@ export default class NodeUpdateStore extends Store { // REQUESTS /* eslint-disable max-len */ @observable nextUpdateRequest: Request = new Request(this.api.ada.nextUpdate); - @observable postponeUpdateRequest: Request = new Request(this.api.ada.postponeUpdate); - @observable applyUpdateRequest: Request = new Request(this.api.ada.applyUpdate); + @observable postponeUpdateRequest: Request> = new Request(this.api.ada.postponeUpdate); + @observable applyUpdateRequest: Request> = new Request(this.api.ada.applyUpdate); /* eslint-disable max-len */ setup() { From 058dee443f9248d92366ca0563ebd370e807e498 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Fri, 14 Sep 2018 01:31:56 -0700 Subject: [PATCH 25/29] [DDW-321] Updates name of flow types and request names in api.js - previously api/ada/index.js --- source/renderer/app/api/api.js | 363 +++++++++++++++------------------ 1 file changed, 163 insertions(+), 200 deletions(-) diff --git a/source/renderer/app/api/api.js b/source/renderer/app/api/api.js index b67873de19..5a121f4d9f 100644 --- a/source/renderer/app/api/api.js +++ b/source/renderer/app/api/api.js @@ -3,28 +3,37 @@ import { split, get } from 'lodash'; import { action } from 'mobx'; import { ipcRenderer } from 'electron'; import BigNumber from 'bignumber.js'; -import { Logger, stringifyData, stringifyError } from '../../../common/logging'; -import patchAdaApi from './utils/patchAdaApi'; + +// domains import Wallet from '../domains/Wallet'; import WalletTransaction, { transactionTypes } from '../domains/WalletTransaction'; import WalletAddress from '../domains/WalletAddress'; -import { isValidMnemonic } from '../../../common/decrypt'; -import { isValidRedemptionKey, isValidPaperVendRedemptionKey } from '../../../common/redemption-key-validation'; -import { LOVELACES_PER_ADA, MAX_TRANSACTIONS_PER_PAGE } from '../config/numbersConfig'; + +// Accounts requests import { getAccounts } from './accounts/requests/getAccounts'; + +// Addresses requests import { getAddress } from './addresses/requests/getAddress'; import { createAddress } from './addresses/requests/createAddress'; -import { resetWalletState } from './wallets/requests/resetWalletState'; + +// Common requests import { sendBugReport } from './common/requests/sendBugReport'; + +// Nodes requests import { applyNodeUpdate } from './nodes/requests/applyNodeUpdate'; import { getNodeInfo } from './nodes/requests/getNodeInfo'; import { getNextNodeUpdate } from './nodes/requests/getNextNodeUpdate'; import { postponeNodeUpdate } from './nodes/requests/postponeNodeUpdate'; + +// Transactions requests import { getTransactionFee } from './transactions/requests/getTransactionFee'; import { getTransactionHistory } from './transactions/requests/getTransactionHistory'; import { createTransaction } from './transactions/requests/createTransaction'; import { redeemAda } from './transactions/requests/redeemAda'; -import { redeemAdaPaperVend } from './transactions/requests/redeemAdaPaperVend'; +import { redeemPaperVendedAda } from './transactions/requests/redeemPaperVendedAda'; + +// Wallets requests +import { resetWalletState } from './wallets/requests/resetWalletState'; import { changeSpendingPassword } from './wallets/requests/changeSpendingPassword'; import { deleteWallet } from './wallets/requests/deleteWallet'; import { exportWalletAsJSON } from './wallets/requests/exportWalletAsJSON'; @@ -34,7 +43,20 @@ import { importWalletAsKey } from './wallets/requests/importWalletAsKey'; import { createWallet } from './wallets/requests/createWallet'; import { restoreWallet } from './wallets/requests/restoreWallet'; import { updateWallet } from './wallets/requests/updateWallet'; + +// utility functions +import patchAdaApi from './utils/patchAdaApi'; +import { isValidMnemonic } from '../../../common/decrypt'; import { utcStringToDate, encryptPassphrase } from './utils'; +import { + Logger, + stringifyData, + stringifyError +} from '../../../common/logging'; +import { + isValidRedemptionKey, + isValidPaperVendRedemptionKey +} from '../utils/redemption-key-validation'; import { unscrambleMnemonics, scrambleMnemonics, @@ -42,133 +64,94 @@ import { generateAdditionalMnemonics } from './utils/mnemonics'; +// config constants +import { + LOVELACES_PER_ADA, + MAX_TRANSACTIONS_PER_PAGE +} from '../config/numbersConfig'; +import { + ADA_CERTIFICATE_MNEMONIC_LENGTH, + ADA_REDEMPTION_PASSPHRASE_LENGTH, + WALLET_RECOVERY_PHRASE_WORD_COUNT +} from '../config/cryptoConfig'; + +// Accounts types +import type { Accounts } from './accounts/types'; + +// Addresses Types +import type { + Address, + GetAddressesRequest, + CreateAddressRequest, + GetAddressesResponse +} from './addresses/types'; + +// Common Types import type { - AdaAddress, - AdaAddresses, - AdaAccounts, - AdaTransaction, - AdaTransactions, - AdaTransactionFee, - AdaWallet, - AdaWallets, - WalletAssuranceLevel, - RedeemAdaParams, - RedeemPaperVendedAdaParams, RequestConfig, + SendBugReportRequest +} from './common/types'; + +// Nodes Types +import type { NodeInfo, NodeSoftware, -} from './types'; + GetNetworkStatusResponse +} from './nodes/types'; + +// Transactions Types +import type { RedeemAdaParams } from './transactions/requests/redeemAda'; +import type { RedeemPaperVendedAdaParams } from './transactions/requests/redeemPaperVendedAda'; import type { + Transaction, + Transactions, + TransactionFee, + TransactionRequest, + GetTransactionsRequest, + GetTransactionsResponse +} from './transactions/types'; + +// Wallets Types +import type { + AdaWallet, + AdaWallets, CreateWalletRequest, DeleteWalletRequest, - GetNetworkStatusResponse, - GetTransactionsRequest, - GetTransactionsResponse, RestoreWalletRequest, - SendBugReportRequest, UpdateWalletPasswordRequest, -} from '../common'; + ExportWalletToFileRequest, + GetWalletCertificateRecoveryPhraseRequest, + GetWalletRecoveryPhraseFromCertificateRequest, + ImportWalletFromKeyRequest, + ImportWalletFromFileRequest, + UpdateWalletRequest +} from './wallets/types'; + +// Common errors import { GenericApiError, IncorrectWalletPasswordError, - WalletAlreadyRestoredError, ReportRequestError, InvalidMnemonicError -} from '../common'; +} from './common/errors'; + +// Wallets errors +import { + WalletAlreadyRestoredError, + WalletAlreadyImportedError, + WalletFileImportError +} from './wallets/errors'; + +// Transactions errors import { AllFundsAlreadyAtReceiverAddressError, NotAllowedToSendMoneyToRedeemAddressError, NotAllowedToSendMoneyToSameAddressError, NotEnoughFundsForTransactionFeesError, NotEnoughMoneyToSendError, - RedeemAdaError, - WalletAlreadyImportedError, - WalletFileImportError, -} from './errors'; -import { - ADA_CERTIFICATE_MNEMONIC_LENGHT, - ADA_REDEMPTION_PASSPHRASE_LENGHT, - WALLET_RECOVERY_PHRASE_WORD_COUNT -} from '../../config/cryptoConfig'; - -/** - * The api layer that is used for all requests to the - * cardano backend when working with the ADA coin. - */ - -// ADA specific Request / Response params -export type GetAddressesResponse = { - accountIndex: ?number, - addresses: AdaAddresses, -}; - -export type GetAddressesRequest = { - walletId: string, -}; -export type CreateAddressResponse = AdaAddress; -export type CreateAddressRequest = { - spendingPassword?: string, - accountIndex: number, - walletId: string, -}; -export type UpdateWalletRequest = { - walletId: string, - assuranceLevel: WalletAssuranceLevel, - name: string -}; -export type ImportWalletFromKeyRequest = { - filePath: string, - spendingPassword: ?string, -}; -export type ImportWalletFromKeyResponse = AdaWallet; -export type ImportWalletFromFileRequest = { - filePath: string, - spendingPassword: ?string, - walletName: ?string, -}; -export type ImportWalletFromFileResponse = AdaWallet; -export type PostponeUpdateResponse = Promise; -export type ApplyUpdateResponse = Promise; -export type TransactionRequest = { - accountIndex: number, - walletId: string, - address: string, - amount: number, - spendingPassword?: ?string, -}; -export type TransactionFeeResponse = BigNumber; -export type ExportWalletToFileRequest = { - walletId: string, - filePath: string, - password: ?string -}; -export type CreateTransactionRequest = TransactionRequest; -export type TransactionFeeRequest = TransactionRequest; -export type ExportWalletToFileResponse = []; -export type GetWalletCertificateRecoveryPhraseRequest = { - passphrase: string, - input: string, -}; -export type GetWalletRecoveryPhraseFromCertificateRequest = { - passphrase: string, - scrambledInput: string, -}; - -// const notYetImplemented = () => new Promise((_, reject) => { -// reject(new ApiMethodNotYetImplementedError()); -// }); + RedeemAdaError +} from './transactions/errors'; -// Commented out helper code for testing async APIs -// (async () => { -// const result = await ClientApi.nextUpdate(); -// console.log('nextUpdate', result); -// })(); - -// Commented out helper code for testing sync APIs -// (() => { -// const result = ClientApi.isValidRedeemCode('HSoXEnt9X541uHvtzBpy8vKfTo1C9TkAX3wat2c6ikg='); -// console.log('isValidRedeemCode', result); -// })(); export default class AdaApi { @@ -188,7 +171,7 @@ export default class AdaApi { try { const response: AdaWallets = await getWallets(this.config); Logger.debug('AdaApi::getWallets success: ' + stringifyData(response)); - return response.map(data => _createWalletFromServerV1Data(data)); + return response.map(data => _createWalletFromServerData(data)); } catch (error) { Logger.error('AdaApi::getWallets error: ' + stringifyError(error)); throw new GenericApiError(); @@ -199,7 +182,7 @@ export default class AdaApi { Logger.debug('AdaApi::getAddresses called: ' + stringifyData(request)); const { walletId } = request; try { - const accounts: AdaAccounts = await getAccounts(this.config, { walletId }); + const accounts: Accounts = await getAccounts(this.config, { walletId }); Logger.debug('AdaApi::getAddresses success: ' + stringifyData(accounts)); if (!accounts || !accounts.length) { @@ -220,7 +203,11 @@ export default class AdaApi { getTransactions = async (request: GetTransactionsRequest): Promise => { Logger.debug('AdaApi::searchHistory called: ' + stringifyData(request)); const { walletId, skip, limit } = request; - const accounts: AdaAccounts = await getAccounts(this.config, { walletId }); + const accounts: Accounts = await getAccounts(this.config, { walletId }); + + if (!accounts.length || !accounts[0].index) { + return new Promise(resolve => resolve({ transactions: [], total: 0 })); + } let perPage = limit; if (limit === null || limit > MAX_TRANSACTIONS_PER_PAGE) { @@ -234,14 +221,11 @@ export default class AdaApi { wallet_id: walletId, sort_by: 'DES[created_at]', }; - const pagesToBeLoaded = Math.ceil(limit / params.per_page); try { - const { - data: history, - meta - }: AdaTransactions = await getTransactionHistory(this.config, params); + const response: Transactions = await getTransactionHistory(this.config, params); + const { meta, data: txnHistory } = response; const { totalPages } = meta.pagination; const hasMultiplePages = (totalPages > 1 && limit > MAX_TRANSACTIONS_PER_PAGE); @@ -253,17 +237,15 @@ export default class AdaApi { for (page; (hasNextPage() && shouldLoadNextPage()); page++) { const { data: pageHistory } = await getTransactionHistory(this.config, Object.assign(params, { page })); - history.push(...pageHistory); + txnHistory.push(...pageHistory); } - if (limit !== null) history.splice(limit); + if (limit !== null) txnHistory.splice(limit); } - const transactions = history.map(data => _createTransactionFromServerDataV1(data)); - Logger.debug('AdaApi::searchHistory success: ' + stringifyData(history)); - return new Promise((resolve) => resolve({ - transactions, - total: transactions.length, - })); + const transactions = txnHistory.map(txn => _createTransactionFromServerData(txn)); + const total = transactions.length; + Logger.debug('AdaApi::searchHistory success: ' + stringifyData(txnHistory)); + return new Promise(resolve => resolve({ transactions, total })); } catch (error) { Logger.error('AdaApi::searchHistory error: ' + stringifyError(error)); throw new GenericApiError(); @@ -272,7 +254,7 @@ export default class AdaApi { createWallet = async (request: CreateWalletRequest): Promise => { Logger.debug('AdaApi::createWallet called'); - const { name, mnemonic, spendingPassword: passwordString } = request; + const { name, mnemonic, spendingPassword } = request; const assuranceLevel = 'normal'; try { const walletInitData = { @@ -280,11 +262,11 @@ export default class AdaApi { backupPhrase: split(mnemonic, ' '), assuranceLevel, name, - spendingPassword: passwordString ? encryptPassphrase(passwordString) : null, + spendingPassword: spendingPassword ? encryptPassphrase(spendingPassword) : null, }; const wallet: AdaWallet = await createWallet(this.config, { walletInitData }); Logger.debug('AdaApi::createWallet success'); - return _createWalletFromServerV1Data(wallet); + return _createWalletFromServerData(wallet); } catch (error) { Logger.error('AdaApi::createWallet error: ' + stringifyError(error)); throw new GenericApiError(); @@ -305,7 +287,7 @@ export default class AdaApi { }; createTransaction = async ( - request: CreateTransactionRequest + request: TransactionRequest ): Promise => { Logger.debug('AdaApi::createTransaction called'); const { accountIndex, walletId, address, amount, spendingPassword: passwordString } = request; @@ -325,9 +307,9 @@ export default class AdaApi { groupingPolicy: 'OptimizeForSecurity', spendingPassword, }; - const response: AdaTransaction = await createTransaction(this.config, { data }); + const response: Transaction = await createTransaction(this.config, { data }); Logger.debug('AdaApi::createTransaction success: ' + stringifyData(response)); - return _createTransactionFromServerDataV1(response); + return _createTransactionFromServerData(response); } catch (error) { Logger.debug('AdaApi::createTransaction error: ' + stringifyError(error)); // eslint-disable-next-line max-len @@ -348,8 +330,8 @@ export default class AdaApi { }; calculateTransactionFee = async ( - request: TransactionFeeRequest - ): Promise => { + request: TransactionRequest + ): Promise => { Logger.debug('AdaApi::calculateTransactionFee called'); const { accountIndex, walletId, address, amount, spendingPassword } = request; try { @@ -367,7 +349,7 @@ export default class AdaApi { groupingPolicy: 'OptimizeForSecurity', spendingPassword, }; - const response: AdaTransactionFee = await getTransactionFee(this.config, { data }); + const response: TransactionFee = await getTransactionFee(this.config, { data }); Logger.debug('AdaApi::calculateTransactionFee success: ' + stringifyData(response)); return _createTransactionFeeFromServerData(response); } catch (error) { @@ -383,12 +365,12 @@ export default class AdaApi { } }; - createAddress = async (request: CreateAddressRequest): Promise => { + createAddress = async (request: CreateAddressRequest): Promise
=> { Logger.debug('AdaApi::createAddress called'); const { spendingPassword: passwordString, accountIndex, walletId } = request; const spendingPassword = passwordString ? encryptPassphrase(passwordString) : ''; try { - const address: AdaAddress = await createAddress( + const address: Address = await createAddress( this.config, { spendingPassword, accountIndex, walletId } ); Logger.debug('AdaApi::createAddress success: ' + stringifyData(address)); @@ -405,7 +387,7 @@ export default class AdaApi { async isValidAddress(address: string): Promise { Logger.debug('AdaApi::isValidAdaAddress called'); try { - const response: AdaAddress = await getAddress(this.config, { address }); + const response: Address = await getAddress(this.config, { address }); Logger.debug(`AdaApi::isValidAdaAddress success: ${stringifyData(response)}`); return true; } catch (error) { @@ -425,11 +407,11 @@ export default class AdaApi { ); isValidRedemptionMnemonic = (mnemonic: string): boolean => ( - isValidMnemonic(mnemonic, ADA_REDEMPTION_PASSPHRASE_LENGHT) + isValidMnemonic(mnemonic, ADA_REDEMPTION_PASSPHRASE_LENGTH) ); isValidCertificateMnemonic = (mnemonic: string): boolean => ( - mnemonic.split(' ').length === ADA_CERTIFICATE_MNEMONIC_LENGHT + mnemonic.split(' ').length === ADA_CERTIFICATE_MNEMONIC_LENGTH ); getWalletRecoveryPhrase(): Promise> { @@ -465,13 +447,10 @@ export default class AdaApi { request: GetWalletCertificateRecoveryPhraseRequest ): Promise> { Logger.debug('AdaApi::getWalletCertificateRecoveryPhrase called'); - const { passphrase, input } = request; + const { passphrase, input: scrambledInput } = request; try { const response: Promise> = new Promise( - (resolve) => resolve(scrambleMnemonics({ - passphrase, - scrambledInput: input, - })) + (resolve) => resolve(scrambleMnemonics({ passphrase, scrambledInput })) ); Logger.debug('AdaApi::getWalletCertificateRecoveryPhrase success'); return response; @@ -530,7 +509,7 @@ export default class AdaApi { importWalletFromKey = async ( request: ImportWalletFromKeyRequest - ): Promise => { + ): Promise => { Logger.debug('AdaApi::importWalletFromKey called'); try { const importedWallet: AdaWallet = await importWalletAsKey(this.config, request); @@ -547,7 +526,7 @@ export default class AdaApi { importWalletFromFile = async ( request: ImportWalletFromFileRequest - ): Promise => { + ): Promise => { Logger.debug('AdaApi::importWalletFromFile called'); const { filePath } = request; const isKeyFile = filePath.split('.').pop().toLowerCase() === 'key'; @@ -568,12 +547,12 @@ export default class AdaApi { } }; - async redeemAda(request: RedeemAdaParams): Promise { + async redeemAda(request: RedeemAdaParams): Promise { Logger.debug('AdaApi::redeemAda called'); try { - const transaction: AdaTransaction = await redeemAda(this.config, request); + const transaction: Transaction = await redeemAda(this.config, request); Logger.debug('AdaApi::redeemAda success'); - return _createTransactionFromServerDataV1(transaction); + return _createTransactionFromServerData(transaction); } catch (error) { Logger.debug('AdaApi::redeemAda error: ' + stringifyError(error)); if (error.message.includes('Passphrase doesn\'t match')) { @@ -585,12 +564,12 @@ export default class AdaApi { async redeemPaperVendedAda( request: RedeemPaperVendedAdaParams - ): Promise { + ): Promise { Logger.debug('AdaApi::redeemAdaPaperVend called'); try { - const transaction: AdaTransaction = await redeemAdaPaperVend(this.config, request); + const transaction: Transaction = await redeemPaperVendedAda(this.config, request); Logger.debug('AdaApi::redeemAdaPaperVend success'); - return _createTransactionFromServerDataV1(transaction); + return _createTransactionFromServerData(transaction); } catch (error) { Logger.debug('AdaApi::redeemAdaPaperVend error: ' + stringifyError(error)); if (error.message.includes('Passphrase doesn\'t match')) { @@ -600,7 +579,7 @@ export default class AdaApi { } } - async sendBugReport(requestFormData: SendBugReportRequest): Promise<*> { + async sendBugReport(requestFormData: SendBugReportRequest): Promise { Logger.debug('AdaApi::sendBugReport called: ' + stringifyData(requestFormData)); try { await sendBugReport({ requestFormData }); @@ -628,7 +607,7 @@ export default class AdaApi { return null; }; - postponeUpdate = async (): PostponeUpdateResponse => { + postponeUpdate = async (): Promise => { Logger.debug('AdaApi::postponeUpdate called'); try { const response: Promise = await postponeNodeUpdate(this.config); @@ -639,7 +618,7 @@ export default class AdaApi { } }; - applyUpdate = async (): ApplyUpdateResponse => { + applyUpdate = async (): Promise => { Logger.debug('AdaApi::applyUpdate called'); try { const response: Promise = await applyNodeUpdate(this.config); @@ -659,7 +638,7 @@ export default class AdaApi { this.config, { walletId, assuranceLevel, name } ); Logger.debug('AdaApi::updateWallet success: ' + stringifyData(wallet)); - return _createWalletFromServerV1Data(wallet); + return _createWalletFromServerData(wallet); } catch (error) { Logger.error('AdaApi::updateWallet error: ' + stringifyError(error)); throw new GenericApiError(); @@ -686,7 +665,7 @@ export default class AdaApi { exportWalletToFile = async ( request: ExportWalletToFileRequest - ): Promise => { + ): Promise<[]> => { const { walletId, filePath } = request; Logger.debug('AdaApi::exportWalletToFile called'); try { @@ -767,24 +746,31 @@ export default class AdaApi { // ========== TRANSFORM SERVER DATA INTO FRONTEND MODELS ========= const _createWalletFromServerData = action( - 'AdaApi::_createWalletFromServerData', (data: AdaWallet) => ( - new Wallet({ - id: data.id, - amount: BigNumber(data.balance).dividedBy(LOVELACES_PER_ADA), - name: data.name, - assurance: data.assuranceLevel, - hasPassword: data.hasSpendingPassword, - passwordUpdateDate: new Date(`${data.spendingPasswordLastUpdate}Z`), - }) - ) + 'AdaApi::_createWalletFromServerData', (data: AdaWallet) => { + const { + id, balance, name, assuranceLevel, + hasSpendingPassword, spendingPasswordLastUpdate, + syncState, + } = data; + + return new Wallet({ + id, + amount: new BigNumber(balance).dividedBy(LOVELACES_PER_ADA), + name, + assurance: assuranceLevel, + hasPassword: hasSpendingPassword, + passwordUpdateDate: new Date(`${spendingPasswordLastUpdate}Z`), + syncState, + }); + } ); const _createAddressFromServerData = action( 'AdaApi::_createAddressFromServerData', - (address: AdaAddress) => new WalletAddress(address) + (address: Address) => new WalletAddress(address) ); -const _conditionToTxStateV1 = (condition: string) => { +const _conditionToTxState = (condition: string) => { switch (condition) { case 'applying': case 'creating': return 'pending'; @@ -795,8 +781,8 @@ const _conditionToTxStateV1 = (condition: string) => { } }; -const _createTransactionFromServerDataV1 = action( - 'AdaApi::_createTransactionFromServerData', (data: AdaTransaction) => { +const _createTransactionFromServerData = action( + 'AdaApi::_createTransactionFromServerData', (data: Transaction) => { const { id, direction, amount, confirmations, creationTime, inputs, outputs, status } = data; return new WalletTransaction({ id, @@ -810,35 +796,12 @@ const _createTransactionFromServerDataV1 = action( from: inputs.map(({ address }) => address), to: outputs.map(({ address }) => address), }, - state: _conditionToTxStateV1(status.tag), + state: _conditionToTxState(status.tag), }); } ); const _createTransactionFeeFromServerData = action( - 'AdaApi::_createTransactionFeeFromServerData', (data: AdaTransactionFee) => + 'AdaApi::_createTransactionFeeFromServerData', (data: TransactionFee) => new BigNumber(data.estimatedAmount).dividedBy(LOVELACES_PER_ADA) ); - - -// ========== V1 API ========= - -const _createWalletFromServerV1Data = action( - 'AdaApi::_createWalletFromServerV1Data', (data: AdaWallet) => { - const { - id, balance, name, assuranceLevel, - hasSpendingPassword, spendingPasswordLastUpdate, - syncState, - } = data; - - return new Wallet({ - id, - amount: new BigNumber(balance).dividedBy(LOVELACES_PER_ADA), - name, - assurance: assuranceLevel, - hasPassword: hasSpendingPassword, - passwordUpdateDate: new Date(`${spendingPasswordLastUpdate}Z`), - syncState, - }); - } -); From 4f0a74445b7f2ec68498739bfeb44eb4b0b93af9 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 17 Sep 2018 16:17:47 -0700 Subject: [PATCH 26/29] [DDW-321] Deletes file that was added after merge conflict --- source/renderer/app/api/common.js | 137 ------------------------------ 1 file changed, 137 deletions(-) delete mode 100644 source/renderer/app/api/common.js diff --git a/source/renderer/app/api/common.js b/source/renderer/app/api/common.js deleted file mode 100644 index dadf6d6106..0000000000 --- a/source/renderer/app/api/common.js +++ /dev/null @@ -1,137 +0,0 @@ -import { defineMessages } from 'react-intl'; -import LocalizableError from '../i18n/LocalizableError'; -import { WalletTransaction, Wallet } from '../domains/WalletTransaction'; -import type { AdaV1Wallet, ResponseBaseV1 } from './ada/types'; -import globalMessages from '../i18n/global-messages'; - -const messages = defineMessages({ - genericApiError: { - id: 'api.errors.GenericApiError', - defaultMessage: '!!!An error occurred, please try again later.', - description: 'Generic error message.' - }, - incorrectWalletPasswordError: { - id: 'api.errors.IncorrectPasswordError', - defaultMessage: '!!!Incorrect wallet password.', - description: '"Incorrect wallet password." error message.' - }, - walletAlreadyRestoredError: { - id: 'api.errors.WalletAlreadyRestoredError', - defaultMessage: '!!!Wallet you are trying to restore already exists.', - description: '"Wallet you are trying to restore already exists." error message.' - }, - reportRequestError: { - id: 'api.errors.ReportRequestError', - defaultMessage: '!!!There was a problem sending the support request.', - description: '"There was a problem sending the support request." error message' - }, -}); - -export class GenericApiError extends LocalizableError { - constructor({ values = {} }: { values?: Object }) { - super({ - id: messages.genericApiError.id, - defaultMessage: messages.genericApiError.defaultMessage, - values, - }); - } -} - -export class IncorrectWalletPasswordError extends LocalizableError { - constructor() { - super({ - id: messages.incorrectWalletPasswordError.id, - defaultMessage: messages.incorrectWalletPasswordError.defaultMessage, - }); - } -} - -export class WalletAlreadyRestoredError extends LocalizableError { - constructor() { - super({ - id: messages.walletAlreadyRestoredError.id, - defaultMessage: messages.walletAlreadyRestoredError.defaultMessage, - }); - } -} - -export class ReportRequestError extends LocalizableError { - constructor() { - super({ - id: messages.reportRequestError.id, - defaultMessage: messages.reportRequestError.defaultMessage, - }); - } -} - -export class InvalidMnemonicError extends LocalizableError { - constructor() { - super({ - id: globalMessages.invalidMnemonic.id, - defaultMessage: globalMessages.invalidMnemonic.defaultMessage, - }); - } -} - -export type CreateTransactionResponse = WalletTransaction; -export type CreateWalletResponse = Wallet; -export type DeleteWalletResponse = boolean; -export type GetWalletsResponse = Array; -export type GetWalletRecoveryPhraseResponse = Array; -export type RestoreWalletResponse = Wallet; -export type UpdateWalletResponse = { - data: AdaV1Wallet, - ...ResponseBaseV1 -}; -export type UpdateWalletPasswordResponse = boolean; -export type IsValidAddressResponse = boolean; - -export type CreateWalletRequest = { - name: string, - mnemonic: string, - spendingPassword: ?string, -}; - -export type UpdateWalletPasswordRequest = { - walletId: string, - oldPassword?: string, - newPassword: ?string, -}; - -export type DeleteWalletRequest = { - walletId: string, -}; - -export type RestoreWalletRequest = { - recoveryPhrase: string, - walletName: string, - walletPassword: ?string, -}; - -export type GetNetworkStatusResponse = { - subscriptionStatus: Object, - syncProgress: number, - blockchainHeight: number, - localBlockchainHeight: number, - localTimeDifference: ?number, -}; - -export type GetTransactionsRequest = { - walletId: string, - searchTerm: string, - skip: number, - limit: number, -}; - -export type GetTransactionsResponse = { - transactions: Array, - total: number, -}; - -export type SendBugReportRequest = { - email: string, - subject: string, - problem: string, - logs: Array, -}; -export type SendBugReportResponse = any; From c36265c31f36af6f01c69910a322694842d18d21 Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 17 Sep 2018 17:45:20 -0700 Subject: [PATCH 27/29] [DDW-321] Updates CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0780d7866b..31e85992fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Changelog ### Features +- Removes depreciated types, requests, and API methods associated with the V0 API. Within the /api directory, organizes requests, types, and errors into subdirectories based on the categories Accounts, Addresses, Common, Nodes, Transactions, and Wallets.([PR 1088](https://github.com/input-output-hk/daedalus/pull/1088)) - Refactors and improves Network Status Store to use V1 API. ([PR 1081](https://github.com/input-output-hk/daedalus/pull/1081)) - Implemented the V1 API endpoints for redeeming ADA with all types of certificates. Updates ADA redemption API methods, flow types, and variable names to match the V1 nomenclature. ([PR 1080](https://github.com/input-output-hk/daedalus/pull/1080)) - Implements the missing V1 API endpoints for checking if a node update is available and responding to the update by either applying it or postponing it. Adds the V1 endpoint for adaTestReset.js. ([PR 1079](https://github.com/input-output-hk/daedalus/pull/1079)) From 59077fb909e300a850616d43624493eca10df35c Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 17 Sep 2018 17:46:29 -0700 Subject: [PATCH 28/29] [DDW-321] Punctuation fix in CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e85992fa..f20ee01177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Changelog ### Features -- Removes depreciated types, requests, and API methods associated with the V0 API. Within the /api directory, organizes requests, types, and errors into subdirectories based on the categories Accounts, Addresses, Common, Nodes, Transactions, and Wallets.([PR 1088](https://github.com/input-output-hk/daedalus/pull/1088)) +- Removes depreciated types, requests, and API methods associated with the V0 API. Within the /api directory, organizes requests, types, and errors into subdirectories based on the categories Accounts, Addresses, Common, Nodes, Transactions, and Wallets. ([PR 1088](https://github.com/input-output-hk/daedalus/pull/1088)) - Refactors and improves Network Status Store to use V1 API. ([PR 1081](https://github.com/input-output-hk/daedalus/pull/1081)) - Implemented the V1 API endpoints for redeeming ADA with all types of certificates. Updates ADA redemption API methods, flow types, and variable names to match the V1 nomenclature. ([PR 1080](https://github.com/input-output-hk/daedalus/pull/1080)) - Implements the missing V1 API endpoints for checking if a node update is available and responding to the update by either applying it or postponing it. Adds the V1 endpoint for adaTestReset.js. ([PR 1079](https://github.com/input-output-hk/daedalus/pull/1079)) From ce81032e2d0a662333dd3779fd73294b232ea38b Mon Sep 17 00:00:00 2001 From: MarcusHurney Date: Mon, 17 Sep 2018 17:49:33 -0700 Subject: [PATCH 29/29] [DDW-321] Runs translation manager --- .../app/i18n/locales/defaultMessages.json | 269 +++++++++--------- 1 file changed, 137 insertions(+), 132 deletions(-) diff --git a/source/renderer/app/i18n/locales/defaultMessages.json b/source/renderer/app/i18n/locales/defaultMessages.json index e7558414dc..ced9b9aa5d 100644 --- a/source/renderer/app/i18n/locales/defaultMessages.json +++ b/source/renderer/app/i18n/locales/defaultMessages.json @@ -2,87 +2,78 @@ { "descriptors": [ { - "defaultMessage": "!!!This API method is not yet implemented.", - "description": "\"This API method is not yet implemented.\" error message.", - "end": { - "column": 3, - "line": 9 - }, - "file": "source/renderer/app/api/ada/errors.js", - "id": "api.errors.ApiMethodNotYetImplementedError", - "start": { - "column": 35, - "line": 5 - } - }, - { - "defaultMessage": "!!!Wallet you are trying to import already exists.", - "description": "\"Wallet you are trying to import already exists.\" error message.", + "defaultMessage": "!!!An error occurred, please try again later.", + "description": "Generic error message.", "end": { "column": 3, - "line": 14 + "line": 10 }, - "file": "source/renderer/app/api/ada/errors.js", - "id": "api.errors.WalletAlreadyImportedError", + "file": "source/renderer/app/api/common/errors.js", + "id": "api.errors.GenericApiError", "start": { - "column": 30, - "line": 10 + "column": 19, + "line": 6 } }, { - "defaultMessage": "!!!Your ADA could not be redeemed correctly.", - "description": "\"Your ADA could not be redeemed correctly.\" error message.", + "defaultMessage": "!!!Incorrect wallet password.", + "description": "\"Incorrect wallet password.\" error message.", "end": { "column": 3, - "line": 19 + "line": 15 }, - "file": "source/renderer/app/api/ada/errors.js", - "id": "api.errors.RedeemAdaError", + "file": "source/renderer/app/api/common/errors.js", + "id": "api.errors.IncorrectPasswordError", "start": { - "column": 18, - "line": 15 + "column": 32, + "line": 11 } }, { - "defaultMessage": "!!!Wallet could not be imported, please make sure you are providing a correct file.", - "description": "\"Wallet could not be imported, please make sure you are providing a correct file.\" error message.", + "defaultMessage": "!!!There was a problem sending the support request.", + "description": "\"There was a problem sending the support request.\" error message", "end": { "column": 3, - "line": 24 + "line": 20 }, - "file": "source/renderer/app/api/ada/errors.js", - "id": "api.errors.WalletFileImportError", + "file": "source/renderer/app/api/common/errors.js", + "id": "api.errors.ReportRequestError", "start": { - "column": 25, - "line": 20 + "column": 22, + "line": 16 } }, { - "defaultMessage": "!!!Not enough money to make this transaction.", - "description": "\"Not enough money to make this transaction.\" error message.", + "defaultMessage": "!!!This API method is not yet implemented.", + "description": "\"This API method is not yet implemented.\" error message.", "end": { "column": 3, - "line": 29 + "line": 25 }, - "file": "source/renderer/app/api/ada/errors.js", - "id": "api.errors.NotEnoughMoneyToSendError", + "file": "source/renderer/app/api/common/errors.js", + "id": "api.errors.ApiMethodNotYetImplementedError", "start": { - "column": 29, - "line": 25 + "column": 35, + "line": 21 } - }, + } + ], + "path": "source/renderer/app/api/common/errors.json" + }, + { + "descriptors": [ { "defaultMessage": "!!!It's not allowed to send money to the same address you are sending from. Make sure you have enough addresses with money in this account or send to a different address.", "description": "\"It's not allowed to send money to the same address you are sending from.\" error message.", "end": { "column": 3, - "line": 34 + "line": 9 }, - "file": "source/renderer/app/api/ada/errors.js", + "file": "source/renderer/app/api/transactions/errors.js", "id": "api.errors.NotAllowedToSendMoneyToSameAddressError", "start": { "column": 43, - "line": 30 + "line": 5 } }, { @@ -90,13 +81,41 @@ "description": "\"It is not allowed to send money to Ada redemption address.\" error message.", "end": { "column": 3, - "line": 39 + "line": 14 }, - "file": "source/renderer/app/api/ada/errors.js", + "file": "source/renderer/app/api/transactions/errors.js", "id": "api.errors.NotAllowedToSendMoneyToRedeemAddressError", "start": { "column": 45, - "line": 35 + "line": 10 + } + }, + { + "defaultMessage": "!!!Not enough money to make this transaction.", + "description": "\"Not enough money to make this transaction.\" error message.", + "end": { + "column": 3, + "line": 19 + }, + "file": "source/renderer/app/api/transactions/errors.js", + "id": "api.errors.NotEnoughMoneyToSendError", + "start": { + "column": 29, + "line": 15 + } + }, + { + "defaultMessage": "!!!Your ADA could not be redeemed correctly.", + "description": "\"Your ADA could not be redeemed correctly.\" error message.", + "end": { + "column": 3, + "line": 24 + }, + "file": "source/renderer/app/api/transactions/errors.js", + "id": "api.errors.RedeemAdaError", + "start": { + "column": 18, + "line": 20 } }, { @@ -104,13 +123,13 @@ "description": "\"All your funds are already at the address you are trying send money to.\" error message.", "end": { "column": 3, - "line": 44 + "line": 29 }, - "file": "source/renderer/app/api/ada/errors.js", + "file": "source/renderer/app/api/transactions/errors.js", "id": "api.errors.AllFundsAlreadyAtReceiverAddressError", "start": { "column": 41, - "line": 40 + "line": 25 } }, { @@ -118,78 +137,64 @@ "description": "\"Not enough Ada for fees. Try sending a smaller amount.\" error message", "end": { "column": 3, - "line": 49 + "line": 34 }, - "file": "source/renderer/app/api/ada/errors.js", + "file": "source/renderer/app/api/transactions/errors.js", "id": "api.errors.NotEnoughFundsForTransactionFeesError", "start": { "column": 41, - "line": 45 + "line": 30 } } ], - "path": "source/renderer/app/api/ada/errors.json" + "path": "source/renderer/app/api/transactions/errors.json" }, { "descriptors": [ { - "defaultMessage": "!!!An error occurred, please try again later.", - "description": "Generic error message.", - "end": { - "column": 3, - "line": 12 - }, - "file": "source/renderer/app/api/common.js", - "id": "api.errors.GenericApiError", - "start": { - "column": 19, - "line": 8 - } - }, - { - "defaultMessage": "!!!Incorrect wallet password.", - "description": "\"Incorrect wallet password.\" error message.", + "defaultMessage": "!!!Wallet you are trying to restore already exists.", + "description": "\"Wallet you are trying to restore already exists.\" error message.", "end": { "column": 3, - "line": 17 + "line": 9 }, - "file": "source/renderer/app/api/common.js", - "id": "api.errors.IncorrectPasswordError", + "file": "source/renderer/app/api/wallets/errors.js", + "id": "api.errors.WalletAlreadyRestoredError", "start": { - "column": 32, - "line": 13 + "column": 30, + "line": 5 } }, { - "defaultMessage": "!!!Wallet you are trying to restore already exists.", - "description": "\"Wallet you are trying to restore already exists.\" error message.", + "defaultMessage": "!!!Wallet you are trying to import already exists.", + "description": "\"Wallet you are trying to import already exists.\" error message.", "end": { "column": 3, - "line": 22 + "line": 14 }, - "file": "source/renderer/app/api/common.js", - "id": "api.errors.WalletAlreadyRestoredError", + "file": "source/renderer/app/api/wallets/errors.js", + "id": "api.errors.WalletAlreadyImportedError", "start": { "column": 30, - "line": 18 + "line": 10 } }, { - "defaultMessage": "!!!There was a problem sending the support request.", - "description": "\"There was a problem sending the support request.\" error message", + "defaultMessage": "!!!Wallet could not be imported, please make sure you are providing a correct file.", + "description": "\"Wallet could not be imported, please make sure you are providing a correct file.\" error message.", "end": { "column": 3, - "line": 27 + "line": 19 }, - "file": "source/renderer/app/api/common.js", - "id": "api.errors.ReportRequestError", + "file": "source/renderer/app/api/wallets/errors.js", + "id": "api.errors.WalletFileImportError", "start": { - "column": 22, - "line": 23 + "column": 25, + "line": 15 } } ], - "path": "source/renderer/app/api/common.json" + "path": "source/renderer/app/api/wallets/errors.json" }, { "descriptors": [ @@ -3290,13 +3295,13 @@ "description": "Transaction type shown for credit card payments.", "end": { "column": 3, - "line": 22 + "line": 26 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.type.card", "start": { "column": 8, - "line": 18 + "line": 22 } }, { @@ -3304,13 +3309,13 @@ "description": "Transaction type shown for {currency} transactions.", "end": { "column": 3, - "line": 27 + "line": 31 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.type", "start": { "column": 8, - "line": 23 + "line": 27 } }, { @@ -3318,13 +3323,13 @@ "description": "Transaction type shown for money exchanges between currencies.", "end": { "column": 3, - "line": 32 + "line": 36 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.type.exchange", "start": { "column": 12, - "line": 28 + "line": 32 } }, { @@ -3332,13 +3337,13 @@ "description": "Transaction assurance level.", "end": { "column": 3, - "line": 37 + "line": 41 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.assuranceLevel", "start": { "column": 18, - "line": 33 + "line": 37 } }, { @@ -3346,13 +3351,13 @@ "description": "Transaction confirmations.", "end": { "column": 3, - "line": 42 + "line": 46 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.confirmations", "start": { "column": 17, - "line": 38 + "line": 42 } }, { @@ -3360,13 +3365,13 @@ "description": "Transaction ID.", "end": { "column": 3, - "line": 47 + "line": 51 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.transactionId", "start": { "column": 17, - "line": 43 + "line": 47 } }, { @@ -3374,13 +3379,13 @@ "description": "Conversion rate.", "end": { "column": 3, - "line": 52 + "line": 56 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.conversion.rate", "start": { "column": 18, - "line": 48 + "line": 52 } }, { @@ -3388,13 +3393,13 @@ "description": "Label \"{currency} sent\" for the transaction.", "end": { "column": 3, - "line": 57 + "line": 61 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.sent", "start": { "column": 8, - "line": 53 + "line": 57 } }, { @@ -3402,13 +3407,13 @@ "description": "Label \"{currency} received\" for the transaction.", "end": { "column": 3, - "line": 62 + "line": 66 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.received", "start": { "column": 12, - "line": 58 + "line": 62 } }, { @@ -3416,13 +3421,13 @@ "description": "From address", "end": { "column": 3, - "line": 67 + "line": 71 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.address.from", "start": { "column": 15, - "line": 63 + "line": 67 } }, { @@ -3430,13 +3435,13 @@ "description": "From addresses", "end": { "column": 3, - "line": 72 + "line": 76 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.addresses.from", "start": { "column": 17, - "line": 68 + "line": 72 } }, { @@ -3444,13 +3449,13 @@ "description": "To address", "end": { "column": 3, - "line": 77 + "line": 81 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.address.to", "start": { "column": 13, - "line": 73 + "line": 77 } }, { @@ -3458,13 +3463,13 @@ "description": "To addresses", "end": { "column": 3, - "line": 82 + "line": 86 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.addresses.to", "start": { "column": 15, - "line": 78 + "line": 82 } }, { @@ -3472,13 +3477,13 @@ "description": "Transaction amount.", "end": { "column": 3, - "line": 87 + "line": 91 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.transactionAmount", "start": { "column": 21, - "line": 83 + "line": 87 } }, { @@ -3486,13 +3491,13 @@ "description": "Transaction assurance level \"low\".", "end": { "column": 3, - "line": 95 + "line": 99 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.assuranceLevel.low", "start": { - "column": 25, - "line": 91 + "column": 34, + "line": 95 } }, { @@ -3500,13 +3505,13 @@ "description": "Transaction assurance level \"medium\".", "end": { "column": 3, - "line": 100 + "line": 104 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.assuranceLevel.medium", "start": { - "column": 28, - "line": 96 + "column": 37, + "line": 100 } }, { @@ -3514,13 +3519,13 @@ "description": "Transaction assurance level \"high\".", "end": { "column": 3, - "line": 105 + "line": 109 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.assuranceLevel.high", "start": { - "column": 26, - "line": 101 + "column": 35, + "line": 105 } }, { @@ -3528,13 +3533,13 @@ "description": "Transaction state \"pending\"", "end": { "column": 3, - "line": 113 + "line": 117 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.state.pending", "start": { "column": 31, - "line": 109 + "line": 113 } }, { @@ -3542,13 +3547,13 @@ "description": "Transaction state \"pending\"", "end": { "column": 3, - "line": 118 + "line": 122 }, "file": "source/renderer/app/components/wallet/transactions/Transaction.js", "id": "wallet.transaction.state.failed", "start": { "column": 30, - "line": 114 + "line": 118 } } ],