Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: integrate gaba/CurrencyRateController #6570

Merged
merged 3 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 0 additions & 205 deletions app/scripts/controllers/currency.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/scripts/controllers/token-rates.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TokenRatesController {
async updateExchangeRates () {
if (!this.isActive) { return }
const contractExchangeRates = {}
const nativeCurrency = this.currency ? this.currency.getState().nativeCurrency.toLowerCase() : 'eth'
const nativeCurrency = this.currency ? this.currency.state.nativeCurrency.toLowerCase() : 'eth'
const pairs = this._tokens.map(token => token.address).join(',')
const query = `contract_addresses=${pairs}&vs_currencies=${nativeCurrency}`
if (this._tokens.length > 0) {
Expand Down
32 changes: 12 additions & 20 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const KeyringController = require('eth-keyring-controller')
const NetworkController = require('./controllers/network')
const PreferencesController = require('./controllers/preferences')
const AppStateController = require('./controllers/app-state')
const CurrencyController = require('./controllers/currency')
const InfuraController = require('./controllers/infura')
const CachedBalancesController = require('./controllers/cached-balances')
const RecentBlocksController = require('./controllers/recent-blocks')
Expand Down Expand Up @@ -56,6 +55,7 @@ const ethUtil = require('ethereumjs-util')
const sigUtil = require('eth-sig-util')
const {
AddressBookController,
CurrencyRateController,
ShapeShiftController,
PhishingController,
} = require('gaba')
Expand Down Expand Up @@ -109,11 +109,7 @@ module.exports = class MetamaskController extends EventEmitter {
})

// currency controller
this.currencyController = new CurrencyController({
initState: initState.CurrencyController,
})
this.currencyController.updateConversionRate()
this.currencyController.scheduleConversionInterval()
this.currencyRateController = new CurrencyRateController(undefined, initState.CurrencyController)

// infura controller
this.infuraController = new InfuraController({
Expand All @@ -130,7 +126,7 @@ module.exports = class MetamaskController extends EventEmitter {

// token exchange rate tracker
this.tokenRatesController = new TokenRatesController({
currency: this.currencyController.store,
currency: this.currencyRateController,
preferences: this.preferencesController.store,
})

Expand Down Expand Up @@ -232,8 +228,7 @@ module.exports = class MetamaskController extends EventEmitter {
})
this.networkController.on('networkDidChange', () => {
this.balancesController.updateAllBalances()
const currentCurrency = this.currencyController.getCurrentCurrency()
this.setCurrentCurrency(currentCurrency, function () {})
this.setCurrentCurrency(this.currencyRateController.state.currentCurrency, function () {})
})
this.balancesController.updateAllBalances()

Expand Down Expand Up @@ -262,7 +257,7 @@ module.exports = class MetamaskController extends EventEmitter {
KeyringController: this.keyringController.store,
PreferencesController: this.preferencesController.store,
AddressBookController: this.addressBookController,
CurrencyController: this.currencyController.store,
CurrencyController: this.currencyRateController,
ShapeShiftController: this.shapeshiftController,
NetworkController: this.networkController.store,
InfuraController: this.infuraController.store,
Expand All @@ -284,7 +279,7 @@ module.exports = class MetamaskController extends EventEmitter {
PreferencesController: this.preferencesController.store,
RecentBlocksController: this.recentBlocksController.store,
AddressBookController: this.addressBookController,
CurrencyController: this.currencyController.store,
CurrencyController: this.currencyRateController,
ShapeshiftController: this.shapeshiftController,
InfuraController: this.infuraController.store,
ProviderApprovalController: this.providerApprovalController.store,
Expand Down Expand Up @@ -1596,16 +1591,13 @@ module.exports = class MetamaskController extends EventEmitter {
setCurrentCurrency (currencyCode, cb) {
const { ticker } = this.networkController.getNetworkConfig()
try {
this.currencyController.setNativeCurrency(ticker)
this.currencyController.setCurrentCurrency(currencyCode)
this.currencyController.updateConversionRate()
const data = {
nativeCurrency: ticker || 'ETH',
conversionRate: this.currencyController.getConversionRate(),
currentCurrency: this.currencyController.getCurrentCurrency(),
conversionDate: this.currencyController.getConversionDate(),
const currencyState = {
nativeCurrency: ticker,
currentCurrency: currencyCode,
}
cb(null, data)
this.currencyRateController.update(currencyState)
this.currencyRateController.configure(currencyState)
cb(null, this.currencyRateController.state)
} catch (err) {
cb(err)
}
Expand Down
Loading