Skip to content
Permalink
Browse files

[DDW-893] Integrate new API endpoint

  • Loading branch information...
nikolaglumac committed Sep 12, 2019
1 parent 184fdc8 commit ce7f934373eace2bc5eb50e165ddcb8ffb13af38
@@ -1,7 +1,7 @@
{
"url": "https://github.com/input-output-hk/cardano-sl",
"rev": "51ad7c0503b1c52a75a6eb36096c407934136468",
"date": "2019-08-10T03:35:47+00:00",
"sha256": "0cqaxk3k8i5z4q4b5na0pcln9fblglmn7900vp1xdzmw75pp1rrz",
"rev": "32890cf55d85b407e87b2ff13a3ae7703b6c444e",
"date": "2019-09-12T07:23:15+00:00",
"sha256": "1a0dfg9gd75f9az1r9ycf9h1whikf203y1hkd537ls1jd5bkisyp",
"fetchSubmodules": false
}
@@ -45,6 +45,7 @@ import { createWallet } from './wallets/requests/createWallet';
import { restoreWallet } from './wallets/requests/restoreWallet';
import { updateWallet } from './wallets/requests/updateWallet';
import { getWalletUtxos } from './wallets/requests/getWalletUtxos';
import { getWalletIdAndBalance } from './wallets/requests/getWalletIdAndBalance';

// utility functions
import {
@@ -118,6 +119,7 @@ import type {
AdaWallet,
AdaWallets,
WalletUtxos,
WalletIdAndBalance,
CreateWalletRequest,
DeleteWalletRequest,
RestoreWalletRequest,
@@ -129,6 +131,8 @@ import type {
ImportWalletFromFileRequest,
UpdateWalletRequest,
GetWalletUtxosRequest,
GetWalletIdAndBalanceRequest,
GetWalletIdAndBalanceResponse,
} from './wallets/types';

// Common errors
@@ -873,6 +877,30 @@ export default class AdaApi {
}
};

getWalletIdAndBalance = async (
request: GetWalletIdAndBalanceRequest
): Promise<WalletIdAndBalance> => {
const { recoveryPhrase } = request;
Logger.debug('AdaApi::getWalletIdAndBalance called');
try {
const response: GetWalletIdAndBalanceResponse = await getWalletIdAndBalance(
this.config,
{
recoveryPhrase,
}
);
Logger.debug('AdaApi::getWalletIdAndBalance success', { response });
const { walletId, balance } = response;
return {
walletId,
balance: new BigNumber(balance).dividedBy(LOVELACES_PER_ADA),
};
} catch (error) {
Logger.error('AdaApi::getWalletIdAndBalance error', { error });
throw new GenericApiError();
}
};

testReset = async (): Promise<void> => {
Logger.debug('AdaApi::testReset called');
try {
@@ -84,6 +84,18 @@ function typedRequest<Response>(
// even if it was successful
const { statusCode, statusMessage } = response;

// TODO: remove once calculate_mnemonic is fixed
if (
options.path === '/api/internal/calculate_mnemonic' &&
statusCode === 200
) {
const data = body;
body = `{
"status": "success",
"data": ${data}
}`;
}

if (!body && statusCode >= 200 && statusCode <= 206) {
// adds status and data properties so JSON.parse doesn't throw an error
body = `{
@@ -0,0 +1,21 @@
// @flow
import type { RequestConfig } from '../../common/types';
import type {
GetWalletIdAndBalanceRequest,
GetWalletIdAndBalanceResponse,
} from '../types';
import { request } from '../../utils/request';

export const getWalletIdAndBalance = (
config: RequestConfig,
{ recoveryPhrase }: GetWalletIdAndBalanceRequest
): Promise<GetWalletIdAndBalanceResponse> =>
request(
{
method: 'POST',
path: '/api/internal/calculate_mnemonic',
...config,
},
{},
recoveryPhrase
);
@@ -1,4 +1,6 @@
// @flow
import BigNumber from 'bignumber.js';

export type AdaWallet = {
createdAt: string,
syncState: WalletSyncState,
@@ -48,6 +50,11 @@ export type WalletUtxos = {
},
};

export type WalletIdAndBalance = {
walletId: string,
balance: BigNumber,
};

// req/res Wallet types
export type CreateWalletRequest = {
name: string,
@@ -69,6 +76,15 @@ export type GetWalletUtxosRequest = {
walletId: string,
};

export type GetWalletIdAndBalanceRequest = {
recoveryPhrase: Array<string>,
};

export type GetWalletIdAndBalanceResponse = {
walletId: string,
balance: number,
};

export type RestoreWalletRequest = {
recoveryPhrase: string,
walletName: string,

0 comments on commit ce7f934

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