From 51b2fce8c13c8e9393558d34dd664b7dd7749941 Mon Sep 17 00:00:00 2001
From: Brandon Millman <brandon.millman@gmail.com>
Date: Wed, 18 Apr 2018 15:22:02 -0400
Subject: Implement backendClient object to unify calls to the portal api

---
 packages/website/ts/components/wallet/wallet.tsx | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

(limited to 'packages/website/ts/components/wallet/wallet.tsx')

diff --git a/packages/website/ts/components/wallet/wallet.tsx b/packages/website/ts/components/wallet/wallet.tsx
index 8c9e3be0f..d1ae38550 100644
--- a/packages/website/ts/components/wallet/wallet.tsx
+++ b/packages/website/ts/components/wallet/wallet.tsx
@@ -36,7 +36,7 @@ import {
     TokenState,
     TokenStateByAddress,
 } from 'ts/types';
-import { configs } from 'ts/utils/configs';
+import { backendClient } from 'ts/utils/backend_client';
 import { constants } from 'ts/utils/constants';
 import { utils } from 'ts/utils/utils';
 import { styles as walletItemStyles } from 'ts/utils/wallet_item_styles';
@@ -72,11 +72,6 @@ interface AccessoryItemConfig {
     allowanceToggleConfig?: AllowanceToggleConfig;
 }
 
-interface WebsiteBackendPriceInfo {
-    price: string;
-    address: string;
-}
-
 const styles: Styles = {
     root: {
         width: 346,
@@ -496,17 +491,15 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
         if (_.isEmpty(tokenAddresses)) {
             return {};
         }
-        const tokenAddressesQueryString = tokenAddresses.join(',');
-        const endpoint = `${configs.BACKEND_BASE_URL}/prices?tokens=${tokenAddressesQueryString}`;
-        const response = await fetch(endpoint);
-        if (response.status !== 200) {
+        try {
+            const websiteBackendPriceInfos = await backendClient.getPriceInfosAsync(tokenAddresses);
+            const addresses = _.map(websiteBackendPriceInfos, info => info.address);
+            const prices = _.map(websiteBackendPriceInfos, info => new BigNumber(info.price));
+            const pricesByAddress = _.zipObject(addresses, prices);
+            return pricesByAddress;
+        } catch (err) {
             return {};
         }
-        const websiteBackendPriceInfos: WebsiteBackendPriceInfo[] = await response.json();
-        const addresses = _.map(websiteBackendPriceInfos, info => info.address);
-        const prices = _.map(websiteBackendPriceInfos, info => new BigNumber(info.price));
-        const pricesByAddress = _.zipObject(addresses, prices);
-        return pricesByAddress;
     }
     private _openWrappedEtherActionRow(wrappedEtherDirection: Side) {
         this.setState({
-- 
cgit v1.2.3

