diff options
Maintain token prices using a background service
Diffstat (limited to 'ui/app')
-rw-r--r-- | ui/app/actions.js | 58 | ||||
-rw-r--r-- | ui/app/components/send/send-v2-container.js | 1 | ||||
-rw-r--r-- | ui/app/reducers/metamask.js | 17 | ||||
-rw-r--r-- | ui/app/send-v2.js | 11 |
4 files changed, 6 insertions, 81 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 6453a2bc2..46f34e149 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -220,10 +220,6 @@ var actions = { coinBaseSubview: coinBaseSubview, SHAPESHIFT_SUBVIEW: 'SHAPESHIFT_SUBVIEW', shapeShiftSubview: shapeShiftSubview, - UPDATE_CONTRACT_EXCHANGE_RATES: 'UPDATE_CONTRACT_EXCHANGE_RATES', - UPDATE_CONTRACT_EXCHANGE_RATE: 'UPDATE_CONTRACT_EXCHANGE_RATE', - updateContractExchangeRates, - updateContractExchangeRate, PAIR_UPDATE: 'PAIR_UPDATE', pairUpdate: pairUpdate, coinShiftRquest: coinShiftRquest, @@ -1082,12 +1078,9 @@ function unlockMetamask (account) { } function updateMetamaskState (newState) { - return async dispatch => { - await dispatch({ - type: actions.UPDATE_METAMASK_STATE, - value: newState, - }) - dispatch(updateContractExchangeRates()) + return { + type: actions.UPDATE_METAMASK_STATE, + value: newState, } } @@ -1300,12 +1293,9 @@ function addTokens (tokens) { } function updateTokens (newTokens) { - return async dispatch => { - await dispatch({ - type: actions.UPDATE_TOKENS, - newTokens, - }) - dispatch(updateContractExchangeRates()) + return { + type: actions.UPDATE_TOKENS, + newTokens, } } @@ -1759,42 +1749,6 @@ function shapeShiftRequest (query, options, cb) { } } -async function fetchContractRate (address) { - try { - const response = await fetch(`https://exchanges.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`) - const json = await response.json() - const rate = json && json.length ? json[0].averagePrice : 0 - return { address, rate } - } catch (error) { } -} - -function updateContractExchangeRates () { - return async (dispatch, getState) => { - const { metamask: { tokens = [] } } = getState() - const newExchangeRates = {} - - for (const i in tokens) { - const address = tokens[i].address - newExchangeRates[address] = (await fetchContractRate(address)).rate - } - - dispatch({ - type: actions.UPDATE_CONTRACT_EXCHANGE_RATES, - payload: { newExchangeRates }, - }) - } -} - -function updateContractExchangeRate (address) { - return async dispatch => { - const { address, rate } = await fetchContractRate(address) - dispatch({ - type: actions.UPDATE_CONTRACT_EXCHANGE_RATE, - payload: { address, rate }, - }) - } -} - function setFeatureFlag (feature, activated, notificationType) { return (dispatch) => { dispatch(actions.showLoadingIndication()) diff --git a/ui/app/components/send/send-v2-container.js b/ui/app/components/send/send-v2-container.js index 75f16b382..adfc91240 100644 --- a/ui/app/components/send/send-v2-container.js +++ b/ui/app/components/send/send-v2-container.js @@ -66,7 +66,6 @@ function mapDispatchToProps (dispatch) { showCustomizeGasModal: () => dispatch(actions.showModal({ name: 'CUSTOMIZE_GAS' })), estimateGas: params => dispatch(actions.estimateGas(params)), getGasPrice: () => dispatch(actions.getGasPrice()), - updateContractExchangeRate: address => dispatch(actions.updateContractExchangeRate(address)), signTokenTx: (tokenAddress, toAddress, amount, txData) => ( dispatch(actions.signTokenTx(tokenAddress, toAddress, amount, txData)) ), diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js index d6b6de3b0..1ed049be2 100644 --- a/ui/app/reducers/metamask.js +++ b/ui/app/reducers/metamask.js @@ -177,23 +177,6 @@ function reduceMetamask (state, action) { conversionDate: action.value.conversionDate, }) - case actions.UPDATE_CONTRACT_EXCHANGE_RATES: - const { payload: { newExchangeRates } } = action - return { - ...metamaskState, - contractExchangeRates: newExchangeRates, - } - - case actions.UPDATE_CONTRACT_EXCHANGE_RATE: - const { payload: { address, rate } } = action - return { - ...metamaskState, - contractExchangeRates: { - ...metamaskState.contractExchangeRates, - [address]: rate, - }, - } - case actions.UPDATE_TOKENS: return extend(metamaskState, { tokens: action.newTokens, diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js index 12cf55f62..30d3d3152 100644 --- a/ui/app/send-v2.js +++ b/ui/app/send-v2.js @@ -88,17 +88,6 @@ SendTransactionScreen.prototype.updateSendTokenBalance = function (usersToken) { } SendTransactionScreen.prototype.componentWillMount = function () { - const { - updateContractExchangeRate, - selectedToken = {}, - } = this.props - - const { address } = selectedToken || {} - - if (address) { - updateContractExchangeRate(address) - } - this.updateGas() } |