Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-738] Refactor V2 API test setup #1553

Merged
merged 23 commits into from Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5f99a75
[DDW-860] Introduce improvements for already integrated wallets API v…
Aug 27, 2019
3f58f95
Merge branch 'develop' into chore/ddw-860-already-integrated-v2-api-e…
Aug 27, 2019
598495e
[DDW-860] Wallets endpoint flow code cleanup and removing unnecessary…
Aug 27, 2019
5e6a3e7
[DDW-860] Introduce improvements for already integrated getAddresses …
Aug 28, 2019
505d5db
[DDW-680] Fix broken transactions screen
Aug 28, 2019
5d300d5
Merge branch 'v2-integration' into chore/ddw-860-already-integrated-v…
Aug 28, 2019
cfa8a6e
[DDW-860] Types improvements regarding to requested changes
Aug 30, 2019
b364c42
[DDW-861] Introduce new error handling logic related to api v2 respon…
Aug 30, 2019
6b0d862
[DDW-861] Fix flow issue
Aug 30, 2019
e75a36f
[DDW-861] Shortens .map callback functions
MarcusHurney Aug 31, 2019
0187cbf
[DDW-861] Fixes ESLint error
MarcusHurney Aug 31, 2019
490ad7c
[DDW-871] Introduce Delete Wallet v2 API endpoint integration
Sep 2, 2019
00fb6d8
[DDW-739] Introduce refactored e2e testReset method
Sep 2, 2019
dcc8043
[DDW-861] Merges-in latest v2-integration branch and fix conflicts
Sep 10, 2019
bcdff00
[DDW-861] Merge latest v2-integration and fix conflict
nikolaglumac Sep 11, 2019
4190dc3
Merge branch 'chore/ddw-861-v2-api-error-handlers' into chore/ddw-871…
Sep 11, 2019
5576c0b
CHANGELOG update
Sep 11, 2019
81bf0a2
Merge branch 'chore/ddw-871-delete-wallet-v2-api-integration' into ch…
Sep 11, 2019
13aafc5
[DDW-738] CHANGELOG update
Sep 11, 2019
7a77746
[DDW-871] Merges-in latest v2-integration branch and fix conflicts
Sep 11, 2019
1b15d2d
[DDW-871] Eslint fix
Sep 11, 2019
809cd16
Merge branch 'chore/ddw-871-delete-wallet-v2-api-integration' into ch…
Sep 11, 2019
109813a
[DDW-738] Merges-in latest v2-integration and fix conflicts
Sep 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions source/renderer/app/api/addresses/requests/getAddresses.js
@@ -1,14 +1,18 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type { Address } from '../types';
import type { Addresses, GetAddressesRequestQueryParams } from '../types';
import { request } from '../../utils/request';

export const getAddresses = (
config: RequestConfig,
walletId: string
): Promise<Address[]> =>
request({
method: 'GET',
path: `/v2/wallets/${walletId}/addresses?state=used`,
...config,
});
walletId: string,
queryParams?: GetAddressesRequestQueryParams
): Promise<Addresses> =>
request(
{
method: 'GET',
path: `/v2/wallets/${walletId}/addresses`,
...config,
},
queryParams
);
17 changes: 12 additions & 5 deletions source/renderer/app/api/addresses/types.js
@@ -1,22 +1,29 @@
// @flow
import WalletAddress from '../../domains/WalletAddress';

export type AddressState = 'used' | 'unused';

export type GetAddressesRequestQueryParams = {
state: AddressState,
};

export type Address = {
id: string,
state: 'used' | 'unused',
state: AddressState,
};

export type Addresses = Array<Address>;

export type GetAddressesRequest = {
walletId: string,
queryParams?: GetAddressesRequestQueryParams,
};

export type GetAddressesResponse = {
accountIndex: ?number,
addresses: Array<WalletAddress>,
};

export type GetAddressesRequest = {
walletId: string,
};

