Fix rateService. Add usd rates

This commit is contained in:
Gustavo Maximiliano Cortez 2017-08-28 15:51:13 -03:00
commit a5a80684eb
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
19 changed files with 87 additions and 80 deletions

View file

@ -83,9 +83,9 @@ angular.module('copayApp.controllers').controller('addressesController', functio
$scope.lowWarning = resp.warning; $scope.lowWarning = resp.warning;
$scope.lowUtxosNb = resp.lowUtxos.length; $scope.lowUtxosNb = resp.lowUtxos.length;
$scope.allUtxosNb = resp.allUtxos.length; $scope.allUtxosNb = resp.allUtxos.length;
$scope.lowUtxosSum = txFormatService.formatAmountStr($scope.wallet, lodash.sum(resp.lowUtxos || 0, 'satoshis')); $scope.lowUtxosSum = txFormatService.formatAmountStr($scope.wallet.coin, lodash.sum(resp.lowUtxos || 0, 'satoshis'));
$scope.allUtxosSum = txFormatService.formatAmountStr($scope.wallet, allSum); $scope.allUtxosSum = txFormatService.formatAmountStr($scope.wallet.coin, allSum);
$scope.minFee = txFormatService.formatAmountStr($scope.wallet, resp.minFee || 0); $scope.minFee = txFormatService.formatAmountStr($scope.wallet.coin, resp.minFee || 0);
$scope.minFeePer = per.toFixed(2) + '%'; $scope.minFeePer = per.toFixed(2) + '%';

View file

@ -200,11 +200,11 @@ angular.module('copayApp.controllers').controller('amountController', function($
}; };
function fromFiat(val) { function fromFiat(val) {
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals)); return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode, $scope.coin) * satToUnit).toFixed(unitDecimals));
}; };
function toFiat(val) { function toFiat(val) {
return parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2)); return parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode, $scope.coin)).toFixed(2));
}; };
function evaluate(val) { function evaluate(val) {

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('buyAmazonController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, $ionicConfig, lodash, amazonService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo, gettextCatalog, txFormatService) { angular.module('copayApp.controllers').controller('buyAmazonController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, $ionicConfig, lodash, amazonService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo, gettextCatalog, txFormatService) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
var createdTx; var createdTx;
@ -64,7 +65,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
}; };
var satToFiat = function(sat, cb) { var satToFiat = function(sat, cb) {
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) { txFormatService.toFiat(coin, sat, $scope.currencyIsoCode, function(value) {
return cb(value); return cb(value);
}); });
}; };
@ -216,7 +217,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
}); });
var initialize = function(wallet) { var initialize = function(wallet) {
var parsedAmount = txFormatService.parseAmount(wallet, amount, currency); var parsedAmount = txFormatService.parseAmount(coin, amount, currency);
$scope.currencyIsoCode = parsedAmount.currency; $scope.currencyIsoCode = parsedAmount.currency;
$scope.amountUnitStr = parsedAmount.amountUnitStr; $scope.amountUnitStr = parsedAmount.amountUnitStr;
var dataSrc = { var dataSrc = {
@ -260,7 +261,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
invoiceUrl: invoice.url, invoiceUrl: invoice.url,
invoiceTime: invoice.invoiceTime invoiceTime: invoice.invoiceTime
}; };
$scope.totalAmountStr = txFormatService.formatAmountStr(wallet, ctxp.amount); $scope.totalAmountStr = txFormatService.formatAmountStr(coin, ctxp.amount);
setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee); setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee);
}); });
}); });
@ -293,7 +294,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
hasFunds: true, hasFunds: true,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
showErrorAndBack(null, gettextCatalog.getString('No wallets available')); showErrorAndBack(null, gettextCatalog.getString('No wallets available'));

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, txFormatService) { angular.module('copayApp.controllers').controller('buyCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, txFormatService) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
@ -96,7 +97,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
$scope.wallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
@ -236,7 +237,7 @@ angular.module('copayApp.controllers').controller('buyCoinbaseController', funct
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
$scope.wallet = wallet; $scope.wallet = wallet;
var parsedAmount = txFormatService.parseAmount( var parsedAmount = txFormatService.parseAmount(
wallet, coin,
amount, amount,
currency); currency);

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('buyGlideraController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, glideraService, popupService, profileService, ongoingProcess, walletService, platformInfo, txFormatService) { angular.module('copayApp.controllers').controller('buyGlideraController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, glideraService, popupService, profileService, ongoingProcess, walletService, platformInfo, txFormatService) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
@ -78,7 +79,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController', functi
$scope.wallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
@ -161,7 +162,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController', functi
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
$scope.wallet = wallet; $scope.wallet = wallet;
var parsedAmount = txFormatService.parseAmount( var parsedAmount = txFormatService.parseAmount(
wallet, coin,
amount, amount,
currency); currency);

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('buyMercadoLibreController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, $ionicConfig, lodash, mercadoLibreService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo, txFormatService, gettextCatalog) { angular.module('copayApp.controllers').controller('buyMercadoLibreController', function($scope, $log, $state, $timeout, $filter, $ionicHistory, $ionicConfig, lodash, mercadoLibreService, popupService, profileService, ongoingProcess, configService, walletService, payproService, bwcError, externalLinkService, platformInfo, txFormatService, gettextCatalog) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
var createdTx; var createdTx;
@ -64,7 +65,7 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
}; };
var satToFiat = function(sat, cb) { var satToFiat = function(sat, cb) {
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) { txFormatService.toFiat(coin, sat, $scope.currencyIsoCode, function(value) {
return cb(value); return cb(value);
}); });
}; };
@ -214,7 +215,7 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
}); });
var initialize = function(wallet) { var initialize = function(wallet) {
var parsedAmount = txFormatService.parseAmount(wallet, amount, currency); var parsedAmount = txFormatService.parseAmount(coin, amount, currency);
$scope.currencyIsoCode = parsedAmount.currency; $scope.currencyIsoCode = parsedAmount.currency;
$scope.amountUnitStr = parsedAmount.amountUnitStr; $scope.amountUnitStr = parsedAmount.amountUnitStr;
var dataSrc = { var dataSrc = {
@ -258,7 +259,7 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
invoiceUrl: invoice.url, invoiceUrl: invoice.url,
invoiceTime: invoice.invoiceTime invoiceTime: invoice.invoiceTime
}; };
$scope.totalAmountStr = txFormatService.formatAmountStr(wallet, ctxp.amount); $scope.totalAmountStr = txFormatService.formatAmountStr(coin, ctxp.amount);
setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee); setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee);
}); });
}); });
@ -285,7 +286,7 @@ angular.module('copayApp.controllers').controller('buyMercadoLibreController', f
$scope.wallets = profileService.getWallets({ $scope.wallets = profileService.getWallets({
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
showErrorAndBack(null, gettextCatalog.getString('No wallets available')); showErrorAndBack(null, gettextCatalog.getString('No wallets available'));

View file

@ -1,6 +1,6 @@
'use strict'; '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, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification) { angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification) {
var countDown = null; var countDown = null;
var CONFIRM_LIMIT_USD = 20; var CONFIRM_LIMIT_USD = 20;
@ -238,10 +238,10 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (!tx.toAmount) return; if (!tx.toAmount) return;
// Amount // Amount
tx.amountStr = txFormatService.formatAmountStr(wallet, tx.toAmount); tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.toAmount);
tx.amountValueStr = tx.amountStr.split(' ')[0]; tx.amountValueStr = tx.amountStr.split(' ')[0];
tx.amountUnitStr = tx.amountStr.split(' ')[1]; tx.amountUnitStr = tx.amountStr.split(' ')[1];
txFormatService.formatAlternativeStr(tx.toAmount, function(v) { txFormatService.formatAlternativeStr(wallet.coin, tx.toAmount, function(v) {
tx.alternativeAmountStr = v; tx.alternativeAmountStr = v;
}); });
} }
@ -292,8 +292,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) { getTxp(lodash.clone(tx), wallet, opts.dryRun, function(err, txp) {
if (err) return cb(err); if (err) return cb(err);
txp.feeStr = txFormatService.formatAmountStr(wallet, txp.fee); txp.feeStr = txFormatService.formatAmountStr(wallet.coin, txp.fee);
txFormatService.formatAlternativeStr(txp.fee, function(v) { txFormatService.formatAlternativeStr(wallet.coin, txp.fee, function(v) {
txp.alternativeFeeStr = v; txp.alternativeFeeStr = v;
}); });
@ -343,20 +343,20 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var warningMsg = []; var warningMsg = [];
if (sendMaxInfo.utxosBelowFee > 0) { if (sendMaxInfo.utxosBelowFee > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", { warningMsg.push(gettextCatalog.getString("A total of {{amountBelowFeeStr}} were excluded. These funds come from UTXOs smaller than the network fee provided.", {
amountBelowFeeStr: txFormatService.formatAmountStr(wallet, sendMaxInfo.amountBelowFee) amountBelowFeeStr: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.amountBelowFee)
})); }));
} }
if (sendMaxInfo.utxosAboveMaxSize > 0) { if (sendMaxInfo.utxosAboveMaxSize > 0) {
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", { warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", {
amountAboveMaxSizeStr: txFormatService.formatAmountStr(wallet, sendMaxInfo.amountAboveMaxSize) amountAboveMaxSizeStr: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.amountAboveMaxSize)
})); }));
} }
return warningMsg.join('\n'); return warningMsg.join('\n');
}; };
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", { var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", {
fee: txFormatService.formatAmountStr(wallet, sendMaxInfo.fee) fee: txFormatService.formatAmountStr(wallet.coin, sendMaxInfo.fee)
}); });
var warningMsg = verifyExcludedUtxos(); var warningMsg = verifyExcludedUtxos();
@ -483,7 +483,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
if (walletService.isEncrypted(wallet)) if (walletService.isEncrypted(wallet))
return cb(); return cb();
var amountUsd = parseFloat(txFormatService.formatToUSD(txp.amount)); var amountUsd = parseFloat(txFormatService.formatToUSD(wallet.coin, txp.amount));
if (amountUsd <= CONFIRM_LIMIT_USD) if (amountUsd <= CONFIRM_LIMIT_USD)
return cb(); return cb();

