2015-03-06 07:00:10 -08:00
|
|
|
'use strict';
|
|
|
|
|
2015-08-20 12:43:03 -07:00
|
|
|
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, feeService, bwsError, utilService) {
|
2015-03-06 07:00:10 -08:00
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
var self = this;
|
2015-04-21 09:06:44 -07:00
|
|
|
$rootScope.hideMenuBar = false;
|
2015-04-23 08:27:43 -07:00
|
|
|
$rootScope.wpInputFocused = false;
|
2015-08-03 16:39:09 -07:00
|
|
|
$scope.currentSpendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
// INIT
|
|
|
|
var config = configService.getSync().wallet.settings;
|
|
|
|
this.unitToSatoshi = config.unitToSatoshi;
|
|
|
|
this.satToUnit = 1 / this.unitToSatoshi;
|
|
|
|
this.unitName = config.unitName;
|
|
|
|
this.alternativeIsoCode = config.alternativeIsoCode;
|
|
|
|
this.alternativeName = config.alternativeName;
|
|
|
|
this.alternativeAmount = 0;
|
|
|
|
this.unitDecimals = config.unitDecimals;
|
|
|
|
this.isCordova = isCordova;
|
|
|
|
this.addresses = [];
|
|
|
|
this.isMobile = isMobile.any();
|
|
|
|
this.isWindowsPhoneApp = isMobile.Windows() && isCordova;
|
|
|
|
this.blockUx = false;
|
|
|
|
this.isRateAvailable = false;
|
|
|
|
this.showScanner = false;
|
|
|
|
this.isMobile = isMobile.any();
|
2015-05-30 19:15:43 -07:00
|
|
|
this.addr = {};
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
|
|
|
|
self.setForm(data);
|
2015-04-28 14:11:06 -07:00
|
|
|
$rootScope.$emit('Local/SetTab', 'send');
|
2015-07-15 12:15:05 -07:00
|
|
|
|
|
|
|
var form = $scope.sendForm;
|
|
|
|
if (form.address.$invalid) {
|
|
|
|
self.resetForm();
|
|
|
|
self.error = gettext('Could not recognize a valid Bitcoin QR Code');
|
|
|
|
}
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
var disablePaymentUriListener = $rootScope.$on('paymentUri', function(event, uri) {
|
|
|
|
$timeout(function() {
|
2015-04-28 14:11:06 -07:00
|
|
|
$rootScope.$emit('Local/SetTab', 'send');
|
2015-04-23 08:27:43 -07:00
|
|
|
self.setForm(uri);
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
|
|
|
var disableAddrListener = $rootScope.$on('Local/NeedNewAddress', function() {
|
2015-06-27 09:22:56 -07:00
|
|
|
self.setAddress(true);
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
var disableFocusListener = $rootScope.$on('Local/NewFocusedWallet', function() {
|
2015-05-30 19:15:43 -07:00
|
|
|
self.addr = {};
|
2015-04-23 22:42:10 -07:00
|
|
|
self.resetForm();
|
|
|
|
});
|
2015-04-23 11:19:30 -07:00
|
|
|
|
2015-04-28 14:00:49 -07:00
|
|
|
var disableResumeListener = $rootScope.$on('Local/Resume', function() {
|
2015-04-28 15:26:22 -07:00
|
|
|
// This is needed then the apps go to sleep
|
2015-05-04 09:27:12 -07:00
|
|
|
self.bindTouchDown();
|
2015-04-28 14:00:49 -07:00
|
|
|
});
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
var disableTabListener = $rootScope.$on('Local/TabChanged', function(e, tab) {
|
2015-04-28 12:58:40 -07:00
|
|
|
// This will slow down switch, do not add things here!
|
2015-04-23 22:42:10 -07:00
|
|
|
switch (tab) {
|
2015-04-23 11:19:30 -07:00
|
|
|
case 'receive':
|
2015-04-28 12:58:40 -07:00
|
|
|
// just to be sure we have an address
|
|
|
|
self.setAddress();
|
2015-04-23 11:19:30 -07:00
|
|
|
break;
|
2015-04-28 12:58:40 -07:00
|
|
|
case 'send':
|
|
|
|
self.resetError();
|
2015-04-23 11:19:30 -07:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2015-07-16 09:08:27 -07:00
|
|
|
var disableOngoingProcessListener = $rootScope.$on('Addon/OngoingProcess', function(e, name) {
|
|
|
|
self.setOngoingProcess(name);
|
|
|
|
});
|
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
disableAddrListener();
|
|
|
|
disableScannerListener();
|
|
|
|
disablePaymentUriListener();
|
2015-04-23 11:19:30 -07:00
|
|
|
disableTabListener();
|
2015-04-23 22:42:10 -07:00
|
|
|
disableFocusListener();
|
2015-04-28 14:00:49 -07:00
|
|
|
disableResumeListener();
|
2015-07-16 09:08:27 -07:00
|
|
|
disableOngoingProcessListener();
|
2015-04-23 08:27:43 -07:00
|
|
|
$rootScope.hideMenuBar = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
self.isRateAvailable = true;
|
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
|
|
|
|
2015-07-29 08:37:51 -07:00
|
|
|
var accept_msg = gettextCatalog.getString('Accept');
|
|
|
|
var cancel_msg = gettextCatalog.getString('Cancel');
|
|
|
|
var confirm_msg = gettextCatalog.getString('Confirm');
|
|
|
|
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.openCopayersModal = function(copayers, copayerId) {
|
2015-04-16 07:35:45 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-05-11 11:21:08 -07:00
|
|
|
|
2015-03-06 07:00:10 -08:00
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
$scope.copayers = copayers;
|
|
|
|
$scope.copayerId = copayerId;
|
2015-04-16 07:35:45 -07:00
|
|
|
$scope.color = fc.backgroundColor;
|
2015-05-11 11:21:08 -07:00
|
|
|
$scope.cancel = function() {
|
2015-03-06 07:00:10 -08:00
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
};
|
2015-05-07 15:02:38 -07:00
|
|
|
var modalInstance = $modal.open({
|
2015-03-06 07:00:10 -08:00
|
|
|
templateUrl: 'views/modals/copayers.html',
|
2015-05-07 15:02:38 -07:00
|
|
|
windowClass: 'full animated slideInUp',
|
2015-03-06 07:00:10 -08:00
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
2015-05-07 15:02:38 -07:00
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
|
|
|
m.addClass('slideOutDown');
|
|
|
|
});
|
2015-03-06 07:00:10 -08:00
|
|
|
};
|
|
|
|
|
2015-06-19 18:01:38 -07:00
|
|
|
|
|
|
|
$scope.openWalletsModal = function(wallets) {
|
|
|
|
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
$scope.wallets = wallets;
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
2015-06-27 09:48:25 -07:00
|
|
|
|
|
|
|
$scope.selectWallet = function(walletId, walletName) {
|
2015-06-28 07:03:28 -07:00
|
|
|
$scope.gettingAddress = true;
|
|
|
|
$scope.selectedWalletName = walletName;
|
|
|
|
$timeout(function() {
|
2015-06-27 09:48:25 -07:00
|
|
|
$scope.$apply();
|
|
|
|
});
|
2015-06-28 07:03:28 -07:00
|
|
|
addressService.getAddress(walletId, false, function(err, addr) {
|
|
|
|
$scope.gettingAddress = false;
|
2015-08-12 07:08:33 -07:00
|
|
|
|
|
|
|
if (err) {
|
2015-06-27 09:48:25 -07:00
|
|
|
self.error = err;
|
|
|
|
$modalInstance.dismiss('cancel');
|
2015-08-12 07:08:33 -07:00
|
|
|
return;
|
2015-06-27 09:48:25 -07:00
|
|
|
}
|
2015-08-12 07:08:33 -07:00
|
|
|
|
|
|
|
$modalInstance.close(addr);
|
2015-06-27 09:48:25 -07:00
|
|
|
});
|
|
|
|
};
|
2015-06-19 18:01:38 -07:00
|
|
|
};
|
2015-06-27 09:48:25 -07:00
|
|
|
|
2015-06-19 18:01:38 -07:00
|
|
|
var modalInstance = $modal.open({
|
|
|
|
templateUrl: 'views/modals/wallets.html',
|
|
|
|
windowClass: 'full animated slideInUp',
|
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
|
|
|
m.addClass('slideOutDown');
|
|
|
|
});
|
2015-06-27 09:48:25 -07:00
|
|
|
|
|
|
|
modalInstance.result.then(function(addr) {
|
|
|
|
if (addr) {
|
|
|
|
self.setForm(addr);
|
|
|
|
}
|
|
|
|
});
|
2015-06-19 18:01:38 -07:00
|
|
|
};
|
|
|
|
|
2015-05-06 07:16:19 -07:00
|
|
|
this.openTxpModal = function(tx, copayers) {
|
2015-03-06 07:00:10 -08:00
|
|
|
var fc = profileService.focusedClient;
|
2015-05-30 18:38:08 -07:00
|
|
|
var refreshUntilItChanges = false;
|
2015-08-11 13:59:41 -07:00
|
|
|
var currentSpendUnconfirmed = $scope.currentSpendUnconfirmed;
|
2015-03-06 07:00:10 -08:00
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
$scope.error = null;
|
|
|
|
$scope.tx = tx;
|
|
|
|
$scope.copayers = copayers
|
2015-05-13 06:56:08 -07:00
|
|
|
$scope.copayerId = fc.credentials.copayerId;
|
2015-08-12 07:49:13 -07:00
|
|
|
$scope.canSign = fc.canSign();
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = null;
|
|
|
|
$scope.color = fc.backgroundColor;
|
2015-05-30 18:38:08 -07:00
|
|
|
refreshUntilItChanges = false;
|
2015-08-11 13:59:41 -07:00
|
|
|
$scope.currentSpendUnconfirmed = currentSpendUnconfirmed;
|
2015-03-06 07:00:10 -08:00
|
|
|
|
|
|
|
$scope.getShortNetworkName = function() {
|
|
|
|
return fc.credentials.networkName.substring(0, 4);
|
|
|
|
};
|
2015-04-17 14:10:22 -07:00
|
|
|
lodash.each(['TxProposalRejectedBy', 'TxProposalAcceptedBy', 'transactionProposalRemoved', 'TxProposalRemoved', 'NewOutgoingTx'], function(eventName) {
|
2015-03-06 07:00:10 -08:00
|
|
|
$rootScope.$on(eventName, function() {
|
|
|
|
fc.getTx($scope.tx.id, function(err, tx) {
|
|
|
|
if (err) {
|
|
|
|
|
2015-09-03 13:34:42 -07:00
|
|
|
if (err.code && err.code == 'TX_NOT_FOUND' &&
|
2015-03-06 07:00:10 -08:00
|
|
|
(eventName == 'transactionProposalRemoved' || eventName == 'TxProposalRemoved')) {
|
|
|
|
$scope.tx.removed = true;
|
2015-06-18 07:17:35 -07:00
|
|
|
$scope.tx.canBeRemoved = false;
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.tx.pendingForUs = false;
|
|
|
|
$scope.$apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var action = lodash.find(tx.actions, {
|
|
|
|
copayerId: fc.credentials.copayerId
|
|
|
|
});
|
2015-08-20 12:43:03 -07:00
|
|
|
$scope.tx = utilService.processTx(tx);
|
2015-03-06 07:00:10 -08:00
|
|
|
if (!action && tx.status == 'pending')
|
|
|
|
$scope.tx.pendingForUs = true;
|
|
|
|
$scope.updateCopayerList();
|
|
|
|
$scope.$apply();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.updateCopayerList = function() {
|
|
|
|
lodash.map($scope.copayers, function(cp) {
|
|
|
|
lodash.each($scope.tx.actions, function(ac) {
|
|
|
|
if (cp.id == ac.copayerId) {
|
|
|
|
cp.action = ac.type;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.sign = function(txp) {
|
|
|
|
var fc = profileService.focusedClient;
|
2015-07-15 18:10:59 -07:00
|
|
|
|
|
|
|
if (!fc.canSign())
|
|
|
|
return;
|
|
|
|
|
2015-03-06 07:00:10 -08:00
|
|
|
if (fc.isPrivKeyEncrypted()) {
|
|
|
|
profileService.unlockFC(function(err) {
|
|
|
|
if (err) {
|
2015-08-12 07:08:33 -07:00
|
|
|
$scope.error = bwsError.msg(err);
|
2015-03-06 07:00:10 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $scope.sign(txp);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-05-18 12:21:36 -07:00
|
|
|
self.setOngoingProcess(gettext('Signing payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.error = null;
|
|
|
|
$timeout(function() {
|
|
|
|
fc.signTxProposal(txp, function(err, txpsi) {
|
|
|
|
profileService.lockFC();
|
2015-04-24 11:02:14 -07:00
|
|
|
self.setOngoingProcess();
|
2015-03-06 07:00:10 -08:00
|
|
|
if (err) {
|
2015-04-24 11:02:14 -07:00
|
|
|
$scope.loading = false;
|
2015-08-13 12:47:10 -07:00
|
|
|
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not accept payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.$digest();
|
|
|
|
} else {
|
|
|
|
//if txp has required signatures then broadcast it
|
|
|
|
var txpHasRequiredSignatures = txpsi.status == 'accepted';
|
|
|
|
if (txpHasRequiredSignatures) {
|
2015-04-29 15:19:10 -07:00
|
|
|
self.setOngoingProcess(gettext('Broadcasting transaction'));
|
2015-04-24 11:02:14 -07:00
|
|
|
$scope.loading = true;
|
2015-05-22 13:16:55 -07:00
|
|
|
fc.broadcastTxProposal(txpsi, function(err, txpsb, memo) {
|
2015-04-24 11:02:14 -07:00
|
|
|
self.setOngoingProcess();
|
|
|
|
$scope.loading = false;
|
2015-03-06 07:00:10 -08:00
|
|
|
if (err) {
|
2015-08-13 12:47:10 -07:00
|
|
|
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not broadcast payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.$digest();
|
|
|
|
} else {
|
2015-05-30 18:38:08 -07:00
|
|
|
$log.debug('Transaction signed and broadcasted')
|
2015-05-22 13:16:55 -07:00
|
|
|
if (memo)
|
|
|
|
$log.info(memo);
|
2015-05-29 07:46:33 -07:00
|
|
|
|
2015-05-30 18:38:08 -07:00
|
|
|
refreshUntilItChanges = true;
|
2015-05-29 08:39:17 -07:00
|
|
|
$modalInstance.close(txpsb);
|
2015-03-06 07:00:10 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2015-04-24 11:02:14 -07:00
|
|
|
$scope.loading = false;
|
2015-03-06 07:00:10 -08:00
|
|
|
$modalInstance.close(txpsi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.reject = function(txp) {
|
2015-05-18 12:21:36 -07:00
|
|
|
self.setOngoingProcess(gettext('Rejecting payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.error = null;
|
|
|
|
$timeout(function() {
|
|
|
|
fc.rejectTxProposal(txp, null, function(err, txpr) {
|
2015-04-24 11:02:14 -07:00
|
|
|
self.setOngoingProcess();
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = false;
|
|
|
|
if (err) {
|
2015-08-13 12:47:10 -07:00
|
|
|
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not reject payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.$digest();
|
|
|
|
} else {
|
|
|
|
$modalInstance.close(txpr);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.remove = function(txp) {
|
2015-05-18 12:21:36 -07:00
|
|
|
self.setOngoingProcess(gettext('Deleting payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.error = null;
|
|
|
|
$timeout(function() {
|
|
|
|
fc.removeTxProposal(txp, function(err, txpb) {
|
2015-04-24 11:02:14 -07:00
|
|
|
self.setOngoingProcess();
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = false;
|
|
|
|
|
|
|
|
// Hacky: request tries to parse an empty response
|
2015-04-21 09:06:44 -07:00
|
|
|
if (err && !(err.message && err.message.match(/Unexpected/))) {
|
2015-08-13 12:47:10 -07:00
|
|
|
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not delete payment proposal'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.$digest();
|
|
|
|
return;
|
2015-04-21 09:06:44 -07:00
|
|
|
}
|
2015-03-06 07:00:10 -08:00
|
|
|
$modalInstance.close();
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.broadcast = function(txp) {
|
2015-05-18 12:21:36 -07:00
|
|
|
self.setOngoingProcess(gettext('Broadcasting Payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = true;
|
|
|
|
$scope.error = null;
|
|
|
|
$timeout(function() {
|
2015-05-22 13:16:55 -07:00
|
|
|
fc.broadcastTxProposal(txp, function(err, txpb, memo) {
|
2015-04-24 11:02:14 -07:00
|
|
|
self.setOngoingProcess();
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.loading = false;
|
|
|
|
if (err) {
|
2015-08-13 12:47:10 -07:00
|
|
|
$scope.error = bwsError.msg(err, gettextCatalog.getString('Could not broadcast payment'));
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.$digest();
|
|
|
|
} else {
|
2015-05-22 13:16:55 -07:00
|
|
|
|
|
|
|
if (memo)
|
|
|
|
$log.info(memo);
|
2015-05-29 08:39:17 -07:00
|
|
|
|
2015-05-30 18:38:08 -07:00
|
|
|
refreshUntilItChanges = true;
|
2015-05-29 08:39:17 -07:00
|
|
|
$modalInstance.close(txpb);
|
2015-03-06 07:00:10 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
2015-04-26 22:31:07 -07:00
|
|
|
$scope.copyAddress = function(addr) {
|
|
|
|
if (!addr) return;
|
|
|
|
self.copyAddress(addr);
|
|
|
|
};
|
|
|
|
|
2015-03-06 07:00:10 -08:00
|
|
|
$scope.cancel = function() {
|
2015-04-21 22:48:00 -07:00
|
|
|
$modalInstance.dismiss('cancel');
|
2015-03-06 07:00:10 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var modalInstance = $modal.open({
|
|
|
|
templateUrl: 'views/modals/txp-details.html',
|
2015-05-11 12:33:40 -07:00
|
|
|
windowClass: 'full animated slideInRight',
|
2015-03-06 07:00:10 -08:00
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
|
|
|
|
2015-05-07 15:02:38 -07:00
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
2015-05-11 12:33:40 -07:00
|
|
|
m.addClass('slideOutRight');
|
2015-05-07 15:02:38 -07:00
|
|
|
});
|
|
|
|
|
2015-05-29 08:39:17 -07:00
|
|
|
modalInstance.result.then(function(txp) {
|
2015-05-12 06:59:10 -07:00
|
|
|
self.setOngoingProcess();
|
2015-03-06 07:00:10 -08:00
|
|
|
if (txp) {
|
2015-05-08 07:38:34 -07:00
|
|
|
txStatus.notify(txp, function() {
|
2015-05-30 18:38:08 -07:00
|
|
|
$scope.$emit('Local/TxProposalAction', refreshUntilItChanges);
|
2015-05-08 07:38:34 -07:00
|
|
|
});
|
2015-05-12 06:59:10 -07:00
|
|
|
} else {
|
|
|
|
$timeout(function() {
|
2015-05-30 18:38:08 -07:00
|
|
|
$scope.$emit('Local/TxProposalAction', refreshUntilItChanges);
|
2015-05-12 06:59:10 -07:00
|
|
|
}, 100);
|
2015-03-06 07:00:10 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-06-27 09:22:56 -07:00
|
|
|
this.setAddress = function(forceNew) {
|
2015-05-29 07:46:33 -07:00
|
|
|
self.addrError = null;
|
2015-04-23 08:27:43 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-05-13 08:41:05 -07:00
|
|
|
if (!fc)
|
|
|
|
return;
|
|
|
|
|
2015-06-27 09:22:56 -07:00
|
|
|
// Address already set?
|
|
|
|
if (!forceNew && self.addr[fc.credentials.walletId]) {
|
2015-05-30 19:15:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-27 09:22:56 -07:00
|
|
|
self.generatingAddress = true;
|
2015-04-23 08:27:43 -07:00
|
|
|
$timeout(function() {
|
2015-06-28 07:03:28 -07:00
|
|
|
addressService.getAddress(fc.credentials.walletId, forceNew, function(err, addr) {
|
2015-06-27 09:22:56 -07:00
|
|
|
self.generatingAddress = false;
|
|
|
|
|
2015-08-12 07:49:13 -07:00
|
|
|
if (err) {
|
2015-08-12 07:08:33 -07:00
|
|
|
self.addrError = err;
|
2015-08-12 07:49:13 -07:00
|
|
|
} else {
|
2015-08-12 07:08:33 -07:00
|
|
|
if (addr)
|
|
|
|
self.addr[fc.credentials.walletId] = addr;
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
2015-06-27 09:22:56 -07:00
|
|
|
|
|
|
|
$scope.$digest();
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
this.copyAddress = function(addr) {
|
|
|
|
if (isCordova) {
|
2015-06-08 07:15:30 -07:00
|
|
|
window.cordova.plugins.clipboard.copy(addr);
|
2015-07-29 08:42:05 -07:00
|
|
|
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
|
2015-05-28 06:52:33 -07:00
|
|
|
} else if (nodeWebkit.isDefined()) {
|
|
|
|
nodeWebkit.writeToClipboard(addr);
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.shareAddress = function(addr) {
|
|
|
|
if (isCordova) {
|
|
|
|
if (isMobile.Android() || isMobile.Windows()) {
|
|
|
|
window.ignoreMobilePause = true;
|
|
|
|
}
|
|
|
|
window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-24 13:55:08 -07:00
|
|
|
this.openCustomizedAmountModal = function(addr) {
|
|
|
|
var self = this;
|
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
$scope.addr = addr;
|
|
|
|
$scope.color = fc.backgroundColor;
|
|
|
|
$scope.unitName = self.unitName;
|
|
|
|
$scope.alternativeAmount = self.alternativeAmount;
|
|
|
|
$scope.alternativeName = self.alternativeName;
|
|
|
|
$scope.alternativeIsoCode = self.alternativeIsoCode;
|
|
|
|
$scope.isRateAvailable = self.isRateAvailable;
|
|
|
|
$scope.unitToSatoshi = self.unitToSatoshi;
|
|
|
|
$scope.unitDecimals = self.unitDecimals;
|
|
|
|
var satToUnit = 1 / self.unitToSatoshi;
|
|
|
|
$scope.showAlternative = false;
|
|
|
|
|
|
|
|
Object.defineProperty($scope,
|
|
|
|
"_customAlternative", {
|
|
|
|
get: function() {
|
|
|
|
return $scope.customAlternative;
|
|
|
|
},
|
|
|
|
set: function(newValue) {
|
|
|
|
$scope.customAlternative = newValue;
|
|
|
|
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
|
|
|
$scope.customAmount = parseFloat((rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed($scope.unitDecimals), 10);
|
2015-08-07 13:21:22 -07:00
|
|
|
} else {
|
|
|
|
$scope.customAmount = null;
|
2015-06-24 13:55:08 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty($scope,
|
|
|
|
"_customAmount", {
|
|
|
|
get: function() {
|
|
|
|
return $scope.customAmount;
|
|
|
|
},
|
|
|
|
set: function(newValue) {
|
|
|
|
$scope.customAmount = newValue;
|
|
|
|
if (typeof(newValue) === 'number' && $scope.isRateAvailable) {
|
|
|
|
$scope.customAlternative = parseFloat((rateService.toFiat(newValue * $scope.unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10);
|
|
|
|
} else {
|
2015-08-07 13:21:22 -07:00
|
|
|
$scope.customAlternative = null;
|
2015-06-24 13:55:08 -07:00
|
|
|
}
|
|
|
|
$scope.alternativeAmount = $scope.customAlternative;
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.submitForm = function(form) {
|
|
|
|
var satToBtc = 1 / 100000000;
|
|
|
|
var amount = form.amount.$modelValue;
|
2015-06-26 10:25:53 -07:00
|
|
|
var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0));
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.customizedAmountUnit = amount + ' ' + $scope.unitName;
|
|
|
|
$scope.customizedAlternativeUnit = $filter('noFractionNumber')(form.alternative.$modelValue, 2) + ' ' + $scope.alternativeIsoCode;
|
|
|
|
if ($scope.unitName == 'bits') {
|
2015-06-26 11:08:59 -07:00
|
|
|
amount = (amountSat * satToBtc).toFixed(8);
|
2015-06-26 10:25:53 -07:00
|
|
|
}
|
|
|
|
$scope.customizedAmountBtc = amount;
|
|
|
|
}, 1);
|
2015-06-24 13:55:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleAlternative = function() {
|
|
|
|
$scope.showAlternative = !$scope.showAlternative;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var modalInstance = $modal.open({
|
|
|
|
templateUrl: 'views/modals/customized-amount.html',
|
|
|
|
windowClass: 'full animated slideInUp',
|
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
|
|
|
m.addClass('slideOutDown');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-07-24 08:11:07 -07:00
|
|
|
// Send
|
2015-04-28 08:06:04 -07:00
|
|
|
|
2015-08-03 16:39:09 -07:00
|
|
|
var unwatchSpendUnconfirmed = $scope.$watch('currentSpendUnconfirmed', function(newVal, oldVal) {
|
|
|
|
if (newVal == oldVal) return;
|
|
|
|
$scope.currentSpendUnconfirmed = newVal;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
unwatchSpendUnconfirmed();
|
|
|
|
});
|
|
|
|
|
2015-04-28 08:06:04 -07:00
|
|
|
this.canShowAlternative = function() {
|
|
|
|
return $scope.showAlternative;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.showAlternative = function() {
|
|
|
|
$scope.showAlternative = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.hideAlternative = function() {
|
|
|
|
$scope.showAlternative = false;
|
|
|
|
};
|
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
this.resetError = function() {
|
2015-05-29 08:39:17 -07:00
|
|
|
this.error = this.success = null;
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
2015-04-28 12:08:43 -07:00
|
|
|
this.bindTouchDown = function(tries) {
|
|
|
|
var self = this;
|
|
|
|
tries = tries || 0;
|
|
|
|
if (tries > 5) return;
|
|
|
|
var e = document.getElementById('menu-walletHome');
|
2015-04-28 16:13:28 -07:00
|
|
|
if (!e) return $timeout(function() {
|
2015-04-28 12:08:43 -07:00
|
|
|
self.bindTouchDown(++tries);
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
// on touchdown elements
|
|
|
|
$log.debug('Binding touchstart elements...');
|
2015-04-29 08:08:16 -07:00
|
|
|
['hamburger', 'menu-walletHome', 'menu-send', 'menu-receive', 'menu-history'].forEach(function(id) {
|
2015-04-28 12:08:43 -07:00
|
|
|
var e = document.getElementById(id);
|
|
|
|
if (e) e.addEventListener('touchstart', function() {
|
2015-05-04 09:27:12 -07:00
|
|
|
try {
|
|
|
|
event.preventDefault();
|
|
|
|
} catch (e) {};
|
2015-04-28 12:08:43 -07:00
|
|
|
angular.element(e).triggerHandler('click');
|
2015-05-04 09:27:12 -07:00
|
|
|
}, true);
|
2015-04-28 12:08:43 -07:00
|
|
|
});
|
|
|
|
}
|
2015-04-23 08:27:43 -07:00
|
|
|
|
2015-04-28 12:08:43 -07:00
|
|
|
this.hideMenuBar = lodash.debounce(function(hide) {
|
2015-04-23 08:27:43 -07:00
|
|
|
if (hide) {
|
|
|
|
$rootScope.hideMenuBar = true;
|
2015-04-28 12:08:43 -07:00
|
|
|
this.bindTouchDown();
|
2015-04-23 08:27:43 -07:00
|
|
|
} else {
|
|
|
|
$rootScope.hideMenuBar = false;
|
|
|
|
}
|
|
|
|
$rootScope.$digest();
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
|
|
|
|
this.formFocus = function(what) {
|
2015-04-24 13:34:18 -07:00
|
|
|
if (isCordova && !this.isWindowsPhoneApp) {
|
2015-04-28 12:08:43 -07:00
|
|
|
this.hideMenuBar(what);
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
if (!this.isWindowsPhoneApp) return
|
|
|
|
|
|
|
|
if (!what) {
|
|
|
|
this.hideAddress = false;
|
|
|
|
this.hideAmount = false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (what == 'amount') {
|
|
|
|
this.hideAddress = true;
|
|
|
|
} else if (what == 'msg') {
|
|
|
|
this.hideAddress = true;
|
|
|
|
this.hideAmount = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$timeout(function() {
|
|
|
|
$rootScope.$digest();
|
|
|
|
}, 1);
|
|
|
|
};
|
|
|
|
|
2015-04-28 12:58:40 -07:00
|
|
|
this.setSendFormInputs = function() {
|
2015-04-23 08:27:43 -07:00
|
|
|
var unitToSat = this.unitToSatoshi;
|
|
|
|
var satToUnit = 1 / unitToSat;
|
|
|
|
/**
|
|
|
|
* Setting the two related amounts as properties prevents an infinite
|
|
|
|
* recursion for watches while preserving the original angular updates
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
Object.defineProperty($scope,
|
|
|
|
"_alternative", {
|
|
|
|
get: function() {
|
|
|
|
return $scope.__alternative;
|
|
|
|
},
|
|
|
|
set: function(newValue) {
|
|
|
|
$scope.__alternative = newValue;
|
|
|
|
if (typeof(newValue) === 'number' && self.isRateAvailable) {
|
|
|
|
$scope._amount = parseFloat((rateService.fromFiat(newValue, self.alternativeIsoCode) * satToUnit).toFixed(self.unitDecimals), 10);
|
2015-08-07 13:21:22 -07:00
|
|
|
} else {
|
|
|
|
$scope.__amount = null;
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
Object.defineProperty($scope,
|
|
|
|
"_amount", {
|
|
|
|
get: function() {
|
|
|
|
return $scope.__amount;
|
|
|
|
},
|
|
|
|
set: function(newValue) {
|
|
|
|
$scope.__amount = newValue;
|
|
|
|
if (typeof(newValue) === 'number' && self.isRateAvailable) {
|
|
|
|
$scope.__alternative = parseFloat((rateService.toFiat(newValue * self.unitToSatoshi, self.alternativeIsoCode)).toFixed(2), 10);
|
|
|
|
} else {
|
2015-08-07 13:21:22 -07:00
|
|
|
$scope.__alternative = null;
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
self.alternativeAmount = $scope.__alternative;
|
|
|
|
self.resetError();
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty($scope,
|
|
|
|
"_address", {
|
|
|
|
get: function() {
|
|
|
|
return $scope.__address;
|
|
|
|
},
|
|
|
|
set: function(newValue) {
|
|
|
|
$scope.__address = self.onAddressChange(newValue);
|
|
|
|
},
|
|
|
|
enumerable: true,
|
|
|
|
configurable: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-05-12 06:48:00 -07:00
|
|
|
this.setSendError = function(err) {
|
2015-04-23 11:23:21 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-08-12 07:08:33 -07:00
|
|
|
var prefix =
|
2015-08-13 12:47:10 -07:00
|
|
|
fc.credentials.m > 1 ? gettextCatalog.getString('Could not create payment proposal') : gettextCatalog.getString('Could not send payment');
|
2015-04-23 08:27:43 -07:00
|
|
|
|
2015-08-12 07:49:13 -07:00
|
|
|
this.error = bwsError.msg(err, prefix);
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$digest();
|
|
|
|
}, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.setOngoingProcess = function(name) {
|
|
|
|
var self = this;
|
2015-04-23 22:42:10 -07:00
|
|
|
self.blockUx = !!name;
|
|
|
|
|
|
|
|
if (isCordova) {
|
|
|
|
if (name) {
|
2015-04-28 13:49:09 -07:00
|
|
|
window.plugins.spinnerDialog.hide();
|
2015-04-23 22:42:10 -07:00
|
|
|
window.plugins.spinnerDialog.show(null, name + '...', true);
|
|
|
|
} else {
|
|
|
|
window.plugins.spinnerDialog.hide();
|
|
|
|
}
|
|
|
|
} else {
|
2015-04-28 13:19:22 -07:00
|
|
|
self.onGoingProcess = name;
|
2015-04-28 13:28:49 -07:00
|
|
|
$timeout(function() {
|
|
|
|
$rootScope.$apply();
|
|
|
|
});
|
2015-04-28 13:19:22 -07:00
|
|
|
};
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
2015-08-11 13:11:40 -07:00
|
|
|
this.setFee = function(level) {
|
|
|
|
this.currentSendFeeLevel = level;
|
|
|
|
};
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
this.submitForm = function() {
|
2015-04-23 11:23:21 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-04-23 08:27:43 -07:00
|
|
|
var unitToSat = this.unitToSatoshi;
|
2015-08-12 07:49:13 -07:00
|
|
|
|
2015-07-02 10:42:53 -07:00
|
|
|
if (isCordova && this.isWindowsPhoneApp) {
|
|
|
|
this.hideAddress = false;
|
|
|
|
this.hideAmount = false;
|
|
|
|
}
|
2015-04-23 08:27:43 -07:00
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
var form = $scope.sendForm;
|
2015-04-23 08:27:43 -07:00
|
|
|
if (form.$invalid) {
|
2015-04-29 15:19:10 -07:00
|
|
|
this.error = gettext('Unable to send transaction proposal');
|
2015-04-23 08:27:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fc.isPrivKeyEncrypted()) {
|
|
|
|
profileService.unlockFC(function(err) {
|
2015-05-12 06:48:00 -07:00
|
|
|
if (err) return self.setSendError(err);
|
2015-04-23 22:42:10 -07:00
|
|
|
return self.submitForm();
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2015-04-29 15:19:10 -07:00
|
|
|
self.setOngoingProcess(gettext('Creating transaction'));
|
2015-04-23 08:27:43 -07:00
|
|
|
$timeout(function() {
|
|
|
|
var comment = form.comment.$modelValue;
|
|
|
|
var paypro = self._paypro;
|
|
|
|
var address, amount;
|
|
|
|
|
|
|
|
address = form.address.$modelValue;
|
|
|
|
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
|
|
|
|
|
2015-08-13 10:54:53 -07:00
|
|
|
var getFee = function(cb) {
|
|
|
|
if (form.feePerKb) {
|
|
|
|
cb(null, form.feePerKb);
|
|
|
|
} else {
|
|
|
|
feeService.getCurrentFeeValue(self.currentSendFeeLevel, cb);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getFee(function(err, feePerKb) {
|
2015-07-24 11:09:19 -07:00
|
|
|
if (err) $log.debug(err);
|
2015-07-24 08:11:07 -07:00
|
|
|
fc.sendTxProposal({
|
|
|
|
toAddress: address,
|
|
|
|
amount: amount,
|
|
|
|
message: comment,
|
|
|
|
payProUrl: paypro ? paypro.url : null,
|
|
|
|
feePerKb: feePerKb,
|
2015-08-03 16:39:09 -07:00
|
|
|
excludeUnconfirmedUtxos: $scope.currentSpendUnconfirmed ? false : true
|
2015-07-24 08:11:07 -07:00
|
|
|
}, function(err, txp) {
|
2015-04-23 08:27:43 -07:00
|
|
|
if (err) {
|
2015-07-24 08:11:07 -07:00
|
|
|
self.setOngoingProcess();
|
|
|
|
profileService.lockFC();
|
|
|
|
return self.setSendError(err);
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
2015-07-24 08:11:07 -07:00
|
|
|
|
|
|
|
if (!fc.canSign()) {
|
|
|
|
$log.info('No signing proposal: No private key')
|
|
|
|
self.setOngoingProcess();
|
|
|
|
self.resetForm();
|
|
|
|
txStatus.notify(txp, function() {
|
|
|
|
return $scope.$emit('Local/TxProposalAction');
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.signAndBroadcast(txp, function(err) {
|
|
|
|
self.setOngoingProcess();
|
|
|
|
profileService.lockFC();
|
|
|
|
self.resetForm();
|
|
|
|
if (err) {
|
|
|
|
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
|
|
|
|
$scope.$emit('Local/TxProposalAction');
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.$digest();
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
});
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.signAndBroadcast = function(txp, cb) {
|
2015-04-23 11:23:21 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-04-29 15:19:10 -07:00
|
|
|
self.setOngoingProcess(gettext('Signing transaction'));
|
2015-04-23 08:27:43 -07:00
|
|
|
fc.signTxProposal(txp, function(err, signedTx) {
|
|
|
|
profileService.lockFC();
|
2015-05-30 08:46:38 -07:00
|
|
|
self.setOngoingProcess();
|
2015-04-26 14:41:21 -07:00
|
|
|
if (err) {
|
2015-08-13 12:47:10 -07:00
|
|
|
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
|
2015-04-24 11:02:14 -07:00
|
|
|
return cb(err);
|
|
|
|
}
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
if (signedTx.status == 'accepted') {
|
2015-04-29 15:19:10 -07:00
|
|
|
self.setOngoingProcess(gettext('Broadcasting transaction'));
|
2015-05-22 13:16:55 -07:00
|
|
|
fc.broadcastTxProposal(signedTx, function(err, btx, memo) {
|
2015-04-28 13:28:49 -07:00
|
|
|
self.setOngoingProcess();
|
2015-04-23 08:27:43 -07:00
|
|
|
if (err) {
|
2015-08-13 12:47:10 -07:00
|
|
|
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was signed but could not be broadcasted. Please try again from home screen'));
|
2015-04-28 13:28:49 -07:00
|
|
|
return cb(err);
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
2015-05-22 13:16:55 -07:00
|
|
|
if (memo)
|
|
|
|
$log.info(memo);
|
|
|
|
|
2015-04-26 22:38:48 -07:00
|
|
|
txStatus.notify(btx, function() {
|
2015-05-28 09:14:54 -07:00
|
|
|
$scope.$emit('Local/TxProposalAction', true);
|
2015-04-26 22:38:48 -07:00
|
|
|
return cb();
|
|
|
|
});
|
2015-04-23 08:27:43 -07:00
|
|
|
});
|
|
|
|
} else {
|
2015-04-28 11:17:13 -07:00
|
|
|
self.setOngoingProcess();
|
2015-04-26 22:38:48 -07:00
|
|
|
txStatus.notify(signedTx, function() {
|
2015-05-08 07:38:34 -07:00
|
|
|
$scope.$emit('Local/TxProposalAction');
|
2015-04-26 22:38:48 -07:00
|
|
|
return cb();
|
|
|
|
});
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-13 10:54:53 -07:00
|
|
|
this.setForm = function(to, amount, comment, feeRate) {
|
2015-04-23 08:27:43 -07:00
|
|
|
var form = $scope.sendForm;
|
|
|
|
if (to) {
|
|
|
|
form.address.$setViewValue(to);
|
|
|
|
form.address.$isValid = true;
|
|
|
|
form.address.$render();
|
|
|
|
this.lockAddress = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amount) {
|
|
|
|
form.amount.$setViewValue("" + amount);
|
|
|
|
form.amount.$isValid = true;
|
|
|
|
form.amount.$render();
|
|
|
|
this.lockAmount = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (comment) {
|
|
|
|
form.comment.$setViewValue(comment);
|
|
|
|
form.comment.$isValid = true;
|
|
|
|
form.comment.$render();
|
|
|
|
}
|
2015-08-13 10:54:53 -07:00
|
|
|
|
|
|
|
if (feeRate) {
|
|
|
|
form.feeRate = feeRate;
|
|
|
|
}
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
this.resetForm = function() {
|
2015-04-23 08:27:43 -07:00
|
|
|
this.resetError();
|
|
|
|
this._paypro = null;
|
|
|
|
|
|
|
|
this.lockAddress = false;
|
|
|
|
this.lockAmount = false;
|
2015-08-03 16:39:09 -07:00
|
|
|
this.currentSendFeeLevel = null;
|
|
|
|
this.hideAdvSend = true;
|
|
|
|
$scope.currentSpendUnconfirmed = configService.getSync().wallet.spendUnconfirmed;
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
this._amount = this._address = null;
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
var form = $scope.sendForm;
|
2015-08-13 10:54:53 -07:00
|
|
|
|
|
|
|
if (form && form.feeRate) {
|
|
|
|
form.feeRate = null;
|
|
|
|
}
|
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
if (form && form.amount) {
|
|
|
|
form.amount.$pristine = true;
|
|
|
|
form.amount.$setViewValue('');
|
|
|
|
form.amount.$render();
|
|
|
|
|
|
|
|
form.comment.$setViewValue('');
|
|
|
|
form.comment.$render();
|
|
|
|
form.$setPristine();
|
|
|
|
|
|
|
|
if (form.address) {
|
|
|
|
form.address.$pristine = true;
|
|
|
|
form.address.$setViewValue('');
|
|
|
|
form.address.$render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$timeout(function() {
|
|
|
|
$rootScope.$digest();
|
|
|
|
}, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.openPPModal = function(paypro) {
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
2015-04-23 11:23:21 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-04-23 08:27:43 -07:00
|
|
|
var satToUnit = 1 / self.unitToSatoshi;
|
|
|
|
$scope.paypro = paypro;
|
|
|
|
$scope.alternative = self.alternativeAmount;
|
|
|
|
$scope.alternativeIsoCode = self.alternativeIsoCode;
|
|
|
|
$scope.isRateAvailable = self.isRateAvailable;
|
|
|
|
$scope.unitTotal = (paypro.amount * satToUnit).toFixed(self.unitDecimals);
|
|
|
|
$scope.unitName = self.unitName;
|
|
|
|
$scope.color = fc.backgroundColor;
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
};
|
2015-05-07 15:02:38 -07:00
|
|
|
var modalInstance = $modal.open({
|
2015-04-23 08:27:43 -07:00
|
|
|
templateUrl: 'views/modals/paypro.html',
|
2015-05-07 15:02:38 -07:00
|
|
|
windowClass: 'full animated slideInUp',
|
2015-04-23 08:27:43 -07:00
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
2015-05-07 15:02:38 -07:00
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
|
|
|
m.addClass('slideOutDown');
|
|
|
|
});
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
2015-04-23 22:42:10 -07:00
|
|
|
this.setFromPayPro = function(uri) {
|
2015-04-23 11:23:21 -07:00
|
|
|
var fc = profileService.focusedClient;
|
2015-04-23 08:27:43 -07:00
|
|
|
if (isChromeApp) {
|
2015-04-29 15:19:10 -07:00
|
|
|
this.error = gettext('Payment Protocol not supported on Chrome App');
|
2015-04-23 08:27:43 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var satToUnit = 1 / this.unitToSatoshi;
|
|
|
|
var self = this;
|
2015-04-30 09:03:30 -07:00
|
|
|
/// Get information of payment if using Payment Protocol
|
|
|
|
self.setOngoingProcess(gettext('Fetching Payment Information'));
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
$log.debug('Fetch PayPro Request...', uri);
|
|
|
|
$timeout(function() {
|
|
|
|
fc.fetchPayPro({
|
|
|
|
payProUrl: uri,
|
|
|
|
}, function(err, paypro) {
|
2015-04-23 22:42:10 -07:00
|
|
|
self.setOngoingProcess();
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
$log.warn(err);
|
2015-04-23 22:42:10 -07:00
|
|
|
self.resetForm();
|
2015-04-23 08:27:43 -07:00
|
|
|
var msg = err.toString();
|
|
|
|
if (msg.match('HTTP')) {
|
2015-04-29 15:19:10 -07:00
|
|
|
msg = gettext('Could not fetch payment information');
|
2015-04-23 08:27:43 -07:00
|
|
|
}
|
|
|
|
self.error = msg;
|
|
|
|
} else {
|
|
|
|
self._paypro = paypro;
|
|
|
|
self.setForm(paypro.toAddress, (paypro.amount * satToUnit).toFixed(self.unitDecimals),
|
|
|
|
paypro.memo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setFromUri = function(uri) {
|
|
|
|
function sanitizeUri(uri) {
|
|
|
|
// Fixes when a region uses comma to separate decimals
|
|
|
|
var regex = /[\?\&]amount=(\d+([\,\.]\d+)?)/i;
|
|
|
|
var match = regex.exec(uri);
|
|
|
|
if (!match || match.length === 0) {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
var value = match[0].replace(',', '.');
|
|
|
|
var newUri = uri.replace(regex, value);
|
|
|
|
return newUri;
|
|
|
|
};
|
|
|
|
|
|
|
|
var satToUnit = 1 / this.unitToSatoshi;
|
|
|
|
|
|
|
|
uri = sanitizeUri(uri);
|
|
|
|
|
|
|
|
if (!bitcore.URI.isValid(uri)) {
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
var parsed = new bitcore.URI(uri);
|
|
|
|
var addr = parsed.address.toString();
|
|
|
|
var message = parsed.message;
|
|
|
|
if (parsed.r)
|
|
|
|
return this.setFromPayPro(parsed.r);
|
|
|
|
|
|
|
|
var amount = parsed.amount ?
|
|
|
|
(parsed.amount.toFixed(0) * satToUnit).toFixed(this.unitDecimals) : 0;
|
|
|
|
|
|
|
|
this.setForm(addr, amount, message);
|
|
|
|
return addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onAddressChange = function(value) {
|
|
|
|
this.resetError();
|
|
|
|
if (!value) return '';
|
|
|
|
|
|
|
|
if (this._paypro)
|
|
|
|
return value;
|
|
|
|
|
|
|
|
if (value.indexOf('bitcoin:') === 0) {
|
|
|
|
return this.setFromUri(value);
|
|
|
|
} else if (/^https?:\/\//.test(value)) {
|
|
|
|
return this.setFromPayPro(value);
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// History
|
|
|
|
|
|
|
|
function strip(number) {
|
|
|
|
return (parseFloat(number.toPrecision(12)));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getUnitName = function() {
|
|
|
|
return this.unitName;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getAlternativeIsoCode = function() {
|
|
|
|
return this.alternativeIsoCode;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.openTxModal = function(btx) {
|
|
|
|
var self = this;
|
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
$scope.btx = btx;
|
|
|
|
$scope.settings = config;
|
|
|
|
$scope.color = fc.backgroundColor;
|
2015-05-13 06:56:08 -07:00
|
|
|
$scope.copayerId = fc.credentials.copayerId;
|
|
|
|
$scope.isShared = fc.credentials.n > 1;
|
2015-04-23 08:27:43 -07:00
|
|
|
|
|
|
|
$scope.getAmount = function(amount) {
|
|
|
|
return self.getAmount(amount);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getUnitName = function() {
|
|
|
|
return self.getUnitName();
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getShortNetworkName = function() {
|
|
|
|
var n = fc.credentials.network;
|
|
|
|
return n.substring(0, 4);
|
|
|
|
};
|
|
|
|
|
2015-04-26 22:31:07 -07:00
|
|
|
$scope.copyAddress = function(addr) {
|
|
|
|
if (!addr) return;
|
|
|
|
self.copyAddress(addr);
|
|
|
|
};
|
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
$scope.cancel = function() {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
2015-07-28 10:22:46 -07:00
|
|
|
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
2015-05-07 15:02:38 -07:00
|
|
|
var modalInstance = $modal.open({
|
2015-04-23 08:27:43 -07:00
|
|
|
templateUrl: 'views/modals/tx-details.html',
|
2015-05-11 12:33:40 -07:00
|
|
|
windowClass: 'full animated slideInRight',
|
2015-04-23 08:27:43 -07:00
|
|
|
controller: ModalInstanceCtrl,
|
|
|
|
});
|
2015-05-07 15:02:38 -07:00
|
|
|
|
|
|
|
modalInstance.result.finally(function() {
|
|
|
|
var m = angular.element(document.getElementsByClassName('reveal-modal'));
|
2015-05-11 12:33:40 -07:00
|
|
|
m.addClass('slideOutRight');
|
2015-05-07 15:02:38 -07:00
|
|
|
});
|
2015-04-23 08:27:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
this.hasAction = function(actions, action) {
|
|
|
|
return actions.hasOwnProperty('create');
|
|
|
|
};
|
|
|
|
|
2015-08-13 10:54:53 -07:00
|
|
|
this._doSendAll = function(amount, feeRate) {
|
|
|
|
this.setForm(null, amount, null, feeRate);
|
2015-06-19 11:00:27 -07:00
|
|
|
};
|
|
|
|
|
2015-06-28 07:03:28 -07:00
|
|
|
this.confirmDialog = function(msg, cb) {
|
2015-08-12 07:49:13 -07:00
|
|
|
if (isCordova) {
|
2015-06-19 11:00:27 -07:00
|
|
|
navigator.notification.confirm(
|
|
|
|
msg,
|
2015-06-22 11:42:39 -07:00
|
|
|
function(buttonIndex) {
|
2015-06-28 07:03:28 -07:00
|
|
|
if (buttonIndex == 1) {
|
2015-06-22 11:42:39 -07:00
|
|
|
$timeout(function() {
|
2015-06-28 07:03:28 -07:00
|
|
|
return cb(true);
|
2015-06-22 11:42:39 -07:00
|
|
|
}, 1);
|
2015-06-28 07:03:28 -07:00
|
|
|
} else {
|
|
|
|
return cb(false);
|
|
|
|
}
|
2015-07-29 08:37:51 -07:00
|
|
|
},
|
|
|
|
confirm_msg, [accept_msg, cancel_msg]
|
2015-06-19 11:00:27 -07:00
|
|
|
);
|
2015-06-28 07:03:28 -07:00
|
|
|
} else if (isChromeApp) {
|
|
|
|
// No feedback, alert/confirm not supported.
|
|
|
|
return cb(true);
|
2015-06-19 11:00:27 -07:00
|
|
|
} else {
|
2015-06-28 07:03:28 -07:00
|
|
|
return cb(confirm(msg));
|
2015-06-19 11:00:27 -07:00
|
|
|
}
|
2015-06-28 07:03:28 -07:00
|
|
|
};
|
|
|
|
|
2015-08-13 10:54:53 -07:00
|
|
|
this.sendAll = function(amount, feeStr, feeRate) {
|
2015-06-28 07:03:28 -07:00
|
|
|
var self = this;
|
|
|
|
var msg = gettextCatalog.getString("{{fee}} will be discounted for bitcoin networking fees", {
|
|
|
|
fee: feeStr
|
|
|
|
});
|
|
|
|
|
2015-08-12 07:49:13 -07:00
|
|
|
this.confirmDialog(msg, function(confirmed) {
|
|
|
|
if (confirmed)
|
2015-08-13 10:54:53 -07:00
|
|
|
self._doSendAll(amount, feeRate);
|
2015-06-28 07:03:28 -07:00
|
|
|
});
|
2015-08-12 07:49:13 -07:00
|
|
|
};
|
2015-06-19 11:00:27 -07:00
|
|
|
|
2015-06-27 09:22:56 -07:00
|
|
|
/* Start setup */
|
2015-06-19 11:00:27 -07:00
|
|
|
|
2015-05-11 11:25:42 -07:00
|
|
|
this.bindTouchDown();
|
|
|
|
this.setAddress();
|
|
|
|
this.setSendFormInputs();
|
2015-03-06 07:00:10 -08:00
|
|
|
});
|