Adds exchange rates during the top-up of the BitPay card

This commit is contained in:
Gustavo Maximiliano Cortez 2016-12-08 16:35:25 -03:00
parent 099f771faf
commit 938862bfe8
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
5 changed files with 43 additions and 1 deletions

View File

@ -229,6 +229,20 @@ angular.module('copayApp.controllers').controller('amountController', function($
return result.replace('x', '*');
};
$scope.getRates = function() {
bitpayCardService.getRates($scope.alternativeIsoCode, function(err, res) {
if (err) {
$log.warn(err);
return;
}
if ($scope.unitName == 'bits') {
$scope.exchangeRate = '1,000,000 bits ~ ' + res.rate + ' ' + $scope.alternativeIsoCode;
} else {
$scope.exchangeRate = '1 BTC ~ ' + res.rate + ' ' + $scope.alternativeIsoCode;
}
});
};
$scope.finish = function() {
var _amount = evaluate(format($scope.amount));

View File

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService, glideraService, bwcError) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService, glideraService, bwcError, bitpayCardService) {
var cachedTxp = {};
var toAmount;
var isChromeApp = platformInfo.isChromeApp;
@ -824,4 +824,21 @@ angular.module('copayApp.controllers').controller('confirmController', function(
});
});
};
$scope.getRates = function() {
var config = configService.getSync().wallet.settings;
var unitName = config.unitName;
var alternativeIsoCode = config.alternativeIsoCode;
bitpayCardService.getRates(alternativeIsoCode, function(err, res) {
if (err) {
$log.warn(err);
return;
}
if (unitName == 'bits') {
$scope.exchangeRate = '1,000,000 bits ~ ' + res.rate + ' ' + alternativeIsoCode;
} else {
$scope.exchangeRate = '1 BTC ~ ' + res.rate + ' ' + alternativeIsoCode;
}
});
};
});

View File

@ -305,6 +305,15 @@ angular.module('copayApp.services').factory('bitpayCardService', function($http,
});
};
root.getRates = function(currency, cb) {
$http(_get('/rates/' + currency)).then(function(data) {
$log.info('BitPay Get Rates: SUCCESS');
return cb(data.data.error, data.data.data);
}, function(data) {
return cb(_setError('BitPay Error: Get Rates', data));
});
};
/*
* CONSTANTS
*/

View File

@ -42,6 +42,7 @@
<div class="title">
<span translate>Amount</span>
<div class="size-12" ng-show="isGiftCard">Purchase Amount is limited to USD 1000 per day</div>
<div class="size-12" ng-if="cardId" ng-init="getRates()">{{exchangeRate}}</div>
<div ng-show="isGlidera">
<div class="limits" ng-show="limits && isGlidera == 'buy'">
<span>Daily buy limit</span>:

View File

@ -19,6 +19,7 @@
</div>
<div class="amount-label">
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
<div class="right size-12" ng-if="cardId" ng-init="getRates()">{{exchangeRate}}</div>
<div class="alternative">{{alternativeAmountStr || '...'}}</div>
</div>
</div>