Merge
This commit is contained in:
commit
230b6e2228
83 changed files with 5830 additions and 2736 deletions
|
|
@ -21,28 +21,14 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
|
|||
});
|
||||
|
||||
$scope.sendTo = function() {
|
||||
$ionicHistory.removeBackView();
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.send');
|
||||
$timeout(function() {
|
||||
var to = '';
|
||||
if ($scope.addressbookEntry.coin == 'bch') {
|
||||
var a = 'bitcoincash:' + $scope.addressbookEntry.address;
|
||||
to = bitcoinCashJsService.readAddress(a).legacy;
|
||||
} else {
|
||||
to = $scope.addressbookEntry.address;
|
||||
}
|
||||
var stateParams = {
|
||||
data: $scope.addressbookEntry.address,
|
||||
toName: $scope.addressbookEntry.name,
|
||||
toEmail: $scope.addressbookEntry.email,
|
||||
coin: $scope.addressbookEntry.coin
|
||||
};
|
||||
|
||||
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);
|
||||
sendFlowService.start(stateParams);
|
||||
};
|
||||
|
||||
$scope.remove = function(addressbookEntry) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('amountController', amountController);
|
||||
(function(){
|
||||
|
||||
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, profileService, walletService, $window) {
|
||||
angular
|
||||
.module('bitcoincom.controllers')
|
||||
.controller('amountController', amountController);
|
||||
|
||||
function amountController(configService, $filter, gettextCatalog, $ionicHistory, $ionicModal, $ionicScrollDelegate, lodash, $log, nodeWebkitService, rateService, $scope, $state, $timeout, sendFlowService, shapeshiftService, txFormatService, platformInfo, ongoingProcess, popupService, profileService, walletService, $window) {
|
||||
var vm = this;
|
||||
|
||||
// Variables
|
||||
vm.allowSend = false;
|
||||
vm.altCurrencyList = [];
|
||||
vm.alternativeAmount = '';
|
||||
vm.alternativeUnit = '';
|
||||
vm.amount = '0';
|
||||
vm.availableFunds = '';
|
||||
vm.canSendAllAvailableFunds = true;
|
||||
vm.errorMessage = '';
|
||||
// Use insufficient for logic, as when the amount is invalid, funds being
|
||||
// either sufficent or insufficient doesn't make sense.
|
||||
vm.fundsAreInsufficient = false;
|
||||
|
|
@ -20,9 +27,13 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
vm.lastUsedPopularList = [];
|
||||
vm.maxAmount = 0;
|
||||
vm.minAmount = 0;
|
||||
vm.sendableFunds = '';
|
||||
vm.showSendMaxButton = false;
|
||||
vm.showSendLimitMaxButton = false;
|
||||
vm.thirdParty = false;
|
||||
vm.unit = '';
|
||||
|
||||
// Functions
|
||||
vm.changeUnit = changeUnit;
|
||||
vm.close = close;
|
||||
vm.findCurrency = findCurrency;
|
||||
|
|
@ -35,7 +46,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
vm.removeDigit = removeDigit;
|
||||
vm.save = save;
|
||||
vm.sendMax = sendMax;
|
||||
vm.errorMessage = '';
|
||||
|
||||
|
||||
$scope.$on('$ionicView.beforeEnter', onBeforeEnter);
|
||||
$scope.$on('$ionicView.leave', onLeave);
|
||||
|
|
@ -46,10 +57,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
var altCurrencyModal = null;
|
||||
var altUnitIndex = 0;
|
||||
var availableFundsInCrypto = '';
|
||||
var availableFundsInFiat = '';
|
||||
var availableSatoshis = null;
|
||||
var availableUnits = [];
|
||||
var canSendMax = true;
|
||||
var fiatCode;
|
||||
var isNW = platformInfo.isNW;
|
||||
var isAndroid = platformInfo.isAndroid;
|
||||
|
|
@ -57,10 +66,18 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
var lastUsedAltCurrencyList = [];
|
||||
var passthroughParams = {};
|
||||
var satToUnit;
|
||||
var transactionSendableAmount = {
|
||||
crypto: '',
|
||||
satoshis: null
|
||||
};
|
||||
var unitDecimals;
|
||||
var unitIndex = 0;
|
||||
var unitToSatoshi;
|
||||
var useSendMax = false;
|
||||
var walletSpendableAmount = {
|
||||
crypto: '',
|
||||
satoshis: null
|
||||
};
|
||||
|
||||
function onLeave() {
|
||||
angular.element($window).off('keydown');
|
||||
|
|
@ -68,42 +85,26 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
function onBeforeEnter(event, data) {
|
||||
if (data.direction == "back") {
|
||||
sendFlowService.popState();
|
||||
sendFlowService.state.pop();
|
||||
}
|
||||
console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
|
||||
|
||||
initCurrencies();
|
||||
|
||||
passthroughParams = sendFlowService.getStateClone();
|
||||
passthroughParams = sendFlowService.state.getClone();
|
||||
console.log('amount onBeforeEnter after back sendflow ', passthroughParams);
|
||||
|
||||
vm.fromWalletId = passthroughParams.fromWalletId;
|
||||
vm.toWalletId = passthroughParams.toWalletId;
|
||||
vm.minAmount = parseFloat(passthroughParams.minAmount);
|
||||
vm.maxAmount = parseFloat(passthroughParams.maxAmount);
|
||||
|
||||
if (passthroughParams.thirdParty) {
|
||||
vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object
|
||||
if (vm.thirdParty) {
|
||||
if (vm.thirdParty.id === 'shapeshift') {
|
||||
if (!vm.thirdParty.data) {
|
||||
vm.thirdParty.data = {};
|
||||
}
|
||||
vm.thirdParty.data['fromWalletId'] = vm.fromWalletId;
|
||||
|
||||
vm.fromWallet = profileService.getWallet(vm.fromWalletId);
|
||||
vm.toWallet = profileService.getWallet(vm.toWalletId);
|
||||
|
||||
shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function(data) {
|
||||
vm.thirdParty.data['minAmount'] = vm.minAmount = parseFloat(data.minimum);
|
||||
vm.thirdParty.data['maxAmount'] = vm.maxAmount = parseFloat(data.maxLimit);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vm.isRequestingSpecificAmount = !passthroughParams.fromWalletId;
|
||||
vm.showSendMaxButton = !vm.isRequestingSpecificAmount;
|
||||
|
||||
var config = configService.getSync().wallet.settings;
|
||||
unitToSatoshi = config.unitToSatoshi;
|
||||
satToUnit = 1 / unitToSatoshi;
|
||||
unitDecimals = config.unitDecimals;
|
||||
|
||||
setAvailableUnits();
|
||||
updateUnitUI();
|
||||
|
|
@ -112,7 +113,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
var reOp = /^[\*\+\-\/]$/;
|
||||
|
||||
if (!isAndroid && !isIos) {
|
||||
var disableKeys = angular.element($window).on('keydown', function(e) {
|
||||
angular.element($window).on('keydown', function(e) {
|
||||
if (!e.key) return;
|
||||
if (e.which === 8) { // you can add others here inside brackets.
|
||||
if (!altCurrencyModal) {
|
||||
|
|
@ -135,10 +136,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
});
|
||||
}
|
||||
|
||||
unitToSatoshi = config.unitToSatoshi;
|
||||
satToUnit = 1 / unitToSatoshi;
|
||||
unitDecimals = config.unitDecimals;
|
||||
|
||||
|
||||
resetAmount();
|
||||
|
||||
processAmount();
|
||||
|
|
@ -210,13 +208,48 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
var fromWallet = profileService.getWallet(passthroughParams.fromWalletId);
|
||||
updateAvailableFundsFromWallet(fromWallet);
|
||||
}
|
||||
|
||||
if (passthroughParams.thirdParty) {
|
||||
vm.thirdParty = passthroughParams.thirdParty; // Parse stringified JSON-object
|
||||
if (vm.thirdParty) {
|
||||
initShapeshift();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
$ionicHistory.goBack();
|
||||
sendFlowService.router.goBack();
|
||||
}
|
||||
|
||||
function initShapeshift() {
|
||||
if (vm.thirdParty.id === 'shapeshift') {
|
||||
vm.thirdParty.data = vm.thirdParty.data || {};
|
||||
|
||||
vm.fromWallet = profileService.getWallet(vm.fromWalletId);
|
||||
vm.toWallet = profileService.getWallet(vm.toWalletId);
|
||||
|
||||
vm.showSendMaxButton = false;
|
||||
vm.showSendLimitMaxButton = false;
|
||||
vm.canSendAllAvailableFunds = false;
|
||||
|
||||
ongoingProcess.set('connectingShapeshift', true);
|
||||
shapeshiftService.getMarketData(vm.fromWallet.coin, vm.toWallet.coin, function onMarketData(err, data) {
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
if (err) {
|
||||
// Error stop here
|
||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.message, function () {
|
||||
goBack();
|
||||
});
|
||||
} else {
|
||||
vm.thirdParty.data.minAmount = vm.minAmount = parseFloat(data.minimum);
|
||||
vm.thirdParty.data.maxAmount = vm.maxAmount = parseFloat(data.maxLimit);
|
||||
setMaximumButtonFromWallet(vm.fromWallet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function paste(value) {
|
||||
vm.amount = value;
|
||||
processAmount();
|
||||
|
|
@ -232,8 +265,28 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
|
||||
function sendMax() {
|
||||
useSendMax = true;
|
||||
finish();
|
||||
if (canSendMax) {
|
||||
useSendMax = true;
|
||||
finish();
|
||||
} else {
|
||||
var transactionSendableAmountInUnits = transactionSendableAmount.satoshis * satToUnit;
|
||||
if (vm.minAmount && transactionSendableAmountInUnits < vm.minAmount) {
|
||||
popupService.showAlert(
|
||||
gettextCatalog.getString('Insufficient funds'),
|
||||
gettextCatalog.getString('Amount below minimum allowed')
|
||||
);
|
||||
} else {
|
||||
// Need to be precise, so use crypto directly rather than fiat with exchange rate
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
var tempIndex = altUnitIndex;
|
||||
altUnitIndex = unitIndex;
|
||||
unitIndex = tempIndex;
|
||||
}
|
||||
vm.amount = transactionSendableAmountInUnits.toFixed(LENGTH_AFTER_COMMA_EXPRESSION_LIMIT);
|
||||
useSendMax = true;
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateUnitUI() {
|
||||
|
|
@ -353,8 +406,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
amountInCrypto = a;
|
||||
var amountInSatoshis = a * unitToSatoshi;
|
||||
vm.fundsAreInsufficient = !!passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
&& availableSatoshis < amountInSatoshis;
|
||||
&& walletSpendableAmount.satoshis !== null
|
||||
&& walletSpendableAmount.satoshis < amountInSatoshis;
|
||||
|
||||
vm.alternativeAmount = txFormatService.formatAmount(amountInSatoshis, true);
|
||||
vm.allowSend = lodash.isNumber(a)
|
||||
|
|
@ -374,8 +427,8 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
} else {
|
||||
amountInCrypto = result;
|
||||
vm.fundsAreInsufficient = passthroughParams.fromWalletId
|
||||
&& availableSatoshis !== null
|
||||
&& availableSatoshis < result * unitToSatoshi;
|
||||
&& walletSpendableAmount.satoshis !== null
|
||||
&& walletSpendableAmount.satoshis < result * unitToSatoshi;
|
||||
|
||||
vm.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
||||
vm.allowSend = lodash.isNumber(result)
|
||||
|
|
@ -449,13 +502,13 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
|
||||
var satoshis = 0;
|
||||
if (unit.isFiat) {
|
||||
satoshis = (fromFiat(uiAmount) * unitToSatoshi).toFixed(0);
|
||||
satoshis = Math.floor(fromFiat(uiAmount) * unitToSatoshi);
|
||||
} else {
|
||||
satoshis = (uiAmount * unitToSatoshi).toFixed(0);
|
||||
satoshis = Math.floor(uiAmount * unitToSatoshi);
|
||||
}
|
||||
|
||||
var confirmData = {
|
||||
amount: useSendMax ? undefined : satoshis,
|
||||
amount: (useSendMax && canSendMax) ? undefined : satoshis,
|
||||
displayAddress: passthroughParams.displayAddress,
|
||||
fromWalletId: passthroughParams.fromWalletId,
|
||||
sendMax: useSendMax,
|
||||
|
|
@ -467,12 +520,11 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
confirmData.thirdParty = vm.thirdParty;
|
||||
}
|
||||
|
||||
sendFlowService.pushState(confirmData);
|
||||
if (!confirmData.fromWalletId) {
|
||||
$state.transitionTo('tabs.paymentRequest.confirm', confirmData);
|
||||
} else {
|
||||
$state.transitionTo('tabs.send.review', confirmData);
|
||||
$scope.useSendMax = null;
|
||||
sendFlowService.goNext(confirmData);
|
||||
useSendMax = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -590,18 +642,73 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
|
||||
function updateAvailableFundsStringIfNeeded() {
|
||||
if (passthroughParams.fromWalletId && availableSatoshis !== null) {
|
||||
availableFundsInFiat = '';
|
||||
vm.availableFunds = availableFundsInCrypto;
|
||||
if (passthroughParams.fromWalletId && walletSpendableAmount.satoshis !== null) {
|
||||
vm.availableFunds = walletSpendableAmount.crypto;
|
||||
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
var coin = availableUnits[altUnitIndex].id;
|
||||
txFormatService.formatAlternativeStr(coin, availableSatoshis, function formatCallback(formatted){
|
||||
if (formatted) {
|
||||
availableFundsInFiat = formatted;
|
||||
txFormatService.formatAlternativeStr(coin, walletSpendableAmount.satoshis, function formatCallback(formatted){
|
||||
|
||||
if (formatted) {
|
||||
$scope.$apply(function() {
|
||||
vm.availableFunds = availableFundsInFiat;
|
||||
vm.availableFunds = formatted;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
updateMaximumButtonIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
function updateAvailableFundsFromWallet(wallet) {
|
||||
console.log('amount updateAvailableFundsFromWallet()');
|
||||
var availableFundsInFiat = '';
|
||||
if (wallet.status && wallet.status.isValid) {
|
||||
walletSpendableAmount.crypto = wallet.status.spendableBalanceStr;
|
||||
walletSpendableAmount.satoshis = wallet.status.spendableAmount;
|
||||
if (wallet.status.alternativeBalanceAvailable) {
|
||||
availableFundsInFiat = wallet.status.spendableBalanceAlternative + ' ' + wallet.status.alternativeIsoCode;
|
||||
} else {
|
||||
availableFundsInFiat = '';
|
||||
}
|
||||
|
||||
} else if (wallet.cachedStatus && wallet.cachedStatus.isValid) {
|
||||
|
||||
if (wallet.cachedStatus.alternativeBalanceAvailable) {
|
||||
availableFundsInFiat = wallet.cachedStatus.spendableBalanceAlternative + ' ' + wallet.cachedStatus.alternativeIsoCode;
|
||||
} else {
|
||||
availableFundsInFiat = '';
|
||||
}
|
||||
walletSpendableAmount.crypto = wallet.cachedStatus.spendableBalanceStr;
|
||||
walletSpendableAmount.satoshis = wallet.cachedStatus.spendableAmount;
|
||||
|
||||
} else {
|
||||
|
||||
walletSpendableAmount.crypto = '';
|
||||
walletSpendableAmount.satoshis = null;
|
||||
}
|
||||
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
vm.availableFunds = availableFundsInFiat || walletSpendableAmount.crypto;
|
||||
} else {
|
||||
vm.availableFunds = walletSpendableAmount.crypto;
|
||||
}
|
||||
|
||||
setMaximumButtonFromWallet(wallet);
|
||||
}
|
||||
|
||||
function updateMaximumButtonIfNeeded() {
|
||||
console.log('sendmax updateMaximumButtonIfNeeded()');
|
||||
if (vm.showSendMaxButton || vm.showSendLimitMaxButton) {
|
||||
transactionSendableAmount.fiat = '';
|
||||
vm.sendableFunds = transactionSendableAmount.crypto;
|
||||
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
var coin = availableUnits[altUnitIndex].id;
|
||||
txFormatService.formatAlternativeStr(coin, transactionSendableAmount.satoshis, function formatCallback(formatted){
|
||||
if (formatted) {
|
||||
$scope.$apply(function onApply() {
|
||||
vm.sendableFunds = formatted;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -609,37 +716,59 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
}
|
||||
|
||||
function updateAvailableFundsFromWallet(wallet) {
|
||||
if (wallet.status && wallet.status.isValid) {
|
||||
availableFundsInCrypto = wallet.status.spendableBalanceStr;
|
||||
availableSatoshis = wallet.status.spendableAmount;
|
||||
if (wallet.status.alternativeBalanceAvailable) {
|
||||
availableFundsInFiat = wallet.status.spendableBalanceAlternative + ' ' + wallet.status.alternativeIsoCode;
|
||||
function setMaximumButtonFromWallet(wallet) {
|
||||
console.log('sendmax setMaximumButtonFromWallet()');
|
||||
var minSatoshis = vm.minAmount * unitToSatoshi;
|
||||
var maxSatoshis = vm.maxAmount * unitToSatoshi;
|
||||
|
||||
if (minSatoshis > walletSpendableAmount.satoshis) {
|
||||
console.log('sendmax Hiding max buttons as minimum is too high.');
|
||||
canSendMax = false;
|
||||
vm.showSendMaxButton = true;
|
||||
vm.showSendLimitMaxButton = false;
|
||||
transactionSendableAmount.satoshis = walletSpendableAmount.satoshis;
|
||||
|
||||
} else if (maxSatoshis) {
|
||||
if (walletSpendableAmount.satoshis > maxSatoshis) {
|
||||
console.log('sendmax Showing max limit button as available is greater than max limit.');
|
||||
canSendMax = false;
|
||||
vm.showSendMaxButton = false;
|
||||
vm.showSendLimitMaxButton = true;
|
||||
transactionSendableAmount.satoshis = maxSatoshis;
|
||||
} else {
|
||||
availableFundsInFiat = '';
|
||||
console.log('sendmax Showing sendmax as all available as less than max limit.');
|
||||
// Enabling send max here is a little dangerous, if they receive funds between pressing
|
||||
// this and the calculation in the Review screen.
|
||||
canSendMax = false;
|
||||
vm.showSendMaxButton = true;
|
||||
vm.showSendLimitMaxButton = false;
|
||||
transactionSendableAmount.satoshis = walletSpendableAmount.satoshis;
|
||||
}
|
||||
|
||||
} else if (wallet.cachedStatus && wallet.status.isValid) {
|
||||
} else {
|
||||
console.log('sendmax Showing sendmax as all available because no limits.');
|
||||
canSendMax = true;
|
||||
vm.showSendMaxButton = true;
|
||||
vm.showSendLimitMaxButton = false;
|
||||
transactionSendableAmount.satoshis = walletSpendableAmount.satoshis;
|
||||
}
|
||||
|
||||
if (wallet.cachedStatus.alternativeBalanceAvailable) {
|
||||
availableFundsInFiat = wallet.cachedStatus.spendableBalanceAlternative + ' ' + wallet.cachedStatus.alternativeIsoCode;
|
||||
} else {
|
||||
availableFundsInFiat = '';
|
||||
if (vm.showSendMaxButton || vm.showSendLimitMaxButton) {
|
||||
console.log('sendmax Setting max button text');
|
||||
transactionSendableAmount.crypto = txFormatService.formatAmountStr(wallet.coin, transactionSendableAmount.satoshis);
|
||||
vm.sendableFunds = transactionSendableAmount.crypto;
|
||||
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
txFormatService.formatAlternativeStr(wallet.coin, transactionSendableAmount.satoshis, function onFormat(formatted){
|
||||
if (formatted) {
|
||||
$scope.$apply(function onApply() {
|
||||
vm.sendableFunds = formatted;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
availableFundsInCrypto = wallet.cachedStatus.spendableBalanceStr;
|
||||
availableSatoshis = wallet.cachedStatus.spendableAmount;
|
||||
|
||||
} else {
|
||||
|
||||
availableFundsInFiat = '';
|
||||
availableFundsInCrypto = '';
|
||||
availableSatoshis = null;
|
||||
}
|
||||
|
||||
if (availableUnits[unitIndex].isFiat) {
|
||||
vm.availableFunds = availableFundsInFiat || availableFundsInCrypto;
|
||||
} else {
|
||||
vm.availableFunds = availableFundsInCrypto;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,12 +1,20 @@
|
|||
describe('amountController', function(){
|
||||
var configCache,
|
||||
configService,
|
||||
configService,
|
||||
gettextCatalog,
|
||||
$controller,
|
||||
$ionicHistory,
|
||||
$rootScope,
|
||||
ongoingProcess,
|
||||
platformInfo,
|
||||
popupService,
|
||||
profileService,
|
||||
rateService,
|
||||
sendFlowService,
|
||||
shapeshiftService,
|
||||
txFormatService,
|
||||
$scope,
|
||||
$state,
|
||||
$stateParams;
|
||||
|
||||
|
||||
|
|
@ -18,7 +26,7 @@ describe('amountController', function(){
|
|||
configCache = {
|
||||
wallet: {
|
||||
settings: {
|
||||
|
||||
unitToSatoshi: 100000000
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -31,18 +39,42 @@ describe('amountController', function(){
|
|||
});
|
||||
configService.getSync.and.returnValue(configCache);
|
||||
|
||||
gettextCatalog = jasmine.createSpyObj(['getString']);
|
||||
gettextCatalog.getString.and.callFake(function(str){ return str; });
|
||||
$ionicHistory = jasmine.createSpyObj(['backView']);
|
||||
|
||||
ongoingProcess = jasmine.createSpyObj(['set']);
|
||||
|
||||
platformInfo = {
|
||||
isChromeApp: false,
|
||||
isAndroid: false,
|
||||
isIos: true
|
||||
};
|
||||
|
||||
profileService = jasmine.createSpyObj(['getWallets']);
|
||||
popupService = jasmine.createSpyObj(['showAlert']);
|
||||
profileService = jasmine.createSpyObj(['getWallet', 'getWallets']);
|
||||
|
||||
rateService = jasmine.createSpyObj(['fromFiat', 'whenAvailable']);
|
||||
rateService = jasmine.createSpyObj(['fromFiat', 'listAlternatives', 'updateRates', 'whenAvailable']);
|
||||
sendFlowService = jasmine.createSpyObj(['getStateClone', 'pushState']);
|
||||
shapeshiftService = jasmine.createSpyObj(['getMarketData']);
|
||||
txFormatService = jasmine.createSpyObj(['formatAlternativeStr', 'formatAmountStr']);
|
||||
|
||||
txFormatService.formatAlternativeStr.and.callFake(function(coin, satoshis, cb) {
|
||||
if (typeof satoshis !== "number") {
|
||||
throw "satoshis in formatAlternativeStr() is not a number."
|
||||
}
|
||||
var units = satoshis / 100000000;
|
||||
var formatted = (units * 10000).toFixed(2) + ' USD';
|
||||
cb(formatted);
|
||||
});
|
||||
|
||||
txFormatService.formatAmountStr.and.callFake(function(coin, satoshis) {
|
||||
if (typeof satoshis !== "number") {
|
||||
throw "satoshis in formatAmountStr() is not a number."
|
||||
}
|
||||
return (satoshis * 100000000).toFixed(8) + ' ' + (coin || 'bch').toUpperCase();
|
||||
});
|
||||
|
||||
$state = jasmine.createSpyObj(['transitionTo']);
|
||||
$stateParams = {};
|
||||
|
||||
inject(function(_$controller_, _$rootScope_){
|
||||
|
|
@ -61,6 +93,14 @@ describe('amountController', function(){
|
|||
stateName: 'ignoreme'
|
||||
};
|
||||
$ionicHistory.backView.and.returnValue(backView);
|
||||
|
||||
var wallet = {
|
||||
status: {
|
||||
isValid: true,
|
||||
spendableAmount: 123456
|
||||
}
|
||||
};
|
||||
profileService.getWallet.and.returnValue(wallet);
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
rateService.fromFiat.and.returnValue(12); // satoshis or coins?
|
||||
|
||||
|
|
@ -69,33 +109,496 @@ describe('amountController', function(){
|
|||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: {},
|
||||
gettextCatalog: gettextCatalog,
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: {},
|
||||
popupService: popupService,
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: {},
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: {},
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
var data = {
|
||||
stateParams: {
|
||||
fromWalletId: 'fd56c1e7-e3ac-4fd9-8afc-27b9c1b3718b',
|
||||
toAddress: 'qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s'
|
||||
}
|
||||
var sendFlowState = {
|
||||
fromWalletId: 'fd56c1e7-e3ac-4fd9-8afc-27b9c1b3718b',
|
||||
toAddress: 'qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s'
|
||||
};
|
||||
$scope.$emit('$ionicView.beforeEnter', data);
|
||||
|
||||
expect($scope.fromWalletId).toBe('fd56c1e7-e3ac-4fd9-8afc-27b9c1b3718b');
|
||||
expect($scope.toAddress).toBe('qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s');
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
//expect($scope.fromWalletId).toBe('fd56c1e7-e3ac-4fd9-8afc-27b9c1b3718b');
|
||||
//expect($scope.toAddress).toBe('qrup46avn8t466xxwlzs4qelht7cnwvesv2e29wf7s');
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('Shapeshift', function() {
|
||||
var walletFrom;
|
||||
var walletTo;
|
||||
|
||||
beforeEach(function(){
|
||||
walletFrom = {};
|
||||
walletTo = {};
|
||||
|
||||
profileService.getWallet.and.callFake(function(walletId){
|
||||
if (walletId === '4cd7673e-7320-4dfa-86e5-d4edb51d460a') {
|
||||
return walletFrom;
|
||||
} else if (walletId === 'bf00af8f-0788-4b57-b30a-0390747407e9') {
|
||||
return walletTo;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
rateService.listAlternatives.and.returnValue([
|
||||
{name: "Australian Dollar", isoCode: "AUD"},
|
||||
{name: "United States Dollar", isoCode: "USD"}
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it ('with available balance below limit, shows sendMax for triggering alert', function() {
|
||||
|
||||
walletFrom.coin = 'btc';
|
||||
walletFrom.status = {
|
||||
isValid: true,
|
||||
spendableAmount: 789
|
||||
};
|
||||
walletTo.coin = 'bch';
|
||||
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
rateService.fromFiat.and.returnValue(12);
|
||||
|
||||
var $scope = $rootScope.$new();
|
||||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: gettextCatalog,
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: popupService,
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: $state,
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
rateService.whenAvailable.and.callFake(function(cb){
|
||||
cb();
|
||||
});
|
||||
|
||||
var sendFlowState = {
|
||||
amount: '',
|
||||
displayAddress: null,
|
||||
fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a',
|
||||
sendMax: false,
|
||||
thirdParty: {
|
||||
id: 'shapeshift',
|
||||
data: {},
|
||||
},
|
||||
toAddress: '',
|
||||
toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9'
|
||||
};
|
||||
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
var reqCoinIn = '';
|
||||
var reqCoinOut = '';
|
||||
shapeshiftService.getMarketData.and.callFake(function(coinIn, coinOut, cb){
|
||||
reqCoinIn = coinIn;
|
||||
reqCoinOut = coinOut;
|
||||
cb({
|
||||
maxLimit: '0.6846239',
|
||||
minimum: '0.00013692'
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
expect(rateService.updateRates.calls.any()).toEqual(true);
|
||||
|
||||
expect(reqCoinIn).toBe('btc');
|
||||
expect(reqCoinOut).toBe('bch');
|
||||
|
||||
expect(amountController.maxAmount).toBe(0.68462390);
|
||||
expect(amountController.minAmount).toBe(0.00013692);
|
||||
|
||||
expect(amountController.showSendMaxButton).toEqual(true);
|
||||
expect(amountController.showSendLimitMaxButton).toEqual(false);
|
||||
|
||||
expect(amountController.sendableFunds).toEqual('0.08 USD');
|
||||
|
||||
// Now hit the Send Max button
|
||||
amountController.sendMax();
|
||||
|
||||
expect(popupService.showAlert.calls.argsFor(0)[0]).toEqual('Insufficient funds');
|
||||
expect(popupService.showAlert.calls.argsFor(0)[1]).toEqual('Amount below minimum allowed');
|
||||
expect(sendFlowService.pushState.calls.any()).toEqual(false);
|
||||
expect($state.transitionTo.calls.any()).toEqual(false);
|
||||
});
|
||||
|
||||
it ('with available balance between limits, uses sendMax', function() {
|
||||
|
||||
walletFrom.coin = 'btc';
|
||||
walletFrom.status = {
|
||||
isValid: true,
|
||||
spendableAmount: 456789
|
||||
};
|
||||
walletTo.coin = 'bch';
|
||||
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
rateService.fromFiat.and.returnValue(12);
|
||||
|
||||
var $scope = $rootScope.$new();
|
||||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: {},
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: {},
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: $state,
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
rateService.whenAvailable.and.callFake(function(cb){
|
||||
cb();
|
||||
});
|
||||
|
||||
var sendFlowState = {
|
||||
amount: '',
|
||||
displayAddress: null,
|
||||
fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a',
|
||||
sendMax: false,
|
||||
thirdParty: {
|
||||
id: 'shapeshift',
|
||||
data: {},
|
||||
},
|
||||
toAddress: '',
|
||||
toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9'
|
||||
};
|
||||
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
var reqCoinIn = '';
|
||||
var reqCoinOut = '';
|
||||
shapeshiftService.getMarketData.and.callFake(function(coinIn, coinOut, cb){
|
||||
reqCoinIn = coinIn;
|
||||
reqCoinOut = coinOut;
|
||||
cb({
|
||||
maxLimit: '0.6846239',
|
||||
minimum: '0.00013692'
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
expect(rateService.updateRates.calls.any()).toEqual(true);
|
||||
|
||||
expect(reqCoinIn).toBe('btc');
|
||||
expect(reqCoinOut).toBe('bch');
|
||||
|
||||
expect(amountController.maxAmount).toBe(0.68462390);
|
||||
expect(amountController.minAmount).toBe(0.00013692);
|
||||
|
||||
expect(amountController.showSendMaxButton).toEqual(true);
|
||||
expect(amountController.showSendLimitMaxButton).toEqual(false);
|
||||
|
||||
// Now hit the Send Max button
|
||||
var pushedState = null;
|
||||
sendFlowService.pushState.and.callFake(function (sendFlowState){
|
||||
pushedState = sendFlowState;
|
||||
});
|
||||
|
||||
amountController.sendMax();
|
||||
|
||||
expect(pushedState.amount).toBeUndefined();
|
||||
expect(pushedState.fromWalletId).toEqual('4cd7673e-7320-4dfa-86e5-d4edb51d460a');
|
||||
expect(pushedState.sendMax).toEqual(true);
|
||||
expect(pushedState.toWalletId).toEqual('bf00af8f-0788-4b57-b30a-0390747407e9');
|
||||
|
||||
expect(pushedState.thirdParty.id).toEqual('shapeshift');
|
||||
expect(pushedState.thirdParty.data.maxAmount).toEqual(0.6846239);
|
||||
expect(pushedState.thirdParty.data.minAmount).toEqual(0.00013692);
|
||||
|
||||
expect($state.transitionTo.calls.count()).toEqual(1);
|
||||
expect($state.transitionTo.calls.argsFor(0)[0]).toEqual('tabs.send.review');
|
||||
});
|
||||
|
||||
it ('with available balance higher than max, uses send limit max instead of sendMax', function() {
|
||||
|
||||
walletFrom.coin = 'btc';
|
||||
walletFrom.status = {
|
||||
isValid: true,
|
||||
spendableAmount: 123456789
|
||||
};
|
||||
walletTo.coin = 'bch';
|
||||
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
rateService.fromFiat.and.returnValue(12); // satoshis or coins?
|
||||
|
||||
var $scope = $rootScope.$new();
|
||||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: {},
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: {},
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: $state,
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
rateService.whenAvailable.and.callFake(function(cb){
|
||||
cb();
|
||||
});
|
||||
|
||||
var sendFlowState = {
|
||||
amount: '',
|
||||
displayAddress: null,
|
||||
fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a',
|
||||
sendMax: false,
|
||||
thirdParty: {
|
||||
id: 'shapeshift',
|
||||
data: {},
|
||||
},
|
||||
toAddress: '',
|
||||
toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9'
|
||||
};
|
||||
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
var reqCoinIn = '';
|
||||
var reqCoinOut = '';
|
||||
shapeshiftService.getMarketData.and.callFake(function(coinIn, coinOut, cb){
|
||||
reqCoinIn = coinIn;
|
||||
reqCoinOut = coinOut;
|
||||
cb({
|
||||
maxLimit: '0.6846239',
|
||||
minimum: '0.00013692'
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
expect(rateService.updateRates.calls.any()).toEqual(true);
|
||||
|
||||
expect(reqCoinIn).toBe('btc');
|
||||
expect(reqCoinOut).toBe('bch');
|
||||
|
||||
expect(amountController.maxAmount).toBe(0.6846239);
|
||||
expect(amountController.minAmount).toBe(0.00013692);
|
||||
|
||||
expect(amountController.showSendMaxButton).toEqual(false);
|
||||
expect(amountController.showSendLimitMaxButton).toEqual(true);
|
||||
|
||||
// Now hit the Send Max button
|
||||
var pushedState = null;
|
||||
sendFlowService.pushState.and.callFake(function (sendFlowState){
|
||||
pushedState = sendFlowState;
|
||||
});
|
||||
|
||||
amountController.sendMax();
|
||||
|
||||
expect(pushedState.amount).toEqual(68462390);
|
||||
expect(pushedState.fromWalletId).toEqual('4cd7673e-7320-4dfa-86e5-d4edb51d460a');
|
||||
expect(pushedState.sendMax).toEqual(false);
|
||||
expect(pushedState.toWalletId).toEqual('bf00af8f-0788-4b57-b30a-0390747407e9');
|
||||
|
||||
expect(pushedState.thirdParty.id).toEqual('shapeshift');
|
||||
expect(pushedState.thirdParty.data.maxAmount).toEqual(0.6846239);
|
||||
expect(pushedState.thirdParty.data.minAmount).toEqual(0.00013692);
|
||||
|
||||
expect($state.transitionTo.calls.count()).toEqual(1);
|
||||
expect($state.transitionTo.calls.argsFor(0)[0]).toEqual('tabs.send.review');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('Wallet transfer', function() {
|
||||
var walletFrom;
|
||||
var walletTo;
|
||||
|
||||
beforeEach(function(){
|
||||
walletFrom = {};
|
||||
walletTo = {};
|
||||
|
||||
profileService.getWallet.and.callFake(function(walletId){
|
||||
if (walletId === '4cd7673e-7320-4dfa-86e5-d4edb51d460a') {
|
||||
return walletFrom;
|
||||
} else if (walletId === 'bf00af8f-0788-4b57-b30a-0390747407e9') {
|
||||
return walletTo;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
rateService.listAlternatives.and.returnValue([
|
||||
{name: "Australian Dollar", isoCode: "AUD"},
|
||||
{name: "United States Dollar", isoCode: "USD"}
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
it('wallet transfer send max.', function() {
|
||||
|
||||
walletFrom.coin = 'btc';
|
||||
walletFrom.status = {
|
||||
isValid: true,
|
||||
spendableAmount: 123456789
|
||||
};
|
||||
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
|
||||
var $scope = $rootScope.$new();
|
||||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: gettextCatalog,
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: popupService,
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: $state,
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
var sendFlowState = {
|
||||
fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a',
|
||||
toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9'
|
||||
};
|
||||
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
expect(amountController.showSendMaxButton).toEqual(true);
|
||||
expect(amountController.showSendLimitMaxButton).toEqual(false);
|
||||
|
||||
expect(amountController.sendableFunds).toEqual('12345.68 USD');
|
||||
|
||||
// Now hit the Send Max button
|
||||
var pushedState = null;
|
||||
sendFlowService.pushState.and.callFake(function (sendFlowState){
|
||||
pushedState = sendFlowState;
|
||||
});
|
||||
|
||||
amountController.sendMax();
|
||||
|
||||
expect(pushedState.amount).toBeUndefined();
|
||||
expect(pushedState.fromWalletId).toEqual('4cd7673e-7320-4dfa-86e5-d4edb51d460a');
|
||||
expect(pushedState.sendMax).toEqual(true);
|
||||
expect(pushedState.toWalletId).toEqual('bf00af8f-0788-4b57-b30a-0390747407e9');
|
||||
|
||||
expect($state.transitionTo.calls.count()).toEqual(1);
|
||||
expect($state.transitionTo.calls.argsFor(0)[0]).toEqual('tabs.send.review');
|
||||
});
|
||||
|
||||
|
||||
// This situation was seen in real life
|
||||
it('wallet transfer with valid cached status only.', function() {
|
||||
|
||||
walletFrom.coin = 'btc';
|
||||
walletFrom.status = {
|
||||
isValid: false,
|
||||
};
|
||||
walletFrom.cachedStatus = {
|
||||
isValid: true,
|
||||
spendableAmount: 5678
|
||||
};
|
||||
|
||||
profileService.getWallets.and.returnValue([{}]);
|
||||
|
||||
var $scope = $rootScope.$new();
|
||||
|
||||
var amountController = $controller('amountController', {
|
||||
configService: configService,
|
||||
gettextCatalog: gettextCatalog,
|
||||
$ionicHistory: $ionicHistory,
|
||||
$ionicModal: {},
|
||||
$ionicScrollDelegate: {},
|
||||
nodeWebkitService: {},
|
||||
ongoingProcess: ongoingProcess,
|
||||
platformInfo: platformInfo,
|
||||
profileService: profileService,
|
||||
popupService: popupService,
|
||||
rateService: rateService,
|
||||
$scope: $scope,
|
||||
sendFlowService: sendFlowService,
|
||||
shapeshiftService: shapeshiftService,
|
||||
$state: $state,
|
||||
$stateParams: $stateParams,
|
||||
txFormatService: txFormatService,
|
||||
walletService: {}
|
||||
});
|
||||
|
||||
var sendFlowState = {
|
||||
fromWalletId: '4cd7673e-7320-4dfa-86e5-d4edb51d460a',
|
||||
toWalletId: 'bf00af8f-0788-4b57-b30a-0390747407e9'
|
||||
};
|
||||
|
||||
sendFlowService.getStateClone.and.returnValue(sendFlowState);
|
||||
|
||||
$scope.$emit('$ionicView.beforeEnter', {});
|
||||
|
||||
expect(amountController.showSendMaxButton).toEqual(true);
|
||||
expect(amountController.showSendLimitMaxButton).toEqual(false);
|
||||
|
||||
expect(amountController.sendableFunds).toEqual('0.57 USD');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.controllers').controller('tourController',
|
||||
function($scope, $state, $log, $timeout, $filter, ongoingProcess, profileService, rateService, popupService, gettextCatalog, startupService, storageService, walletService, $q) {
|
||||
function ($scope, $state, $log, $timeout, $filter, ongoingProcess, configService, profileService, rateService, popupService, gettextCatalog, lodash, startupService, storageService, uxLanguage, walletService, $q) {
|
||||
|
||||
$scope.data = {
|
||||
index: 0
|
||||
|
|
@ -46,62 +46,90 @@ angular.module('copayApp.controllers').controller('tourController',
|
|||
creatingWallet = true;
|
||||
ongoingProcess.set('creatingWallet', true);
|
||||
$timeout(function() {
|
||||
profileService.createDefaultWallet(function(err, walletClients) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
uxLanguage.init(function(lang) {
|
||||
var rateCode = uxLanguage.getRateCode(lang);
|
||||
console.log("When Available: rateService");
|
||||
rateService.whenAvailable(function() {
|
||||
var alternatives = rateService.listAlternatives(true);
|
||||
|
||||
return $timeout(function() {
|
||||
$log.warn('Retrying to create default wallet.....:' + ++retryCount);
|
||||
if (retryCount > 3) {
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
popupService.showAlert(
|
||||
gettextCatalog.getString('Cannot Create Wallet'), err,
|
||||
function() {
|
||||
retryCount = 0;
|
||||
return $scope.createDefaultWallet();
|
||||
}, gettextCatalog.getString('Retry'));
|
||||
} else {
|
||||
return $scope.createDefaultWallet();
|
||||
}
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
var bchWallet = walletClients[0];
|
||||
var btcWallet = walletClients[1];
|
||||
var bchWalletId = bchWallet.credentials.walletId;
|
||||
var btcWalletId = btcWallet.credentials.walletId;
|
||||
|
||||
function createAddressPromise(wallet) {
|
||||
return $q(function(resolve, reject) {
|
||||
walletService.getAddress(wallet, true, function(e, addr) {
|
||||
if (e) reject(e);
|
||||
resolve(addr);
|
||||
var newAltCurrency = lodash.find(alternatives, {
|
||||
'isoCode': rateCode
|
||||
});
|
||||
|
||||
configService.whenAvailable(function(config) {
|
||||
var opts = {
|
||||
wallet: {
|
||||
settings: {
|
||||
alternativeName: newAltCurrency.name,
|
||||
alternativeIsoCode: newAltCurrency.isoCode,
|
||||
}
|
||||
}
|
||||
};
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.warn(err);
|
||||
|
||||
profileService.createDefaultWallet(function(err, walletClients) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
|
||||
return $timeout(function() {
|
||||
$log.warn('Retrying to create default wallet.....:' + ++retryCount);
|
||||
if (retryCount > 3) {
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
popupService.showAlert(
|
||||
gettextCatalog.getString('Cannot Create Wallet'), err,
|
||||
function() {
|
||||
retryCount = 0;
|
||||
return $scope.createDefaultWallet();
|
||||
}, gettextCatalog.getString('Retry'));
|
||||
} else {
|
||||
return $scope.createDefaultWallet();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
;
|
||||
|
||||
ongoingProcess.set('creatingWallet', false);
|
||||
var bchWallet = walletClients[0];
|
||||
var btcWallet = walletClients[1];
|
||||
var bchWalletId = bchWallet.credentials.walletId;
|
||||
var btcWalletId = btcWallet.credentials.walletId;
|
||||
|
||||
function createAddressPromise(wallet) {
|
||||
return $q(function (resolve, reject) {
|
||||
walletService.getAddress(wallet, true, function (e, addr) {
|
||||
if (e) reject(e);
|
||||
resolve(addr);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function goToCollectEmail() {
|
||||
$state.go('onboarding.collectEmail', {
|
||||
bchWalletId: bchWalletId,
|
||||
btcWalletId: btcWalletId
|
||||
});
|
||||
}
|
||||
|
||||
var bchAddressPromise = createAddressPromise(bchWallet);
|
||||
var btcAddressPromise = createAddressPromise(btcWallet);
|
||||
ongoingProcess.set('generatingNewAddress', true);
|
||||
|
||||
$q.all([bchAddressPromise, btcAddressPromise]).then(function (addresses) {
|
||||
ongoingProcess.set('generatingNewAddress', false);
|
||||
$state.go('tabs.home');
|
||||
}, function (e) {
|
||||
ongoingProcess.set('generatingNewAddress', false);
|
||||
$log.warn(e);
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), e);
|
||||
$state.go('tabs.home');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
$log.debug('Setting default currency : ' + newAltCurrency);
|
||||
});
|
||||
}
|
||||
|
||||
function goToCollectEmail() {
|
||||
$state.go('onboarding.collectEmail', {
|
||||
bchWalletId: bchWalletId,
|
||||
btcWalletId: btcWalletId
|
||||
});
|
||||
}
|
||||
|
||||
var bchAddressPromise = createAddressPromise(bchWallet);
|
||||
var btcAddressPromise = createAddressPromise(btcWallet);
|
||||
ongoingProcess.set('generatingNewAddress', true);
|
||||
|
||||
$q.all([bchAddressPromise, btcAddressPromise]).then(function(addresses) {
|
||||
ongoingProcess.set('generatingNewAddress', false);
|
||||
$state.go('tabs.home');
|
||||
}, function(e) {
|
||||
ongoingProcess.set('generatingNewAddress', false);
|
||||
$log.warn(e);
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), e);
|
||||
$state.go('tabs.home');
|
||||
});
|
||||
});
|
||||
}, 300);
|
||||
};
|
||||
});
|
||||
})
|
||||
}, 300);
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -78,11 +78,15 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
|
||||
|
||||
function onBeforeEnter(event, data) {
|
||||
console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state);
|
||||
console.log('review onBeforeEnter sendflow ', sendFlowService.state);
|
||||
defaults = configService.getDefaults();
|
||||
sendFlowData = sendFlowService.getStateClone();
|
||||
sendFlowData = sendFlowService.state.getClone();
|
||||
originWalletId = sendFlowData.fromWalletId;
|
||||
satoshis = parseInt(sendFlowData.amount, 10);
|
||||
if (typeof sendFlowData.amount === 'string') {
|
||||
satoshis = parseInt(sendFlowData.amount, 10);
|
||||
} else {
|
||||
satoshis = sendFlowData.amount;
|
||||
}
|
||||
toAddress = sendFlowData.toAddress;
|
||||
destinationWalletId = sendFlowData.toWalletId;
|
||||
|
||||
|
|
@ -93,26 +97,48 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
|
||||
if (sendFlowData.thirdParty) {
|
||||
vm.thirdParty = sendFlowData.thirdParty;
|
||||
handleThirdPartyInitIfBip70();
|
||||
handleThirdPartyInitIfShapeshift();
|
||||
switch (vm.thirdParty.id) {
|
||||
case 'shapeshift':
|
||||
initShapeshift(function (err) {
|
||||
if (err) {
|
||||
// Error stop here
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
|
||||
$ionicHistory.goBack();
|
||||
});
|
||||
} else {
|
||||
_next(data);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'bip70':
|
||||
initBip70();
|
||||
default:
|
||||
_next(data);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
_next(data);
|
||||
}
|
||||
|
||||
configService.get(function onConfig(err, configCache) {
|
||||
if (err) {
|
||||
$log.err('Error getting config.', err);
|
||||
} else {
|
||||
config = configCache;
|
||||
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
|
||||
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor);
|
||||
console.log("coin", vm.originWallet.coin, vm.origin.currencyColor, config.bitcoinWalletColor, vm.originWallet.coin === 'btc');
|
||||
unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
|
||||
}
|
||||
updateSendAmounts();
|
||||
getOriginWalletBalance(vm.originWallet);
|
||||
handleDestinationAsAddress(toAddress, coin);
|
||||
handleDestinationAsWallet(sendFlowData.toWalletId);
|
||||
createVanityTransaction(data);
|
||||
});
|
||||
function _next() {
|
||||
configService.get(function onConfig(err, configCache) {
|
||||
if (err) {
|
||||
$log.err('Error getting config.', err);
|
||||
} else {
|
||||
config = configCache;
|
||||
priceDisplayIsFiat = config.wallet.settings.priceDisplay === 'fiat';
|
||||
vm.origin.currencyColor = (vm.originWallet.coin === 'btc' ? defaults.bitcoinWalletColor : defaults.bitcoinCashWalletColor);
|
||||
console.log("coin", vm.originWallet.coin, vm.origin.currencyColor, config.bitcoinWalletColor, vm.originWallet.coin === 'btc');
|
||||
unitFromSat = 1 / config.wallet.settings.unitToSatoshi;
|
||||
}
|
||||
updateSendAmounts();
|
||||
getOriginWalletBalance(vm.originWallet);
|
||||
handleDestinationAsAddress(toAddress, coin);
|
||||
handleDestinationAsWallet(sendFlowData.toWalletId);
|
||||
createVanityTransaction(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
vm.approve = function() {
|
||||
|
|
@ -403,7 +429,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
}
|
||||
|
||||
function goBack() {
|
||||
$ionicHistory.goBack();
|
||||
sendFlowService.router.goBack();
|
||||
}
|
||||
|
||||
function handleDestinationAsAddress(address, originCoin) {
|
||||
|
|
@ -458,72 +484,62 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
vm.destination.balanceCurrency = balanceText.currency;
|
||||
}
|
||||
|
||||
function handleThirdPartyInitIfBip70() {
|
||||
if (vm.thirdParty.id === 'bip70') {
|
||||
vm.sendingTitle = gettextCatalog.getString('You are paying');
|
||||
vm.memo = vm.thirdParty.memo;
|
||||
vm.memoExpanded = !!vm.memo;
|
||||
vm.destination.name = vm.thirdParty.name;
|
||||
function initBip70() {
|
||||
vm.sendingTitle = gettextCatalog.getString('You are paying');
|
||||
vm.memo = vm.thirdParty.memo;
|
||||
vm.memoExpanded = !!vm.memo;
|
||||
vm.destination.name = vm.thirdParty.name;
|
||||
|
||||
txPayproData = {
|
||||
caTrusted: vm.thirdParty.caTrusted,
|
||||
domain: vm.thirdParty.domain,
|
||||
expires: vm.thirdParty.expires,
|
||||
toAddress: toAddress,
|
||||
url: vm.thirdParty.url,
|
||||
verified: vm.thirdParty.verified,
|
||||
};
|
||||
}
|
||||
txPayproData = {
|
||||
caTrusted: vm.thirdParty.caTrusted,
|
||||
domain: vm.thirdParty.domain,
|
||||
expires: vm.thirdParty.expires,
|
||||
toAddress: toAddress,
|
||||
url: vm.thirdParty.url,
|
||||
verified: vm.thirdParty.verified,
|
||||
};
|
||||
}
|
||||
|
||||
function handleThirdPartyInitIfShapeshift() {
|
||||
if (vm.thirdParty.id === 'shapeshift') {
|
||||
vm.sendingTitle = gettextCatalog.getString('You are shifting');
|
||||
if (!vm.thirdParty.data) {
|
||||
vm.thirdParty.data = {};
|
||||
}
|
||||
function initShapeshift(cb) {
|
||||
vm.sendingTitle = gettextCatalog.getString('You are shifting');
|
||||
if (!vm.thirdParty.data) {
|
||||
vm.thirdParty.data = {};
|
||||
}
|
||||
|
||||
var toWallet = profileService.getWallet(destinationWalletId);
|
||||
vm.destination.name = toWallet.name;
|
||||
vm.destination.color = toWallet.color;
|
||||
vm.destination.currency = toWallet.coin.toUpperCase();
|
||||
var toWallet = profileService.getWallet(destinationWalletId);
|
||||
vm.destination.name = toWallet.name;
|
||||
vm.destination.color = toWallet.color;
|
||||
vm.destination.currency = toWallet.coin.toUpperCase();
|
||||
|
||||
|
||||
ongoingProcess.set('connectingShapeshift', true);
|
||||
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
|
||||
ongoingProcess.set('connectingShapeshift', true);
|
||||
walletService.getAddress(vm.originWallet, false, function onReturnWalletAddress(err, returnAddr) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) {
|
||||
if (err) {
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
popupService.showAlert(gettextCatalog.getString('Shapeshift Error'), err.toString(), function () {
|
||||
$ionicHistory.goBack();
|
||||
});
|
||||
return;
|
||||
return cb(err);
|
||||
}
|
||||
walletService.getAddress(toWallet, false, function onWithdrawalWalletAddress(err, withdrawalAddr) {
|
||||
if (err) {
|
||||
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) {
|
||||
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;
|
||||
tx.toAddress = shapeshiftData.toAddress;
|
||||
vm.destination.address = toAddress;
|
||||
vm.destination.kind = 'shapeshift';
|
||||
}
|
||||
});
|
||||
// Need to use the correct service to do it.
|
||||
var amount = parseFloat(satoshis / 100000000);
|
||||
|
||||
shapeshiftService.shiftIt(vm.originWallet.coin, toWallet.coin, withdrawalAddr, returnAddr, amount, function onShiftIt(err, shapeshiftData) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
} else {
|
||||
vm.destination.kind = 'shapeshift';
|
||||
vm.destination.address = toAddress;
|
||||
tx.toAddress = shapeshiftData.toAddress;
|
||||
vm.memo = 'ShapeShift Order:\nhttps://www.shapeshift.io/#/status/' + shapeshiftData.orderId;
|
||||
vm.memoExpanded = !!vm.memo;
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onShareTransaction() {
|
||||
|
|
@ -766,8 +782,12 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
|
|||
((processName === 'signingTx') && vm.originWallet.m > 1) ||
|
||||
(processName == 'sendingTx' && !vm.originWallet.canSign() && !vm.originWallet.isPrivKeyExternal())
|
||||
) && !isOn) {
|
||||
// Show the popup
|
||||
vm.sendStatus = 'success';
|
||||
|
||||
// Clear the send flow service state
|
||||
sendFlowService.state.clear();
|
||||
|
||||
if ($state.current.name === "tabs.send.review") { // XX SP: Otherwise all open wallets on other devices play this sound if you have been in a send flow before on that device.
|
||||
soundService.play('misc/payment_sent.mp3');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,6 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
|
||||
$scope.showMyAddress = showMyAddress;
|
||||
|
||||
function generateAddress(wallet, cb) {
|
||||
if (!wallet) return;
|
||||
walletService.getAddress(wallet, false, function(err, addr) {
|
||||
if (err) {
|
||||
popupService.showAlert(err);
|
||||
}
|
||||
return cb(addr);
|
||||
});
|
||||
}
|
||||
|
||||
function showToWallets() {
|
||||
$scope.toWallets = $scope.fromWallet.coin === 'btc' ? walletsBch : walletsBtc;
|
||||
$scope.onToWalletSelect($scope.toWallets[0]);
|
||||
$scope.singleToWallet = $scope.toWallets.length === 1;
|
||||
}
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
walletsBtc = profileService.getWallets({coin: 'btc'});
|
||||
walletsBch = profileService.getWallets({coin: 'bch'});
|
||||
|
|
@ -62,18 +46,7 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
id: 'shapeshift'
|
||||
}
|
||||
};
|
||||
|
||||
// Starting new send flow, so ensure everything is reset
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.home').then(function() {
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send').then(function() {
|
||||
$timeout(function () {
|
||||
sendFlowService.pushState(stateParams);
|
||||
$state.transitionTo('tabs.send.origin');
|
||||
}, 60);
|
||||
});
|
||||
});
|
||||
sendFlowService.start(stateParams);
|
||||
}
|
||||
|
||||
function showMyAddress() {
|
||||
|
|
|
|||
|
|
@ -43,21 +43,20 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
});
|
||||
}
|
||||
|
||||
if ($scope.isNW) {
|
||||
latestReleaseService.checkLatestRelease(function(err, newRelease) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
return;
|
||||
}
|
||||
if (newRelease) {
|
||||
$scope.newRelease = true;
|
||||
$scope.updateText = gettextCatalog.getString('There is a new version of {{appName}} available', {
|
||||
appName: $scope.name
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
latestReleaseService.checkLatestRelease(function(err, newReleaseData) {
|
||||
if (err) {
|
||||
$log.warn(err);
|
||||
return;
|
||||
}
|
||||
if (newReleaseData) {
|
||||
$scope.newRelease = true;
|
||||
$scope.newReleaseText = gettextCatalog.getString('There is a new version of {{appName}} available', {
|
||||
appName: $scope.name
|
||||
});
|
||||
$scope.newReleaseNotes = newReleaseData.releaseNotes;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onEnter(event, data) {
|
||||
$ionicNavBarDelegate.showBar(true);
|
||||
|
|
@ -109,31 +108,24 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
$scope.$apply();
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
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');
|
||||
sendFlowService.start();
|
||||
}
|
||||
|
||||
$scope.openExternalLink = function() {
|
||||
var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest';
|
||||
var optIn = true;
|
||||
var title = gettextCatalog.getString('Update Available');
|
||||
var message = gettextCatalog.getString('An update to this app is available. For your security, please update to the latest version.');
|
||||
var okText = gettextCatalog.getString('View Update');
|
||||
var cancelText = gettextCatalog.getString('Go Back');
|
||||
externalLinkService.open(url, optIn, title, message, okText, cancelText);
|
||||
$scope.showUpdatePopup = function() {
|
||||
latestReleaseService.showUpdatePopup();
|
||||
};
|
||||
|
||||
$scope.openBannerUrl = function() {
|
||||
|
|
@ -18,10 +18,10 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
$scope.displayBalanceAsFiat = true;
|
||||
|
||||
$scope.requestSpecificAmount = function() {
|
||||
sendFlowService.pushState({
|
||||
toWalletId: $scope.wallet.credentials.walletId
|
||||
sendFlowService.start({
|
||||
toWalletId: $scope.wallet.credentials.walletId,
|
||||
isRequestAmount: true
|
||||
});
|
||||
$state.go('tabs.paymentRequest.amount');
|
||||
};
|
||||
|
||||
$scope.setAddress = function(newAddr, copyAddress) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabScanController', function($scope, $log, $timeout, scannerService, incomingData, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) {
|
||||
angular.module('copayApp.controllers').controller('tabScanController', function(gettextCatalog, popupService, $scope, $log, $timeout, scannerService, incomingDataService, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) {
|
||||
|
||||
var scannerStates = {
|
||||
unauthorized: 'unauthorized',
|
||||
|
|
@ -111,7 +111,18 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
// Sometimes (testing in Chrome, when reading QR Code) data is an object
|
||||
// that has a string data.result.
|
||||
contents = contents.result || contents;
|
||||
incomingData.redir(contents);
|
||||
incomingDataService.redir(contents, function onError(err) {
|
||||
if (err) {
|
||||
var title = gettextCatalog.getString('Scan Failed');
|
||||
popupService.showAlert(title, err.message, function onAlertShown() {
|
||||
// Enable another scan since we won't receive incomingDataMenu.menuHidden
|
||||
activate();
|
||||
});
|
||||
} else {
|
||||
scannerService.resumePreview();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$rootScope.$on('incomingDataMenu.menuHidden', function() {
|
||||
|
|
@ -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, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) {
|
||||
angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService) {
|
||||
var clipboardHasAddress = false;
|
||||
var clipboardHasContent = false;
|
||||
var originalList;
|
||||
|
|
@ -29,7 +29,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
|
||||
var stateParams = sendFlowService.getStateClone();
|
||||
var stateParams = sendFlowService.state.getClone();
|
||||
$scope.fromWallet = profileService.getWallet(stateParams.fromWalletId);
|
||||
|
||||
clipboardService.readFromClipboard(function(text) {
|
||||
|
|
@ -39,7 +39,9 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
|
||||
$scope.clipboardHasAddress = false;
|
||||
$scope.clipboardHasContent = false;
|
||||
if ((text.indexOf('bitcoincash:') === 0 || text[0] === 'C' || text[0] === 'H' || text[0] === 'p' || text[0] === 'q') && text.replace('bitcoincash:', '').length === 42) { // CashAddr
|
||||
var parsed = bitcoinUriService.parse(text);
|
||||
console.log('parsed', parsed);
|
||||
if (parsed.isValid && parsed.publicAddress && parsed.coin === 'bch' && !parsed.testnet) { // CashAddr
|
||||
$scope.clipboardHasAddress = true;
|
||||
} else if ((text[0] === "1" || text[0] === "3" || text.substring(0, 3) === "bc1") && text.length >= 26 && text.length <= 35) { // Legacy Addresses
|
||||
$scope.clipboardHasAddress = true;
|
||||
|
|
@ -60,11 +62,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
});
|
||||
|
||||
$scope.findContact = function(search) {
|
||||
|
||||
if (incomingData.redir(search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!search || search.length < 1) {
|
||||
$scope.list = originalList;
|
||||
$timeout(function() {
|
||||
|
|
@ -73,12 +70,16 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
return;
|
||||
}
|
||||
|
||||
var result = lodash.filter(originalList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
|
||||
var params = sendFlowService.state.getClone();
|
||||
params.data = search;
|
||||
sendFlowService.start(params, function onError() {
|
||||
var result = lodash.filter(originalList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
|
||||
});
|
||||
|
||||
$scope.list = result;
|
||||
});
|
||||
|
||||
$scope.list = result;
|
||||
};
|
||||
|
||||
var hasWallets = function() {
|
||||
|
|
@ -184,27 +185,18 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
|
||||
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
|
||||
|
||||
var stateParams = sendFlowService.getStateClone();
|
||||
stateParams.toAddress = toAddress,
|
||||
var stateParams = sendFlowService.state.getClone();
|
||||
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');
|
||||
}
|
||||
|
||||
sendFlowService.start(stateParams);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.startWalletToWalletTransfer = function() {
|
||||
console.log('startWalletToWalletTransfer()');
|
||||
var params = sendFlowService.getStateClone();
|
||||
sendFlowService.pushState(params);
|
||||
$state.transitionTo('tabs.send.wallet-to-wallet', {
|
||||
fromWalletId: sendFlowService.fromWalletId
|
||||
});
|
||||
var params = sendFlowService.state.getClone();
|
||||
params.isWalletTransfer = true;
|
||||
sendFlowService.start(params);
|
||||
}
|
||||
|
||||
// This could probably be enhanced refactoring the routes abstract states
|
||||
|
|
@ -238,7 +230,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
|
|||
});
|
||||
|
||||
if (data.direction == "back") {
|
||||
sendFlowService.clear();
|
||||
sendFlowService.state.clear();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
|
||||
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingDataService, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
|
||||
|
||||
$scope.onScan = function(data) {
|
||||
if (!incomingData.redir(data)) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid data'));
|
||||
}
|
||||
incomingDataService.redir(data, function onError(err) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.setScanFn = function(scanFn) {
|
||||
|
|
@ -16,8 +18,7 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
};
|
||||
|
||||
$scope.startFreshSend = function() {
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.send');
|
||||
sendFlowService.start();
|
||||
};
|
||||
|
||||
$scope.importInit = function() {
|
||||
|
|
@ -28,7 +29,6 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
};
|
||||
|
||||
$scope.chooseScanner = function() {
|
||||
sendFlowService.clear();
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
if (!isWindowsPhoneApp) {
|
||||
|
|
@ -38,10 +38,14 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
|
||||
scannerService.useOldScanner(function(err, contents) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
} else {
|
||||
incomingDataService.redir(contents, function onError(err) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
incomingData.redir(contents);
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -55,34 +55,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
var log = new window.BitAnalytics.LogEvent("wallet_details_open", [], [channel]);
|
||||
window.BitAnalytics.LogEventHandlers.postEvent(log);
|
||||
|
||||
$scope.amountIsCollapsible = !$scope.isAndroid;
|
||||
|
||||
$scope.openExternalLink = function(url, target) {
|
||||
externalLinkService.open(url, target);
|
||||
};
|
||||
|
||||
var setPendingTxps = function(txps) {
|
||||
|
||||
/* Uncomment to test multiple outputs */
|
||||
|
||||
// var txp = {
|
||||
// message: 'test multi-output',
|
||||
// fee: 1000,
|
||||
// createdOn: new Date() / 1000,
|
||||
// outputs: [],
|
||||
// wallet: $scope.wallet
|
||||
// };
|
||||
//
|
||||
// function addOutput(n) {
|
||||
// txp.outputs.push({
|
||||
// amount: 600,
|
||||
// toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
|
||||
// message: 'output #' + (Number(n) + 1)
|
||||
// });
|
||||
// };
|
||||
// lodash.times(15, addOutput);
|
||||
// txps.push(txp);
|
||||
|
||||
if (!txps) {
|
||||
$scope.txps = [];
|
||||
return;
|
||||
|
|
@ -359,103 +336,36 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
};
|
||||
|
||||
var prevPos;
|
||||
|
||||
$scope.txHistoryPaddingBottom = 0;
|
||||
function getScrollPosition() {
|
||||
var scrollPosition = $ionicScrollDelegate.getScrollPosition();
|
||||
|
||||
$timeout(function() {
|
||||
getScrollPosition();
|
||||
}, 200);
|
||||
|
||||
if (!scrollPosition) {
|
||||
$window.requestAnimationFrame(function() {
|
||||
getScrollPosition();
|
||||
});
|
||||
return;
|
||||
}
|
||||
var pos = scrollPosition.top;
|
||||
if (pos > 0) {
|
||||
$scope.txHistoryPaddingBottom = "200px";
|
||||
}
|
||||
if (pos === prevPos) {
|
||||
$window.requestAnimationFrame(function() {
|
||||
getScrollPosition();
|
||||
});
|
||||
return;
|
||||
}
|
||||
prevPos = pos;
|
||||
refreshAmountSection(pos);
|
||||
};
|
||||
|
||||
function refreshAmountSection(scrollPos) {
|
||||
var AMOUNT_HEIGHT_BASE = 210;
|
||||
$scope.showBalanceButton = false;
|
||||
if ($scope.status) {
|
||||
$scope.showBalanceButton = ($scope.status.totalBalanceSat != $scope.status.spendableAmount);
|
||||
if ($scope.showBalanceButton) {
|
||||
AMOUNT_HEIGHT_BASE = 270;
|
||||
}
|
||||
}
|
||||
if (!$scope.amountIsCollapsible) {
|
||||
var t = ($scope.showBalanceButton ? 15 : 45);
|
||||
$scope.amountScale = 'translateY(' + t + 'px)';
|
||||
return;
|
||||
}
|
||||
|
||||
scrollPos = scrollPos || 0;
|
||||
var amountHeight = AMOUNT_HEIGHT_BASE - scrollPos;
|
||||
if (amountHeight < 80) {
|
||||
amountHeight = 80;
|
||||
}
|
||||
var contentMargin = amountHeight;
|
||||
if (contentMargin > AMOUNT_HEIGHT_BASE) {
|
||||
contentMargin = AMOUNT_HEIGHT_BASE;
|
||||
}
|
||||
|
||||
var amountScale = (amountHeight / AMOUNT_HEIGHT_BASE);
|
||||
if (amountScale < 0.5) {
|
||||
amountScale = 0.5;
|
||||
}
|
||||
if (amountScale > 1.1) {
|
||||
amountScale = 1.1;
|
||||
}
|
||||
|
||||
var s = amountScale;
|
||||
|
||||
// Make space for the balance button when it needs to display.
|
||||
var TOP_NO_BALANCE_BUTTON = 115;
|
||||
var TOP_BALANCE_BUTTON = 30;
|
||||
var top = TOP_NO_BALANCE_BUTTON;
|
||||
if ($scope.showBalanceButton) {
|
||||
top = TOP_BALANCE_BUTTON;
|
||||
}
|
||||
|
||||
var amountTop = ((amountScale - 0.80) / 0.80) * top;
|
||||
if (amountTop < -2) {
|
||||
amountTop = -2;
|
||||
}
|
||||
if (amountTop > top) {
|
||||
amountTop = top;
|
||||
}
|
||||
|
||||
var t = amountTop;
|
||||
|
||||
$scope.altAmountOpacity = (amountHeight - 100) / 80;
|
||||
$scope.buttonsOpacity = (amountHeight - 140) / 70;
|
||||
$window.requestAnimationFrame(function() {
|
||||
$scope.amountHeight = amountHeight + 'px';
|
||||
$scope.contentMargin = contentMargin + 'px';
|
||||
$scope.amountScale = 'scale3d(' + s + ',' + s + ',' + s + ') translateY(' + t + 'px)';
|
||||
$scope.$digest();
|
||||
getScrollPosition();
|
||||
});
|
||||
$scope.scrollPosition = pos;
|
||||
}
|
||||
|
||||
var scrollWatcherInitialized;
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
if ($scope.isCordova && $scope.isAndroid) setAndroidStatusBarColor();
|
||||
if (scrollWatcherInitialized || !$scope.amountIsCollapsible) {
|
||||
return;
|
||||
}
|
||||
scrollWatcherInitialized = true;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
sendFlowService.clear();
|
||||
|
||||
configService.whenAvailable(function (config) {
|
||||
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
||||
|
||||
|
|
@ -491,11 +401,12 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
var refreshInterval;
|
||||
|
||||
$scope.$on("$ionicView.afterEnter", function(event, data) {
|
||||
updateTxHistoryFromCachedData();
|
||||
$scope.updateAll(false, true);
|
||||
refreshAmountSection();
|
||||
$scope.updateAll();
|
||||
// refreshAmountSection();
|
||||
refreshInterval = $interval($scope.onRefresh, 10 * 1000);
|
||||
//refreshInterval = $interval($scope.onRefresh, 120 * 1000); // For testing
|
||||
$timeout(function() {
|
||||
getScrollPosition();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.afterLeave", function(event, data) {
|
||||
|
|
@ -555,16 +466,10 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
}
|
||||
|
||||
$scope.goToSend = function() {
|
||||
sendFlowService.startSend({
|
||||
sendFlowService.start({
|
||||
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', {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
|
||||
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $state, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
|
||||
|
||||
var fromWalletId = '';
|
||||
var priceDisplayAsFiat = false;
|
||||
|
|
@ -12,31 +12,22 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
|
||||
function onBeforeEnter(event, data) {
|
||||
if (data.direction == "back") {
|
||||
sendFlowService.popState();
|
||||
sendFlowService.state.pop();
|
||||
}
|
||||
console.log('walletSelector onBeforeEnter after back sendflow', sendFlowService.state);
|
||||
|
||||
$scope.params = sendFlowService.getStateClone();
|
||||
$scope.params = sendFlowService.state.getClone();
|
||||
|
||||
console.log('walletSelector onBeforeEnter after back sendflow', $scope.params);
|
||||
|
||||
var config = configService.getSync().wallet.settings;
|
||||
priceDisplayAsFiat = config.priceDisplay === 'fiat';
|
||||
unitDecimals = config.unitDecimals;
|
||||
unitsFromSatoshis = 1 / config.unitToSatoshi;
|
||||
|
||||
switch($state.current.name) {
|
||||
case 'tabs.send.wallet-to-wallet':
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
|
||||
break;
|
||||
case 'tabs.send.destination':
|
||||
if ($scope.params.fromWalletId && !$scope.params.thirdParty) {
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (!$scope.params.thirdParty) {
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Send');
|
||||
}
|
||||
// nop
|
||||
if ($scope.params.isWalletTransfer) {
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
|
||||
} else if (!$scope.params.thirdParty) {
|
||||
$scope.sendFlowTitle = gettextCatalog.getString('Send');
|
||||
}
|
||||
|
||||
$scope.coin = false; // Wallets to show (for destination screen or contacts)
|
||||
|
|
@ -99,21 +90,12 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
$scope.requestAmountSecondary = fiatAmount;
|
||||
$scope.requestCurrencySecondary = fiatCurrrency;
|
||||
}
|
||||
$scope.$apply();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getNextStep(params) {
|
||||
if (!params.toWalletId && !params.toAddress) { // If we have no toAddress or fromWallet
|
||||
return 'tabs.send.destination';
|
||||
} else if (!params.amount) { // If we have no amount
|
||||
return 'tabs.send.amount';
|
||||
} else { // If we do have them
|
||||
return 'tabs.send.review';
|
||||
}
|
||||
}
|
||||
|
||||
function handleThirdPartyIfShapeshift() {
|
||||
console.log($scope.thirdParty, $scope.coin);
|
||||
if ($scope.thirdParty.id === 'shapeshift' && $scope.type === 'destination') { // Shapeshift wants to know the
|
||||
|
|
@ -191,20 +173,17 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
|
|||
|
||||
|
||||
$scope.useWallet = function(wallet) {
|
||||
var params = sendFlowService.getStateClone();
|
||||
var params = sendFlowService.state.getClone();
|
||||
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
|
||||
params.fromWalletId = wallet.id;
|
||||
} else { // we're on the destination screen, set wallet to send to
|
||||
params.toWalletId = wallet.id;
|
||||
}
|
||||
sendFlowService.pushState(params);
|
||||
var nextStep = getNextStep(params);
|
||||
console.log('walletSelector nextStep', nextStep);
|
||||
$state.transitionTo(nextStep, $scope.params);
|
||||
sendFlowService.goNext(params);
|
||||
};
|
||||
|
||||
$scope.goBack = function() {
|
||||
$ionicHistory.goBack();
|
||||
sendFlowService.router.goBack();
|
||||
}
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue