Merged sprint/20.

This commit is contained in:
Brendon Duncan 2018-08-13 15:55:57 +12:00
commit 5da475f1ee
68 changed files with 3433 additions and 851 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) {
angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, sendFlowService, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) {
var config = configService.getSync();
var defaults = configService.getDefaults();
@ -22,6 +22,7 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
$scope.sendTo = function() {
$ionicHistory.removeBackView();
sendFlowService.clear();
$state.go('tabs.send');
$timeout(function() {
var to = '';
@ -31,12 +32,16 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
} else {
to = $scope.addressbookEntry.address;
}
$state.transitionTo('tabs.send.amount', {
var stateParams = {
toAddress: to,
toName: $scope.addressbookEntry.name,
toEmail: $scope.addressbookEntry.email,
coin: $scope.addressbookEntry.coin
});
};
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
}, 100);
};

View file

@ -2,7 +2,7 @@
angular.module('copayApp.controllers').controller('amountController', amountController);
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) {
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) {
var vm = this;
vm.allowSend = false;
@ -29,6 +29,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.finish = finish;
vm.goBack = goBack;
vm.loadMore = loadMore;
vm.next = next;
vm.openPopup = openPopup;
vm.pushDigit = pushDigit;
vm.removeDigit = removeDigit;
@ -66,19 +67,22 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}
function onBeforeEnter(event, data) {
if (data.direction == "back") {
sendFlowService.popState();
}
console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
initCurrencies();
passthroughParams = data.stateParams;
console.log('stateParams:', data.stateParams);
passthroughParams = sendFlowService.getStateClone();
vm.fromWalletId = data.stateParams.fromWalletId;
vm.toWalletId = data.stateParams.toWalletId;
vm.minAmount = parseFloat(data.stateParams.minAmount);
vm.maxAmount = parseFloat(data.stateParams.maxAmount);
vm.fromWalletId = passthroughParams.fromWalletId;
vm.toWalletId = passthroughParams.toWalletId;
vm.minAmount = parseFloat(passthroughParams.minAmount);
vm.maxAmount = parseFloat(passthroughParams.maxAmount);
if (passthroughParams.thirdParty) {
vm.thirdParty = JSON.parse(passthroughParams.thirdParty); // Parse stringified JSON-object
vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object
if (vm.thirdParty) {
if (vm.thirdParty.id === 'shapeshift') {
if (!vm.thirdParty.data) {
@ -90,7 +94,6 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.toWallet = profileService.getWallet(vm.toWalletId);
shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function(data) {
console.log(data);
vm.thirdParty.data['minAmount'] = vm.minAmount = parseFloat(data.minimum);
vm.thirdParty.data['maxAmount'] = vm.maxAmount = parseFloat(data.maxLimit);
});
@ -98,7 +101,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}
}
vm.isRequestingSpecificAmount = !data.stateParams.fromWalletId;
vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId;
var config = configService.getSync().wallet.settings;
@ -179,8 +182,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
// currency have preference
var fiatName;
if (data.stateParams.currency) {
fiatCode = data.stateParams.currency;
if (passthroughParams.currency) {
fiatCode = passthroughParams.currency;
altUnitIndex = unitIndex
unitIndex = availableUnits.length;
} else {
@ -207,20 +210,11 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
var fromWallet = profileService.getWallet(passthroughParams.fromWalletId);
updateAvailableFundsFromWallet(fromWallet);
}
};
};
}
}
function goBack() {
if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
$state.go('tabs.send').then(function() {
$ionicHistory.clearHistory();
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.shapeshift');
});
});
} else {
$ionicHistory.goBack();
}
$ionicHistory.goBack();
}
function paste(value) {
@ -229,18 +223,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
$timeout(function() {
$scope.$apply();
});
};
}
function processClipboard() {
if (!isNW) return;
var value = nodeWebkitService.readFromClipboard();
if (value && evaluate(value) > 0) paste(evaluate(value));
};
}
function sendMax() {
useSendMax = true;
finish();
};
}
function updateUnitUI() {
vm.unit = availableUnits[unitIndex].shortName;
@ -248,7 +242,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
processAmount();
$log.debug('Update unit coin @amount unit:' + vm.unit + " alternativeUnit:" + vm.alternativeUnit);
};
}
function changeUnit() {
@ -269,7 +263,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
updateAvailableFundsStringIfNeeded();
updateUnitUI();
};
}
function pushDigit(digit) {
if (vm.amount && digit != '.') {
@ -293,7 +287,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.amount = (vm.amount + digit).replace('..', '.');
processAmount();
};
}
function pushOperator(operator) {
if (!vm.amount || vm.amount.length == 0) return;
@ -305,18 +299,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} else {
return val.slice(0, -1) + operator;
}
};
};
}
}
function isOperator(val) {
var regex = /[\/\-\+\x\*]/;
return regex.test(val);
};
}
function isExpression(val) {
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
return regex.test(val);
};
}
function removeDigit() {
vm.amount = (vm.amount).toString().slice(0, -1);
@ -341,7 +335,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
function close() {
altCurrencyModal.remove();
altCurrencyModal = null;
};
}
function processAmount() {
var formatedValue = format(vm.amount);
@ -411,22 +405,22 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} else {
vm.errorMessage = '';
}
};
}
function processResult(val) {
if (availableUnits[unitIndex].isFiat) return $filter('formatFiatAmount')(val);
else return txFormatService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
};
}
function fromFiat(val) {
return parseFloat((rateService.fromFiat(val, fiatCode, availableUnits[altUnitIndex].id) * satToUnit).toFixed(unitDecimals));
};
}
function toFiat(val) {
if (!rateService.getRate(fiatCode)) return;
return parseFloat((rateService.toFiat(val * unitToSatoshi, fiatCode, availableUnits[unitIndex].id)).toFixed(2));
};
}
function evaluate(val) {
var result;
@ -437,7 +431,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}
if (!lodash.isFinite(result)) return 0;
return result;
};
}
function format(val) {
if (!val) return;
@ -447,7 +441,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
if (isOperator(lodash.last(val))) result = result.slice(0, -1);
return result.replace('x', '*');
};
}
function finish() {
var unit = availableUnits[unitIndex];
@ -469,23 +463,22 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
};
if (vm.thirdParty) {
confirmData['thirdParty'] = JSON.stringify(this.thirdParty);
confirmData.thirdParty = vm.thirdParty;
}
console.log('confirmData:', confirmData);
sendFlowService.pushState(confirmData);
if (!confirmData.fromWalletId) {
$state.transitionTo('tabs.paymentRequest.confirm', confirmData);
} else {
$state.transitionTo('tabs.send.review', confirmData);
$scope.useSendMax = null;
}
};
}
// Currency
var next = 10;
var nextCurrencies = 10;
var completeAlternativeList = [];
var popularCurrencyList = [
@ -499,7 +492,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
{isoCode: 'CNY', order: 7},
{isoCode: 'KRW', order: 8},
{isoCode: 'HKD', order: 9},
]
];
function initCurrencies() {
var unusedCurrencyList = [{
@ -544,12 +537,17 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
function loadMore() {
$timeout(function() {
vm.altCurrencyList = completeAlternativeList.slice(0, next);
next += 10;
vm.altCurrencyList = completeAlternativeList.slice(0, nextCurrencies);
nextCurrencies += 10;
vm.listComplete = vm.altCurrencyList.length >= completeAlternativeList.length;
$scope.$broadcast('scroll.infiniteScrollComplete');
}, 100);
};
}
function next() {
useSendMax = false;
vm.finish();
}
function findCurrency(search) {
if (!search) initCurrencies();
@ -562,7 +560,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
$timeout(function() {
$scope.$apply();
});
};
}
function save(newAltCurrency) {
var opts = {
@ -588,26 +586,25 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
updateUnitUI();
close();
});
};
}
function updateAvailableFundsStringIfNeeded() {
if (passthroughParams.fromWalletId && availableSatoshis !== null) {
availableFundsInFiat = '';
vm.availableFunds = availableFundsInCrypto;
var coin = availableUnits[altUnitIndex].isFiat ? availableUnits[unitIndex].id : availableUnits[altUnitIndex].id;
txFormatService.formatAlternativeStr(coin, availableSatoshis, function formatCallback(formatted){
if (formatted) {
availableFundsInFiat = formatted;
$scope.$apply(function() {
if (availableUnits[unitIndex].isFiat) {
if (availableUnits[unitIndex].isFiat) {
var coin = availableUnits[altUnitIndex].id;
txFormatService.formatAlternativeStr(coin, availableSatoshis, function formatCallback(formatted){
if (formatted) {
availableFundsInFiat = formatted;
$scope.$apply(function() {
vm.availableFunds = availableFundsInFiat;
} else {
vm.availableFunds = availableFundsInCrypto;
}
});
}
});
});
}
});
}
}
}
@ -644,5 +641,4 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
vm.availableFunds = availableFundsInCrypto;
}
}
}

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($scope, $timeout, $log, $state, $stateParams, $ionicHistory, lodash, profileService, bwcService, walletService, ongoingProcess, popupService, gettextCatalog, $ionicModal, firebaseEventsService) {
function($scope, $timeout, $log, $state, $stateParams, $ionicHistory, lodash, profileService, bwcService, walletService, ongoingProcess, popupService, gettextCatalog, $ionicModal) {
if ($state.current.name == 'onboarding.backup') {
$scope.onboarding = true;
@ -89,7 +89,8 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.setFlow(2);
})
} else {
firebaseEventsService.logEvent('backed_up_wallet');
//firebaseEventsService.logEvent('backed_up_wallet');
openConfirmBackupModal();
}
};

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, $ionicLoading, ionicToast, addressbookService, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService, clipboardService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $timeout, $ionicScrollDelegate, $ionicLoading, ionicToast, addressbookService, gettextCatalog, walletService, platformInfo, lodash, configService, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, feeService, bitcoinCashJsService, bwcError, txConfirmNotification, soundService, clipboardService) {
var countDown = null;
var FEE_TOO_HIGH_LIMIT_PER = 15;
@ -708,8 +708,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
}], [channel, "adjust"]);
window.BitAnalytics.LogEventHandlers.postEvent(log);
// Should be removed
firebaseEventsService.logEvent('sent_bitcoin', { coin: $scope.wallet.coin });
$timeout(function() {
$scope.$digest();
}, 100);

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $timeout, $log, lodash, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, storageService, popupService, appConfigService, pushNotificationsService, firebaseEventsService, $ionicNavBarDelegate) {
function($scope, $timeout, $log, lodash, $state, $ionicScrollDelegate, $ionicHistory, profileService, configService, gettextCatalog, ledger, trezor, intelTEE, derivationPathHelper, ongoingProcess, walletService, popupService, appConfigService, pushNotificationsService, $ionicNavBarDelegate) {
/* For compressed keys, m*73 + n*34 <= 496 */
var COPAYER_PAIR_LIMITS = {
@ -268,7 +268,7 @@ angular.module('copayApp.controllers').controller('createController',
}, 100);
}
else {
firebaseEventsService.logEvent('wallet_created', { coin: opts.coin });
//firebaseEventsService.logEvent('wallet_created', { coin: opts.coin });
$state.go('tabs.home');
}
}

