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) {

View file

@ -0,0 +1,29 @@
'use strict';
angular.module('copayApp.directives')
.directive('logOptions', function($timeout, platformInfo) {
return {
restrict: 'E',
templateUrl: 'views/includes/logOptions.html',
transclude: true,
scope: {
show: '=logOptionsShow',
options: '=logOptions',
fillClass: '=logOptionsFillClass',
onSelect: '=logOptionsOnSelect',
onCopy: '=logOptionsOnCopy',
onSend: '=logOptionsOnSend'
},
link: function(scope, element, attrs) {
scope.isCordova = platformInfo.isCordova;
scope.hide = function() {
scope.show = false;
};
scope.getFillClass = function(index) {
scope.onSelect(index);
};
}
};
});

View file

@ -44,7 +44,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
function($delegate, platformInfo) {
var historicLog = historicLogProvider.$get();
['debug', 'info', 'warn', 'error', 'log'].forEach(function(level) {
historicLog.getLevels().forEach(function(levelDesc) {
var level = levelDesc.level;
if (platformInfo.isDevel && level == 'error') return;
var orig = $delegate[level];
@ -1083,7 +1084,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
},
params: {
cardClaimCode: null
invoiceId: null
}
})
.state('tabs.giftcards.amazon.amount', {

View file

@ -3,6 +3,8 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
var root = {};
var credentials = {};
root.limitPerDay = 1000;
/*
* Development: 'testnet'
* Production: 'livenet'

View file

@ -9,36 +9,155 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
return error;
};
var _processTransactions = function(invoices, history) {
invoices = invoices ||  [];
for (var i = 0; i < invoices.length; i++) {
var matched = false;
for (var j = 0; j < history.length; j++) {
if (history[j].description[0] && history[j].description[0].indexOf(invoices[i].id) > -1) {
matched = true;
}
var _buildDate = function(date, time) {
date = date.match(/(\d{2})\/(\d{2})\/(\d{4})/);
time = time.match(/(\d{2})(\d{2})(\d{2})/);
var newDate = new Date(date[1] + '/' + date[2] + '/' + date[3]);
newDate.setHours(time[1], time[2], time[3]);
return newDate;
};
var _lowercaseMerchant = function(merchant) {
if (merchant.name && merchant.name.toLowerCase) {
merchant.name = merchant.name.toLowerCase();
}
if (merchant.city && merchant.city.toLowerCase) {
merchant.city = merchant.city.toLowerCase();
}
return merchant;
};
var _getMerchantInfo = function(tx) {
var bpTranCodes = root.bpTranCodes;
lodash.keys(bpTranCodes).forEach(function(code) {
if (tx.type.indexOf(code) === 0) {
lodash.assign(tx, bpTranCodes[code]);
}
var isInvoiceLessThanOneDayOld = moment() < moment(new Date(invoices[i].invoiceTime)).add(1, 'day');
if (!matched && isInvoiceLessThanOneDayOld) {
var isInvoiceUnderpaid = invoices[i].exceptionStatus === 'paidPartial';
});
return tx;
};
if (['paid', 'confirmed', 'complete'].indexOf(invoices[i].status) >= 0 ||
(invoices[i].status === 'invalid' || isInvoiceUnderpaid)) {
var _getIconName = function(tx) {
var icon = tx.mcc || tx.category || null;
if (!icon || root.iconMap[icon] == undefined) return 'default';
return root.iconMap[icon];
};
history.unshift({
timestamp: new Date(invoices[i].invoiceTime),
description: invoices[i].itemDesc,
amount: invoices[i].price,
type: '00611 = Client Funded Deposit',
pending: true,
status: invoices[i].status,
transactionId: invoices[i].transactions && invoices[i].transactions[0] ? invoices[i].transactions[0].txid : '',
exceptionStatus: invoices[i].exceptionStatus
});
var _processDescription = function(tx) {
if (lodash.isArray(tx.description)) {
return tx.description[0];
}
return tx.description;
};
var _processLocation = function(tx) {
if (tx.merchant.city && tx.merchant.state) {
return tx.merchant.city + ', ' + tx.merchant.state;
} else {
return tx.merchant.city || tx.merchant.state || '';
}
};
var _fromTransaction = function(txn, runningBalance) {
var dateTime = _buildDate(txn.date, txn.time);
var merchant = _lowercaseMerchant(txn.merchant);
return _getMerchantInfo({
date: txn.timestamp || dateTime,
category: txn.mcc,
merchant: merchant,
description: txn.description[0],
price: parseFloat(txn.amount) + parseFloat(txn.fee),
type: txn.type,
runningBalance: runningBalance
});
};
var _processTransactions = function(invoices, history) {
var balance = history.endingBalance || history.currentCardBalance;
var runningBalance = parseFloat(balance);
var activityList = [];
if(history && history.transactionList){
for (var j = 0; j < history.transactionList.length; j++) {
runningBalance -= parseFloat(history.transactionList[j].amount);
activityList.push(_fromTransaction(history.transactionList[j], runningBalance));
}
}
if (activityList.length > 0) {
invoices = invoices ||  [];
for (var i = 0; i < invoices.length; i++) {
var matched = false;
for (var j = 0; j < history.transactionList.length; j++) {
var description = history.transactionList[j].description;
for (var k = 0; k < description.length; k++) {
if (description[k] && description[k].indexOf(invoices[i].id) > -1) {
matched = true;
}
}
}
var isInvoiceLessThanOneDayOld = moment() < moment(new Date(invoices[i].invoiceTime)).add(1, 'day');
if (!matched && isInvoiceLessThanOneDayOld) {
var isInvoiceUnderpaid = invoices[i].exceptionStatus === 'paidPartial';
if (['paid', 'confirmed', 'complete'].indexOf(invoices[i].status) >= 0 ||
(invoices[i].status === 'invalid' || isInvoiceUnderpaid)) {
activityList.unshift(_getMerchantInfo({
date: new Date(invoices[i].invoiceTime),
category: '',
merchant: '',
description: invoices[i].itemDesc,
price: invoices[i].price,
type: '00611 = Client Funded Deposit',
runningBalance: null,
pending: true,
transactionId: invoices[i].transactions && invoices[i].transactions[0] ? invoices[i].transactions[0].txid : ''
}));
}
}
}
}
return history;
for (var i = 0; i < activityList.length; i++) {
activityList[i].icon = _getIconName(activityList[i]);
activityList[i].desc = _processDescription(activityList[i]);
activityList[i].merchant['location'] = _processLocation(activityList[i]);
}
return activityList;
};
root.filterTransactions = function(type, txns) {
var list,
getPreAuth = lodash.filter(txns, function(txn) {
return txn.type.indexOf('93') > -1;
}),
getPending = lodash.filter(txns, function(txn) {
return txn.pending;
}),
getCompleted = lodash.filter(txns, function(txn) {
return !txn.pending && txn.type.indexOf('93') == -1;
});
switch (type) {
case "preAuth":
list = lodash.filter(getPreAuth);
break;
case "confirming":
list = lodash.filter(getPending);
break;
case "completed":
list = lodash.filter(getCompleted);
break;
default:
// code...
break;
}
return list;
};
root.sync = function(apiContext, cb) {
@ -91,12 +210,11 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
// opts: range
root.getHistory = function(cardId, opts, cb) {
var invoices, transactions;
var invoices, history;
opts = opts || {};
var json = {
method: 'getInvoiceHistory',
params: JSON.stringify(opts)
method: 'getInvoiceHistory'
};
appIdentityService.getIdentity(bitpayService.getEnvironment().network, function(err, appIdentity) {
@ -123,17 +241,17 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
method: 'getTransactionHistory',
params: JSON.stringify(opts)
};
// Get transactions list
// Get transactions History list
bitpayService.post('/api/v2/' + card.token, json, function(data) {
$log.info('BitPay Get Transactions: SUCCESS');
transactions = data.data.data || {};
transactions['txs'] = _processTransactions(invoices, transactions.transactionList);
$log.info('BitPay Get History: SUCCESS');
history = data.data.data || {};
history['txs'] = _processTransactions(invoices, history);
root.setLastKnownBalance(cardId, transactions.currentCardBalance, function() {});
root.setLastKnownBalance(cardId, history.currentCardBalance, function() {});
return cb(data.data.error, transactions);
return cb(data.data.error, history);
}, function(data) {
return cb(_setError('BitPay Card Error: Get Transactions', data));
return cb(_setError('BitPay Card Error: Get History', data));
});
}, function(data) {
return cb(_setError('BitPay Card Error: Get Invoices', data));
@ -338,7 +456,22 @@ angular.module('copayApp.services').factory('bitpayCardService', function($log,
category: 'bp002',
description: ''
},
'9991': { // General assignment of a fee for WC card
'load': {
merchant: {
name: 'BitPay',
city: 'Atlanta',
state: 'GA'
},
category: 'bp001',
description: 'Top-Up'
},
'unload | pos': {
description: 'Purchase'
},
'unload | epos': {
description: 'Online Purchase'
},
'transactionfee': {
merchant: {
name: 'Transaction Fee',
},

View file

@ -88,9 +88,17 @@ angular.module('copayApp.services').factory('configService', function(storageSer
pushNotificationsEnabled: true,
confirmedTxsNotifications: {
enabled: true,
},
emailNotifications: {
enabled: false,
},
log: {
filter: 'debug',
},
};
var configCache = null;

View file

@ -11,7 +11,8 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
priority: gettext('Priority'),
normal: gettext('Normal'),
economy: gettext('Economy'),
superEconomy: gettext('Super Economy')
superEconomy: gettext('Super Economy'),
custom: gettext('Custom')
};
var cache = {
@ -24,6 +25,9 @@ angular.module('copayApp.services').factory('feeService', function($log, $timeou
root.getFeeRate = function(network, feeLevel, cb) {
if (feeLevel == 'custom') return cb();
network = network || 'livenet';
root.getFeeLevels(function(err, levels, fromCache) {

View file

@ -1,18 +1,54 @@
'use strict';
var logs = [];
angular.module('copayApp.services')
.factory('historicLog', function historicLog() {
.factory('historicLog', function historicLog(lodash) {
var root = {};
var levels = [
{ level: 'error', weight: 0, label: 'Error'},
{ level: 'warn', weight: 1, label: 'Warning'},
{ level: 'info', weight: 2, label: 'Info', default: true},
{ level: 'debug', weight: 3, label: 'Debug'}
];
// Create an array of level weights for performant filtering.
var weight = {};
for (var i = 0; i < levels.length; i++) {
weight[levels[i].level] = levels[i].weight;
}
root.getLevels = function() {
return levels;
};
root.getLevel = function(level) {
return lodash.find(levels, function(l) {
return l.level == level;
});
};
root.getDefaultLevel = function() {
return lodash.find(levels, function(l) {
return l.default;
});
};
root.add = function(level, msg) {
logs.push({
timestamp: new Date().toISOString(),
level: level,
msg: msg,
});
};
root.get = function() {
return logs;
root.get = function(filterWeight) {
var filteredLogs = logs;
if (filterWeight != undefined) {
filteredLogs = lodash.filter(logs, function(l) {
return weight[l.level] <= filterWeight;
});
}
return filteredLogs;
};
return root;

View file

@ -72,7 +72,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni
var okText = gettextCatalog.getString('OK');
var cancelText = gettextCatalog.getString('Cancel');
title = title ? title : '';
navigator.notification.prompt(message, onPrompt, title, [cancelText, okText], opts.defaultText);
navigator.notification.prompt(message, onPrompt, title, [okText, cancelText], opts.defaultText);
};
/**

View file

@ -134,7 +134,7 @@ angular.module('copayApp.services')
wallet.setNotificationsInterval(UPDATE_PERIOD);
wallet.openWallet(function(err) {
if (wallet.status !== true)
$log.log('Wallet + ' + walletId + ' status:' + wallet.status)
$log.debug('Wallet + ' + walletId + ' status:' + wallet.status)
});
});

View file

@ -1 +1 @@
@import "gravatar"
@import "gravatar";

View file

@ -43,8 +43,8 @@ $v-wallet-color-map: (
13: (color: #7a8c9e, name: 'Light Slate Grey')
) !default;
/* Theme */
$v-default-wallet-color-index: 6 !default; // See $v-wallet-color-map
/* Theme */
$v-default-wallet-color-index: 8 !default; // See $v-wallet-color-map
$v-subtle-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25) !default;
$v-hovering-box-shadow: 0px 6px 12px 0px rgba(0, 0, 0, 0.3) !default;
$v-subtle-radius: 3px !default;

View file

@ -88,14 +88,18 @@
margin: 0;
border: 0;
&.send .svg #-Transaction-icons {
&.send svg .nc-icon-wrapper g,
&.send svg .nc-icon-wrapper path,
&.send .tx-icon .houston {
}
&.receive .svg #-Transaction-icons,
&.receive svg .nc-icon-wrapper g,
&.receive svg .nc-icon-wrapper path,
&.receive .tx-icon .houston {
stroke: #09C286;
color: #09C286;
}
&.pending .svg #-Transaction-icons,
&.pending svg .nc-icon-wrapper g,
&.pending svg .nc-icon-wrapper path,
&.pending .tx-icon .houston {
stroke: $v-bitcoin-orange;
color: $v-bitcoin-orange;
@ -154,11 +158,13 @@
}
.tx-message {
margin-right: 1rem;
text-transform: capitalize;
}
.tx-location {
margin-right: 1rem;
font-size: 12.5px;
color: $v-light-gray;
text-transform: capitalize;
}
.tx-amount {
font-size: 16px;

View file

@ -0,0 +1,62 @@
#check-bar {
$bar-widths: (
// defined by user, example:
// error: 10%,
// warn: 37%,
// info: 65%,
// debug: 90%
);
.item {
padding: 40px;
}
.checkbox-icon {
width: 22px;
height: 22px;
}
.checkbox-icon:after {
border: none;
}
.check-bar {
position: relative;
.initial-bar-default {
border: 2px solid $v-success-color;
width: 0%;
top: 40px;
z-index: 99;
border-radius: 10px;
position: absolute;
}
.initial-bar {
}
@each $name, $bar-width in $bar-widths {
.fill-bar-#{$name} {
width: $bar-width !important;
transition: width .2s;
}
}
.base-bar {
position: absolute;
width: 100%;
border-bottom: 2px solid #f2f2f2;
top: 41px;
z-index: 98;
left: 0px;
}
&.list {
margin-top: 20px;
display: flex;
justify-content: space-between;
.custom-checkbox {
text-align: -webkit-center;
.item {
border-style: none;
z-index: 999;
background-color: inherit;
}
label {
padding-top: 5px;
}
}
}
}
}

View file

@ -0,0 +1,88 @@
log-options {
$border-color: #EFEFEF;
.bp-action-sheet__sheet {
padding-left: 2rem;
padding-right: .75rem;
}
.entry {
border: 0;
padding-right: 0;
padding-top: 0;
padding-bottom: 0;
margin-bottom: 1px;
overflow: visible;
> i {
color: $v-accent-color;
padding: 0 0 5px 0;
margin-left: -5px;
> img {
height: 39px;
width: 39px;
padding: 4px;
}
}
}
.entry-inner {
display: flex;
position: relative;
padding-top: 16px;
padding-bottom: 16px;
&::after {
display: block;
position: absolute;
width: 100%;
height: 1px;
background: $border-color;
bottom: 0;
right: 0;
content: '';
}
}
.entry-details {
flex-grow: 1;
.entry-name {
padding-bottom: 5px;
}
}
#check-bar {
$bar-widths: (
// Order must match weight, see services/historicLog.js
error: 10%,
warn: 35%,
info: 65%,
debug: 90%
);
.check-bar {
.initial-bar {
border: 2px solid $v-accent-color;
}
@each $name, $bar-width in $bar-widths {
.fill-bar-#{$name} {
width: $bar-width !important;
}
}
}
.head .checkbox-icon {
width: 22px;
height: 22px;
top: 0;
}
.checkbox-icon {
width: 10px;
height: 10px;
top: 6px;
}
}
}

View file

@ -0,0 +1,57 @@
#choose-fee-level {
@extend .deflash-blue;
.selected-fee-level {
text-align: center;
background: #f9f9f9;
font-size: 11px;
height: 140px;
padding-top: 25px;
.row {
padding: 0;
}
.col {
padding-top: 15px;
}
.separator {
border-left: 1px solid #d9d9df;
height: 75%;
}
.value {
font-size: 20px;
margin-bottom: 10px;
}
.rate .list {
margin-bottom: 0;
}
.item-input {
input[type="number"] {
text-align: right;
padding-right: 90px;
}
.unit {
color: #9c9c9c;
background: #f2f2f2;
position: absolute;
right: 0;
top: 0;
padding: 15px 10px 12px 10px;
}
}
}
.error-fee {
padding: 8px 10px;
color: $v-error-color;
font-size: 12px;
text-align: center;
i {
margin-right: 8px;
}
}
.box-notification {
margin: 0;
padding: 1px;
text-align: center;
}
}

