This commit is contained in:
Matias Alejo Garcia 2016-08-18 10:08:23 -03:00
commit 09425dc344
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
11 changed files with 390 additions and 281 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, ongoingProcess, fingerprintService, gettext) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $filter, $timeout, $ionicScrollDelegate, walletService, platformInfo, lodash, configService, go, rateService, $stateParams, $window, $state, $log, profileService, bitcore, $ionicPopup, txStatus, gettext) {
// An alert dialog
var showAlert = function(title, msg, cb) {
@ -16,49 +16,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
};
// An alert dialog
var askPassword = function(name, cb) {
$scope.data = [];
var pass = $ionicPopup.show({
template: '<input type="password" ng-model="data.pass">',
title: 'Enter Spending Password',
subTitle: name,
scope: $scope,
buttons: [{
text: 'Cancel'
}, {
text: '<b>OK</b>',
type: 'button-positive',
onTap: function(e) {
console.log('[confirm.js.32]', $scope, $scope.data); //TODO
if (!$scope.data.pass) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
return;
}
return $scope.data.pass;
}
}]
});
pass.then(function(res) {
console.log('Tapped!', res);
return cb(res);
});
};
var handleEncryptedWallet = function(wallet, cb) {
if (!walletService.isEncrypted(wallet)) return cb();
askPassword(wallet.name, function(password) {
if (!password) return cb('no password');
return cb(walletService.unlock(wallet, password));
});
};
var unitToSatoshi;
var satToUnit;
@ -118,6 +76,7 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
};
var createTx = function(toAddress, toAmount, comment) {
console.log('[confirm.js.78:toAddress:]',toAddress); //TODO
//
var currentSpendUnconfirmed = config.spendUnconfirmed;
@ -146,37 +105,39 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
return setSendError(gettext(msg));
};
$timeout(function() {
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': comment
});
var txp = {};
var txp = {};
// TODO
if (!lodash.isEmpty($scope.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee;
// TODO
if (!lodash.isEmpty($scope.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee;
}
txp.outputs = outputs;
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.feeLevel || 'normal';
console.log('[confirm.js.129]'); //TODO
walletService.createTx(wallet, txp, function(err, createdTxp) {
console.log('[confirm.js.132]', err); //TODO
if (err) {
return setSendError(err);
}
txp.outputs = outputs;
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = config.spendUnconfirmed ? false : true;
txp.feeLevel = config.feeLevel || 'normal';
walletService.createTx(wallet, txp, function(err, createdTxp) {
if (err) {
return setSendError(err);
}
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
$scope.txp = createdTxp;
});
$scope.fee = ((createdTxp.fee) * satToUnit).toFixed(unitDecimals);
$scope.txp = createdTxp;
$scope.$apply();
});
};
@ -196,76 +157,16 @@ console.log('[confirm.js.32]', $scope, $scope.data); //TODO
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
ongoingProcess.set('sendingTx', true);
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) {
return setSendError(err);
}
$state.transitionTo('tab.home');
var type = txStatus.notify(createdTxp);
$scope.openStatusModal(type, createdTxp, function() {
return $scope.$emit('Local/TxProposalAction');
});
return walletService.onlyPublish(wallet,txp, function(err, txp){
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
return;
}
fingerprintService.check(wallet, function(err) {
if (err) {
return setSendError(err);
}
handleEncryptedWallet(wallet, function(err) {
if (err) {
return setSendError(err);
}
ongoingProcess.set('sendingTx', true);
walletService.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) {
return setSendError(err);
}
ongoingProcess.set('signingTx', true);
walletService.signTx(wallet, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
walletService.lock(wallet);
if (err) {
$scope.$emit('Local/TxProposalAction');
return setSendError(
err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen'));
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
if (err) {
return setSendError(err);
}
$state.transitionTo('tabs.send');
var type = txStatus.notify(broadcastedTxp);
$scope.openStatusModal(type, broadcastedTxp, function() {
$scope.$emit('Local/TxProposalAction', broadcastedTxp.status == 'broadcasted');
});
});
} else {
$state.transitionTo('tabs.send');
var type = txStatus.notify(signedTxp);
$scope.openStatusModal(type, signedTxp, function() {
$scope.$emit('Local/TxProposalAction');
});
}
});
});
});
walletService.publishAndSign(wallet, txp, function(err, txp) {
if (err) return setSendError(err);
$state.transitionTo('tabs.home');
});
};

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,18 @@
'use strict';
angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, ongoingProcess, platformInfo, txStatus, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, profileService, walletService) {
angular.module('copayApp.controllers').controller('txpDetailsController', function($scope, $rootScope, $timeout, $interval, $ionicModal, ongoingProcess, platformInfo, txStatus, $ionicScrollDelegate, txFormatService, fingerprintService, bwcError, gettextCatalog, lodash, walletService) {
var self = $scope.self;
var tx = $scope.tx;
var copayers = $scope.copayers;
var isGlidera = $scope.isGlidera;
var now = Math.floor(Date.now() / 1000);
var fc = profileService.focusedClient;
$scope.loading = null;
$scope.copayerId = fc.credentials.copayerId;
$scope.isShared = fc.credentials.n > 1;
$scope.canSign = fc.canSign() || fc.isPrivKeyExternal();
$scope.color = fc.backgroundColor;
$scope.copayerId = $scope.wallet.credentials.copayerId;
$scope.isShared = $scope.wallet.credentials.n > 1;
$scope.canSign = $scope.wallet.canSign() || $scope.wallet.isPrivKeyExternal();
$scope.color = $scope.wallet.color;
checkPaypro();
@ -23,51 +24,18 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}
}
$scope.sign = function(txp) {
var setSendError = function(msg) {
$scope.error = msg || gettextCatalog.getString('Could not send payment');
}
$scope.sign = function() {
$scope.error = null;
$scope.loading = true;
$timeout(function() {
fingerprintService.check(fc, function(err) {
if (err) {
$scope.error = gettextCatalog.getString('Could not send payment');
$scope.loading = false;
$timeout(function() {
$scope.$digest();
}, 1);
return;
}
handleEncryptedWallet(function(err) {
if (err) {
return setError(err);
}
ongoingProcess.set('signingTx', true);
walletService.signTx(fc, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
if (err) {
return setError(err);
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
walletService.broadcastTx(fc, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
$scope.$emit('UpdateTx');
$scope.close(broadcastedTxp);
if (err) {
return setError(err);
}
});
} else {
$scope.$emit('UpdateTx');
$scope.close(signedTxp);
}
});
});
});
}, 10);
walletService.publishAndSign($scope.wallet, $scope.tx, function(err, txp) {
$scope.$emit('UpdateTx');
if (err) return setSendError(err);
$scope.close(signedTxp);
});
};
function setError(err, prefix) {
@ -79,7 +47,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
};
$scope.$on('$destroy', function() {
walletService.lock(fc);
walletService.lock($scope.wallet);
});
$scope.reject = function(txp) {
@ -88,7 +56,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
$timeout(function() {
ongoingProcess.set('rejectTx', true);
walletService.rejectTx(fc, txp, function(err, txpr) {
walletService.rejectTx($scope.wallet, $scope.tx, function(err, txpr) {
ongoingProcess.set('rejectTx', false);
if (err) {
@ -101,13 +69,13 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
}, 10);
};
$scope.remove = function(txp) {
$scope.remove = function() {
$scope.loading = true;
$scope.error = null;
$timeout(function() {
ongoingProcess.set('removeTx', true);
walletService.removeTx(fc, txp, function(err) {
walletService.removeTx($scope.wallet, $scope.tx, function(err) {
ongoingProcess.set('removeTx', false);
// Hacky: request tries to parse an empty response
@ -127,7 +95,7 @@ angular.module('copayApp.controllers').controller('txpDetailsController', functi
$timeout(function() {
ongoingProcess.set('broadcastTx', true);
walletService.broadcastTx(fc, txp, function(err, txpb) {
walletService.broadcastTx($scope.wallet, $scope.tx, function(err, txpb) {
ongoingProcess.set('broadcastTx', false);
if (err) {

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService ) {
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log) {
var self = this;
@ -23,10 +23,88 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.wallets = profileService.getWallets();
};
var setPendingTxps = function(txps) {
$scope.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = profileService.getWallet(tx.walletId);
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
if (tx.creatorId != tx.wallet.copayerId) {
$scope.pendingTxProposalsCountForUs = $scope.pendingTxProposalsCountForUs + 1;
}
});
$scope.txps = txps;
};
self.updateAllClients = function() {
lodash.each(profileService.getWallets(), function(wallet) {
walletService.updateStatus(wallet, {}, function(err, status) {
if (err) {} // TODO
var txps = [];
var wallets = profileService.getWallets();
var l = wallets.length,
i = 0;
lodash.each(wallets, function(wallet) {
walletService.updateStatus(wallet, {}, function(err) {
var status = wallet.status;
if (err) {
console.log('[tab-home.js.35:err:]',$log.error(err)); //TODO
return;
} // TODO
if (status.pendingTxps && status.pendingTxps[0]) {
txps = txps.concat(status.pendingTxps);
}
if (++i == l) {
setPendingTxps(txps);
}
});
});
}
@ -36,5 +114,28 @@ angular.module('copayApp.controllers').controller('tabHomeController',
$scope.bitpayCardEnabled = true; // TODO
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
var config = configService.getSync().wallet;
var GLIDERA_LOCK_TIME = 6 * 60 * 60;
var glideraActive = true; // TODO TODO TODO
// isGlidera flag is a security measure so glidera status is not
// only determined by the tx.message
$scope.openTxpModal = function(tx) {
var scope = $rootScope.$new(true);
scope.tx = tx;
scope.wallet = tx.wallet;
scope.copayers = tx.wallet.copayers;
scope.isGlidera = glideraActive;
scope.currentSpendUnconfirmed = config.spendUnconfirmed;
$ionicModal.fromTemplateUrl('views/modals/txp-details.html', {
scope: scope
}).then(function(modal) {
scope.txpDetailsModal = modal;
scope.txpDetailsModal.show();
});
};
// $state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
});

View file

@ -82,6 +82,7 @@ angular.module('copayApp.services')
c.name = config.aliasFor[walletId] || client.credentials.walletName;
c.color = config.colorFor[walletId] || '#4A90E2';
c.network = client.credentials.network;
c.copayerId = client.credentials.copayerId;
c.m = client.credentials.m;
c.n = client.credentials.n;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('txFormatService', function(profileService, rateService, configService, lodash) {
angular.module('copayApp.services').factory('txFormatService', function(walletService, rateService, configService, lodash) {
var root = {};
var formatAmountStr = function(amount) {

View file

@ -1,7 +1,7 @@
'use strict';
// DO NOT INCLUDE STORAGE HERE \/ \/
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError) {
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus) {
// DO NOT INCLUDE STORAGE HERE ^^
//
//
@ -10,6 +10,26 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var root = {};
// UI Related
root.openStatusModal = function(type, txp, cb) {
var scope = $rootScope.$new(true);
scope.type = type;
scope.tx = txFormatService.processTx(txp);
scope.color = txp.color;
scope.cb = cb;
$ionicModal.fromTemplateUrl('views/modals/tx-status.html', {
scope: scope,
animation: 'slide-in-up'
}).then(function(modal) {
scope.txStatusModal = modal;
scope.txStatusModal.show();
});
};
// // RECEIVE
// // Check address
// root.isUsed(wallet.walletId, balance.byAddress, function(err, used) {
@ -108,12 +128,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
self.notAuthorized = true;
go.walletHome();
} else if (err instanceof errors.NOT_FOUND) {
self.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
root.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
} else {
var msg = ""
$scope.$emit('Local/ClientError', (err.error ? err.error : err));
$rootScope.$emit('Local/ClientError', (err.error ? err.error : err));
var msg = bwcError.msg(err, gettext('Error at Wallet Service'));
self.showErrorPopup(msg);
root.showErrorPopup(msg);
}
};
root.handleError = lodash.debounce(_handleError, 1000);
@ -183,6 +203,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
wallet.isValid = true;
root.setBalance(wallet, status.balance);
wallet.email = status.preferences.email;
wallet.copayers = status.wallet.copayers;
};
root.updateStatus = function(wallet, opts, cb, initStatusHash, tries) {
@ -692,26 +713,18 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.updateHistory();
}, 5000);
self.showErrorPopup = function(msg, cb) {
root.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg);
function openErrorPopup(msg, cb) {
$scope.msg = msg;
self.errorPopup = $ionicPopup.show({
templateUrl: 'views/includes/alert.html',
scope: $scope,
});
$scope.close = function() {
return cb();
};
}
openErrorPopup(msg, function() {
self.errorPopup.close();
if (cb) return cb();
// An alert dialog
var alertPopup = $ionicPopup.alert({
title: title,
template: msg
});
if (!cb) cb = function() {};
alertPopup.then(cb);
};
root.recreate = function(wallet, cb) {
@ -841,12 +854,124 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
// An alert dialog
var askPassword = function(name, cb) {
var scope = $rootScope.$new(true);
scope.data = [];
var pass = $ionicPopup.show({
template: '<input type="password" ng-model="data.pass">',
title: 'Enter Spending Password',
subTitle: name,
scope: scope,
buttons: [{
text: 'Cancel'
}, {
text: '<b>OK</b>',
type: 'button-positive',
onTap: function(e) {
if (!scope.data.pass) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
return;
root.handleEncryptedWallet = function(client, cb) {
if (!root.isEncrypted(client)) return cb();
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
}
return scope.data.pass;
}
}]
});
pass.then(function(res) {
console.log('Tapped!', res);
return cb(res);
});
};
root.handleEncryptedWallet = function(wallet, cb) {
if (!root.isEncrypted(wallet)) return cb();
askPassword(wallet.name, function(password) {
if (!password) return cb('no password');
return cb(root.unlock(wallet, password));
});
};
root.onlyPublish = function(wallet, txp, cb) {
ongoingProcess.set('sendingTx', true);
root.publishTx(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) return cb(err);
return cb(walletService.unlock(client, password));
var type = txStatus.notify(createdTxp);
root.openStatusModal(type, createdTxp, function() {
// TODO?
//return $scope.$emit('Local/TxProposalAction');
});
return cb(null, publishedTxp);
});
};
root.publishAndSign = function(wallet, txp, cb) {
var publishFn = root.publishTx;
// Already published?
if (txp.status == 'pending') {
publishFn = function(wallet, txp, cb) {
return cb(null, txp);
};
}
fingerprintService.check(wallet, function(err) {
if (err) return cb(err);
root.handleEncryptedWallet(wallet, function(err) {
if (err) return cb(err);
ongoingProcess.set('sendingTx', true);
publishFn(wallet, txp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) return cb(err);
ongoingProcess.set('signingTx', true);
root.signTx(wallet, txp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
root.lock(wallet);
if (err) {
// TODO?
//$scope.$emit('Local/TxProposalAction');
var msg = err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen');
return cb(err);
}
if (signedTxp.status == 'accepted') {
ongoingProcess.set('broadcastingTx', true);
root.broadcastTx(wallet, signedTxp, function(err, broadcastedTxp) {
ongoingProcess.set('broadcastingTx', false);
if (err) return cb(err);
var type = txStatus.notify(broadcastedTxp);
root.openStatusModal(type, broadcastedTxp, function() {
// TODO?
//$scope.$emit('Local/TxProposalAction', broadcastedTxp.status == 'broadcasted');
});
return cb(null, broadcastedTxp)
});
} else {
var type = txStatus.notify(signedTxp);
root.openStatusModal(type, signedTxp, function() {
// TODO?
//$scope.$emit('Local/TxProposalAction');
});
return cb(null, signedTxp);
}
});
});
});
});
};