[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

View on GitHub
File Changes
m
+1/-1

                      
### 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))
      | 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
      | 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
    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
    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        |
-
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;
};
        daedalus.api.ada.createWallet({
          name: wallet.name,
          mnemonic: daedalus.utils.crypto.generateMnemonic(),
-
          spendingPassword: wallet.password || null,
+
          spendingPassword: wallet.password || 'Secret123',
        })
      )
    )
        .createWallet({
          name: wallet.name,
          mnemonic: daedalus.utils.crypto.generateMnemonic(),
-
          spendingPassword: wallet.password || null,
+
          spendingPassword: wallet.password || 'Secret123',
        })
        .then(() =>
          daedalus.stores.wallets.walletsRequest
    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,
      ? 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, {
      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 (
// @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,
    },
    {},
// @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 = (
  request(
    {
      method: 'POST',
-
      path: '/api/v1/wallets',
+
      path: '/v2/wallets',
      ...config,
    },
    {},
  },
};

                      
+
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 = {
              label={intl.formatMessage(messages.passwordSwitchPlaceholder)}
              checked={createPassword}
              skin={SwitchSkin}
+
              disabled // @API TODO: in V2 API passphrase is required
            />
          </div>

                      
              label={intl.formatMessage(messages.passwordSwitchPlaceholder)}
              checked={createPassword}
              skin={SwitchSkin}
+
              disabled // @API TODO: in V2 API passphrase is required
            />
          </div>

                      
// @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;
    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 {
      isRestoreActive:
        get(wallet, ['syncState', 'status'], '') ===
        WalletSyncStateStatuses.RESTORING,
-
      restoreProgress: get(wallet, 'syncState.progress.quantity', 0),
+
      restoreProgress: get(wallet, ['syncState', 'progress', 'quantity'], 0),
      isLegacy: wallet.isLegacy,
    }));
  }
  |  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: