Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #425 from ArkEcosystem/bug/fix-market-prices
Browse files Browse the repository at this point in the history
Market Prices updating caused an occasional error
  • Loading branch information
alexbarnsley authored Nov 21, 2017
2 parents 106a422 + 0831cc1 commit d2d5958
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions client/app/src/services/network.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@
if (res.data[0] && res.data[0].price_btc) {
res.data[0].price_btc = convertToSatoshi(res.data[0].price_btc) // store BTC price in satoshi
}
peer.market = res.data[0]
peer = updatePeerWithCurrencies(peer, res)
updatePeerWithCurrencies(peer, res)
.then((prices) => {
res.data[0].price = prices
peer.market = res.data[0]
})
.catch(() => {
peer.market = res.data[0]
})
storageService.set('lastPrice', { market: peer.market, date: new Date() })
}, failedTicker)
.catch(failedTicker)
Expand Down Expand Up @@ -348,6 +354,7 @@

// Updates peer with all currency values relative to the USD price.
function updatePeerWithCurrencies(peer, res) {
let deferred = $q.defer()
$http.get('https://api.fixer.io/latest?base=USD', { timeout: 2000}).then( function (result) {
const USD_PRICE = Number(res.data[0].price_usd)
var currencies = ["aud", "brl", "cad", "chf", "cny", "eur", "gbp", "hkd", "idr", "inr", "jpy", "krw", "mxn", "rub"]
Expand All @@ -357,11 +364,13 @@
})
prices["btc"] = res.data[0].price_btc
prices["usd"] = res.data[0].price_usd
peer.market.price = prices
storageService.setGlobal('peerCurrencies', prices)
deferred.resolve(prices)
}, () => {
deferred.reject(false)
})

return peer
return deferred.promise
}

listenNetworkHeight()
Expand Down

0 comments on commit d2d5958

Please sign in to comment.