Merge pull request #2177 from MetaMask/new-currency-test

Switching To Infura's Currency API
feature/default_network_editable
kumavis 7 years ago committed by GitHub
commit e451655c10
  1. 6
      CHANGELOG.md
  2. 6
      app/scripts/controllers/currency.js
  3. 20
      test/unit/currency-controller-test.js
  4. 3
      ui/app/components/fiat-value.js
  5. 8
      ui/app/config.js
  6. 207
      ui/app/conversion.json
  7. 653
      ui/app/infura-conversion.json

@ -2,6 +2,8 @@
## Current Master ## Current Master
- Added AUD, HKD, SGD, IDR, PHP to currency conversion list
## 3.10.6 2017-9-27 ## 3.10.6 2017-9-27
- Fix bug where newly created accounts were not selected. - Fix bug where newly created accounts were not selected.
@ -35,7 +37,8 @@ rollback to 3.10.0 due to bug
- Fixed a long standing memory leak associated with filters installed by dapps - Fixed a long standing memory leak associated with filters installed by dapps
- Fix link to support center. - Fix link to support center.
- Fixed tooltip icon locations to avoid overflow. - Fixed tooltip icon locations to avoid overflow.
- Warn users when a dapp proposes a high gas limit (90% of blockGasLimit or higher) - Warn users when a dapp proposes a high gas limit (90% of blockGasLimit or higher
- Sort currencies by currency name (thanks to strelok1: https://github.com/strelok1).
## 3.10.0 2017-9-11 ## 3.10.0 2017-9-11
@ -45,6 +48,7 @@ rollback to 3.10.0 due to bug
- Add validation preventing users from inputting their own addresses as token tracking addresses. - Add validation preventing users from inputting their own addresses as token tracking addresses.
- Added button to reject all transactions (thanks to davidp94! https://github.com/davidp94) - Added button to reject all transactions (thanks to davidp94! https://github.com/davidp94)
## 3.9.13 2017-9-8 ## 3.9.13 2017-9-8
- Changed the way we initialize the inpage provider to fix a bug affecting some developers. - Changed the way we initialize the inpage provider to fix a bug affecting some developers.

@ -8,7 +8,7 @@ class CurrencyController {
constructor (opts = {}) { constructor (opts = {}) {
const initState = extend({ const initState = extend({
currentCurrency: 'USD', currentCurrency: 'usd',
conversionRate: 0, conversionRate: 0,
conversionDate: 'N/A', conversionDate: 'N/A',
}, opts.initState) }, opts.initState)
@ -45,10 +45,10 @@ class CurrencyController {
updateConversionRate () { updateConversionRate () {
const currentCurrency = this.getCurrentCurrency() const currentCurrency = this.getCurrentCurrency()
return fetch(`https://api.cryptonator.com/api/ticker/eth-${currentCurrency}`) return fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency}`)
.then(response => response.json()) .then(response => response.json())
.then((parsedResponse) => { .then((parsedResponse) => {
this.setConversionRate(Number(parsedResponse.ticker.price)) this.setConversionRate(Number(parsedResponse.bid))
this.setConversionDate(Number(parsedResponse.timestamp)) this.setConversionDate(Number(parsedResponse.timestamp))
}).catch((err) => { }).catch((err) => {
if (err) { if (err) {

@ -15,11 +15,11 @@ describe('currency-controller', function () {
describe('currency conversions', function () { describe('currency conversions', function () {
describe('#setCurrentCurrency', function () { describe('#setCurrentCurrency', function () {
it('should return USD as default', function () { it('should return USD as default', function () {
assert.equal(currencyController.getCurrentCurrency(), 'USD') assert.equal(currencyController.getCurrentCurrency(), 'usd')
}) })
it('should be able to set to other currency', function () { it('should be able to set to other currency', function () {
assert.equal(currencyController.getCurrentCurrency(), 'USD') assert.equal(currencyController.getCurrentCurrency(), 'usd')
currencyController.setCurrentCurrency('JPY') currencyController.setCurrentCurrency('JPY')
var result = currencyController.getCurrentCurrency() var result = currencyController.getCurrentCurrency()
assert.equal(result, 'JPY') assert.equal(result, 'JPY')
@ -36,12 +36,12 @@ describe('currency-controller', function () {
describe('#updateConversionRate', function () { describe('#updateConversionRate', function () {
it('should retrieve an update for ETH to USD and set it in memory', function (done) { it('should retrieve an update for ETH to USD and set it in memory', function (done) {
this.timeout(15000) this.timeout(15000)
nock('https://api.cryptonator.com') nock('https://api.infura.io')
.get('/api/ticker/eth-USD') .get('/v1/ticker/ethusd')
.reply(200, '{"ticker":{"base":"ETH","target":"USD","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') .reply(200, '{"base": "ETH", "quote": "USD", "bid": 288.45, "ask": 288.46, "volume": 112888.17569277, "exchange": "bitfinex", "total_volume": 272175.00106721005, "num_exchanges": 8, "timestamp": 1506444677}')
assert.equal(currencyController.getConversionRate(), 0) assert.equal(currencyController.getConversionRate(), 0)
currencyController.setCurrentCurrency('USD') currencyController.setCurrentCurrency('usd')
currencyController.updateConversionRate() currencyController.updateConversionRate()
.then(function () { .then(function () {
var result = currencyController.getConversionRate() var result = currencyController.getConversionRate()
@ -57,14 +57,14 @@ describe('currency-controller', function () {
this.timeout(15000) this.timeout(15000)
assert.equal(currencyController.getConversionRate(), 0) assert.equal(currencyController.getConversionRate(), 0)
nock('https://api.cryptonator.com') nock('https://api.infura.io')
.get('/api/ticker/eth-JPY') .get('/v1/ticker/ethjpy')
.reply(200, '{"ticker":{"base":"ETH","target":"JPY","price":"11.02456145","volume":"44948.91745289","change":"-0.01472534"},"timestamp":1472072136,"success":true,"error":""}') .reply(200, '{"base": "ETH", "quote": "JPY", "bid": 32300.0, "ask": 32400.0, "volume": 247.4616071, "exchange": "kraken", "total_volume": 247.4616071, "num_exchanges": 1, "timestamp": 1506444676}')
var promise = new Promise( var promise = new Promise(
function (resolve, reject) { function (resolve, reject) {
currencyController.setCurrentCurrency('JPY') currencyController.setCurrentCurrency('jpy')
currencyController.updateConversionRate().then(function () { currencyController.updateConversionRate().then(function () {
resolve() resolve()
}) })

@ -13,6 +13,7 @@ function FiatValue () {
FiatValue.prototype.render = function () { FiatValue.prototype.render = function () {
const props = this.props const props = this.props
const { conversionRate, currentCurrency } = props const { conversionRate, currentCurrency } = props
const renderedCurrency = currentCurrency || ''
const value = formatBalance(props.value, 6) const value = formatBalance(props.value, 6)
@ -28,7 +29,7 @@ FiatValue.prototype.render = function () {
fiatTooltipNumber = 'Unknown' fiatTooltipNumber = 'Unknown'
} }
return fiatDisplay(fiatDisplayNumber, currentCurrency) return fiatDisplay(fiatDisplayNumber, renderedCurrency.toUpperCase())
} }
function fiatDisplay (fiatDisplayNumber, fiatSuffix) { function fiatDisplay (fiatDisplayNumber, fiatSuffix) {

@ -3,7 +3,9 @@ const Component = require('react').Component
const h = require('react-hyperscript') const h = require('react-hyperscript')
const connect = require('react-redux').connect const connect = require('react-redux').connect
const actions = require('./actions') const actions = require('./actions')
const currencies = require('./conversion.json').rows const infuraCurrencies = require('./infura-conversion.json').objects.sort((a, b) => {
return a.quote.name.toLocaleLowerCase().localeCompare(b.quote.name.toLocaleLowerCase())
})
const validUrl = require('valid-url') const validUrl = require('valid-url')
const exportAsFile = require('./util').exportAsFile const exportAsFile = require('./util').exportAsFile
@ -167,8 +169,8 @@ function currentConversionInformation (metamaskState, state) {
state.dispatch(actions.setCurrentCurrency(newCurrency)) state.dispatch(actions.setCurrentCurrency(newCurrency))
}, },
defaultValue: currentCurrency, defaultValue: currentCurrency,
}, currencies.map((currency) => { }, infuraCurrencies.map((currency) => {
return h('option', {key: currency.code, value: currency.code}, `${currency.code} - ${currency.name}`) return h('option', {key: currency.quote.code, value: currency.quote.code}, `${currency.quote.code.toUpperCase()} - ${currency.quote.name}`)
}) })
), ),
]) ])

@ -1,207 +0,0 @@
{
"rows": [
{
"code": "REP",
"name": "Augur",
"statuses": [
"primary"
]
},
{
"code": "BCN",
"name": "Bytecoin",
"statuses": [
"primary"
]
},
{
"code": "BTC",
"name": "Bitcoin",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "BTS",
"name": "BitShares",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "BLK",
"name": "Blackcoin",
"statuses": [
"primary"
]
},
{
"code": "GBP",
"name": "British Pound Sterling",
"statuses": [
"secondary"
]
},
{
"code": "CAD",
"name": "Canadian Dollar",
"statuses": [
"secondary"
]
},
{
"code": "CNY",
"name": "Chinese Yuan",
"statuses": [
"secondary"
]
},
{
"code": "DSH",
"name": "Dashcoin",
"statuses": [
"primary"
]
},
{
"code": "DOGE",
"name": "Dogecoin",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "ETC",
"name": "Ethereum Classic",
"statuses": [
"primary"
]
},
{
"code": "EUR",
"name": "Euro",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "GNO",
"name": "GNO",
"statuses": [
"primary"
]
},
{
"code": "GNT",
"name": "GNT",
"statuses": [
"primary"
]
},
{
"code": "JPY",
"name": "Japanese Yen",
"statuses": [
"secondary"
]
},
{
"code": "LTC",
"name": "Litecoin",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "MAID",
"name": "MaidSafeCoin",
"statuses": [
"primary"
]
},
{
"code": "XEM",
"name": "NEM",
"statuses": [
"primary"
]
},
{
"code": "XLM",
"name": "Stellar",
"statuses": [
"primary"
]
},
{
"code": "XMR",
"name": "Monero",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "XRP",
"name": "Ripple",
"statuses": [
"primary"
]
},
{
"code": "RUR",
"name": "Ruble",
"statuses": [
"secondary"
]
},
{
"code": "STEEM",
"name": "Steem",
"statuses": [
"primary"
]
},
{
"code": "STRAT",
"name": "STRAT",
"statuses": [
"primary"
]
},
{
"code": "UAH",
"name": "Ukrainian Hryvnia",
"statuses": [
"secondary"
]
},
{
"code": "USD",
"name": "US Dollar",
"statuses": [
"primary",
"secondary"
]
},
{
"code": "WAVES",
"name": "WAVES",
"statuses": [
"primary"
]
},
{
"code": "ZEC",
"name": "Zcash",
"statuses": [
"primary"
]
}
]
}

@ -0,0 +1,653 @@
{
"objects": [
{
"symbol": "ethaud",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "aud",
"name": "Australian Dollar"
}
},
{
"symbol": "ethhkd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "hkd",
"name": "Hong Kong Dollar"
}
},
{
"symbol": "ethsgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sgd",
"name": "Singapore Dollar"
}
},
{
"symbol": "ethidr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "idr",
"name": "Indonesian Rupiah"
}
},
{
"symbol": "ethphp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "php",
"name": "Philippine Peso"
}
},
{
"symbol": "eth1st",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "1st",
"name": "FirstBlood"
}
},
{
"symbol": "ethadt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "adt",
"name": "adToken"
}
},
{
"symbol": "ethadx",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "adx",
"name": "AdEx"
}
},
{
"symbol": "ethant",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ant",
"name": "Aragon"
}
},
{
"symbol": "ethbat",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "bat",
"name": "Basic Attention Token"
}
},
{
"symbol": "ethbnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "bnt",
"name": "Bancor"
}
},
{
"symbol": "ethbtc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "btc",
"name": "Bitcoin"
}
},
{
"symbol": "ethcad",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cad",
"name": "Canadian Dollar"
}
},
{
"symbol": "ethcfi",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cfi",
"name": "Cofound.it"
}
},
{
"symbol": "ethcrb",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "crb",
"name": "CreditBit"
}
},
{
"symbol": "ethcvc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "cvc",
"name": "Civic"
}
},
{
"symbol": "ethdash",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "dash",
"name": "Dash"
}
},
{
"symbol": "ethdgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "dgd",
"name": "DigixDAO"
}
},
{
"symbol": "ethetc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "etc",
"name": "Ethereum Classic"
}
},
{
"symbol": "etheur",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "eur",
"name": "Euro"
}
},
{
"symbol": "ethfun",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "fun",
"name": "FunFair"
}
},
{
"symbol": "ethgbp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gbp",
"name": "Pound Sterling"
}
},
{
"symbol": "ethgno",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gno",
"name": "Gnosis"
}
},
{
"symbol": "ethgnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gnt",
"name": "Golem"
}
},
{
"symbol": "ethgup",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "gup",
"name": "Matchpool"
}
},
{
"symbol": "ethhmq",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "hmq",
"name": "Humaniq"
}
},
{
"symbol": "ethjpy",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "jpy",
"name": "Japanese Yen"
}
},
{
"symbol": "ethlgd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lgd",
"name": "Legends Room"
}
},
{
"symbol": "ethlsk",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lsk",
"name": "Lisk"
}
},
{
"symbol": "ethltc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ltc",
"name": "Litecoin"
}
},
{
"symbol": "ethlun",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "lun",
"name": "Lunyr"
}
},
{
"symbol": "ethmco",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "mco",
"name": "Monaco"
}
},
{
"symbol": "ethmtl",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "mtl",
"name": "Metal"
}
},
{
"symbol": "ethmyst",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "myst",
"name": "Mysterium"
}
},
{
"symbol": "ethnmr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "nmr",
"name": "Numeraire"
}
},
{
"symbol": "ethomg",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "omg",
"name": "OmiseGO"
}
},
{
"symbol": "ethpay",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "pay",
"name": "TenX"
}
},
{
"symbol": "ethptoy",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "ptoy",
"name": "Patientory"
}
},
{
"symbol": "ethqrl",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "qrl",
"name": "Quantum-Resistant Ledger"
}
},
{
"symbol": "ethqtum",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "qtum",
"name": "Qtum"
}
},
{
"symbol": "ethrep",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rep",
"name": "Augur"
}
},
{
"symbol": "ethrlc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rlc",
"name": "iEx.ec"
}
},
{
"symbol": "ethrub",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "rub",
"name": "Russian Ruble"
}
},
{
"symbol": "ethsc",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sc",
"name": "Siacoin"
}
},
{
"symbol": "ethsngls",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "sngls",
"name": "SingularDTV"
}
},
{
"symbol": "ethsnt",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "snt",
"name": "Status"
}
},
{
"symbol": "ethsteem",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "steem",
"name": "Steem"
}
},
{
"symbol": "ethstorj",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "storj",
"name": "Storj"
}
},
{
"symbol": "ethtime",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "time",
"name": "ChronoBank"
}
},
{
"symbol": "ethtkn",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "tkn",
"name": "TokenCard"
}
},
{
"symbol": "ethtrst",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "trst",
"name": "WeTrust"
}
},
{
"symbol": "ethuah",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "uah",
"name": "Ukrainian Hryvnia"
}
},
{
"symbol": "ethusd",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "usd",
"name": "United States Dollar"
}
},
{
"symbol": "ethwings",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "wings",
"name": "Wings"
}
},
{
"symbol": "ethxem",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xem",
"name": "NEM"
}
},
{
"symbol": "ethxlm",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xlm",
"name": "Stellar Lumen"
}
},
{
"symbol": "ethxmr",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xmr",
"name": "Monero"
}
},
{
"symbol": "ethxrp",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "xrp",
"name": "Ripple"
}
},
{
"symbol": "ethzec",
"base": {
"code": "eth",
"name": "Ethereum"
},
"quote": {
"code": "zec",
"name": "Zcash"
}
}
]
}
Loading…
Cancel
Save