View on GitHub
File Changes
{
  "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
}
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 {
  AdaWallet,
  AdaWallets,
  WalletUtxos,
+
  WalletIdAndBalance,
  CreateWalletRequest,
  DeleteWalletRequest,
  RestoreWalletRequest,
  ImportWalletFromFileRequest,
  UpdateWalletRequest,
  GetWalletUtxosRequest,
+
  GetWalletIdAndBalanceRequest,
+
  GetWalletIdAndBalanceResponse,
} from './wallets/types';

                      
// Common errors
    }
  };

                      
+
  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 {
          // 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 = `{
+
// @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
+
  );
// @flow
+
import BigNumber from 'bignumber.js';
+

                      
export type AdaWallet = {
  createdAt: string,
  syncState: WalletSyncState,
  },
};

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

                      
// req/res Wallet types
export type CreateWalletRequest = {
  name: string,
  walletId: string,
};

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

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

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