export type CreateAddressRequest = {
spendingPassword: ?string,
accountIndex: number,
Expand Down
76 changes: 39 additions & 37 deletions source/renderer/app/api/api.js
@@ -1,11 +1,11 @@
// @flow
import { split, get } from 'lodash';
import { split, get, size } from 'lodash';
import { action } from 'mobx';
import BigNumber from 'bignumber.js';
// import moment from 'moment';

// domains
import Wallet from '../domains/Wallet';
import Wallet, { WalletDelegationStatuses } from '../domains/Wallet';
import {
WalletTransaction,
transactionTypes,
Expand All @@ -14,7 +14,7 @@ import WalletAddress from '../domains/WalletAddress';

// Addresses requests
import { getAddress } from './addresses/requests/getAddress';
import { getAddresses as getAddressesFromApi } from './addresses/requests/getAddresses';
import { getAddresses } from './addresses/requests/getAddresses';
import { createAddress } from './addresses/requests/createAddress';

// Nodes requests
Expand All @@ -32,7 +32,6 @@ import { getTransactionFee } from './transactions/requests/getTransactionFee';
import { createTransaction } from './transactions/requests/createTransaction';

// 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';
Expand Down Expand Up @@ -81,8 +80,8 @@ import type {
Address,
Addresses,
GetAddressesRequest,
CreateAddressRequest,
GetAddressesResponse,
CreateAddressRequest,
} from './addresses/types';

// Common Types
Expand Down Expand Up @@ -128,7 +127,6 @@ import type {
ImportWalletFromFileRequest,
UpdateWalletRequest,
GetWalletUtxosRequest,
// WalletSyncState,
} from './wallets/types';

// Common errors
Expand Down Expand Up @@ -175,7 +173,7 @@ export default class AdaApi {
try {
const response: AdaWallets = await getWallets(this.config);
Logger.debug('AdaApi::getWallets success', { wallets: response });
return response.map(data => _createWalletFromServerData(data));
return response.map(_createWalletFromServerData);
} catch (error) {
Logger.error('AdaApi::getWallets error', { error });
throw new GenericApiError();
Expand All @@ -188,16 +186,17 @@ export default class AdaApi {
Logger.debug('AdaApi::getAddresses called', {
parameters: filterLogData(request),
});
const { walletId } = request;
const { walletId, queryParams } = request;
try {
const response: Addresses = await getAddressesFromApi(
const response: Addresses = await getAddresses(
this.config,
walletId
walletId,
queryParams
);

Logger.debug('AdaApi::getAddresses success', { addresses: response });
const addresses = response.map(data =>
_createAddressFromServerData(data)
);
const addresses = response.map(_createAddressFromServerData);

return new Promise(resolve => resolve({ accountIndex: 0, addresses }));
} catch (error) {
Logger.error('AdaApi::getAddresses error', { error });
Expand Down Expand Up @@ -369,12 +368,10 @@ export default class AdaApi {
const spendingPassword = passwordString
? encryptPassphrase(passwordString)
: '';
const assuranceLevel = 'normal';
try {
const walletInitData = {
operation: 'create',
backupPhrase: split(mnemonic, ' '),
assuranceLevel,
name,
spendingPassword,
};
Expand Down Expand Up @@ -665,11 +662,9 @@ export default class AdaApi {
const spendingPassword = passwordString
? encryptPassphrase(passwordString)
: '';
const assuranceLevel = 'normal';
const walletInitData = {
operation: 'restore',
backupPhrase: split(recoveryPhrase, ' '),
assuranceLevel,
name: walletName,
spendingPassword,
};
Expand Down Expand Up @@ -801,11 +796,10 @@ export default class AdaApi {
Logger.debug('AdaApi::updateWallet called', {
parameters: filterLogData(request),
});
const { walletId, assuranceLevel, name } = request;
const { walletId, name } = request;
try {
const wallet: AdaWallet = await updateWallet(this.config, {
walletId,
assuranceLevel,
name,
});
Logger.debug('AdaApi::updateWallet success', { wallet });
Expand Down Expand Up @@ -883,9 +877,9 @@ export default class AdaApi {
testReset = async (): Promise<void> => {
Logger.debug('AdaApi::testReset called');
try {
const response: Promise<void> = await resetWalletState(this.config);
const wallets: AdaWallets = await getWallets(this.config);
wallets.map(wallet => deleteWallet(this.config, { walletId: wallet.id }));
Logger.debug('AdaApi::testReset success');
return response;
} catch (error) {
Logger.error('AdaApi::testReset error', { error });
throw new GenericApiError();
Expand All @@ -901,7 +895,7 @@ export default class AdaApi {
}`;
Logger.debug(`${loggerText} called`);
try {
/* TODO: Uncomment once implemented
/* @API TODO: Uncomment once implemented

const nodeInfo: NodeInfoResponse = await getNodeInfo(
this.config,
Expand Down Expand Up @@ -1043,30 +1037,38 @@ export default class AdaApi {
const _createWalletFromServerData = action(
'AdaApi::_createWalletFromServerData',
(data: AdaWallet) => {
const { id, balance, name, state, passphrase } = data;
const {
id,
address_pool_gap, // eslint-disable-line
balance,
name,
state,
passphrase,
delegation,
} = data;

const isDelegated =
delegation.status === WalletDelegationStatuses.DELEGATING;
const passphraseLastUpdatedAt = get(passphrase, 'last_updated_at', null);
const walletBalance =
balance.total.unit === 'lovelace'
? new BigNumber(balance.total.quantity).dividedBy(LOVELACES_PER_ADA)
: new BigNumber(balance.total.quantity);

// TODO: Should conform to WalletSyncState, but can't match the type
// at the moment
const walletSyncState: any = {
tag: state.status === 'ready' ? 'synced' : 'restoring',
};

return new Wallet({
id,
amount: walletBalance,
addressPoolGap: address_pool_gap,
name,
// NOTE: Assurance not currently returned on GET /v2/wallets
assurance: 'normal',
// TODO: Determine if hasPassword still applies
hasPassword: true,
passwordUpdateDate: new Date(passphrase.last_updated_at),
syncState: walletSyncState,
isLegacy: false,
amount: walletBalance,
hasPassword: size(passphrase) > 0,
passwordUpdateDate:
passphraseLastUpdatedAt && new Date(passphraseLastUpdatedAt),
syncState: state,
isLegacy: false, // @API TODO - legacy declaration not exist for now
isDelegated,
// @API TODO - integrate once "Stake Pools" endpoints are done
// inactiveStakePercentage: 0,
// delegatedStakePool: new StakePool(),
});
}
);
Expand Down
2 changes: 0 additions & 2 deletions source/renderer/app/api/transactions/types.js
Expand Up @@ -27,8 +27,6 @@ export type PaymentDistribution = {
amount: number,
};

export type TxnAssuranceLevel = 'low' | 'medium' | 'high';

export type TransactionState = 'pending' | 'failed' | 'ok';

export type TransactionFee = ResponseBase & {
Expand Down
21 changes: 16 additions & 5 deletions source/renderer/app/api/utils/patchAdaApi.js
@@ -1,15 +1,15 @@
// @flow
import { get } from 'lodash';
import AdaApi from '../api';
import { getNodeInfo } from '../nodes/requests/getNodeInfo';
// import { getNodeInfo } from '../nodes/requests/getNodeInfo';
import { getNodeSettings } from '../nodes/requests/getNodeSettings';
import { getLatestAppVersion } from '../nodes/requests/getLatestAppVersion';
import { GenericApiError } from '../common/errors';
import { Logger } from '../../utils/logging';
import type { NodeInfoQueryParams } from '../nodes/requests/getNodeInfo';
import type {
LatestAppVersionInfoResponse,
NodeInfoResponse,
// NodeInfoResponse,
GetNetworkStatusResponse,
NodeSettingsResponse,
GetNodeSettingsResponse,
Expand All @@ -33,6 +33,7 @@ export default (api: AdaApi) => {
): Promise<GetNetworkStatusResponse> => {
Logger.debug('AdaApi::getNetworkStatus (PATCHED) called');
try {
/* @API TODO: Uncomment once implemented
const nodeInfo: NodeInfoResponse = await getNodeInfo(
api.config,
queryInfoParams
Expand All @@ -46,7 +47,13 @@ export default (api: AdaApi) => {
subscriptionStatus,
syncProgress,
localBlockchainHeight,
} = nodeInfo;
} = nodeInfo; */

const blockchainHeight = { quantity: 100 };
const subscriptionStatus = 'subscribed';
const syncProgress = { quantity: 1 };
const localTimeInformation = { status: 'available' };
const localBlockchainHeight = { quantity: 100 };

// extract relevant data before sending to NetworkStatusStore
const response = {
Expand All @@ -57,8 +64,12 @@ export default (api: AdaApi) => {
localBlockchainHeight:
LOCAL_BLOCK_HEIGHT || localBlockchainHeight.quantity,
localTimeInformation: {
status: 'available',
difference: LOCAL_TIME_DIFFERENCE,
status: localTimeInformation.status,
difference: get(
localTimeInformation,
'localTimeDifference.quantity',
LOCAL_TIME_DIFFERENCE
),
},
};

Expand Down