mirror of https://github.com/BTCPrivate/copay.git
added rates to tx history
This commit is contained in:
parent
3eb45e529f
commit
bdec000af5
|
@ -46,9 +46,8 @@ var defaultConfig = {
|
||||||
storageSalt: 'mjuBtGybi/4=',
|
storageSalt: 'mjuBtGybi/4=',
|
||||||
},
|
},
|
||||||
|
|
||||||
rate: {
|
rates: {
|
||||||
url: 'https://bitpay.com/api/rates',
|
url: 'https://insight.bitpay.com:443/api/rates',
|
||||||
updateFrequencySeconds: 60 * 60
|
|
||||||
},
|
},
|
||||||
|
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
|
|
|
@ -140,19 +140,18 @@ angular.module('copayApp.controllers').controller('HistoryController',
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = res.items;
|
var items = res.items;
|
||||||
|
var now = new Date();
|
||||||
_.each(items, function(tx) {
|
_.each(items, function(tx) {
|
||||||
tx.ts = tx.minedTs || tx.sentTs;
|
tx.ts = tx.minedTs || tx.sentTs;
|
||||||
|
tx.rateTs = Math.floor((tx.ts || now) / 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
var index = _.indexBy(res.items, function(tx) {
|
var index = _.indexBy(items, 'rateTs');
|
||||||
return Math.floor(tx.ts / 1000);
|
|
||||||
});
|
|
||||||
rateService.getHistoricRates(w.settings.alternativeIsoCode, _.keys(index), function(err, res) {
|
rateService.getHistoricRates(w.settings.alternativeIsoCode, _.keys(index), function(err, res) {
|
||||||
console.log(res);
|
|
||||||
if (!err && res) {
|
if (!err && res) {
|
||||||
_.each(res, function(r) {
|
_.each(res, function(r) {
|
||||||
var tx = index[r.ts];
|
var tx = index[r.ts];
|
||||||
tx.alternativeAmount = tx.amountSat * rateService.SAT_TO_BTC * r.rate;
|
tx.alternativeAmount = r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null;
|
||||||
});
|
});
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, controllerUtils, notification) {
|
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, controllerUtils, notification) {
|
||||||
|
|
||||||
|
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
|
||||||
$scope.title = 'Settings';
|
$scope.title = 'Settings';
|
||||||
|
@ -93,6 +91,9 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
||||||
url: insightSettings.livenet.url + '/api/email'
|
url: insightSettings.livenet.url + '/api/email'
|
||||||
}),
|
}),
|
||||||
|
rates: _.extend(config.rates, {
|
||||||
|
url: insightSettings.livenet.url + '/api/rates'
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Go home reloading the application
|
// Go home reloading the application
|
||||||
|
|
|
@ -21,6 +21,8 @@ var RateService = function(opts) {
|
||||||
self.UNAVAILABLE_ERROR = 'Service is not available - check for service.isAvailable() or use service.whenAvailable()';
|
self.UNAVAILABLE_ERROR = 'Service is not available - check for service.isAvailable() or use service.whenAvailable()';
|
||||||
self.UNSUPPORTED_CURRENCY_ERROR = 'Currency not supported';
|
self.UNSUPPORTED_CURRENCY_ERROR = 'Currency not supported';
|
||||||
|
|
||||||
|
self._url = opts.url || 'https://insight.bitpay.com:443/api/rates';
|
||||||
|
|
||||||
self._isAvailable = false;
|
self._isAvailable = false;
|
||||||
self._rates = {};
|
self._rates = {};
|
||||||
self._alternatives = [];
|
self._alternatives = [];
|
||||||
|
@ -86,7 +88,7 @@ RateService.prototype.getHistoricRate = function(code, date, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.request.get({
|
self.request.get({
|
||||||
url: 'http://localhost:3001/api/rates/' + code + '?ts=' + date,
|
url: self._url + '/' + code + '?ts=' + date,
|
||||||
json: true
|
json: true
|
||||||
}, function(err, res, body) {
|
}, function(err, res, body) {
|
||||||
if (err || res.statusCode != 200 || !body) return cb(err || res);
|
if (err || res.statusCode != 200 || !body) return cb(err || res);
|
||||||
|
@ -97,12 +99,15 @@ RateService.prototype.getHistoricRate = function(code, date, cb) {
|
||||||
RateService.prototype.getHistoricRates = function(code, dates, cb) {
|
RateService.prototype.getHistoricRates = function(code, dates, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
dates = [].concat(dates).join(',');
|
var tsList = dates.join(',');
|
||||||
self.request.get({
|
self.request.get({
|
||||||
url: 'http://localhost:3001/api/rates/' + code + '?ts=' + dates,
|
url: self._url + '/' + code + '?ts=' + tsList,
|
||||||
json: true
|
json: true
|
||||||
}, function(err, res, body) {
|
}, function(err, res, body) {
|
||||||
if (err || res.statusCode != 200 || !body) return cb(err || res);
|
if (err || res.statusCode != 200 || !body) return cb(err || res);
|
||||||
|
if (!_.isArray(body)) {
|
||||||
|
body = [{ ts: dates[0], rate: body.rate }];
|
||||||
|
}
|
||||||
return cb(null, body);
|
return cb(null, body);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services').factory('rateService', function(request) {
|
angular.module('copayApp.services').factory('rateService', function(request) {
|
||||||
return copay.RateService.singleton({
|
var cfg = _.extend(config.rates, {
|
||||||
request: request
|
request: request
|
||||||
});
|
});
|
||||||
|
return copay.RateService.singleton(cfg);
|
||||||
});
|
});
|
||||||
|
|
|
@ -86,7 +86,7 @@ describe('RateService model', function() {
|
||||||
it('should return current valuation', function() {
|
it('should return current valuation', function() {
|
||||||
var rs = new RateService();
|
var rs = new RateService();
|
||||||
rs.isAvailable = sinon.stub().returns(true);
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
var getRateStub = sinon.stub(rs, '_getRate')
|
var getRateStub = sinon.stub(rs, 'getRate')
|
||||||
getRateStub.withArgs('USD').returns(300.00);
|
getRateStub.withArgs('USD').returns(300.00);
|
||||||
getRateStub.withArgs('EUR').returns(250.00);
|
getRateStub.withArgs('EUR').returns(250.00);
|
||||||
var params = [{
|
var params = [{
|
||||||
|
@ -119,7 +119,7 @@ describe('RateService model', function() {
|
||||||
rs.isAvailable = sinon.stub().returns(true);
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
var today = Date.now();
|
var today = Date.now();
|
||||||
var yesterday = today - 24 * 3600;
|
var yesterday = today - 24 * 3600;
|
||||||
var getHistoricalRateStub = sinon.stub(rs, '_getHistoricRate');
|
var getHistoricalRateStub = sinon.stub(rs, 'getHistoricRate');
|
||||||
getHistoricalRateStub.withArgs('USD', today).yields(null, 300.00);
|
getHistoricalRateStub.withArgs('USD', today).yields(null, 300.00);
|
||||||
getHistoricalRateStub.withArgs('USD', yesterday).yields(null, 250.00);
|
getHistoricalRateStub.withArgs('USD', yesterday).yields(null, 250.00);
|
||||||
getHistoricalRateStub.withArgs('EUR', today).yields(null, 250.00);
|
getHistoricalRateStub.withArgs('EUR', today).yields(null, 250.00);
|
||||||
|
@ -185,7 +185,7 @@ describe('RateService model', function() {
|
||||||
it('should return current valuation', function() {
|
it('should return current valuation', function() {
|
||||||
var rs = new RateService();
|
var rs = new RateService();
|
||||||
rs.isAvailable = sinon.stub().returns(true);
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
var getRateStub = sinon.stub(rs, '_getRate')
|
var getRateStub = sinon.stub(rs, 'getRate')
|
||||||
getRateStub.withArgs('USD').returns(300.00);
|
getRateStub.withArgs('USD').returns(300.00);
|
||||||
getRateStub.withArgs('EUR').returns(250.00);
|
getRateStub.withArgs('EUR').returns(250.00);
|
||||||
var params = [{
|
var params = [{
|
||||||
|
@ -223,7 +223,7 @@ describe('RateService model', function() {
|
||||||
it('should return list of available currencies', function() {
|
it('should return list of available currencies', function() {
|
||||||
var rs = new RateService();
|
var rs = new RateService();
|
||||||
rs.isAvailable = sinon.stub().returns(true);
|
rs.isAvailable = sinon.stub().returns(true);
|
||||||
sinon.stub(rs, '_getAlternatives').returns([{
|
sinon.stub(rs, 'getAlternatives').returns([{
|
||||||
name: 'United States Dollar',
|
name: 'United States Dollar',
|
||||||
isoCode: 'USD',
|
isoCode: 'USD',
|
||||||
rate: 300.00,
|
rate: 300.00,
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
'text-warning': btx.action == 'sent',
|
'text-warning': btx.action == 'sent',
|
||||||
'text-gray': btx.action == 'moved'}">
|
'text-gray': btx.action == 'moved'}">
|
||||||
<b>{{btx.amount| noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
<b>{{btx.amount| noFractionNumber}} {{$root.wallet.settings.unitName}}</b>
|
||||||
<b ng-show="btx.alternativeAmount >= 0">{{btx.alternativeAmount| noFractionNumber}} {{$root.wallet.settings.alternativeIsoCode}}</b>
|
<b ng-show="btx.alternativeAmount != null">{{btx.alternativeAmount| noFractionNumber}} {{$root.wallet.settings.alternativeIsoCode}}</b>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue