init fiat rate service from within bws
This commit is contained in:
parent
aac0b70df4
commit
10ac3a4d65
|
@ -52,6 +52,10 @@ var config = {
|
|||
subjectPrefix: '',
|
||||
pushServerUrl: 'http://localhost:8000/send',
|
||||
},
|
||||
fiatRateServiceOpts: {
|
||||
defaultProvider: 'BitPay',
|
||||
fetchInterval: 15, // in minutes
|
||||
},
|
||||
// To use email notifications uncomment this:
|
||||
// emailOpts: {
|
||||
// host: 'localhost',
|
||||
|
|
|
@ -502,13 +502,10 @@ ExpressApp.prototype.start = function(opts, cb) {
|
|||
|
||||
router.get('/v1/fiatrates/:code/', function(req, res) {
|
||||
var opts = {
|
||||
code: req.params['code'],
|
||||
source: req.query.source,
|
||||
ts: req.query.ts,
|
||||
}
|
||||
// if (_.isString(ts) && ts.indexOf(',') !== -1) {
|
||||
// ts = ts.split(',');
|
||||
// }
|
||||
code: req.params['code'],
|
||||
source: req.query.source,
|
||||
ts: req.query.ts,
|
||||
}
|
||||
server.getFiatRate(opts, function(err, rates) {
|
||||
if (err) returnError({
|
||||
code: 500,
|
||||
|
|
|
@ -22,6 +22,7 @@ var Lock = require('./lock');
|
|||
var Storage = require('./storage');
|
||||
var MessageBroker = require('./messagebroker');
|
||||
var BlockchainExplorer = require('./blockchainexplorer');
|
||||
var FiatRateService = require('./fiatrateservice');
|
||||
|
||||
var Model = require('./model');
|
||||
var Wallet = Model.Wallet;
|
||||
|
@ -33,6 +34,7 @@ var storage;
|
|||
var blockchainExplorer;
|
||||
var blockchainExplorerOpts;
|
||||
var messageBroker;
|
||||
var fiatRateService;
|
||||
var serviceVersion;
|
||||
|
||||
var HISTORY_LIMIT = 10;
|
||||
|
@ -50,6 +52,7 @@ function WalletService() {
|
|||
this.blockchainExplorer = blockchainExplorer;
|
||||
this.blockchainExplorerOpts = blockchainExplorerOpts;
|
||||
this.messageBroker = messageBroker;
|
||||
this.fiatRateService = fiatRateService;
|
||||
this.notifyTicker = 0;
|
||||
};
|
||||
|
||||
|
@ -101,6 +104,22 @@ WalletService.initialize = function(opts, cb) {
|
|||
return cb();
|
||||
};
|
||||
|
||||
function initFiatRateService(cb) {
|
||||
if (opts.fiatRateService) {
|
||||
fiatRateService = opts.fiatRateService;
|
||||
return cb();
|
||||
} else {
|
||||
var newFiatRateService = new FiatRateService();
|
||||
var opts2 = opts.fiatRateServiceOpts || {};
|
||||
opts2.storage = storage;
|
||||
newFiatRateService.init(opts2, function(err) {
|
||||
if (err) return cb(err);
|
||||
fiatRateService = newFiatRateService;
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async.series([
|
||||
|
||||
function(next) {
|
||||
|
@ -109,6 +128,9 @@ WalletService.initialize = function(opts, cb) {
|
|||
function(next) {
|
||||
initMessageBroker(next);
|
||||
},
|
||||
function(next) {
|
||||
initFiatRateService(next);
|
||||
},
|
||||
], function(err) {
|
||||
if (err) {
|
||||
log.error('Could not initialize', err);
|
||||
|
@ -2373,13 +2395,16 @@ WalletService.prototype.startScan = function(opts, cb) {
|
|||
* @param {String} [opts.provider] - A provider of exchange rates (default 'BitPay').
|
||||
* @returns {Object} rates - The exchange rate.
|
||||
*/
|
||||
WalletService.prototype.getRate = function(opts, cb) {
|
||||
WalletService.prototype.getFiatRate = function(opts, cb) {
|
||||
var self = this;
|
||||
|
||||
if (!Utils.checkRequired(opts, ['code']))
|
||||
return cb(new ClientError('Required argument missing'));
|
||||
|
||||
|
||||
self.fiatRateService.getRate(opts, function(err, rate) {
|
||||
if (err) return cb(err);
|
||||
return cb(null, rate);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ var helpers = require('./helpers');
|
|||
|
||||
var FiatRateService = require('../../lib/fiatrateservice');
|
||||
|
||||
describe.only('Fiat rate service', function() {
|
||||
describe('Fiat rate service', function() {
|
||||
var service, request;
|
||||
|
||||
before(function(done) {
|
||||
|
|
Loading…
Reference in New Issue