aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/provider-approval.js10
-rw-r--r--app/scripts/controllers/token-rates.js38
2 files changed, 23 insertions, 25 deletions
diff --git a/app/scripts/controllers/provider-approval.js b/app/scripts/controllers/provider-approval.js
index d3b7f6dff..21d7fd22e 100644
--- a/app/scripts/controllers/provider-approval.js
+++ b/app/scripts/controllers/provider-approval.js
@@ -88,7 +88,10 @@ class ProviderApprovalController {
_handlePrivacyRequest () {
const privacyMode = this.preferencesController.getFeatureFlags().privacyMode
if (!privacyMode) {
- this.platform && this.platform.sendMessage({ action: 'approve-provider-request' }, { active: true })
+ this.platform && this.platform.sendMessage({
+ action: 'approve-legacy-provider-request',
+ selectedAddress: this.publicConfigStore.getState().selectedAddress,
+ }, { active: true })
this.publicConfigStore.emit('update', this.publicConfigStore.getState())
}
}
@@ -101,7 +104,10 @@ class ProviderApprovalController {
approveProviderRequest (origin) {
this.closePopup && this.closePopup()
const requests = this.store.getState().providerRequests || []
- this.platform && this.platform.sendMessage({ action: 'approve-provider-request' }, { active: true })
+ this.platform && this.platform.sendMessage({
+ action: 'approve-provider-request',
+ selectedAddress: this.publicConfigStore.getState().selectedAddress,
+ }, { active: true })
this.publicConfigStore.emit('update', this.publicConfigStore.getState())
const providerRequests = requests.filter(request => request.origin !== origin)
this.store.updateState({ providerRequests })
diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js
index b6f084841..a8936f13b 100644
--- a/app/scripts/controllers/token-rates.js
+++ b/app/scripts/controllers/token-rates.js
@@ -14,8 +14,9 @@ class TokenRatesController {
*
* @param {Object} [config] - Options to configure controller
*/
- constructor ({ interval = DEFAULT_INTERVAL, preferences } = {}) {
+ constructor ({ interval = DEFAULT_INTERVAL, currency, preferences } = {}) {
this.store = new ObservableStore()
+ this.currency = currency
this.preferences = preferences
this.interval = interval
}
@@ -26,33 +27,24 @@ class TokenRatesController {
async updateExchangeRates () {
if (!this.isActive) { return }
const contractExchangeRates = {}
- // copy array to ensure its not modified during iteration
- const tokens = this._tokens.slice()
- for (const token of tokens) {
- if (!token) return log.error(`TokenRatesController - invalid tokens state:\n${JSON.stringify(tokens, null, 2)}`)
- const address = token.address
- contractExchangeRates[address] = await this.fetchExchangeRate(address)
+ const nativeCurrency = this.currency ? this.currency.getState().nativeCurrency.toUpperCase() : 'ETH'
+ const pairs = this._tokens.map(token => `pairs[]=${token.address}/${nativeCurrency}`)
+ const query = pairs.join('&')
+ if (this._tokens.length > 0) {
+ try {
+ const response = await fetch(`https://exchanges.balanc3.net/pie?${query}&autoConversion=true`)
+ const { prices = [] } = await response.json()
+ prices.forEach(({ pair, price }) => {
+ contractExchangeRates[pair.split('/')[0]] = typeof price === 'number' ? price : 0
+ })
+ } catch (error) {
+ log.warn(`MetaMask - TokenRatesController exchange rate fetch failed.`, error)
+ }
}
this.store.putState({ contractExchangeRates })
}
/**
- * Fetches a token exchange rate by address
- *
- * @param {String} address - Token contract address
- */
- async fetchExchangeRate (address) {
- try {
- const response = await fetch(`https://metamask.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`)
- const json = await response.json()
- return json && json.length ? json[0].averagePrice : 0
- } catch (error) {
- log.warn(`MetaMask - TokenRatesController exchange rate fetch failed for ${address}.`, error)
- return 0
- }
- }
-
- /**
* @type {Number}
*/
set interval (interval) {