View file

@ -28,9 +28,9 @@ angular.module('copayApp.controllers').controller('customAmountController', func
$scope.address = addr; $scope.address = addr;
$scope.coin = (data.stateParams.coin).toLowerCase(); $scope.coin = data.stateParams.coin;
var parsedAmount = txFormatService.parseAmount( var parsedAmount = txFormatService.parseAmount(
$scope.wallet, $scope.wallet.coin,
data.stateParams.amount, data.stateParams.amount,
data.stateParams.currency); data.stateParams.currency);
@ -43,13 +43,13 @@ angular.module('copayApp.controllers').controller('customAmountController', func
// Convert to BTC or BCH // Convert to BTC or BCH
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
var amountUnit = txFormatService.satToUnit(parsedAmount.amountSat); var amountUnit = txFormatService.satToUnit(parsedAmount.amountSat);
var btcParsedAmount = txFormatService.parseAmount($scope.wallet, amountUnit, $scope.wallet.coin); var btcParsedAmount = txFormatService.parseAmount($scope.wallet.coin, amountUnit, $scope.wallet.coin);
$scope.amountBtc = btcParsedAmount.amount; $scope.amountBtc = btcParsedAmount.amount;
$scope.altAmountStr = btcParsedAmount.amountUnitStr; $scope.altAmountStr = btcParsedAmount.amountUnitStr;
} else { } else {
$scope.amountBtc = amount; // BTC or BCH $scope.amountBtc = amount; // BTC or BCH
$scope.altAmountStr = txFormatService.formatAlternativeStr(parsedAmount.amountSat); $scope.altAmountStr = txFormatService.formatAlternativeStr($scope.wallet.coin, parsedAmount.amountSat);
} }
}); });
}); });
@ -63,12 +63,12 @@ angular.module('copayApp.controllers').controller('customAmountController', func
$scope.shareAddress = function() { $scope.shareAddress = function() {
if (!platformInfo.isCordova) return; if (!platformInfo.isCordova) return;
var data = 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc; var data = 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc + '&coin=' + $scope.wallet.coin;
window.plugins.socialsharing.share(data, null, null, null); window.plugins.socialsharing.share(data, null, null, null);
} }
$scope.copyToClipboard = function() { $scope.copyToClipboard = function() {
return 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc + '&coin=' + $scope.coin; return 'bitcoin:' + $scope.address + '?amount=' + $scope.amountBtc + '&coin=' + $scope.wallet.coin;
}; };
}); });