View file

@ -4,7 +4,7 @@ angular
.module('copayApp.controllers')
.controller('reviewController', reviewController);
function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicLoading, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
function reviewController(addressbookService, bitcoinCashJsService, bitcore, bitcoreCash, bwcError, configService, feeService, gettextCatalog, $interval, $ionicHistory, $ionicModal, lodash, $log, ongoingProcess, platformInfo, popupService, profileService, $scope, sendFlowService, shapeshiftService, soundService, $state, $timeout, txConfirmNotification, txFormatService, walletService) {
var vm = this;
vm.buttonText = '';
@ -49,9 +49,10 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
vm.memoExpanded = false;
// Functions
vm.goBack = goBack;
vm.onSuccessConfirm = onSuccessConfirm;
var sendFlowData;
var config = null;
var countDown = null;
var defaults = {};
@ -74,22 +75,22 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
function onBeforeEnter(event, data) {
console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state);
defaults = configService.getDefaults();
originWalletId = data.stateParams.fromWalletId;
satoshis = parseInt(data.stateParams.amount, 10);
toAddress = data.stateParams.toAddress;
destinationWalletId = data.stateParams.toWalletId;
sendFlowData = sendFlowService.getStateClone();
originWalletId = sendFlowData.fromWalletId;
satoshis = parseInt(sendFlowData.amount, 10);
toAddress = sendFlowData.toAddress;
destinationWalletId = sendFlowData.toWalletId;
vm.originWallet = profileService.getWallet(originWalletId);
vm.origin.currency = vm.originWallet.coin.toUpperCase();
coin = vm.originWallet.coin;
if (data.stateParams.thirdParty) {
vm.thirdParty = JSON.parse(data.stateParams.thirdParty); // Parse stringified JSON-object
if (vm.thirdParty) {
handleThirdPartyInitIfBip70();
handleThirdPartyInitIfShapeshift();
}
if (sendFlowData.thirdParty) {
vm.thirdParty = sendFlowData.thirdParty;
handleThirdPartyInitIfBip70();
handleThirdPartyInitIfShapeshift();
}
configService.get(function onConfig(err, configCache) {
@ -105,7 +106,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
updateSendAmounts();
getOriginWalletBalance(vm.originWallet);
handleDestinationAsAddress(toAddress, coin);
handleDestinationAsWallet(data.stateParams.toWalletId);
handleDestinationAsWallet(sendFlowData.toWalletId);
createVanityTransaction(data);
});
}
@ -115,7 +116,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (!tx || !vm.originWallet) return;
if (vm.paymentExpired) {
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.'));
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.', function () {
$ionicHistory.goBack();
}));
vm.sendStatus = '';
$timeout(function() {
$scope.$apply();
@ -221,10 +224,10 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
// Grab stateParams
tx = {
amount: parseInt(data.stateParams.amount),
sendMax: data.stateParams.sendMax === 'true' ? true : false,
fromWalletId: data.stateParams.fromWalletId,
toAddress: data.stateParams.toAddress,
amount: parseInt(sendFlowData.amount),
sendMax: sendFlowData.sendMax,
fromWalletId: sendFlowData.fromWalletId,
toAddress: sendFlowData.toAddress,
paypro: txPayproData,
feeLevel: configFeeLevel,
@ -241,7 +244,6 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
};
if (data.stateParams.requiredFeeRate) {
vm.usingMerchantFee = true;
tx.feeRate = parseInt(data.stateParams.requiredFeeRate);
@ -251,18 +253,18 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
tx.feeLevel = 'normal';
}
var B = data.stateParams.coin === 'bch' ? bitcoreCash : bitcore;
var B = tx.coin === 'bch' ? bitcoreCash : bitcore;
var networkName;
try {
if (vm.destination.kind === 'wallet') { // This is a wallet-to-wallet transfer
$ionicLoading.show();
ongoingProcess.set('generatingNewAddress', true);
var toWallet = profileService.getWallet(destinationWalletId);
// We need an address to send to, so we ask the walletService to create a new address for the toWallet.
console.log('Getting address for wallet...');
walletService.getAddress(toWallet, true, function onWalletAddress(err, addr) {
console.log('getAddress cb called', err);
$ionicLoading.hide();
ongoingProcess.set('generatingNewAddress', false);
tx.toAddress = addr;
networkName = (new B.Address(tx.toAddress)).network.name;
tx.network = networkName;
@ -395,6 +397,10 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
};
}
function goBack() {
$ionicHistory.goBack();
}
function handleDestinationAsAddress(address, originCoin) {
if (!address) {
return;
@ -403,16 +409,20 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
// Check if the recipient is a contact
addressbookService.get(originCoin + address, function(err, contact) {
if (!err && contact) {
handleDestinationAsContact(contact);
handleDestinationAsAddressOfContact(contact);
} else {
vm.destination.address = address;
if (originCoin === 'bch') {
vm.destination.address = bitcoinCashJsService.readAddress(address).cashaddr;
} else {
vm.destination.address = address;
}
vm.destination.kind = 'address';
}
});
}
function handleDestinationAsContact(contact) {
function handleDestinationAsAddressOfContact(contact) {
vm.destination.kind = 'contact';
vm.destination.name = contact.name;
vm.destination.email = contact.email;
@ -473,24 +483,31 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
vm.destination.color = toWallet.color;
vm.destination.currency = toWallet.coin.toUpperCase();
$ionicLoading.show();
ongoingProcess.set('connectingShapeshift', true);
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
if (err) {
$ionicLoading.hide();
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString());
ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
return;
}
walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) {
if (err) {
$ionicLoading.hide();
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString());
ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
return;
}
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, function onShiftIt(err, shapeshiftData) {
if (err && err != null) {
$ionicLoading.hide();
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString());
ongoingProcess.set('connectingShapeshift', false);
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
$ionicHistory.goBack();
});
} else {
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
vm.memoExpanded = !!vm.memo;
@ -631,7 +648,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
$timeout(function() {
$scope.$apply();
});
popupService.showAlert(gettextCatalog.getString('Error at confirm'), bwcError.msg(msg));
popupService.showAlert(gettextCatalog.getString('Error at confirm'), bwcError.msg(msg), function () {
$ionicHistory.goBack();
});
};
function setupTx(tx) {
@ -816,7 +835,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
if (tx.sendMax && sendMaxInfo.amount == 0) {
ongoingProcess.set('calculatingFee', false);
setNotReady(gettextCatalog.getString('Insufficient confirmed funds'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'));
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Not enough funds for fee'), function () {
$ionicHistory.goBack();
});
return cb('no_funds');
}

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $state, $interval, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) {
angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, sendFlowService, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) {
var walletsBtc = [];
var walletsBch = [];
@ -63,11 +63,22 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
};
$scope.shapeshift = function() {
var params = {
thirdParty: JSON.stringify({id: 'shapeshift'})
var stateParams = {
thirdParty: {
id: 'shapeshift'
}
};
// Starting new send flow, so ensure everything is reset
sendFlowService.clear();
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.send.origin', params);
$ionicHistory.clearHistory();
$state.go('tabs.send').then(function() {
$timeout(function () {
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
}, 60);
});
});
}
});

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) {
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, communityService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, sendFlowService, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) {
var wallet;
var listeners = [];
var notifications = [];
@ -20,7 +20,12 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.bannerUrl = '';
$scope.$on("$ionicView.afterEnter", function() {
$scope.$on("$ionicView.beforeEnter", onBeforeEnter);
$scope.$on("$ionicView.enter", onEnter);
$scope.$on("$ionicView.afterEnter", onAfterEnter);
$scope.$on("$ionicView.leave", onLeave);
function onAfterEnter () {
startupService.ready();
bannerService.getBanner(function (banner) {
@ -28,9 +33,10 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.bannerUrl = banner.url;
$scope.bannerIsLoading = false;
});
});
};
function onBeforeEnter (event, data) {
$scope.$on("$ionicView.beforeEnter", function(event, data) {
if (!$scope.homeTip) {
storageService.getHomeTipAccepted(function(error, value) {
$scope.homeTip = (value == 'accepted') ? false : true;
@ -51,9 +57,9 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}
});
}
});
};
$scope.$on("$ionicView.enter", function(event, data) {
function onEnter(event, data) {
$ionicNavBarDelegate.showBar(true);
updateAllWallets();
@ -97,26 +103,29 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}
$scope.showServices = true;
pushNotificationsService.init();
firebaseEventsService.init();
$timeout(function() {
$ionicScrollDelegate.resize();
$scope.$apply();
}, 10);
});
});
};
$scope.$on("$ionicView.leave", function(event, data) {
function onLeave (event, data) {
lodash.each(listeners, function(x) {
x();
});
});
};
$scope.createdWithinPastDay = function(time) {
return timeService.withinPastDay(time);
};
$scope.startFreshSend = function() {
sendFlowService.clear();
$state.go('tabs.send');
}
$scope.openExternalLink = function() {
var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest';
var optIn = true;
@ -205,6 +214,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
var j = 0;
lodash.each(wallets, function(wallet) {
walletService.invalidateCache(wallet); // Temporary solution, to have the good balance, when we ask to reload the wallets.
walletService.getStatus(wallet, {}, function(err, status) {
if (err) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService, soundService, clipboardService) {
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, sendFlowService, txFormatService, soundService, clipboardService) {
var listeners = [];
$scope.bchAddressType = { type: 'cashaddr' };
@ -18,9 +18,10 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
$scope.displayBalanceAsFiat = true;
$scope.requestSpecificAmount = function() {
$state.go('tabs.paymentRequest.amount', {
sendFlowService.pushState({
toWalletId: $scope.wallet.credentials.walletId
});
$state.go('tabs.paymentRequest.amount');
};
$scope.setAddress = function(newAddr, copyAddress) {
@ -158,6 +159,10 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
soundService.play('misc/payment_received.mp3');
}
// Notify new tx
$scope.$emit('bwsEvent', $scope.wallet.id);
$scope.$apply(function () {
$scope.showingPaymentReceived = true;
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
angular.module('copayApp.controllers').controller('tabSendController', function($scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
var clipboardHasAddress = false;
var clipboardHasContent = false;
var originalList;
@ -28,6 +28,10 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
};
$scope.$on("$ionicView.enter", function(event, data) {
var stateParams = sendFlowService.getStateClone();
$scope.fromWallet = profileService.getWallet(stateParams.fromWalletId);
clipboardService.readFromClipboard(function(text) {
if (text.length > 200) {
text = text.substring(0, 200);
@ -179,14 +183,30 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
var stateParams = sendFlowService.getStateClone();
stateParams.toAddress = toAddress,
stateParams.coin = item.coin;
sendFlowService.pushState(stateParams);
if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet
$state.transitionTo('tabs.send.origin');
} else {
$state.transitionTo('tabs.send.amount');
}
return $state.transitionTo('tabs.send.origin', {
toAddress: toAddress,
coin: item.coin
});
});
};
$scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()');
var params = sendFlowService.getStateClone();
sendFlowService.pushState(params);
$state.transitionTo('tabs.send.wallet-to-wallet', {
fromWalletId: sendFlowService.fromWalletId
});
}
// This could probably be enhanced refactoring the routes abstract states
$scope.createWallet = function() {
$state.go('tabs.home').then(function() {
@ -201,6 +221,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
};
$scope.$on("$ionicView.beforeEnter", function(event, data) {
console.log(data);
console.log('tab-send onBeforeEnter sendflow ', sendFlowService.state);
$scope.isIOS = platformInfo.isIOS && platformInfo.isCordova;
$scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false;
@ -215,5 +237,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.displayBalanceAsFiat = _config.wallet.settings.priceDisplay === 'fiat';
});
if (data.direction == "back") {
sendFlowService.clear();
}
});
});
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService) {
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
$scope.onScan = function(data) {
if (!incomingData.redir(data)) {
@ -15,6 +15,11 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
};
};
$scope.startFreshSend = function() {
sendFlowService.clear();
$state.go('tabs.send');
};
$scope.importInit = function() {
$scope.fromOnboarding = $stateParams.fromOnboarding;
$timeout(function() {
@ -23,7 +28,7 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
};
$scope.chooseScanner = function() {
sendFlowService.clear();
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
if (!isWindowsPhoneApp) {

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, appConfigService, rateService) {
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, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) {
var HISTORY_SHOW_LIMIT = 10;
var currentTxHistoryPage = 0;
@ -374,6 +374,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
sendFlowService.clear();
configService.whenAvailable(function (config) {
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
@ -470,13 +471,18 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
$scope.goToSend = function() {
$state.go('tabs.home', {
walletId: $scope.wallet.id
}).then(function () {
sendFlowService.startSend({
fromWalletId: $scope.wallet.id
});
// Go home first so that the Home tab works properly
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory();
$state.go('tabs.send');
});
};
$scope.goToReceive = function() {
$state.go('tabs.home', {
@ -488,6 +494,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
});
};
$scope.goToBuy = function() {
$state.go('tabs.home', {
walletId: $scope.wallet.id

View file

@ -1,13 +1,23 @@
'use strict';
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, configService, gettextCatalog, profileService, txFormatService) {
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
var fromWalletId = '';
var priceDisplayAsFiat = false;
var unitDecimals = 0;
var unitsFromSatoshis = 0;
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.$on("$ionicView.beforeEnter", onBeforeEnter);
$scope.$on("$ionicView.enter", onEnter);
function onBeforeEnter(event, data) {
if (data.direction == "back") {
sendFlowService.popState();
}
console.log('walletSelector onBeforeEnter after back sendflow', sendFlowService.state);
$scope.params = sendFlowService.getStateClone();
var config = configService.getSync().wallet.settings;
priceDisplayAsFiat = config.priceDisplay === 'fiat';
unitDecimals = config.unitDecimals;
@ -18,18 +28,24 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
break;
case 'tabs.send.destination':
if (data.stateParams.fromWalletId) {
if ($scope.params.fromWalletId && !$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
}
break;
default:
if (!$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Send');
}
// nop
}
$scope.params = $state.params;
$scope.coin = false; // Wallets to show (for destination screen or contacts)
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
fromWalletId = data.stateParams && data.stateParams.fromWalletId;
$scope.type = $scope.params['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
fromWalletId = $scope.params['fromWalletId'];
if ($scope.type === 'destination' && $scope.params.toAddress) {
$state.transitionTo(getNextStep($scope.params));
}
if ($scope.params.coin) {
$scope.coin = $scope.params.coin; // Contacts have a coin embedded
@ -41,11 +57,11 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.isPaymentRequest = true;
}
if ($scope.params.thirdParty) {
$scope.thirdParty = JSON.parse($scope.params.thirdParty); // Parse stringified JSON-object
$scope.thirdParty = $scope.params.thirdParty;
}
});
};
$scope.$on("$ionicView.enter", function(event, data) {
function onEnter (event, data) {
configService.whenAvailable(function(config) {
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
});
@ -57,7 +73,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
prepareWalletLists();
formatRequestedAmount();
});
};
function formatRequestedAmount() {
if ($scope.params.amount) {
@ -88,13 +104,10 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
}
}
function getNextStep() {
if ($scope.thirdParty) {
$scope.params.thirdParty = JSON.stringify($scope.thirdParty) // re-stringify JSON-object
}
if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet
function getNextStep(params) {
if (!params.toWalletId && !params.toAddress) { // If we have no toAddress or fromWallet
return 'tabs.send.destination';
} else if (!$scope.params.amount) { // If we have no amount
} else if (!params.amount) { // If we have no amount
return 'tabs.send.amount';
} else { // If we do have them
return 'tabs.send.review';
@ -178,12 +191,16 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.useWallet = function(wallet) {
var params = sendFlowService.getStateClone();
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
$scope.params['fromWalletId'] = wallet.id;
params.fromWalletId = wallet.id;
} else { // we're on the destination screen, set wallet to send to
$scope.params['toWalletId'] = wallet.id;
params.toWalletId = wallet.id;
}
$state.transitionTo(getNextStep(), $scope.params);
sendFlowService.pushState(params);
var nextStep = getNextStep(params);
console.log('walletSelector nextStep', nextStep);
$state.transitionTo(nextStep, $scope.params);
};
$scope.goBack = function() {

View file

@ -1,92 +0,0 @@
'use strict';
/**
* @desc amount directive that can be used to display formatted financial values
* size-equal attribute is optional, defaults to false.
* @example fee = {
* value: 12.49382901,
* currency: 'BCH'
* }
* @example <amount value="fee.value" currency="fee.currency"></amount>
* @example <amount value="fee.value" currency="fee.currency" size-equal="true"></amount>
*/
angular.module('bitcoincom.directives')
.directive('amount', [
'$timeout',
function($timeout) {
return {
restrict: 'E',
scope: {
value: '=',
currency: '=',
sizeEqual: '='
},
templateUrl: 'views/includes/amount.html',
controller: ['$scope', function($scope) {
$scope.displaySizeEqual = typeof $scope.sizeEqual == 'undefined' ? false : true;
var decimalPlaces = {
'0': ['BIF', 'CLP', 'DJF', 'GNF', 'ILS', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'],
'3': ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND'],
'8': ['BCH', 'BTC']
};
var numberWithCommas = function(x) {
return parseFloat(x).toLocaleString();
};
var buildAmount = function(start, middle, end) {
$scope.start = start;
$scope.middle = middle;
$scope.end = end;
};
var getDecimalPlaces = function(currency) {
if (decimalPlaces['0'].indexOf($scope.currency.toUpperCase()) > -1) return '0';
if (decimalPlaces['3'].indexOf($scope.currency.toUpperCase()) > -1) return '3';
if (decimalPlaces['8'].indexOf($scope.currency.toUpperCase()) > -1) return '8';
return '2';
};
var formatNumbers = function(currency, value) {
switch (getDecimalPlaces(currency)) {
case '0':
var valueFormatted = numberWithCommas(Math.round(parseFloat(value)));
buildAmount(valueFormatted, '', '');
break;
case '2':
var valueProcessing = parseFloat(parseFloat(value).toFixed(2));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat(value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat(value).toFixed(8);
if (parseFloat(value) == 0) {
buildAmount('0', '', '');
} else {
buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5));
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
}
}
formatNumbers($scope.currency, $scope.value);
$scope.$watchGroup(['currency', 'value'], function() {
formatNumbers($scope.currency, $scope.value);
});
}]
};
}
]);

View file

@ -0,0 +1,190 @@
'use strict';
(function(){
/**
* @desc amount directive that can be used to display formatted financial values
* size-equal attribute is optional, defaults to false.
* @example fee = {
* value: 12.49382901,
* currency: 'BCH'
* }
* @example <formatted-amount value="fee.value" currency="fee.currency"></formatted-amount>
* @example <formatted-amount value="fee.value" currency="fee.currency" size-equal="true"></formatted-amount>
*/
angular
.module('bitcoincom.directives')
.directive('formattedAmount', function() {
return {
restrict: 'E',
scope: {
value: '@',
currency: '@',
sizeEqual: '@'
},
templateUrl: 'views/includes/formatted-amount.html',
controller: formattedAmountController
}
});
function formattedAmountController($scope, $timeout, uxLanguage) {
$scope.canShow = false;
$scope.displaySizeEqual = !!$scope.sizeEqual;
var decimalPlaces = {
'0': ['BIF', 'CLP', 'DJF', 'GNF', 'ILS', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'],
'3': ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND'],
'8': ['BCH', 'BTC']
};
$scope.$watch('value', function onFormattedAmountWatch() {
formatNumbers();
});
function buildAmount(start, middle, end) {
$scope.start = start;
$scope.middle = middle;
$scope.end = end;
};
/**
* On Android 4.4, toLocaleString() only returns 3 fractional digits when 8 is specified.
*/
function ensureEnoughFractionDigits(localizedString, number, desiredFractionDigits) {
if (desiredFractionDigits === 0) {
// Assume it is OK
return localizedString;
}
var fractionalRe = /^-*(\d*\D)(\d+)$/;
var match = fractionalRe.exec(localizedString);
if (!match || match.length !== 3) {
// Don't know what's happening, just return what we have
return localizedString;
}
var decimals = match[2];
var decimalCount = decimals.length;
if (decimalCount >= desiredFractionDigits) {
// Everything is OK.
return localizedString;
}
if (typeof number !== 'number') {
number = parseFloat(number);
}
var fixed = number.toFixed(desiredFractionDigits);
var fixedMatch = fractionalRe.exec(fixed);
if (!fixedMatch || fixedMatch.length !== 3) {
// Don't know what's happening, just return what we have
return localizedString;
}
// Keeps locale decimal separator.
var enough = match[1] + fixedMatch[2];
return enough;
}
function formatNumbers() {
// Might get "< 0.01 USD" being passed in.
// During watch, may be changed from having a separate currency value,
// to both being in value. Don't want to use previous currency value.
// Try to extract currency from value..
var currencySplit = $scope.value.split(" ");
if (currencySplit.length >= 2 && !$scope.currency) {
$scope.currency = currencySplit[currencySplit.length - 1];
}
$scope.currency = $scope.currency || '';
// Redo this when we have proper formatting for low fees
if ($scope.value.indexOf("<") === 0) {
buildAmount($scope.value, '', '');
$scope.currency = '';
$scope.canShow = true;
return;
}
// Remove thousands separators for parseFloat()
$scope.value = $scope.value.replace(',', '');
var parsed = parseFloat($scope.value);
var valueFormatted = '';
var valueProcessing = '';
switch (getDecimalPlaces($scope.currency)) {
case '0':
if (isNaN(parsed)) {
buildAmount('-', '', '');
} else {
valueFormatted = localizeNumbers(Math.round(parsed), 0);
buildAmount(valueFormatted, '', '');
}
break;
case '3':
if (isNaN(parsed)) {
buildAmount('-' + getDecimalSeparator() + '---', '', '');
} else {
valueProcessing = parsed.toFixed(3);
valueFormatted = localizeNumbers(valueProcessing, 3);
buildAmount(valueFormatted, '', '');
}
break;
case '8':
if (isNaN(parsed)) {
buildAmount('-' + getDecimalSeparator() + '---', '', '');
} else if (parsed === 0) {
buildAmount('0', '', '');
} else {
valueFormatted = parsed.toFixed(8);
valueFormatted = localizeNumbers(valueFormatted, 8);
var start = valueFormatted.slice(0, -5);
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
default: // 2
if (isNaN(parsed)) {
buildAmount('-' + getDecimalSeparator() + '--', '', '');
} else {
valueProcessing = parseFloat(parsed.toFixed(2));
valueFormatted = localizeNumbers(valueProcessing, 2);
buildAmount(valueFormatted, '', '');
}
break;
}
$scope.canShow = true;
};
function getDecimalPlaces(currency) {
if (decimalPlaces['0'].indexOf(currency.toUpperCase()) > -1) return '0';
if (decimalPlaces['3'].indexOf(currency.toUpperCase()) > -1) return '3';
if (decimalPlaces['8'].indexOf(currency.toUpperCase()) > -1) return '8';
return '2';
};
function getDecimalSeparator() {
var testNum = 1.5;
var testString = testNum.toLocaleString(uxLanguage.getCurrentLanguage());
// Some environments let you set decimal separators that are more than one character
var separator = /^1(.+)5$/.exec(testString)[1]
return separator;
};
function localizeNumbers(x, minimumFractionDigits) {
var parsed = parseFloat(x);
var opts = {
minimumFractionDigits: minimumFractionDigits,
useGrouping: true
};
var lang = uxLanguage.getCurrentLanguage();
var localized = parsed.toLocaleString(lang, opts);
var corrected = ensureEnoughFractionDigits(localized, x, minimumFractionDigits);
return corrected;
};
}
})();

View file

@ -0,0 +1,120 @@
'use strict';
(function(){
angular
.module('bitcoincom.directives')
.directive('walletBalance', function() {
return {
restrict: 'E',
scope: {
displayAsFiat: '@',
totalBalanceSat: '@',
// The Wallet object is sometimes not stringify()-able, so not interpolatable,
// so can't be passed to a directive.
walletStatus: '@',
walletCachedBalance: '@',
walletCachedBalanceUpdatedOn: '@',
walletCachedStatus: '@'
},
templateUrl: 'views/includes/wallet-balance.html',
controller: walletBalanceController
}
});
function walletBalanceController($log, $scope, txFormatService) {
var cryptoBalanceHasBeenDisplayed = false;
formatBalance();
$scope.$watchGroup(['displayAsFiat', 'totalBalanceSat'], function onWalletBalanceWatch() {
formatBalance();
});
function displayCryptoBalance(walletStatus, walletCachedBalance, walletCachedBalanceUpdatedOn, walletCachedStatus) {
console.log('displayCryptoBalance()');
if (walletStatus && walletStatus.isValid && walletStatus.totalBalanceStr) {
setDisplay(walletStatus.totalBalanceStr, '');
cryptoBalanceHasBeenDisplayed = true;
return;
}
if (walletCachedBalance) {
setDisplay(walletCachedBalance, walletCachedBalanceUpdatedOn);
return;
}
if (walletCachedStatus && walletCachedStatus.isValid && walletCachedStatus.totalBalanceStr) {
setDisplay(walletCachedStatus.totalBalanceStr, '');
return;
}
setDisplay('', '');
}
function displayFiatBalance(walletStatus, walletCachedStatus) {
var displayAmount = '';
if (walletStatus && walletStatus.isValid && walletStatus.alternativeBalanceAvailable) {
displayAmount = walletStatus.totalBalanceAlternative + ' ' + walletStatus.alternativeIsoCode;
setDisplay(displayAmount, '');
return;
}
if (walletCachedStatus && walletCachedStatus.isValid && walletCachedStatus.alternativeBalanceAvailable) {
displayAmount = walletCachedStatus.totalBalanceAlternative + ' ' + walletCachedStatus.alternativeIsoCode;
setDisplay(displayAmount, '');
return;
}
getFiatBalance(wallet);
}
function formatBalance() {
var displayAsFiat = $scope.displayAsFiat === 'true';
var walletStatusObj = null;
var walletCachedBalance = null;
var walletCachedBalanceUpdatedOn = null;
var walletCachedStatusObj = null;
try {
walletStatusObj = JSON.parse($scope.walletStatus);
} catch (e) {
$log.warn('Failed to parse walletStatus.', e);
}
try {
walletCachedStatusObj = JSON.parse($scope.walletCachedStatus);
} catch (e) {
$log.warn('Failed to parse walletCachedStatus.', e);
}
if (!displayAsFiat || displayAsFiat && !cryptoBalanceHasBeenDisplayed) {
displayCryptoBalance(walletStatusObj, walletCachedBalance, walletCachedBalanceUpdatedOn, walletCachedStatusObj);
}
if (displayAsFiat) {
displayFiatBalance(walletStatusObj, walletCachedStatusObj);
}
}
function getFiatBalance(wallet) {
if (!(wallet.status && wallet.status.isValid)) {
$log.warn('Abandoning call to get fiat balance, because no valid wallet status.');
return;
}
txFormatService.formatAlternativeStr(wallet.coin, wallet.status.totalBalanceSat, function onFormatAlernativeStr(formatted) {
if (formatted) {
setDisplay(formatted, '');
}
});
}
function setDisplay(amount, cachedBalanceUpdatedOn) {
$scope.displayAmount = amount;
$scope.cachedBalanceUpdatedOn = cachedBalanceUpdatedOn;
}
}
})();

View file

@ -287,7 +287,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*/
.state('tabs.send.amount', {
url: '/amount/:thirdParty/:fromWalletId/:maxAmount/:minAmount/:toWalletId/:toAddress',
url: '/amount',
views: {
'tab-send@tabs': {
controller: 'amountController',
@ -306,7 +306,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.send.origin', {
url: '/origin/:thirdParty/:amount/:toAddress/:toWalletId/:coin',
url: '/origin',
views: {
'tab-send@tabs': {
controller: 'walletSelectorController',
@ -315,7 +315,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.send.destination', {
url: '/destination/:thirdParty/:amount/:fromWalletId',
url: '/destination',
views: {
'tab-send@tabs': {
controller: 'walletSelectorController',
@ -324,7 +324,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('tabs.send.confirm', {
url: '/confirm/:thirdParty/:amount/:fromWalletId/:toWalletId/:toAddress',
url: '/confirm',
views: {
'tab-send@tabs': {
controller: 'confirmController',
@ -1207,7 +1207,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
});
})
.run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) {
.run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, pushNotificationsService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) {
$ionicPlatform.ready(function() {
@ -1231,6 +1231,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
});
configService.whenAvailable(function(config) {
pushNotificationsService.init();
});
//firebaseEventsService.init();
var channel = "ga";
if (platformInfo.isCordova) {
channel = "firebase";
@ -1272,6 +1277,13 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
});
window.BitAnalytics.ActionHandlers.trackAction(actionTabOpen);
var actionShapeShiftStart = new window.BitAnalytics.ActionFactory.createAction('click', {
name: 'shapeshift_start_click',
class: 'track_shapeshift_start_click',
channels: [channel]
});
window.BitAnalytics.ActionHandlers.trackAction(actionShapeShiftStart);
// Init language
uxLanguage.init(function (lang) {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
angular.module('copayApp.services').factory('clipboardService', function ($http, $log, $timeout, platformInfo, nodeWebkitService, gettextCatalog, ionicToast, clipboard) {
var root = {};
root.copyToClipboard = function (data) {
@ -13,7 +13,7 @@ angular.module('copayApp.services').factory('clipboardService', function ($http,
nodeWebkitService.writeToClipboard(data);
} else if (navigator && navigator.clipboard) {
$log.debug("Use navigator clipboard.")
navigator.clipboard.writeText(data).catch(err => {
navigator.clipboard.writeText(data).catch(function onClipboardError(err) {
$log.debug("Clipboard writing is not supported in your browser..");
});
} else if (clipboard.supported) {
@ -31,7 +31,9 @@ angular.module('copayApp.services').factory('clipboardService', function ($http,
cb(text);
})
} else if (platformInfo.isNW) {
cb(nodeWebkitService.readFromClipboard());
$timeout(function() {
cb(nodeWebkitService.readFromClipboard());
},0);
} else {
navigator.clipboard.readText()
.then(function (text) {

View file

@ -1,5 +1,5 @@
'use strict';
angular.module('copayApp.services').factory('firebaseEventsService', function firebaseEventsService($log, $state, $ionicHistory, sjcl, platformInfo, lodash, appConfigService, profileService, configService) {
angular.module('copayApp.services').factory('firebaseEventsService', function firebaseEventsService($log, platformInfo) {
var root = {};
var useEvents = platformInfo.isCordova && !platformInfo.isWP;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
angular.module('copayApp.services').factory('incomingData', function($log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
var root = {};
@ -82,7 +82,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
});
// Timeout is required to enable the "Back" button
$timeout(function() {
var params = {};
var params = sendFlowService.getStateClone();
if (amount) {
params.amount = amount;
@ -105,10 +105,11 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
params.thirdParty = [];
params.thirdParty.id = serviceId;
params.thirdParty.data = serviceData;
params.thirdParty = JSON.stringify(params.thirdParty);
$state.transitionTo('tabs.send.amount', params);
sendFlowService.pushState(params);
$state.transitionTo('tabs.send.amount');
} else {
$state.transitionTo('tabs.send.origin', params);
sendFlowService.pushState(params);
$state.transitionTo('tabs.send.origin');
}
}, 100);
}
@ -387,11 +388,13 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
'notify': $state.current.name == 'tabs.send' ? false : true
});
$timeout(function() {
$state.transitionTo('tabs.send.origin', {
var stateParams = {
toAddress: toAddress,
coin: coin,
noPrefix: 1
});
};
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
}, 100);
}
@ -444,7 +447,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
amount: thirdPartyData.amount,
toAddress: thirdPartyData.toAddress,
coin: coin,
thirdParty: JSON.stringify(thirdPartyData)
thirdParty: thirdPartyData
};
// fee
@ -452,13 +455,17 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
stateParams.requiredFeeRate = thirdPartyData.requiredFeeRate * 1024;
}
// This does not make sense, thirdPartyData gets added by stateParams below
//sendFlowService.pushState(thirdPartyData);
scannerService.pausePreview();
$state.go('tabs.send', {}, {
'reload': true,
'notify': $state.current.name == 'tabs.send' ? false : true
}).then(function() {
$timeout(function() {
$state.transitionTo('tabs.send.origin', stateParams);
sendFlowService.pushState(stateParams); // Need to do more here
$state.transitionTo('tabs.send.origin');
});
});
}

View file

@ -0,0 +1,101 @@
'use strict';
(function(){
angular
.module('copayApp.services')
.factory('sendFlowService', sendFlowService);
function sendFlowService($log) {
var service = {
// A separate state variable so we can ensure it is cleared of everything,
// even other properties added that this service does not know about. (such as "coin")
state: {
amount: '',
fromWalletId: '',
sendMax: false,
thirdParty: null,
toAddress: '',
toWalletId: ''
},
previousStates: [],
// Functions
clear: clear,
getStateClone: getStateClone,
map: map,
popState: popState,
pushState: pushState,
startSend: startSend
};
return service;
function clear() {
console.log("sendFlow clear()");
clearCurrent();
service.previousStates = [];
}
function clearCurrent() {
console.log("sendFlow clearCurrent()");
service.state = {
amount: '',
fromWalletId: '',
sendMax: false,
thirdParty: null,
toAddress: '',
toWalletId: ''
}
}
/**
* Handy for debugging
*/
function getStateClone() {
var currentState = {};
Object.keys(service.state).forEach(function forCurrentParam(key) {
if (typeof service.state[key] !== 'function' && key !== 'previousStates') {
currentState[key] = service.state[key];
}
});
return currentState;
}
/**
* Clears all previous state
*/
function startSend(params) {
console.log('startSend()');
clear();
map(params);
}
function map(params) {
Object.keys(params).forEach(function forNewParam(key) {
service.state[key] = params[key];
});
};
function popState() {
console.log('sendFlow pop');
if (service.previousStates.length) {
var params = service.previousStates.pop();
clearCurrent();
map(params);
} else {
clear();
}
};
function pushState(params) {
console.log('sendFlow push');
var currentParams = getStateClone();
service.previousStates.push(currentParams);
clearCurrent();
map(params);
};
};
})();

View file

@ -1,7 +1,12 @@
'use strict'
angular.module('copayApp.services').factory('servicesService', function(configService, $log, lodash) {
var root = {};
var services = [];
var services = [{
name: 'shapeshift',
title: 'Shapeshift',
icon: 'icon-shapeshift',
sref: 'tabs.shapeshift',
}];
root.register = function(serviceInfo) {
$log.info('Adding Services entry:' + serviceInfo.name);

View file

@ -343,21 +343,19 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err) return cb(err);
if (!txsFromServer.length)
return cb();
return cb(null, []);
var res = lodash.takeWhile(txsFromServer, function(tx) {
return tx.txid != endingTxid;
});
return cb(null, res, res.length >= limit);
return cb(null, txsFromServer);
});
};
var removeAndMarkSoftConfirmedTx = function(txs) {
return lodash.filter(txs, function(tx) {
if (tx.confirmations >= root.SOFT_CONFIRMATION_LIMIT)
return tx;
tx.recent = true;
var isConfirm = (tx.confirmations >= root.SOFT_CONFIRMATION_LIMIT);
if (!isConfirm) {
tx.recent = true;
}
return isConfirm;
});
}
@ -437,12 +435,14 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null;
var endingTs = confirmedTxs[0] ? confirmedTxs[0].time : null;
$log.debug('Confirmed TXs. Got:' + confirmedTxs.length + '/' + txsFromLocal.length);
// First update
progressFn(txsFromLocal, 0);
wallet.completeHistory = txsFromLocal;
function getNewTxs(newTxs, skip, next) {
getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res) {
if (err) {
$log.warn(bwcError.msg(err, 'Server Error')); //TODO
if (err instanceof errors.CONNECTION_ERROR || (err.message && err.message.match(/5../))) {
@ -454,7 +454,22 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
return next(err);
}
newTxs = newTxs.concat(processNewTxs(wallet, lodash.compact(res)));
// Check if new txs are founds, if yes, lets investigate in the 50 next
// To be sure we are not missing txs by sorting (maybe a new tx is after the "endingTxid"
var newDiscoveredTxs = res.filter(function (x) {
return confirmedTxs.filter(function (confX) {
return confX.txid == x.txid;
}).length == 0;
});
$log.debug('Discovering TXs. Got:' + newDiscoveredTxs.length);
var shouldContinue = newDiscoveredTxs.length > 0;
// If no new tx, no need to check
if (shouldContinue) {
newTxs = newTxs.concat(processNewTxs(wallet, lodash.compact(newDiscoveredTxs)));
}
progressFn(newTxs.concat(txsFromLocal), newTxs.length);

View file

@ -55,6 +55,7 @@
.button {
border-radius: 6px;
&.button-full {
border-radius: 0;
display: block;
}
&-green {
@ -73,7 +74,7 @@
color: #FFF;
}
&-outline {
@include button-style(transparent, #FFFFFF, #FAFAFA, #FFF, #FFFFFF);
@include button-style(transparent, #FFFFFF, #FFFFFF, #FFFFFF, #FFFFFF);
@include button-outline(#FFFFFF);
background: none;
box-shadow: none;

View file

@ -8,4 +8,5 @@
@import "action-minor";
@import "expand-content";
@import "fee-summary";
@import "amount.scss";
@import "formatted-amount";
@import "wallet-balance";

View file

@ -1,4 +1,6 @@
.amount {
.formatted-amount {
display: inline-block;
.start,
.middle,
.end,

View file

@ -0,0 +1,3 @@
.wallet-balance-directive {
display: inline-block;
}

View file

@ -468,3 +468,7 @@ input[type=file] {
.white-space-initial {
white-space: initial;
}
.height-spacer {
height: 15px;
}

View file

@ -305,7 +305,8 @@
&.very-long {
input, .unit, .primary-amount-display {
font-size: 0.9em;
font-size: 1.2em; // OK for iPhone 5 / SE with BCH to 8dp
@media (min-width: 375px) {
font-size: 1.3em;
@ -382,41 +383,46 @@
.available-funds {
color: #6F6F70;
text-align: left;
}
.change-currency {
text-align: right;
}
.warning {
color: $v-warning-color-2;
}
.extra,
button.extra {
/*display: flex;*/
flex: 0 1 auto;
}
button.extra {
background: none;
border: none;
color: #000;
font-family: 'ProximaNova';
font-size: 14px;
.extra {
flex: 1;
line-height: normal;
min-height: auto;
min-width: auto;
padding: 0;
}
.button .icon:before {
font-size: 14px;
line-height: normal;
}
.button {
background: none;
border: none;
border-radius: 0;
color: #000;
font-family: 'ProximaNova';
font-size: 14px;
line-height: normal;
min-height: auto;
min-width: auto;
padding: 0;
}
.button {
span {
display: flex;
align-items: center;
justify-content: center;
.button .icon:before {
font-size: 14px;
line-height: normal;
}
.button {
span {
display: flex;
align-items: center;
justify-content: center;
}
}
}
}

View file

@ -8,6 +8,7 @@ click-to-accept {
.click-to-accept {
&__button.button.button-primary.button-standard {
border-radius: 0;
height: 100%;
max-width: 9999px;
width: 100%;

View file

@ -13,6 +13,9 @@ slide-to-accept {
}
.slide {
.button {
border-radius: 0;
}
&__listener {
height: 100%;
width: 100%;

View file

@ -1,5 +1,4 @@
#view-review {
background-color: #494949;
slide-to-accept, slide-to-accept-success {
margin-bottom: constant(safe-area-inset-bottom); /* iOS 11.0 */

View file

@ -2,15 +2,15 @@
@extend .deflash-blue;
&-header{
height: 300px;
//height: 300px;
width: 100%;
}
&-contacts {
height: calc(100vh - 300px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */
//height: calc(100vh - 300px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */
&.ios {
height: calc(100vh - 300px - 50px - 44px - 18px); // Remove the notification-bar height on iOS
//height: calc(100vh - 300px - 50px - 44px - 18px); // Remove the notification-bar height on iOS
}
overflow: scroll;
//overflow: scroll;
}
.input {
@ -223,12 +223,12 @@
}
}
#tab-send-header {
height: 270px;
//height: 270px;
}
#tab-send-contacts {
height: calc(100vh - 270px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */
//height: calc(100vh - 270px - 50px - 44px); /* screen size - button container - bottom-tab-menu - header top */
&.ios {
height: calc(100vh - 270px - 50px - 44px - 18px); // Remove the notification-bar height on iOS
//height: calc(100vh - 270px - 50px - 44px - 18px); // Remove the notification-bar height on iOS
}
}
}