Skip to content
Permalink
Browse files

[DEVOPS-1195] Improve code style

  • Loading branch information...
nikolaglumac committed Mar 13, 2019
1 parent 7e7c9ab commit 48243c8095be7551d962d3b43009d0b4d1a4df09
@@ -59,7 +59,7 @@ export const addOrSetWalletsForScenario = function (wallet) {

export const importWalletWithFunds = async (client, { keyFilePath, password }) => (
await client.executeAsync((filePath, spendingPassword, done) => {
daedalus.api.ada.importWalletFromKey({ filePath, spendingPassword })
daedalus.api.ada.importWalletFromKeyFile({ filePath, spendingPassword })
.then(() => (
daedalus.stores.wallets.refreshWalletsData()
.then(done)
@@ -10,10 +10,7 @@ import type {
} from '../types/report-request.types';
import type { GeneratePaperWalletParams } from '../types/paper-wallet-request.types';
import type { CheckDiskSpaceResponse } from '../types/no-disk-space.types';
import type {
ExtractedWallet,
ExtractedWallets,
} from '../types/wallet-importer.types';
import type { ExtractedWallets } from '../types/wallet-importer.types';

/**
* Channel for loading an base64 encoded asset from within the `source/renderer` folder
@@ -77,13 +74,6 @@ export const ExtractWalletsChannelName = 'ExtractWalletsChannel';
export type ExtractWalletsRendererRequest = { secretKeyFilePath: string };
export type ExtractWalletsMainResponse = ExtractedWallets;

/**
* Channel for generating wallet key file
*/
export const GenerateRawSecretChannelName = 'GenerateRawSecretChannel';
export type GenerateRawSecretRendererRequest = { wallet: ExtractedWallet };
export type GenerateRawSecretMainResponse = string;

/**
* Channel for matching extracted wallets passwords
*/
@@ -1,7 +1,7 @@
// @flow
export type ExtractedWallet = {
index: number,
raw: Array<Buffer>,
encryptedSecretKey: string,
passwordHash: string,
password: ?string,
balance: ?string,
@@ -28,7 +28,7 @@ export const handleExtractWalletsRequests = () => {
keys.forEach((key, index) => {
wallets.push({
index: index + 1,
raw: key,
encryptedSecretKey: cbor.encode(key).toString('hex'),
passwordHash: key[1].toString('ascii'),
password: null,
balance: null,

This file was deleted.

Oops, something went wrong.
@@ -8,7 +8,6 @@ import resizeWindowApi from './resize-window';
import loadAsset from './load-asset';
import getGpuStatus from './get-gpu-status';
import { handleExtractWalletsRequests } from './extractWalletsChannel';
import { handleGenerateRawSecretRequests } from './generateRawSecretChannel';
import { handleMatchWalletsPasswordsRequests } from './matchWalletsPasswordsChannel';
import { handleReportRequests } from './reportRequestChannel';
import { handlePaperWalletRequests } from './generatePaperWalletChannel';
@@ -23,7 +22,6 @@ export default (window: BrowserWindow) => {
loadAsset();
getGpuStatus();
handleExtractWalletsRequests();
handleGenerateRawSecretRequests();
handleMatchWalletsPasswordsRequests();
handleReportRequests();
handlePaperWalletRequests();
@@ -33,12 +33,12 @@ import { redeemPaperVendedAda } from './transactions/requests/redeemPaperVendedA
import { resetWalletState } from './wallets/requests/resetWalletState';
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 { exportWalletToJSONFile } from './wallets/requests/exportWalletToJSONFile';
import { importWalletFromJSONFile } from './wallets/requests/importWalletFromJSONFile';
import { getWallets } from './wallets/requests/getWallets';
import { getWalletBalance } from './wallets/requests/getWalletBalance';
import { importWalletAsKey } from './wallets/requests/importWalletAsKey';
import { importWalletAsRawSecret } from './wallets/requests/importWalletAsRawSecret';
import { importWalletFromKeyFile } from './wallets/requests/importWalletFromKeyFile';
import { importWalletFromSecretKey } from './wallets/requests/importWalletFromSecretKey';
import { createWallet } from './wallets/requests/createWallet';
import { restoreWallet } from './wallets/requests/restoreWallet';
import { updateWallet } from './wallets/requests/updateWallet';
@@ -125,9 +125,9 @@ import type {
GetWalletBalanceResponse,
GetWalletCertificateRecoveryPhraseRequest,
GetWalletRecoveryPhraseFromCertificateRequest,
ImportWalletFromKeyRequest,
ImportWalletFromKeyFileRequest,
ImportWalletFromFileRequest,
ImportWalletFromRawSecretRequest,
ImportWalletFromSecretKeyRequest,
UpdateWalletRequest
} from './wallets/types';

@@ -615,20 +615,20 @@ export default class AdaApi {
}
};

importWalletFromKey = async (
request: ImportWalletFromKeyRequest
importWalletFromKeyFile = async (
request: ImportWalletFromKeyFileRequest
): Promise<Wallet> => {
Logger.debug('AdaApi::importWalletFromKey called', { parameters: filterLogData(request) });
Logger.debug('AdaApi::importWalletFromKeyFile called', { parameters: filterLogData(request) });
const { filePath, spendingPassword: passwordString } = request;
const spendingPassword = passwordString ? encryptPassphrase(passwordString) : '';
try {
const importedWallet: AdaWallet = await importWalletAsKey(
const importedWallet: AdaWallet = await importWalletFromKeyFile(
this.config, { filePath, spendingPassword }
);
Logger.debug('AdaApi::importWalletFromKey success', { importedWallet });
Logger.debug('AdaApi::importWalletFromKeyFile success', { importedWallet });
return _createWalletFromServerData(importedWallet);
} catch (error) {
Logger.error('AdaApi::importWalletFromKey error', { error });
Logger.error('AdaApi::importWalletFromKeyFile error', { error });
if (error.message === 'WalletAlreadyExists') {
throw new WalletAlreadyImportedError(error);
}
@@ -645,9 +645,9 @@ export default class AdaApi {
const isKeyFile = filePath.split('.').pop().toLowerCase() === 'key';
try {
const importedWallet: AdaWallet = isKeyFile ? (
await importWalletAsKey(this.config, { filePath, spendingPassword })
await importWalletFromKeyFile(this.config, { filePath, spendingPassword })
) : (
await importWalletAsJSON(this.config, filePath)
await importWalletFromJSONFile(this.config, filePath)
);
Logger.debug('AdaApi::importWalletFromFile success', { importedWallet });
return _createWalletFromServerData(importedWallet);
@@ -660,20 +660,20 @@ export default class AdaApi {
}
};

importWalletFromRawSecret = async (
request: ImportWalletFromRawSecretRequest
importWalletFromSecretKey = async (
request: ImportWalletFromSecretKeyRequest
): Promise<Wallet> => {
Logger.debug('AdaApi::importWalletFromRawSecret called');
const { rawSecret, spendingPassword: passwordString } = request;
Logger.debug('AdaApi::importWalletFromSecretKey called');
const { encryptedSecretKey, spendingPassword: passwordString } = request;
const spendingPassword = passwordString ? encryptPassphrase(passwordString) : '';
try {
const importedWallet: AdaWallet = await importWalletAsRawSecret(
this.config, { rawSecret, spendingPassword }
const importedWallet: AdaWallet = await importWalletFromSecretKey(
this.config, { rawSecret: encryptedSecretKey, spendingPassword }
);
Logger.debug('AdaApi::importWalletFromRawSecret success', { importedWallet });
Logger.debug('AdaApi::importWalletFromSecretKey success', { importedWallet });
return _createWalletFromServerData(importedWallet);
} catch (error) {
Logger.error('AdaApi::importWalletFromRawSecret error', { error });
Logger.error('AdaApi::importWalletFromSecretKey error', { error });
if (error.message === 'WalletAlreadyExists') {
throw new WalletAlreadyImportedError(error);
}
@@ -685,10 +685,10 @@ export default class AdaApi {
request: GetWalletBalanceRequest
): Promise<WalletBalance> => {
Logger.debug('AdaApi::getWalletBalance called');
const { rawSecret } = request;
const { encryptedSecretKey } = request;
try {
const walletBalance: GetWalletBalanceResponse =
await getWalletBalance(this.config, rawSecret);
await getWalletBalance(this.config, encryptedSecretKey);
Logger.debug('AdaApi::getWalletBalance success', { walletBalance });
const { balance, walletId } = walletBalance;
return {
@@ -828,7 +828,7 @@ export default class AdaApi {
const { walletId, filePath } = request;
Logger.debug('AdaApi::exportWalletToFile called', { parameters: filterLogData(request) });
try {
const response: Promise<[]> = await exportWalletAsJSON(
const response: Promise<[]> = await exportWalletToJSONFile(
this.config, { walletId, filePath }
);
Logger.debug('AdaApi::exportWalletToFile success', { response });
@@ -2,14 +2,14 @@
import type { RequestConfig } from '../../common/types';
import { request } from '../../utils/requestV0';

export type ExportWalletAsJSONParams = {
export type ExportWalletToJSONFileParams = {
walletId: string,
filePath: string,
};

export const exportWalletAsJSON = (
export const exportWalletToJSONFile = (
config: RequestConfig,
{ walletId, filePath }: ExportWalletAsJSONParams,
{ walletId, filePath }: ExportWalletToJSONFileParams,
): Promise<[]> => (
request({
method: 'POST',
@@ -5,11 +5,11 @@ import { request } from '../../utils/request';

export const getWalletBalance = (
config: RequestConfig,
rawSecret: string, // EncryptedSecretKey (hex-encoded)
encryptedSecretKey: string, // EncryptedSecretKey (hex-encoded)
): Promise<GetWalletBalanceResponse> => (
request({
method: 'POST',
path: '/api/internal/query-balance',
...config,
}, {}, rawSecret)
}, {}, encryptedSecretKey)
);
@@ -3,7 +3,7 @@ import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/requestV0';

export const importWalletAsJSON = (
export const importWalletFromJSONFile = (
config: RequestConfig,
filePath: string,
): Promise<AdaWallet> => (
@@ -3,14 +3,14 @@ import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/request';

export type ImportWalletAsKey = {
export type ImportWalletFromKeyFile = {
filePath: string,
spendingPassword?: string,
};

export const importWalletAsKey = (
export const importWalletFromKeyFile = (
config: RequestConfig,
walletImportData: ImportWalletAsKey
walletImportData: ImportWalletFromKeyFile
): Promise<AdaWallet> => (
request({
method: 'POST',
@@ -3,14 +3,14 @@ import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import { request } from '../../utils/request';

export type ImportWalletAsRawSecret = {
export type ImportWalletFromSecretKey = {
rawSecret: string,
spendingPassword?: string,
};

export const importWalletAsRawSecret = (
export const importWalletFromSecretKey = (
config: RequestConfig,
walletImportData: ImportWalletAsRawSecret
walletImportData: ImportWalletFromSecretKey
): Promise<AdaWallet> => (
request({
method: 'POST',
@@ -72,13 +72,13 @@ export type UpdateWalletRequest = {
name: string
};

export type ImportWalletFromKeyRequest = {
export type ImportWalletFromKeyFileRequest = {
filePath: string,
spendingPassword: ?string,
};

export type ImportWalletFromRawSecretRequest = {
rawSecret: string,
export type ImportWalletFromSecretKeyRequest = {
encryptedSecretKey: string,
spendingPassword: ?string,
};

@@ -105,7 +105,7 @@ export type GetWalletRecoveryPhraseFromCertificateRequest = {
};

export type GetWalletBalanceRequest = {
rawSecret: string,
encryptedSecretKey: string,
};

export type GetWalletBalanceResponse = {

This file was deleted.

Oops, something went wrong.
@@ -6,7 +6,6 @@ import Store from './lib/Store';
import Request from './lib/LocalizedRequest';
import Wallet from '../domains/Wallet';
import { extractWalletsChannel } from '../ipc/extractWalletsChannel';
import { generateRawSecretChannel } from '../ipc/generateRawSecretChannel';
import { matchWalletsPasswordsChannel } from '../ipc/matchWalletsPasswordsChannel';
import { formattedWalletAmount } from '../utils/formatters';
import type { WalletBalance } from '../api/wallets/types';
@@ -24,8 +23,8 @@ export default class WalletImporterStore extends Store {
@observable extractedWallets: ExtractedWallets = [];

/* eslint-disable max-len */
@observable importWalletFromRawSecretRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromRawSecret);
@observable getWalletBalanceRequest: Request<WalletBalance> = new Request(this.api.ada.getWalletBalance);
@observable importWalletFromSecretKeyRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromSecretKey);
/* eslint-disable max-len */

setup() {
@@ -80,13 +79,13 @@ export default class WalletImporterStore extends Store {

@action _extractBalances = async (wallets: ExtractedWallets) => {
const walletsWithBalances = [];
for (const wallet of toJS(wallets)) {
for (const wallet of wallets) {
const { balance } = wallet;
if (balance == null) {
const rawSecret = await generateRawSecretChannel.send({ wallet });
const { encryptedSecretKey } = wallet;
try {
const walletBalance =
await this.getWalletBalanceRequest.execute({ rawSecret }).promise;
await this.getWalletBalanceRequest.execute({ encryptedSecretKey }).promise;
const { balance: amount, walletId } = walletBalance;
const isImported = this.stores.wallets.getWalletById(walletId) != null;
wallet.id = walletId;
@@ -101,10 +100,9 @@ export default class WalletImporterStore extends Store {

@action _importKeyFile = async (params: { wallet: ExtractedWallet }) => {
const { wallet } = params;
const rawSecret = await generateRawSecretChannel.send({ wallet: toJS(wallet) });
const spendingPassword = wallet.password;
const importedWallet = await this.importWalletFromRawSecretRequest.execute({
rawSecret, spendingPassword,
const { password: spendingPassword, encryptedSecretKey } = wallet;
const importedWallet = await this.importWalletFromSecretKeyRequest.execute({
encryptedSecretKey, spendingPassword,
}).promise;
if (!importedWallet) throw new Error('Imported wallet was not received correctly');
await this.stores.wallets._patchWalletRequestWithNewWallet(importedWallet);
@@ -29,7 +29,7 @@ export default class WalletsStore extends Store {
@observable isRestoreActive: boolean = false;
@observable restoringWalletId: ?string = null;
@observable walletsRequest: Request<Array<Wallet>> = new Request(this.api.ada.getWallets);
@observable importFromKeyRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromKey);
@observable importFromKeyRequest: Request<Wallet> = new Request(this.api.ada.importWalletFromKeyFile);
@observable createWalletRequest: Request<Wallet> = new Request(this.api.ada.createWallet);
@observable getWalletAddressesRequest: Request<any> = new Request(this.api.ada.getAddresses);
@observable deleteWalletRequest: Request<boolean> = new Request(this.api.ada.deleteWallet);

0 comments on commit 48243c8

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