View file

@ -23,7 +23,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}; };
function displayFeeValues() { function displayFeeValues() {
txFormatService.formatAlternativeStr($scope.tx.fee, function(v) { txFormatService.formatAlternativeStr($scope.wallet.coin, $scope.tx.fee, function(v) {
$scope.tx.feeFiatStr = v; $scope.tx.feeFiatStr = v;
}); });
$scope.tx.feeRateStr = ($scope.tx.fee / ($scope.tx.amount + $scope.tx.fee) * 100).toFixed(2) + '%'; $scope.tx.feeRateStr = ($scope.tx.fee / ($scope.tx.amount + $scope.tx.fee) * 100).toFixed(2) + '%';
@ -219,7 +219,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
copayerId: $scope.wallet.credentials.copayerId copayerId: $scope.wallet.credentials.copayerId
}); });
$scope.tx = txFormatService.processTx($scope.wallet, tx); $scope.tx = txFormatService.processTx($scope.wallet.coin, tx);
if (!action && tx.status == 'pending') if (!action && tx.status == 'pending')
$scope.tx.pendingForUs = true; $scope.tx.pendingForUs = true;

View file

@ -27,7 +27,7 @@ angular.module('copayApp.controllers').controller('tourController',
rateService.whenAvailable(function() { rateService.whenAvailable(function() {
var localCurrency = 'USD'; var localCurrency = 'USD';
var btcAmount = 1; var btcAmount = 1;
var rate = rateService.toFiat(btcAmount * 1e8, localCurrency); var rate = rateService.toFiat(btcAmount * 1e8, localCurrency, 'btc');
$scope.localCurrencySymbol = '$'; $scope.localCurrencySymbol = '$';
$scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10)); $scope.localCurrencyPerBtc = $filter('formatFiatAmount')(parseFloat(rate.toFixed(2), 10));
$timeout(function() { $timeout(function() {

View file

@ -45,8 +45,7 @@ angular.module('copayApp.controllers').controller('paperWalletController',
$scope.balanceSat = balance; $scope.balanceSat = balance;
if ($scope.balanceSat <= 0) if ($scope.balanceSat <= 0)
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not funds found')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not funds found'));
var config = configService.getSync().wallet.settings; $scope.balance = txFormatService.formatAmountStr($scope.wallet.coin, balance);
$scope.balance = txFormatService.formatAmount(balance) + ' ' + config.unitName;
} }
$scope.$apply(); $scope.$apply();
}); });

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('sellCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, appConfigService, configService, txFormatService) { angular.module('copayApp.controllers').controller('sellCoinbaseController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicScrollDelegate, $ionicConfig, lodash, coinbaseService, popupService, profileService, ongoingProcess, walletService, appConfigService, configService, txFormatService) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
@ -183,7 +184,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
hasFunds: true, hasFunds: true,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
@ -304,7 +305,7 @@ angular.module('copayApp.controllers').controller('sellCoinbaseController', func
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
$scope.wallet = wallet; $scope.wallet = wallet;
var parsedAmount = txFormatService.parseAmount( var parsedAmount = txFormatService.parseAmount(
wallet, coin,
amount, amount,
currency); currency);

View file

@ -2,6 +2,7 @@
angular.module('copayApp.controllers').controller('sellGlideraController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, glideraService, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, txFormatService) { angular.module('copayApp.controllers').controller('sellGlideraController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, glideraService, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, txFormatService) {
var coin = 'btc';
var amount; var amount;
var currency; var currency;
@ -80,7 +81,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController', funct
onlyComplete: true, onlyComplete: true,
network: $scope.network, network: $scope.network,
hasFunds: true, hasFunds: true,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
@ -229,7 +230,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController', funct
$scope.onWalletSelect = function(wallet) { $scope.onWalletSelect = function(wallet) {
$scope.wallet = wallet; $scope.wallet = wallet;
var parsedAmount = txFormatService.parseAmount( var parsedAmount = txFormatService.parseAmount(
wallet, coin,
amount, amount,
currency); currency);

View file

@ -3,6 +3,7 @@
angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService, bwcError, txFormatService, sendMaxService, gettextCatalog) { angular.module('copayApp.controllers').controller('topUpController', function($scope, $log, $state, $timeout, $ionicHistory, $ionicConfig, lodash, popupService, profileService, ongoingProcess, walletService, configService, platformInfo, bitpayService, bitpayCardService, payproService, bwcError, txFormatService, sendMaxService, gettextCatalog) {
$scope.isCordova = platformInfo.isCordova; $scope.isCordova = platformInfo.isCordova;
var coin = 'btc';
var cardId; var cardId;
var useSendMax; var useSendMax;
var amount; var amount;
@ -36,7 +37,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
}; };
var satToFiat = function(sat, cb) { var satToFiat = function(sat, cb) {
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) { txFormatService.toFiat(coin, sat, $scope.currencyIsoCode, function(value) {
return cb(value); return cb(value);
}); });
}; };
@ -218,7 +219,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
// Save TX in memory // Save TX in memory
createdTx = ctxp; createdTx = ctxp;
$scope.totalAmountStr = txFormatService.formatAmountStr(wallet, ctxp.amount); $scope.totalAmountStr = txFormatService.formatAmountStr(coin, ctxp.amount);
setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee); setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee);
@ -257,7 +258,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
onlyComplete: true, onlyComplete: true,
network: bitpayService.getEnvironment().network, network: bitpayService.getEnvironment().network,
hasFunds: true, hasFunds: true,
coin: 'btc' coin: coin
}); });
if (lodash.isEmpty($scope.wallets)) { if (lodash.isEmpty($scope.wallets)) {
@ -320,7 +321,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
}); });
return; return;
} }
var parsedAmount = txFormatService.parseAmount(wallet, a, c); var parsedAmount = txFormatService.parseAmount(coin, a, c);
initializeTopUp(wallet, parsedAmount); initializeTopUp(wallet, parsedAmount);
}); });
}; };

