This commit is contained in:
magmahindenburg 2017-07-27 17:00:54 +09:00
commit d1b7cc44b3
110 changed files with 4431 additions and 3044 deletions

View file

@ -51,8 +51,8 @@ angular.module('copayApp.controllers').controller('amazonCardsController',
remove: true
}, function(err) {
updateGiftCards();
return;
});
return;
}
amazonService.savePendingGiftCard(newData, null, function(err) {
@ -85,11 +85,11 @@ angular.module('copayApp.controllers').controller('amazonCardsController',
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.cardClaimCode = data.stateParams.cardClaimCode;
$scope.invoiceId = data.stateParams.invoiceId;
updateGiftCards(function() {
if ($scope.cardClaimCode) {
if ($scope.invoiceId) {
var card = lodash.find($scope.giftCards, {
claimCode: $scope.cardClaimCode
invoiceId: $scope.invoiceId
});
if (lodash.isEmpty(card)) {
popupService.showAlert(null, 'Card not found');

View file

@ -3,7 +3,6 @@
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, moment, popupService, gettextCatalog, $ionicHistory, bitpayService, externalLinkService, timeService) {
var self = this;
var runningBalance;
$scope.dateRange = {
value: 'last30Days'
};
@ -63,8 +62,6 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
self.bitpayCardTransactionHistoryCompleted = null;
self.bitpayCardTransactionHistoryConfirming = null;
self.bitpayCardTransactionHistoryPreAuth = null;
self.underpaidInvoiceInList = null;
self.delayedInvoiceInList = null;
self.balance = null;
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get transactions'));
return;
@ -73,42 +70,10 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
setGetStarted(history, function() {
var txs = lodash.clone(history.txs);
runningBalance = parseFloat(history.endingBalance);
for (var i = 0; i < txs.length; i++) {
txs[i] = _getMerchantInfo(txs[i]);
txs[i].icon = _getIconName(txs[i]);
txs[i].desc = _processDescription(txs[i]);
txs[i].price = _price(txs[i]);
txs[i].runningBalance = runningBalance;
txs[i].pending = txs[i].status.toLowerCase() == 'pending';
_runningBalance(txs[i]);
if (txs[i].merchant.city && txs[i].merchant.state) {
txs[i].merchant.location = txs[i].merchant.city + ', ' + txs[i].merchant.state;
} else {
txs[i].merchant.location = txs[i].merchant.city || txs[i].merchant.state || '';
}
}
self.bitpayCardTransactionHistoryCompleted = lodash.filter(txs, function(tx) {
return !tx.pending && tx.type.indexOf('93') == -1;
});
self.bitpayCardTransactionHistoryConfirming = lodash.filter(txs, function(tx) {
return tx.pending && tx.type.indexOf('93') == -1;
});
self.bitpayCardTransactionHistoryPreAuth = lodash.filter(txs, function(tx) {
return tx.pending && tx.type.indexOf('93') > -1;
});
lodash.forEach(self.bitpayCardTransactionHistoryConfirming, function(tx) {
if (lodash.includes(tx, 'paidPartial'))
self.underpaidInvoiceInList = true;
});
lodash.forEach(self.bitpayCardTransactionHistoryConfirming, function(tx) {
if (lodash.includes(tx, 'paid') || lodash.includes(tx, 'invalid'))
self.delayedInvoiceInList = true;
});
self.bitpayCardTransactionHistoryConfirming = bitpayCardService.filterTransactions('confirming', txs);
self.bitpayCardTransactionHistoryCompleted = bitpayCardService.filterTransactions('completed', txs);
self.bitpayCardTransactionHistoryPreAuth = bitpayCardService.filterTransactions('preAuth', txs);
self.balance = history.currentCardBalance;
self.updatedOn = null;
@ -133,42 +98,10 @@ angular.module('copayApp.controllers').controller('bitpayCardController', functi
});
};
var _getMerchantInfo = function(tx) {
var bpTranCodes = bitpayCardService.bpTranCodes;
lodash.keys(bpTranCodes).forEach(function(code) {
if (tx.type.indexOf(code) === 0) {
lodash.assign(tx, bpTranCodes[code]);
}
});
return tx;
};
var _getIconName = function(tx) {
var icon = tx.mcc || tx.category || null;
if (!icon || bitpayCardService.iconMap[icon] == undefined) return 'default';
return bitpayCardService.iconMap[icon];
};
var _processDescription = function(tx) {
if (lodash.isArray(tx.description)) {
return tx.description[0];
}
return tx.description;
};
var _price = function(tx) {
var price = tx.fee ? parseFloat(tx.amount) + parseFloat(tx.fee) : parseFloat(tx.amount);
return price;
};
var _runningBalance = function(tx) {
runningBalance -= parseFloat(tx.amount);
};
$scope.createdWithinPastDay = function(tx) {
var result = false;
if (tx.timestamp) {
result = timeService.withinPastDay(tx.timestamp);
if (tx.date) {
result = timeService.withinPastDay(tx.date);
}
return result;
};

View file

@ -1,34 +1,46 @@
'use strict';
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) {
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 amount;
var currency;
$scope.isCordova = platformInfo.isCordova;
var createdTx;
var message;
var invoiceId;
var configWallet = configService.getSync().wallet;
$scope.isCordova = platformInfo.isCordova;
$scope.openExternalLink = function(url) {
externalLinkService.open(url);
};
var showErrorAndBack = function(msg, err) {
var _resetValues = function() {
$scope.totalAmountStr = $scope.amount = $scope.invoiceFee = $scope.networkFee = $scope.totalAmount = $scope.wallet = null;
createdTx = message = invoiceId = null;
};
var showErrorAndBack = function(title, msg) {
title = title || gettextCatalog.getString('Error');
$scope.sendStatus = '';
$log.error(err);
err = err && err.errors ? err.errors[0].message : err;
popupService.showAlert(msg, err, function() {
$log.error(msg);
msg = (msg && msg.errors) ? msg.errors[0].message : msg;
popupService.showAlert(title, msg, function() {
$ionicHistory.goBack();
});
};
var showError = function(msg, err) {
var showError = function(title, msg, cb) {
cb = cb || function() {};
title = title || gettextCatalog.getString('Error');
$scope.sendStatus = '';
$log.error(err);
err = err && err.errors ? err.errors[0].message : (err || '');
popupService.showAlert(msg, err);
$log.error(msg);
msg = (msg && msg.errors) ? msg.errors[0].message : msg;
popupService.showAlert(title, msg, cb);
};
var publishAndSign = function(wallet, txp, onSendStatusChange, cb) {
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
var err = 'No signing proposal: No private key';
var err = gettextCatalog.getString('No signing proposal: No private key');
$log.info(err);
return cb(err);
}
@ -51,6 +63,111 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
}
};
var satToFiat = function(sat, cb) {
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) {
return cb(value);
});
};
var setTotalAmount = function(amountSat, invoiceFeeSat, networkFeeSat) {
satToFiat(amountSat, function(a) {
$scope.amount = Number(a);
satToFiat(invoiceFeeSat, function(i) {
$scope.invoiceFee = Number(i);
satToFiat(networkFeeSat, function(n) {
$scope.networkFee = Number(n);
$scope.totalAmount = $scope.amount + $scope.invoiceFee + $scope.networkFee;
$timeout(function() {
$scope.$digest();
});
});
});
});
};
var createInvoice = function(data, cb) {
amazonService.createBitPayInvoice(data, function(err, dataInvoice) {
if (err) {
var err_title = gettextCatalog.getString('Error creating the invoice');
var err_msg;
if (err && err.message && err.message.match(/suspended/i)) {
err_title = gettextCatalog.getString('Service not available');
err_msg = gettextCatalog.getString('Amazon.com is not available at this moment. Please try back later.');
} else if (err && err.message) {
err_msg = err.message;
} else {
err_msg = gettextCatalog.getString('Could not access to Amazon.com');
};
return cb({
title: err_title,
message: err_msg
});
}
var accessKey = dataInvoice ? dataInvoice.accessKey : null;
if (!accessKey) {
return cb({
message: gettextCatalog.getString('No access key defined')
});
}
amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
if (err) {
return cb({
message: gettextCatalog.getString('Could not get the invoice')
});
}
return cb(null, invoice, accessKey);
});
});
};
var createTx = function(wallet, invoice, message, cb) {
var payProUrl = (invoice && invoice.paymentUrls) ? invoice.paymentUrls.BIP73 : null;
if (!payProUrl) {
return cb({
title: gettextCatalog.getString('Error in Payment Protocol'),
message: gettextCatalog.getString('Invalid URL')
});
}
var outputs = [];
var toAddress = invoice.bitcoinAddress;
var amountSat = parseInt((invoice.btcDue * 100000000).toFixed(0)); // BTC to Satoshi
outputs.push({
'toAddress': toAddress,
'amount': amountSat,
'message': message
});
var txp = {
toAddress: toAddress,
amount: amountSat,
outputs: outputs,
message: message,
payProUrl: payProUrl,
excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true,
feeLevel: configWallet.settings.feeLevel || 'normal'
};
walletService.createTx(wallet, txp, function(err, ctxp) {
if (err) {
return cb({
title: gettextCatalog.getString('Could not create transaction'),
message: bwcError.msg(err)
});
}
return cb(null, ctxp);
});
};
var checkTransaction = lodash.throttle(function(count, dataSrc) {
amazonService.createGiftCard(dataSrc, function(err, giftCard) {
$log.debug("creating gift card " + count);
@ -58,7 +175,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
giftCard = {};
giftCard.status = 'FAILURE';
showError('Error creating gift card', err);
showError(gettextCatalog.getString('Error creating gift card'), err);
}
if (giftCard.status == 'PENDING' && count < 3) {
@ -83,9 +200,9 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
}, function(err) {
$log.error(err);
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Gift card expired');
return;
showError(null, gettextCatalog.getString('Gift card expired'));
});
return;
}
amazonService.savePendingGiftCard(newData, null, function(err) {
@ -98,6 +215,57 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
'leading': true
});
var initialize = function(wallet) {
var parsedAmount = txFormatService.parseAmount(amount, currency);
$scope.currencyIsoCode = parsedAmount.alternativeIsoCode;
$scope.amountUnitStr = parsedAmount.amountUnitStr;
var dataSrc = {
amount: parsedAmount.amount,
currency: parsedAmount.currency,
uuid: wallet.id
};
ongoingProcess.set('loadingTxInfo', true);
createInvoice(dataSrc, function(err, invoice, accessKey) {
if (err) {
ongoingProcess.set('loadingTxInfo', false);
showErrorAndBack(err.title, err.message);
return;
}
// Sometimes API does not return this element;
invoice['buyerPaidBtcMinerFee'] = invoice.buyerPaidBtcMinerFee || 0;
var invoiceFeeSat = (invoice.buyerPaidBtcMinerFee * 100000000).toFixed();
message = gettextCatalog.getString("{{amountStr}} for Amazon.com Gift Card", {
amountStr: $scope.amountUnitStr
});
createTx(wallet, invoice, message, function(err, ctxp) {
ongoingProcess.set('loadingTxInfo', false);
if (err) {
_resetValues();
showError(err.title, err.message);
return;
}
// Save in memory
createdTx = ctxp;
invoiceId = invoice.id;
createdTx['giftData'] = {
currency: dataSrc.currency,
amount: dataSrc.amount,
uuid: dataSrc.uuid,
accessKey: accessKey,
invoiceId: invoice.id,
invoiceUrl: invoice.url,
invoiceTime: invoice.invoiceTime
};
$scope.totalAmountStr = txFormatService.formatAmountStr(ctxp.amount);
setTotalAmount(parsedAmount.amountSat, invoiceFeeSat, ctxp.fee);
});
});
};
$scope.$on("$ionicView.beforeLeave", function(event, data) {
$ionicConfig.views.swipeBackEnabled(true);
});
@ -110,13 +278,16 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
amount = data.stateParams.amount;
currency = data.stateParams.currency;
if (amount > 1000) {
showErrorAndBack('Purchase Amount is limited to USD 1000 per day');
$scope.limitPerDayMessage = gettextCatalog.getString('Purchase Amount is limited to {{limitPerDay}} {{currency}} per day', {
limitPerDay: amazonService.limitPerDay,
currency: currency
});
if (amount > amazonService.limitPerDay) {
showErrorAndBack(null, $scope.limitPerDayMessage);
return;
}
$scope.amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
$scope.network = amazonService.getNetwork();
$scope.wallets = profileService.getWallets({
onlyComplete: true,
@ -124,135 +295,47 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
hasFunds: true
});
if (lodash.isEmpty($scope.wallets)) {
showErrorAndBack('No wallets with funds');
showErrorAndBack(null, gettextCatalog.getString('No wallets available'));
return;
}
$scope.wallet = $scope.wallets[0]; // Default first wallet
$scope.onWalletSelect($scope.wallets[0]); // Default first wallet
});
$scope.buyConfirm = function() {
var message = 'Buy gift card for ' + amount + ' ' + currency;
var okText = 'Confirm';
var cancelText = 'Cancel';
popupService.showConfirm(null, message, okText, cancelText, function(ok) {
if (!ok) return;
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
// Get first wallet as UUID
var uuid = $scope.wallet.id;
var dataSrc = {
currency: currency,
amount: amount,
uuid: uuid
};
if (!createdTx) {
showError(null, gettextCatalog.getString('Transaction has not been created'));
return;
}
var title = gettextCatalog.getString('Confirm');
var okText = gettextCatalog.getString('OK');
var cancelText = gettextCatalog.getString('Cancel');
popupService.showConfirm(title, message, okText, cancelText, function(ok) {
if (!ok) {
$scope.sendStatus = '';
return;
}
ongoingProcess.set('buyingGiftCard', true, statusChangeHandler);
amazonService.createBitPayInvoice(dataSrc, function(err, dataInvoice) {
publishAndSign($scope.wallet, createdTx, function() {}, function(err, txSent) {
if (err) {
_resetValues();
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
if (err && err.message && err.message.match(/suspended/i)) {
showError('Service not available', 'Amazon Gift Card Service is not available at this moment. Please try back later.');
} else {
showError('Could not access Gift Card Service', err);
};
showError(gettextCatalog.getString('Could not send transaction'), err);
return;
}
var accessKey = dataInvoice ? dataInvoice.accessKey : null;
if (!accessKey) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('No access key defined');
return;
}
amazonService.getBitPayInvoice(dataInvoice.invoiceId, function(err, invoice) {
if (err) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Error getting BitPay invoice', err);
return;
}
var payProUrl = (invoice && invoice.paymentUrls) ? invoice.paymentUrls.BIP73 : null;
if (!payProUrl) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Error fetching invoice');
return;
}
payproService.getPayProDetails(payProUrl, function(err, payProDetails) {
if (err) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Error fetching payment info', bwcError.msg(err));
return;
}
var outputs = [];
var toAddress = payProDetails.toAddress;
var amountSat = payProDetails.amount;
var comment = amount + ' ' + currency + ' Amazon.com Gift Card';
outputs.push({
'toAddress': toAddress,
'amount': amountSat,
'message': comment
});
var txp = {
toAddress: toAddress,
amount: amountSat,
outputs: outputs,
message: comment,
payProUrl: payProUrl,
excludeUnconfirmedUtxos: configWallet.spendUnconfirmed ? false : true,
feeLevel: walletSettings.feeLevel || 'normal'
};
walletService.createTx($scope.wallet, txp, function(err, ctxp) {
if (err) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Could not create transaction', bwcError.msg(err));
return;
}
publishAndSign($scope.wallet, ctxp, function() {}, function(err, txSent) {
if (err) {
ongoingProcess.set('buyingGiftCard', false, statusChangeHandler);
showError('Could not send transaction', err);
return;
}
$log.debug('Transaction broadcasted. Waiting for confirmation...');
var invoiceId = JSON.parse(payProDetails.merchant_data).invoiceId;
var dataSrc = {
currency: currency,
amount: amount,
uuid: uuid,
accessKey: accessKey,
invoiceId: invoice.id,
invoiceUrl: payProUrl,
invoiceTime: invoice.invoiceTime
};
checkTransaction(1, dataSrc);
});
});
}, true); // Disable loader
});
checkTransaction(1, createdTx.giftData);
});
});
};
$scope.showWalletSelector = function() {
$scope.walletSelectorTitle = 'Buy from';
$scope.walletSelectorTitle = gettextCatalog.getString('Buy from');
$scope.showWallets = true;
};
$scope.onWalletSelect = function(wallet) {
$scope.wallet = wallet;
initialize(wallet);
};
$scope.goBackHome = function() {
@ -262,14 +345,13 @@ angular.module('copayApp.controllers').controller('buyAmazonController', functio
historyRoot: true
});
$ionicHistory.clearHistory();
var claimCode = $scope.amazonGiftCard ? $scope.amazonGiftCard.claimCode : null;
$state.go('tabs.home').then(function() {
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.transitionTo('tabs.giftcards.amazon').then(function() {
$state.transitionTo('tabs.giftcards.amazon.cards', {
cardClaimCode: claimCode
invoiceId: invoiceId
});
});
});

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, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, 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, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification) {
var countDown = null;
var CONFIRM_LIMIT_USD = 20;
@ -22,6 +22,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var isCordova = platformInfo.isCordova;
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
//custom fee flag
var usingCustomFee = null;
function refresh() {
$timeout(function() {
$scope.$apply();
@ -57,7 +60,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
function setNoWallet(msg) {
$scope.wallet = null;
$scope.noWalletMessage = gettextCatalog.getString(msg);
$scope.noWalletMessage = msg;
$log.warn('Not ready to make the payment:' + msg);
$timeout(function() {
$scope.$apply();
@ -77,7 +80,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
});
if (!$scope.wallets || !$scope.wallets.length) {
setNoWallet('No wallets available');
setNoWallet(gettextCatalog.getString('No wallets available'));
return cb();
}
@ -106,7 +109,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
return cb('Could not update any wallet');
if (lodash.isEmpty(filteredWallets)) {
setNoWallet('Insufficent funds');
setNoWallet(gettextCatalog.getString('Insufficient funds'));
}
$scope.wallets = lodash.clone(filteredWallets);
return cb();
@ -202,7 +205,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
txp.inputs = tx.sendMaxInfo.inputs;
txp.fee = tx.sendMaxInfo.fee;
} else {
txp.feeLevel = tx.feeLevel;
if (usingCustomFee) {
txp.feePerKb = tx.feeRate;
} else txp.feeLevel = tx.feeLevel;
}
txp.message = tx.description;
@ -245,12 +250,12 @@ angular.module('copayApp.controllers').controller('confirmController', function(
refresh();
// End of quick refresh, before wallet is selected.
if (!wallet)return cb();
if (!wallet) return cb();
feeService.getFeeRate(tx.network, tx.feeLevel, function(err, feeRate) {
if (err) return cb(err);
tx.feeRate = feeRate;
if (!usingCustomFee) tx.feeRate = feeRate;
tx.feeLevelName = feeService.feeOpts[tx.feeLevel];
if (!wallet)
@ -267,7 +272,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
$log.debug('Send max info', sendMaxInfo);
if (tx.sendMax && sendMaxInfo.amount == 0) {
setNoWallet('Insufficent funds');
setNoWallet(gettextCatalog.getString('Insufficient funds'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
return cb('no_funds');
}
@ -294,8 +299,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var per = (txp.fee / (txp.amount + txp.fee) * 100);
txp.feeRatePerStr = per.toFixed(2) + '%';
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PER;
txp.feeToHigh = per > FEE_TOO_HIGH_LIMIT_PER;
tx.txp[wallet.id] = txp;
$log.debug('Confirm. TX Fully Updated for wallet:' + wallet.id, tx);
@ -505,6 +509,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
if (config.confirmedTxsNotifications && config.confirmedTxsNotifications.enabled) {
txConfirmNotification.subscribe(wallet, {
txid: txp.txid
});
}
}, onSendStatusChange);
};
@ -559,8 +568,15 @@ angular.module('copayApp.controllers').controller('confirmController', function(
scope.feeLevel = tx.feeLevel;
scope.noSave = true;
if (usingCustomFee) {
scope.customFeePerKB = tx.feeRate;
scope.feePerSatByte = tx.feeRate / 1000;
}
$ionicModal.fromTemplateUrl('views/modals/chooseFeeLevel.html', {
scope: scope,
backdropClickToClose: false,
hardwareBackButtonClose: false
}).then(function(modal) {
scope.chooseFeeLevelModal = modal;
scope.openModal();
@ -569,18 +585,21 @@ angular.module('copayApp.controllers').controller('confirmController', function(
scope.chooseFeeLevelModal.show();
};
scope.hideModal = function(customFeeLevel) {
scope.hideModal = function(newFeeLevel, customFeePerKB) {
scope.chooseFeeLevelModal.hide();
$log.debug('Custom fee level choosen:' + customFeeLevel + ' was:' + tx.feeLevel);
if (tx.feeLevel == customFeeLevel)
return;
$log.debug('New fee level choosen:' + newFeeLevel + ' was:' + tx.feeLevel);
usingCustomFee = newFeeLevel == 'custom' ? true : false;
if (tx.feeLevel == newFeeLevel && !usingCustomFee) return;
tx.feeLevel = newFeeLevel;
if (usingCustomFee) tx.feeRate = parseInt(customFeePerKB);
tx.feeLevel = customFeeLevel;
updateTx(tx, wallet, {
clearCache: true,
dryRun: true,
}, function() {
});
dryRun: true
}, function() {});
};
};

View file

@ -0,0 +1,119 @@
'use strict';
angular.module('copayApp.controllers').controller('feeLevelsController', function($scope, $timeout, $log, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
var FEE_MULTIPLIER = 10;
var FEE_MIN = 0;
var showErrorAndClose = function(title, msg) {
title = title || gettextCatalog.getString('Error');
$log.error(msg);
popupService.showAlert(title, msg, function() {
$scope.chooseFeeLevelModal.hide();
});
};
var getMinRecommended = function() {
var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'superEconomy'
});
return parseInt((value.feePerKB / 1000).toFixed());
};
var getMaxRecommended = function() {
var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'urgent'
});
return parseInt((value.feePerKB / 1000).toFixed());
};
$scope.ok = function() {
$scope.customFeePerKB = $scope.customFeePerKB ? ($scope.customSatPerByte.value * 1000).toFixed() : null;
$scope.hideModal($scope.feeLevel, $scope.customFeePerKB);
};
$scope.setFeesRecommended = function() {
$scope.maxFeeRecommended = getMaxRecommended();
$scope.minFeeRecommended = getMinRecommended();
$scope.minFeeAllowed = FEE_MIN;
$scope.maxFeeAllowed = $scope.maxFeeRecommended * FEE_MULTIPLIER;
};
$scope.checkFees = function(feePerSatByte) {
var fee = Number(feePerSatByte);
if (fee <= $scope.minFeeAllowed) $scope.showError = true;
else $scope.showError = false;
if (fee > $scope.minFeeAllowed && fee < $scope.minFeeRecommended) $scope.showMinWarning = true;
else $scope.showMinWarning = false;
if (fee < $scope.maxFeeAllowed && fee > $scope.maxFeeRecommended) $scope.showMaxWarning = true;
else $scope.showMaxWarning = false;
};
$scope.updateFeeRate = function() {
var value = lodash.find($scope.feeLevels[$scope.network], {
level: $scope.feeLevel
});
// If no custom fee
if (value) {
$scope.customFeePerKB = null;
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed();
$scope.avgConfirmationTime = value.nbBlocks * 10;
} else {
$scope.avgConfirmationTime = null;
$scope.customSatPerByte = { value: Number($scope.feePerSatByte) };
$scope.customFeePerKB = ($scope.feePerSatByte * 1000).toFixed();
}
// Warnings
$scope.setFeesRecommended();
$scope.checkFees($scope.feePerSatByte);
$timeout(function() {
$scope.$apply();
});
};
$scope.$watch(
"selectedFee.value",
function ( newValue, oldValue ) {
if (newValue != oldValue) {
$log.debug('New fee level: ' + newValue);
$scope.feeLevel = $scope.selectedFee.value;
$scope.updateFeeRate();
}
}
);
// From parent controller
// $scope.network
// $scope.feeLevel
//
// IF usingCustomFee
// $scope.customFeePerKB
// $scope.feePerSatByte
if (lodash.isEmpty($scope.feeLevel)) showErrorAndClose(null, gettextCatalog.getString('Fee level is not defined') );
$scope.selectedFee = { value: $scope.feeLevel };
$scope.feeOpts = feeService.feeOpts;
$scope.loadingFee = true;
feeService.getFeeLevels(function(err, levels) {
$scope.loadingFee = false;
if (err || lodash.isEmpty(levels)) {
showErrorAndClose(null, err);
return;
}
if (lodash.isEmpty(levels)) {
showErrorAndClose(null, gettextCatalog.getString('Could not get fee levels'));
return;
}
$scope.feeLevels = levels;
$scope.updateFeeRate();
});
});

View file

@ -2,14 +2,14 @@
angular.module('copayApp.controllers').controller('preferencesFeeController', function($scope, $timeout, $ionicHistory, lodash, gettextCatalog, configService, feeService, ongoingProcess, popupService) {
var network;
$scope.save = function(newFee) {
$scope.currentFeeLevel = newFee;
updateCurrentValues();
if ($scope.noSave)
return;
$scope.currentFeeLevel = newFee;
if ($scope.currentFeeLevel != 'custom') updateCurrentValues();
else showCustomFeePrompt();
if ($scope.noSave) return;
var opts = {
wallet: {
@ -32,7 +32,6 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
});
$scope.init = function() {
$scope.network = $scope.network || 'livenet';
$scope.feeOpts = feeService.feeOpts;
$scope.currentFeeLevel = $scope.feeLevel || feeService.getCurrentFeeLevel();
@ -60,16 +59,60 @@ angular.module('copayApp.controllers').controller('preferencesFeeController', fu
});
if (lodash.isEmpty(value)) {
$scope.feePerSatByte = null;
$scope.feePerSatByte = $scope.currentFeeLevel == 'custom' ? $scope.feePerSatByte : null;
$scope.avgConfirmationTime = null;
setMinWarning();
setMaxWarning();
return;
}
$scope.feePerSatByte = (value.feePerKB / 1000).toFixed();
$scope.avgConfirmationTime = value.nbBlocks * 10;
$scope.invalidCustomFeeEntered = false;
setMinWarning();
setMaxWarning();
};
$scope.chooseNewFee = function() {
$scope.hideModal($scope.currentFeeLevel);
$scope.hideModal($scope.currentFeeLevel, $scope.customFeePerKB);
};
var showCustomFeePrompt = function() {
$scope.invalidCustomFeeEntered = true;
$scope.showMaxWarning = false;
$scope.showMinWarning = false;
popupService.showPrompt(gettextCatalog.getString('Custom Fee'), gettextCatalog.getString('Set your own fee in satoshis/byte'), null, function(text) {
if (!text || !parseInt(text) || parseInt(text) <= 0) return;
$scope.feePerSatByte = parseInt(text);
$scope.customFeePerKB = ($scope.feePerSatByte * 1000).toFixed();
setMaxWarning();
setMinWarning();
$timeout(function() {
$scope.$apply();
});
});
};
$scope.getMinimumRecommeded = function() {
var value = lodash.find($scope.feeLevels[$scope.network], {
level: 'superEconomy'
});
return parseInt((value.feePerKB / 1000).toFixed());
};
var setMinWarning = function() {
if (parseInt($scope.feePerSatByte) < $scope.getMinimumRecommeded()) $scope.showMinWarning = true;
else $scope.showMinWarning = false;
};
var setMaxWarning = function() {
if (parseInt($scope.feePerSatByte) > 1000) {
$scope.showMaxWarning = true;
$scope.invalidCustomFeeEntered = true;
} else {
$scope.showMaxWarning = false;
$scope.invalidCustomFeeEntered = false;
}
};
});

View file

@ -1,39 +1,73 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesLogs',
function($scope, historicLog, platformInfo) {
function($scope, historicLog, lodash, configService, gettextCatalog) {
var config = configService.getSync();
var logLevels = historicLog.getLevels();
var selectedLevel;
$scope.logOptions = lodash.indexBy(logLevels, 'level');
var filterLogs = function(weight) {
$scope.filteredLogs = historicLog.get(weight);
};
$scope.setOptionSelected = function(level) {
var weight = $scope.logOptions[level].weight;
$scope.fillClass = 'fill-bar-' + level;
filterLogs(weight);
lodash.each($scope.logOptions, function(opt) {
opt.selected = opt.weight <= weight ? true : false;
opt.head = opt.weight == weight;
});
// Save the setting.
var opts = {
log: {
filter: level
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.prepareLogs = function() {
var log = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n';
log += '\n\n';
log += historicLog.get().map(function(v) {
return '[' + v.timestamp + '][' + v.level + ']' + v.msg;
}).join('\n');
return log;
};
$scope.sendLogs = function() {
var body = $scope.prepareLogs();
window.plugins.socialsharing.shareViaEmail(
body,
'Copay Logs',
null, // TO: must be null or an array
null, // CC: must be null or an array
null, // BCC: must be null or an array
null, // FILES: can be null, a string, or an array
function() {},
function() {}
);
};
$scope.showOptionsMenu = function() {
$scope.showOptions = true;
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.isCordova = platformInfo.isCordova;
selectedLevel = lodash.has(config, 'log.filter') ? historicLog.getLevel(config.log.filter) : historicLog.getDefaultLevel();
$scope.setOptionSelected(selectedLevel.level);
});
$scope.$on("$ionicView.enter", function(event, data) {
$scope.logs = historicLog.get();
$scope.prepare = function() {
var log = 'Copay Session Logs\n Be careful, this could contain sensitive private data\n\n';
log += '\n\n';
log += $scope.logs.map(function(v) {
return v.msg;
}).join('\n');
return log;
};
$scope.sendLogs = function() {
var body = $scope.prepare();
window.plugins.socialsharing.shareViaEmail(
body,
'Copay Logs',
null, // TO: must be null or an array
null, // CC: must be null or an array
null, // BCC: must be null or an array
null, // FILES: can be null, a string, or an array
function() {},
function() {}
);
};
filterLogs(selectedLevel.weight);
});
});

View file

@ -12,6 +12,11 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr
value: config.pushNotificationsEnabled
};
var isConfirmedTxsNotificationsEnabled = config.confirmedTxsNotifications ? config.confirmedTxsNotifications.enabled : false;
$scope.confirmedTxsNotifications = {
value: isConfirmedTxsNotificationsEnabled
};
$scope.latestEmail = {
value: emailService.getEmailIfEnabled()
};
@ -42,6 +47,18 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr
});
};
$scope.confirmedTxsNotificationsChange = function() {
if (!$scope.pushNotifications) return;
var opts = {
confirmedTxsNotifications: {
enabled: $scope.confirmedTxsNotifications.value
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.emailNotificationsChange = function() {
var opts = {
enabled: $scope.emailNotifications.value,

View file

@ -11,6 +11,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
var message;
var configWallet = configService.getSync().wallet;
var _resetValues = function() {
$scope.totalAmountStr = $scope.amount = $scope.invoiceFee = $scope.networkFee = $scope.totalAmount = $scope.wallet = null;
createdTx = message = null;
};
var showErrorAndBack = function(title, msg) {
title = title || gettextCatalog.getString('Error');
$scope.sendStatus = '';
@ -112,7 +117,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
var outputs = [];
var toAddress = invoice.bitcoinAddress;
var amountSat = parseInt(invoice.btcDue * 100000000); // BTC to Satoshi
var amountSat = parseInt((invoice.btcDue * 100000000).toFixed(0)); // BTC to Satoshi
outputs.push({
'toAddress': toAddress,
@ -193,6 +198,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
return;
}
// Sometimes API does not return this element;
invoice['buyerPaidBtcMinerFee'] = invoice.buyerPaidBtcMinerFee || 0;
var invoiceFeeSat = (invoice.buyerPaidBtcMinerFee * 100000000).toFixed();
message = gettextCatalog.getString("Top up {{amountStr}} to debit card ({{cardLastNumber}})", {
@ -203,7 +210,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
createTx(wallet, invoice, message, function(err, ctxp) {
ongoingProcess.set('loadingTxInfo', false);
if (err) {
showErrorAndBack(err.title, err.message);
_resetValues();
showError(err.title, err.message);
return;
}
@ -284,8 +292,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
ongoingProcess.set('topup', true, statusChangeHandler);
publishAndSign($scope.wallet, createdTx, function() {}, function(err, txSent) {
if (err) {
ongoingProcess.set('topup', false);
$scope.sendStatus = '';
_resetValues();
ongoingProcess.set('topup', false, statusChangeHandler);
showError(gettextCatalog.getString('Could not send transaction'), err);
return;
}
@ -295,7 +303,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
};
$scope.showWalletSelector = function() {
$scope.walletSelectorTitle = 'From';
$scope.walletSelectorTitle = gettextCatalog.getString('From');
$scope.showWallets = true;
};
@ -305,7 +313,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
calculateAmount(wallet, function(err, a, c) {
ongoingProcess.set('retrievingInputs', false);
if (err) {
createdTx = message = $scope.totalAmountStr = $scope.amountUnitStr = $scope.wallet = null;
_resetValues();
showError(err.title, err.message, function() {
$scope.showWalletSelector();
});

View file

@ -1,9 +1,10 @@
'use strict';
angular.module('copayApp.controllers').controller('txDetailsController', function($rootScope, $log, $ionicHistory, $scope, $timeout, walletService, lodash, gettextCatalog, profileService, externalLinkService, popupService, ongoingProcess, txFormatService, txConfirmNotification, feeService) {
angular.module('copayApp.controllers').controller('txDetailsController', function($rootScope, $log, $ionicHistory, $scope, $timeout, walletService, lodash, gettextCatalog, profileService, externalLinkService, popupService, ongoingProcess, txFormatService, txConfirmNotification, feeService, configService) {
var txId;
var listeners = [];
var config = configService.getSync();
$scope.$on("$ionicView.beforeEnter", function(event, data) {
txId = data.stateParams.txid;
@ -12,6 +13,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
$scope.color = $scope.wallet.color;
$scope.copayerId = $scope.wallet.credentials.copayerId;
$scope.isShared = $scope.wallet.credentials.n > 1;
$scope.txsUnsubscribedForNotifications = config.confirmedTxsNotifications ? !config.confirmedTxsNotifications.enabled : true;
txConfirmNotification.checkIfEnabled(txId, function(res) {
$scope.txNotification = {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService) {
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService) {
var HISTORY_SHOW_LIMIT = 10;
var currentTxHistoryPage = 0;
@ -52,9 +52,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
var analyzeUtxos = function() {
if (analyzeUtxosDone) return;
feeService.getFeeLevels(function(err, levels){
feeService.getFeeLevels(function(err, levels) {
if (err) return;
walletService.getLowUtxos($scope.wallet, levels, function(err, resp){
walletService.getLowUtxos($scope.wallet, levels, function(err, resp) {
if (err || !resp) return;
analyzeUtxosDone = true;
$scope.lowUtxosWarning = resp.warning;
@ -171,7 +171,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
};
feeService.getFeeLevels(function(err, levels){
feeService.getFeeLevels(function(err, levels) {
walletService.getTxHistory($scope.wallet, {
progressFn: progressFn,
feeLevels: levels,
@ -378,9 +378,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
refreshAmountSection();
});
$scope.$on("$ionicView.beforeLeave", function(event, data) {
$scope.$on("$ionicView.afterLeave", function(event, data) {
if ($window.StatusBar) {
$window.StatusBar.backgroundColorByHexString('#1e3186');
var statusBarColor = appConfigService.name == 'copay' ? '#192c3a' : '#1e3186';
$window.StatusBar.backgroundColorByHexString(statusBarColor);
}
});
@ -392,7 +394,10 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
function setAndroidStatusBarColor() {
var SUBTRACT_AMOUNT = 15;
var rgb = hexToRgb($scope.wallet.color);
var walletColor;
if (!$scope.wallet.color) walletColor = appConfigService.name == 'copay' ? '#019477' : '#4a90e2';
else walletColor = $scope.wallet.color;
var rgb = hexToRgb(walletColor);
var keys = Object.keys(rgb);
keys.forEach(function(k) {
if (rgb[k] - SUBTRACT_AMOUNT < 0) {