Clean UI. Adds amount parser for coinbaseService

This commit is contained in:
Gustavo Maximiliano Cortez 2017-01-14 19:22:33 -03:00
commit 8d1d59cb3b
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
9 changed files with 85 additions and 46 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, platformInfo, lodash, storageService, configService, appConfigService) {
angular.module('copayApp.services').factory('coinbaseService', function($http, $log, $window, $filter, platformInfo, lodash, storageService, configService, appConfigService, txFormatService) {
var root = {};
var credentials = {};
var isCordova = platformInfo.isCordova;
@ -104,6 +104,35 @@ angular.module('copayApp.services').factory('coinbaseService', function($http, $
});
};
root.getAvailableCurrency = function() {
var config = configService.getSync().wallet.settings;
// ONLY "USD" and "EUR"
switch(config.alternativeIsoCode) {
case 'EUR' : return 'EUR';
default : return 'USD'
};
};
root.parseAmount = function(amount, currency) {
var config = configService.getSync().wallet.settings;
var satToBtc = 1 / 100000000;
var unitToSatoshi = config.unitToSatoshi;
var amountUnitStr;
// IF 'USD'
if (currency) {
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
} else {
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
amountUnitStr = txFormatService.formatAmountStr(amountSat);
// convert unit to BTC
amount = (amountSat * satToBtc).toFixed(8);
currency = 'BTC';
}
return [amount, currency, amountUnitStr];
};
root.getOauthCodeUrl = function() {
return credentials.HOST
+ '/oauth/authorize?response_type=code&client_id='