Skip to content
Permalink
Browse files

[DDW-874] Create / Restore wallet V2 API integration (#1557)

* [DDW-860] Introduce improvements for already integrated wallets API v2 endpoint

* [DDW-860] Wallets endpoint flow code cleanup and removing unnecessary assurance declarations

* [DDW-860] Introduce improvements for already integrated getAddresses API v2 endpoint

* [DDW-680] Fix broken transactions screen

* [DDW-860] Types improvements regarding to requested changes

* [DDW-861] Introduce new error handling logic related to api v2 responsees

* [DDW-861] Fix flow issue

* [DDW-861] Shortens .map callback functions

* [DDW-861] Fixes ESLint error

* [DDW-871] Introduce Delete Wallet v2 API endpoint integration

* [DDW-739] Introduce refactored e2e testReset method

* [DDW-872] Introduce Update Wallet Metadata V2 API endpoint integration

* [DDW-873] Introduce Get Single Wallet v2 API integration

* [DDW-874] Introduce Create / Restore Wallet V2 API endpoint integration and e2e tests improvement

* [DDW-874] Remove unnecessary @watch flags from e2e

* CHANGELOG update

* [DDW-738] CHANGELOG update

* [DDW-872] CHANGELOG update

* [DDW-873] CHANGELOG update

* [DDW-874] CHANGELOG update

* [DDW-871] Eslint fix
  • Loading branch information...
tomothespian authored and nikolaglumac committed Sep 12, 2019
1 parent 9e6161b commit 1d76e6c6ebece8f9e92e5b1975df5457b56ed2b2
@@ -5,7 +5,7 @@ Changelog

### Features

- Integrated Cardano V2 API endpoints ([PR 1548](https://github.com/input-output-hk/daedalus/pull/1548), [PR 1551](https://github.com/input-output-hk/daedalus/pull/1551), [PR 1552](https://github.com/input-output-hk/daedalus/pull/1552), [PR 1553](https://github.com/input-output-hk/daedalus/pull/1553), [PR 1555](https://github.com/input-output-hk/daedalus/pull/1555), [PR 1556](https://github.com/input-output-hk/daedalus/pull/1556))
- Integrated Cardano V2 API endpoints ([PR 1548](https://github.com/input-output-hk/daedalus/pull/1548), [PR 1551](https://github.com/input-output-hk/daedalus/pull/1551), [PR 1552](https://github.com/input-output-hk/daedalus/pull/1552), [PR 1553](https://github.com/input-output-hk/daedalus/pull/1553), [PR 1555](https://github.com/input-output-hk/daedalus/pull/1555), [PR 1556](https://github.com/input-output-hk/daedalus/pull/1556), [PR 1557](https://github.com/input-output-hk/daedalus/pull/1557))
- Removed select dropdown arrow ([PR 1550](https://github.com/input-output-hk/daedalus/pull/1550))
- Implemented automated and manual update flows unification ([PR 1491](https://github.com/input-output-hk/daedalus/pull/1491))
- Updated behavior of system dialogs ([PR 1494](https://github.com/input-output-hk/daedalus/pull/1494))
@@ -7,6 +7,8 @@ Feature: Add Wallet via Sidebar
| name |
| Test wallet |

# It is not possible to create wallet without password with API v2
@skip
Scenario: Successfully Adding a Wallet
Given The sidebar shows the "wallets" category
When I click on the add wallet button in the sidebar
@@ -7,6 +7,8 @@ Feature: Add Wallet via Sidebar
| name |
| Test wallet |

# It is not possible to create wallet without password with API v2
@skip
Scenario: Successfully Restoring a Wallet
Given The sidebar shows the "wallets" category
When I click on the add wallet button in the sidebar
@@ -16,15 +18,15 @@ Feature: Add Wallet via Sidebar
And I enter wallet name "Restored wallet" in restore wallet dialog
And I enter recovery phrase in restore wallet dialog:
| recoveryPhrase |
| marriage glide need gold actress grant judge eager spawn plug sister whip |
| turkey size valley cross wear erase enjoy post vivid leisure sustain that twelve grow travel |
And I toggle "Spending password" switch on the restore wallet dialog
And I submit the restore wallet dialog
Then I should not see the restore wallet dialog anymore
And I should have newly created "Restored wallet" wallet loaded
And I should be on the "Restored wallet" wallet "summary" screen
And I should see the restore status notification while restore is running
And I should not see the restore status notification once restore is finished

Scenario: Successfully Restoring a Wallet with spending password
Given The sidebar shows the "wallets" category
When I click on the add wallet button in the sidebar
@@ -34,7 +36,7 @@ Feature: Add Wallet via Sidebar
And I enter wallet name "Restored wallet" in restore wallet dialog
And I enter recovery phrase in restore wallet dialog:
| recoveryPhrase |
| marriage glide need gold actress grant judge eager spawn plug sister whip |
| turkey size valley cross wear erase enjoy post vivid leisure sustain that twelve grow travel |
And I enter wallet password in restore wallet dialog:
| password | repeatedPassword |
| Secret123 | Secret123 |
@@ -1,10 +1,10 @@
import { WalletSyncStateTags } from '../../../../source/renderer/app/domains/Wallet';
import { WalletSyncStateStatuses } from '../../../../source/renderer/app/domains/Wallet';

export const isActiveWalletBeingRestored = async client => {
const result = await client.execute(
expectedSyncTag =>
daedalus.stores.wallets.active.syncState.tag === expectedSyncTag,
WalletSyncStateTags.RESTORING
WalletSyncStateStatuses.RESTORING
);
return result.value;
};
@@ -100,7 +100,7 @@ const createWalletsAsync = async (table, context) => {
daedalus.api.ada.createWallet({
name: wallet.name,
mnemonic: daedalus.utils.crypto.generateMnemonic(),
spendingPassword: wallet.password || null,
spendingPassword: wallet.password || 'Secret123',
})
)
)
@@ -133,7 +133,7 @@ const createWalletsSequentially = async (wallets, context) => {
.createWallet({
name: wallet.name,
mnemonic: daedalus.utils.crypto.generateMnemonic(),
spendingPassword: wallet.password || null,
spendingPassword: wallet.password || 'Secret123',
})
.then(() =>
daedalus.stores.wallets.walletsRequest
@@ -380,16 +380,23 @@ export default class AdaApi {
Logger.debug('AdaApi::createWallet called', {
parameters: filterLogData(request),
});
const { name, mnemonic, spendingPassword: passwordString } = request;
const {
name,
mnemonic,
mnemonicPassphrase,
spendingPassword: passwordString,
addressPoolGap,
} = request;
const spendingPassword = passwordString
? encryptPassphrase(passwordString)
: '';
try {
const walletInitData = {
operation: 'create',
backupPhrase: split(mnemonic, ' '),
name,
spendingPassword,
mnemonic_sentence: split(mnemonic, ' '),
mnemonic_second_factor: mnemonicPassphrase,
passphrase: spendingPassword,
address_pool_gap: addressPoolGap,
};
const wallet: AdaWallet = await createWallet(this.config, {
walletInitData,
@@ -679,10 +686,9 @@ export default class AdaApi {
? encryptPassphrase(passwordString)
: '';
const walletInitData = {
operation: 'restore',
backupPhrase: split(recoveryPhrase, ' '),
mnemonic_sentence: split(recoveryPhrase, ' '),
name: walletName,
spendingPassword,
passphrase: spendingPassword,
};
try {
const wallet: AdaWallet = await restoreWallet(this.config, {
@@ -692,9 +698,10 @@ export default class AdaApi {
return _createWalletFromServerData(wallet);
} catch (error) {
Logger.error('AdaApi::restoreWallet error', { error });
if (error.message === 'WalletAlreadyExists') {
if (error.code === 'wallet_already_exists') {
throw new WalletAlreadyRestoredError();
}
// @API TOOD - improve once error is handled by v2 API (REPORT to BE team)
if (error.message === 'JSONValidationFailed') {
const validationError = get(error, 'diagnostic.validationError', '');
if (
@@ -1,23 +1,16 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { AdaWallet } from '../types';
import type { AdaWallet, WalletInitData } from '../types';
import { request } from '../../utils/request';

export type WalletInitData = {
operation: 'create' | 'restore',
backupPhrase: [string],
name: string,
spendingPassword?: string,
};

export const createWallet = (
config: RequestConfig,
{ walletInitData }: { walletInitData: WalletInitData }
): Promise<AdaWallet> =>
request(
{
method: 'POST',
path: '/api/v1/wallets',
path: '/v2/wallets',
...config,
},
{},
@@ -1,7 +1,6 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { WalletInitData } from './createWallet';
import type { AdaWallet } from '../types';
import type { AdaWallet, WalletInitData } from '../types';
import { request } from '../../utils/request';

export const restoreWallet = (
@@ -11,7 +10,7 @@ export const restoreWallet = (
request(
{
method: 'POST',
path: '/api/v1/wallets',
path: '/v2/wallets',
...config,
},
{},
@@ -54,11 +54,21 @@ export type WalletUtxos = {
},
};

export type WalletInitData = {
name: string,
mnemonic_sentence: [string], // [ 15 .. 24 ] words
mnemonic_second_factor?: [string], // [ 9 .. 12 ] words
passphrase: string,
address_pool_gap?: number,
};

// req/res Wallet types
export type CreateWalletRequest = {
name: string,
mnemonic: string,
mnemonic: [string],
mnemonicPassphrase?: [string],
spendingPassword: ?string,
addressPoolGap?: number,
};

export type UpdateSpendingPasswordRequest = {
@@ -260,6 +260,7 @@ export default class WalletCreateDialog extends Component<Props, State> {
label={intl.formatMessage(messages.passwordSwitchPlaceholder)}
checked={createPassword}
skin={SwitchSkin}
disabled // @API TODO: in V2 API passphrase is required
/>
</div>

@@ -441,6 +441,7 @@ export default class WalletRestoreDialog extends Component<Props, State> {
label={intl.formatMessage(messages.passwordSwitchPlaceholder)}
checked={createPassword}
skin={SwitchSkin}
disabled // @API TODO: in V2 API passphrase is required
/>
</div>

@@ -1,6 +1,6 @@
// @flow
// Cryptographic constants go here
export const WALLET_RECOVERY_PHRASE_WORD_COUNT = 12;
export const WALLET_RECOVERY_PHRASE_WORD_COUNT = 15;
export const ADA_CERTIFICATE_MNEMONIC_LENGTH = 18;
export const PAPER_WALLET_RECOVERY_PHRASE_WORD_COUNT = 27;
export const PAPER_WALLET_PRINTED_WORDS_COUNT = 18;
@@ -655,8 +655,10 @@ export default class NetworkStatusStore extends Store {
return this.isNodeResponding && this.isNodeSubscribed && this.isNodeSyncing;
}

// @API TODO - uncomment checking once api v2 is integrated
@computed get isSystemTimeCorrect(): boolean {
return this.isNodeTimeCorrect || this.isSystemTimeIgnored;
// return this.isNodeTimeCorrect || this.isSystemTimeIgnored;
return true;
}

@computed get isSynced(): boolean {
@@ -36,7 +36,7 @@ export default class SidebarStore extends Store {
isRestoreActive:
get(wallet, ['syncState', 'status'], '') ===
WalletSyncStateStatuses.RESTORING,
restoreProgress: get(wallet, 'syncState.progress.quantity', 0),
restoreProgress: get(wallet, ['syncState', 'progress', 'quantity'], 0),
isLegacy: wallet.isLegacy,
}));
}
@@ -19,7 +19,7 @@ import validWords from '../../../common/crypto/valid-words.en';
| 224 | 7 | 231 | 21 |
| 256 | 8 | 264 | 24 |
*/
export const generateMnemonic = (ms: ?number = 12) => {
export const generateMnemonic = (ms: ?number = 15) => {
let ent;
switch (ms) {
case 9:

0 comments on commit 1d76e6c

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