View file

@ -25,6 +25,15 @@
background-color: #fff;
font-size:0.9em;
color: $v-mid-gray;
.text {
padding-left: 25px;
}
.icon {
position: absolute;
img {
width: 20px;
}
}
}
&-explanation, &-button-group {
padding: 0 1rem;
@ -91,6 +100,10 @@
.item-button-right > .button {
top: 16px;
}
.toggle-small.item-toggle .toggle,
.item-button-right > .button {
top: 25px;
}
.item-button-right > .button {
font-size: 16px;
}
@ -110,6 +123,20 @@
color: #00901B;
}
}
.log-bg {
background: white;
}
.log-entry {
font-size: 12px;
line-height: 18px;
border: none;
}
.log-timestamp {
font-weight: bold;
}
.log-level {
font-weight: bold;
}
}
#tab-settings {
@ -162,6 +189,7 @@
#settings-fee {
.estimates {
min-height: 6rem;
font-size: 15px;
color: $v-dark-gray;
margin-bottom: .5rem;

View file

@ -34,6 +34,7 @@
@import "includes/walletActivity";
@import "includes/wallets";
@import "includes/modals/modals";
@import "includes/modals/choose-fee-level";
@import "includes/clickToAccept";
@import "includes/incomingDataMenu";
@import "includes/slideToAccept";
@ -47,3 +48,5 @@
@import "integrations/integrations";
@import "custom-amount";
@import "includes/pin";
@import "includes/logOptions";
@import "includes/checkBar";