approve
This commit is contained in:
parent
78b51ff938
commit
09425dc344
11 changed files with 390 additions and 281 deletions
|
|
@ -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
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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'});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue