From 39ccb7b288a3b7cda66539849d4570655e6753d7 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Tue, 23 Apr 2019 13:42:45 +0400 Subject: [PATCH] move fetchTokenList function to separate api folder, add fetchToken func --- src/logic/tokens/api/fetchToken.js | 12 ++++++++++++ src/logic/tokens/api/fetchTokenList.js | 12 ++++++++++++ src/logic/tokens/api/index.js | 3 +++ src/logic/tokens/store/actions/fetchTokens.js | 10 +--------- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/logic/tokens/api/fetchToken.js create mode 100644 src/logic/tokens/api/fetchTokenList.js create mode 100644 src/logic/tokens/api/index.js diff --git a/src/logic/tokens/api/fetchToken.js b/src/logic/tokens/api/fetchToken.js new file mode 100644 index 00000000..c3250853 --- /dev/null +++ b/src/logic/tokens/api/fetchToken.js @@ -0,0 +1,12 @@ +// @flow +import axios from 'axios' +import { getRelayUrl } from '~/config/index' + +const fetchToken = (tokenAddress: string) => { + const apiUrl = getRelayUrl() + const url = `${apiUrl}/tokens/${tokenAddress}` + + return axios.get(url) +} + +export default fetchToken \ No newline at end of file diff --git a/src/logic/tokens/api/fetchTokenList.js b/src/logic/tokens/api/fetchTokenList.js new file mode 100644 index 00000000..63b3b9eb --- /dev/null +++ b/src/logic/tokens/api/fetchTokenList.js @@ -0,0 +1,12 @@ +// @flow +import axios from 'axios' +import { getRelayUrl } from '~/config/index' + +const fetchTokenList = () => { + const apiUrl = getRelayUrl() + const url = `${apiUrl}/tokens` + + return axios.get(url) +} + +export default fetchTokenList diff --git a/src/logic/tokens/api/index.js b/src/logic/tokens/api/index.js new file mode 100644 index 00000000..7ee9a1aa --- /dev/null +++ b/src/logic/tokens/api/index.js @@ -0,0 +1,3 @@ +// @flow +export { default as fetchTokenList } from './fetchTokenList' +export { default as fetchToken } from './fetchToken' diff --git a/src/logic/tokens/store/actions/fetchTokens.js b/src/logic/tokens/store/actions/fetchTokens.js index 82385118..204dc54a 100644 --- a/src/logic/tokens/store/actions/fetchTokens.js +++ b/src/logic/tokens/store/actions/fetchTokens.js @@ -1,16 +1,15 @@ // @flow import { List } from 'immutable' import contract from 'truffle-contract' -import axios from 'axios' import type { Dispatch as ReduxDispatch } from 'redux' import StandardToken from '@gnosis.pm/util-contracts/build/contracts/GnosisStandardToken.json' import HumanFriendlyToken from '@gnosis.pm/util-contracts/build/contracts/HumanFriendlyToken.json' import { getWeb3 } from '~/logic/wallets/getWeb3' import { type GlobalState } from '~/store/index' import { makeToken, type TokenProps } from '~/logic/tokens/store/model/token' +import { fetchTokenList } from '~/logic/tokens/api' import { ensureOnce } from '~/utils/singleton' import saveTokens from './saveTokens' -import { getRelayUrl } from '~/config/index' const createStandardTokenContract = async () => { const web3 = getWeb3() @@ -31,13 +30,6 @@ export const getHumanFriendlyToken = ensureOnce(createHumanFriendlyTokenContract export const getStandardTokenContract = ensureOnce(createStandardTokenContract) -const fetchTokenList = async () => { - const apiUrl = getRelayUrl() - const url = `${apiUrl}/tokens` - const errMsg = 'Error querying safe balances' - return axios.get(url, errMsg) -} - export const fetchTokens = () => async (dispatch: ReduxDispatch) => { try { const {