From 3c87e196e40014b1b64be29c1abfc80f1ce65793 Mon Sep 17 00:00:00 2001 From: juampibermani Date: Tue, 1 Jun 2021 13:44:38 -0300 Subject: [PATCH] Config service file with safe apps retrieval --- src/logic/configService/index.ts | 20 +++++++++++++++++ .../components/Apps/api/config-service.ts | 22 ------------------- .../components/Apps/components/AppsList.tsx | 2 +- .../safe/components/Apps/hooks/useAppList.ts | 4 ++-- src/utils/constants.ts | 3 +-- 5 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 src/logic/configService/index.ts delete mode 100644 src/routes/safe/components/Apps/api/config-service.ts diff --git a/src/logic/configService/index.ts b/src/logic/configService/index.ts new file mode 100644 index 00000000..b547cc8a --- /dev/null +++ b/src/logic/configService/index.ts @@ -0,0 +1,20 @@ +import axios from 'axios' +import { getNetworkId } from 'src/config' +import { CONFIG_SERVICE_URL } from 'src/utils/constants' + +export type AppData = { + url: string + name?: string + disabled?: boolean + description?: string + networks: number[] +} + +enum Endpoints { + SAFE_APPS = '/safe-apps/', +} + +export const fetchSafeAppsList = async (): Promise => { + const networkId = getNetworkId() + return axios.get(`${CONFIG_SERVICE_URL}${Endpoints['SAFE_APPS']}?network_id=${networkId}`).then(({ data }) => data) +} diff --git a/src/routes/safe/components/Apps/api/config-service.ts b/src/routes/safe/components/Apps/api/config-service.ts deleted file mode 100644 index e2d1d792..00000000 --- a/src/routes/safe/components/Apps/api/config-service.ts +++ /dev/null @@ -1,22 +0,0 @@ -import axios from 'axios' -import { getNetworkId } from 'src/config' -import { SAFE_APPS_LIST_URL } from 'src/utils/constants' - -export type TokenListResult = { - name: string - timestamp: string - apps: AppData[] -} - -export type AppData = { - url: string - name?: string - disabled?: boolean - description?: string - networks: number[] -} - -export const fetchSafeAppsList = async (): Promise => { - const networkId = getNetworkId() - return axios.get(`${SAFE_APPS_LIST_URL}?network_id=${networkId}`).then(({ data }) => data) -} diff --git a/src/routes/safe/components/Apps/components/AppsList.tsx b/src/routes/safe/components/Apps/components/AppsList.tsx index ecbf52a8..8ba5ba82 100644 --- a/src/routes/safe/components/Apps/components/AppsList.tsx +++ b/src/routes/safe/components/Apps/components/AppsList.tsx @@ -14,7 +14,7 @@ import { SAFELIST_ADDRESS } from 'src/routes/routes' import { useAppList } from '../hooks/useAppList' import { SAFE_APP_FETCH_STATUS, SafeApp } from '../types' import AddAppForm from './AddAppForm' -import { AppData } from '../api/config-service' +import { AppData } from 'src/logic/configService/index' const Wrapper = styled.div` height: 100%; diff --git a/src/routes/safe/components/Apps/hooks/useAppList.ts b/src/routes/safe/components/Apps/hooks/useAppList.ts index c52bd7d2..189add93 100644 --- a/src/routes/safe/components/Apps/hooks/useAppList.ts +++ b/src/routes/safe/components/Apps/hooks/useAppList.ts @@ -1,7 +1,7 @@ import { useState, useEffect, useCallback } from 'react' import { loadFromStorage, saveToStorage } from 'src/utils/storage' import { APPS_STORAGE_KEY, getAppInfoFromUrl, getEmptySafeApp } from '../utils' -import { AppData, fetchSafeAppsList } from '../api/config-service' +import { AppData, fetchSafeAppsList } from 'src/logic/configService' import { SafeApp, StoredSafeApp, SAFE_APP_FETCH_STATUS } from '../types' import { getNetworkId } from 'src/config' import enqueueSnackbar from 'src/logic/notifications/store/actions/enqueueSnackbar' @@ -26,7 +26,7 @@ const useAppList = (): UseAppListReturnType => { setIsLoading(true) try { const result = await fetchSafeAppsList() - setApiAppsList(result && result?.apps.length ? result.apps : apiAppsList) + setApiAppsList(result && result?.length ? result : apiAppsList) } catch (err) { dispatch(enqueueSnackbar(NOTIFICATIONS.SAFE_APPS_FETCH_ERROR_MSG)) } diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 216e0414..956a8288 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -26,8 +26,7 @@ export const ETHERSCAN_API_KEY = process.env.REACT_APP_ETHERSCAN_API_KEY export const ETHGASSTATION_API_KEY = process.env.REACT_APP_ETHGASSTATION_API_KEY export const EXCHANGE_RATE_URL = 'https://api.exchangeratesapi.io/latest' export const EXCHANGE_RATE_URL_FALLBACK = 'https://api.coinbase.com/v2/exchange-rates' -export const SAFE_APPS_LIST_URL = - process.env.REACT_APP_SAFE_APPS_LIST_URL || 'https://safe-config.staging.gnosisdev.com/api/v1/safe-apps/' +export const CONFIG_SERVICE_URL = process.env.CONFIG_SERVICE_URL || 'https://safe-config.staging.gnosisdev.com/api/v1' export const IPFS_GATEWAY = process.env.REACT_APP_IPFS_GATEWAY export const SPENDING_LIMIT_MODULE_ADDRESS = process.env.REACT_APP_SPENDING_LIMIT_MODULE_ADDRESS || '0xCFbFaC74C26F8647cBDb8c5caf80BB5b32E43134'