View file

@ -112,8 +112,8 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not available at this time')); return popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Transaction not available at this time'));
} }
$scope.btx = txFormatService.processTx($scope.wallet, tx); $scope.btx = txFormatService.processTx($scope.wallet.coin, tx);
txFormatService.formatAlternativeStr(tx.fees, function(v) { txFormatService.formatAlternativeStr($scope.wallet.coin, tx.fees, function(v) {
$scope.btx.feeFiatStr = v; $scope.btx.feeFiatStr = v;
$scope.btx.feeRateStr = ($scope.btx.fees / ($scope.btx.amount + $scope.btx.fees) * 100).toFixed(2) + '%'; $scope.btx.feeRateStr = ($scope.btx.fees / ($scope.btx.amount + $scope.btx.fees) * 100).toFixed(2) + '%';
}); });

View file

@ -667,7 +667,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
abstract: true, abstract: true,
params: { params: {
id: null, id: null,
nextStep: 'tabs.paymentRequest.confirm' nextStep: 'tabs.paymentRequest.confirm',
forceCoin: true
} }
}) })

View file

@ -118,7 +118,7 @@ console.log('[rateService.js.84:retry:] BCH'); //TODO
}; };
RateService.prototype.getRate = function(code, chain) { RateService.prototype.getRate = function(code, chain) {
if (chain = 'bch') if (chain == 'bch')
return this._ratesBCH[code]; return this._ratesBCH[code];
else else
return this._rates[code]; return this._rates[code];

View file

@ -17,15 +17,15 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
return this.Utils.formatAmount(satoshis, config.unitCode, opts); return this.Utils.formatAmount(satoshis, config.unitCode, opts);
}; };
root.formatAmountStr = function(wallet, satoshis) { root.formatAmountStr = function(coin, satoshis) {
if (isNaN(satoshis)) return; if (isNaN(satoshis)) return;
return root.formatAmount(satoshis) + ' ' + wallet.coin; return root.formatAmount(satoshis) + ' ' + coin;
}; };
root.toFiat = function(satoshis, code, cb) { root.toFiat = function(coin, satoshis, code, cb) {
if (isNaN(satoshis)) return; if (isNaN(satoshis)) return;
var val = function() { var val = function() {
var v1 = rateService.toFiat(satoshis, code); var v1 = rateService.toFiat(satoshis, code, coin);
if (!v1) return null; if (!v1) return null;
return v1.toFixed(2); return v1.toFixed(2);
@ -42,10 +42,10 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
}; };
}; };
root.formatToUSD = function(satoshis, cb) { root.formatToUSD = function(coin, satoshis, cb) {
if (isNaN(satoshis)) return; if (isNaN(satoshis)) return;
var val = function() { var val = function() {
var v1 = rateService.toFiat(satoshis, 'USD'); var v1 = rateService.toFiat(satoshis, 'USD', coin);
if (!v1) return null; if (!v1) return null;
return v1.toFixed(2); return v1.toFixed(2);
@ -62,12 +62,12 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
}; };
}; };
root.formatAlternativeStr = function(satoshis, cb) { root.formatAlternativeStr = function(coin, satoshis, cb) {
if (isNaN(satoshis)) return; if (isNaN(satoshis)) return;
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
var val = function() { var val = function() {
var v1 = parseFloat((rateService.toFiat(satoshis, config.alternativeIsoCode)).toFixed(2)); var v1 = parseFloat((rateService.toFiat(satoshis, config.alternativeIsoCode, coin)).toFixed(2));
v1 = $filter('formatFiatAmount')(v1); v1 = $filter('formatFiatAmount')(v1);
if (!v1) return null; if (!v1) return null;
@ -85,7 +85,7 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
}; };
}; };
root.processTx = function(wallet, tx) { root.processTx = function(coin, tx) {
if (!tx || tx.action == 'invalid') if (!tx || tx.action == 'invalid')
return tx; return tx;
@ -100,17 +100,17 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
tx.hasMultiplesOutputs = true; tx.hasMultiplesOutputs = true;
} }
tx.amount = lodash.reduce(tx.outputs, function(total, o) { tx.amount = lodash.reduce(tx.outputs, function(total, o) {
o.amountStr = root.formatAmountStr(wallet, o.amount); o.amountStr = root.formatAmountStr(coin, o.amount);
o.alternativeAmountStr = root.formatAlternativeStr(o.amount); o.alternativeAmountStr = root.formatAlternativeStr(coin, o.amount);
return total + o.amount; return total + o.amount;
}, 0); }, 0);
} }
tx.toAddress = tx.outputs[0].toAddress; tx.toAddress = tx.outputs[0].toAddress;
} }
tx.amountStr = root.formatAmountStr(wallet, tx.amount); tx.amountStr = root.formatAmountStr(coin, tx.amount);
tx.alternativeAmountStr = root.formatAlternativeStr(tx.amount); tx.alternativeAmountStr = root.formatAlternativeStr(coin, tx.amount);
tx.feeStr = root.formatAmountStr(wallet, tx.fee || tx.fees); tx.feeStr = root.formatAmountStr(coin, tx.fee || tx.fees);
if (tx.amountStr) { if (tx.amountStr) {
tx.amountValueStr = tx.amountStr.split(' ')[0]; tx.amountValueStr = tx.amountStr.split(' ')[0];
@ -154,7 +154,7 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
return; return;
} }
tx = txFormatService.processTx(tx.wallet, tx); tx = txFormatService.processTx(tx.wallet.coin, tx);
var action = lodash.find(tx.actions, { var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId copayerId: tx.wallet.copayerId
@ -179,7 +179,7 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
return txps; return txps;
}; };
root.parseAmount = function(wallet, amount, currency) { root.parseAmount = function(coin, amount, currency) {
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
var satToBtc = 1 / 100000000; var satToBtc = 1 / 100000000;
var unitToSatoshi = config.unitToSatoshi; var unitToSatoshi = config.unitToSatoshi;
@ -190,19 +190,19 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
// If fiat currency // If fiat currency
if (currency != 'BCH' && currency != 'BTC' && currency != 'sat') { if (currency != 'BCH' && currency != 'BTC' && currency != 'sat') {
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency; amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
amountSat = rateService.fromFiat(amount, currency).toFixed(0); amountSat = rateService.fromFiat(amount, currency, coin).toFixed(0);
} else if (currency == 'sat') { } else if (currency == 'sat') {
amountSat = amount; amountSat = amount;
amountUnitStr = root.formatAmountStr(wallet, amountSat); amountUnitStr = root.formatAmountStr(coin, amountSat);
// convert sat to BTC or BCH // convert sat to BTC or BCH
amount = (amountSat * satToBtc).toFixed(8); amount = (amountSat * satToBtc).toFixed(8);
currency = (wallet.coin).toUpperCase(); currency = (coin).toUpperCase();
} else { } else {
amountSat = parseInt((amount * unitToSatoshi).toFixed(0)); amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
amountUnitStr = root.formatAmountStr(wallet, amountSat); amountUnitStr = root.formatAmountStr(coin, amountSat);
// convert unit to BTC or BCH // convert unit to BTC or BCH
amount = (amountSat * satToBtc).toFixed(8); amount = (amountSat * satToBtc).toFixed(8);
currency = (wallet.coin).toUpperCase(); currency = (coin).toUpperCase();
} }
return { return {

View file

@ -130,7 +130,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
lodash.each(txps, function(tx) { lodash.each(txps, function(tx) {
tx = txFormatService.processTx(wallet, tx); tx = txFormatService.processTx(wallet.coin, tx);
// no future transactions... // no future transactions...
if (tx.createdOn > now) if (tx.createdOn > now)
@ -237,11 +237,11 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
rateService.whenAvailable(function() { rateService.whenAvailable(function() {
var totalBalanceAlternative = rateService.toFiat(cache.totalBalanceSat, cache.alternativeIsoCode); var totalBalanceAlternative = rateService.toFiat(cache.totalBalanceSat, cache.alternativeIsoCode, wallet.coin);
var pendingBalanceAlternative = rateService.toFiat(cache.pendingAmount, cache.alternativeIsoCode); var pendingBalanceAlternative = rateService.toFiat(cache.pendingAmount, cache.alternativeIsoCode, wallet.coin);
var lockedBalanceAlternative = rateService.toFiat(cache.lockedBalanceSat, cache.alternativeIsoCode); var lockedBalanceAlternative = rateService.toFiat(cache.lockedBalanceSat, cache.alternativeIsoCode, wallet.coin);
var spendableBalanceAlternative = rateService.toFiat(cache.spendableAmount, cache.alternativeIsoCode); var spendableBalanceAlternative = rateService.toFiat(cache.spendableAmount, cache.alternativeIsoCode, wallet.coin);
var alternativeConversionRate = rateService.toFiat(100000000, cache.alternativeIsoCode); var alternativeConversionRate = rateService.toFiat(100000000, cache.alternativeIsoCode, wallet.coin);
cache.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative); cache.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
cache.pendingBalanceAlternative = $filter('formatFiatAmount')(pendingBalanceAlternative); cache.pendingBalanceAlternative = $filter('formatFiatAmount')(pendingBalanceAlternative);
@ -365,7 +365,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
wallet.hasUnsafeConfirmed = false; wallet.hasUnsafeConfirmed = false;
lodash.each(txs, function(tx) { lodash.each(txs, function(tx) {
tx = txFormatService.processTx(wallet, tx); tx = txFormatService.processTx(wallet.coin, tx);
// no future transactions... // no future transactions...
if (tx.time > now) if (tx.time > now)
@ -419,8 +419,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Fixing Tx Cache Unit to: ' + wallet.coin) $log.debug('Fixing Tx Cache Unit to: ' + wallet.coin)
lodash.each(txs, function(tx) { lodash.each(txs, function(tx) {
tx.amountStr = txFormatService.formatAmountStr(wallet, tx.amount); tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.amount);
tx.feeStr = txFormatService.formatAmountStr(wallet, tx.fees); tx.feeStr = txFormatService.formatAmountStr(wallet.coin, tx.fees);
}); });
}; };