fix copayers

This commit is contained in:
Matias Alejo Garcia 2016-08-17 13:16:06 -03:00
commit 3cb0676815
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
30 changed files with 786 additions and 177 deletions

View file

@ -1,7 +1,20 @@
'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) {
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) {
// An alert dialog
var showAlert = function(title, msg, cb) {
$log.warn(title + ":"+ msg);
var alertPopup = $ionicPopup.alert({
title: title,
template: msg
});
if (!cb) cb = function() {};
alertPopup.then(cb);
};
var unitToSatoshi;
@ -11,6 +24,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
var self = $scope.self;
var SMALL_FONT_SIZE_LIMIT = 13;
var LENGTH_EXPRESSION_LIMIT = 19;
var config;
$scope.init = function() {
console.log('[confirm.js.23:$scope:]',$stateParams); //TODO
@ -23,11 +37,12 @@ console.log('[confirm.js.23:$scope:]',$stateParams); //TODO
$scope.isCordova = platformInfo.isCordova;
var config = configService.getSync().wallet.settings;
$scope.unitName = config.unitName;
$scope.alternativeIsoCode = config.alternativeIsoCode;
config = configService.getSync().wallet;
unitToSatoshi = config.unitToSatoshi;
$scope.unitName = config.settings.unitName;
$scope.alternativeIsoCode = config.settings.alternativeIsoCode;
unitToSatoshi = config.settings.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
satToBtc = 1 / 100000000;
@ -40,112 +55,145 @@ console.log('[confirm.js.23:$scope:]',$stateParams); //TODO
$scope.setWallets(network);
$scope.alternativeAmount = toFiat($scope.toAmount);
unitDecimals = config.unitDecimals;
unitDecimals = config.settings.unitDecimals;
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
$scope.wallet = $scope.wallets[data.slider.activeIndex];
});
createTx($scope.toAddress, $scope.toAmount);
$timeout(function() {
$ionicScrollDelegate.resize();
}, 100);
};
var setSendError = function(msg) {
showAlert('Error creating transaction', msg);
};
var createTx = function(toAddress, toAmount, comment) {
//
var currentSpendUnconfirmed = config.spendUnconfirmed;
var send = function() {
if (!$scope._amount || !$scope._address) return;
var unitToSat = this.unitToSatoshi;
var currentSpendUnconfirmed = configWallet.spendUnconfirmed;
////
var wallet = $scope.wallet;
if (!wallet) {
$log.error('No wallet selected')
return;
};
var outputs = [];
this.resetError();
if (isCordova && this.isWindowsPhoneApp)
$rootScope.shouldHideMenuBar = true;
var form = $scope.sendForm;
var comment = form.comment.$modelValue;
var comment = $scope.comment;
var paypro = $scope.paypro;
// ToDo: use a credential's (or fc's) function for this
if (comment && !client.credentials.sharedEncryptingKey) {
if (comment && !wallet.credentials.sharedEncryptingKey) {
var msg = 'Could not add message to imported wallet without shared encrypting key';
$log.warn(msg);
return self.setSendError(gettext(msg));
return setSendError(gettext(msg));
}
if (form.amount.$modelValue * unitToSat > Number.MAX_SAFE_INTEGER) {
if (toAmount > Number.MAX_SAFE_INTEGER) {
var msg = 'Amount too big';
$log.warn(msg);
return self.setSendError(gettext(msg));
return setSendError(gettext(msg));
};
$timeout(function() {
var paypro = self._paypro;
var address, amount;
outputs.push({
'toAddress': toAddress,
'amount': toAmount,
'message': comment
});
address = form.address.$modelValue;
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
var txp = {};
outputs.push({
'toAddress': address,
'amount': amount,
'message': comment
});
var txp = {};
if (!lodash.isEmpty(self.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = self.sendMaxInfo.inputs;
txp.fee = self.sendMaxInfo.fee;
} else {
txp.amount = amount;
}
txp.toAddress = address;
txp.outputs = outputs;
txp.message = comment;
txp.payProUrl = paypro ? paypro.url : null;
txp.excludeUnconfirmedUtxos = configWallet.spendUnconfirmed ? false : true;
txp.feeLevel = walletSettings.feeLevel || 'normal';
ongoingProcess.set('creatingTx', true);
walletService.createTx(client, txp, function(err, createdTxp) {
ongoingProcess.set('creatingTx', false);
if (err) {
return self.setSendError(err);
}
if (!client.canSign() && !client.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
ongoingProcess.set('sendingTx', true);
walletService.publishTx(client, createdTxp, function(err, publishedTxp) {
ongoingProcess.set('sendingTx', false);
if (err) {
return self.setSendError(err);
}
self.resetForm();
go.walletHome();
var type = txStatus.notify(createdTxp);
$scope.openStatusModal(type, createdTxp, function() {
return $scope.$emit('Local/TxProposalAction');
});
});
// TODO
if (!lodash.isEmpty($scope.sendMaxInfo)) {
txp.sendMax = true;
txp.inputs = $scope.sendMaxInfo.inputs;
txp.fee = $scope.sendMaxInfo.fee;
} else {
$rootScope.$emit('Local/NeedsConfirmation', createdTxp, function(accept) {
if (accept) self.confirmTx(createdTxp);
else self.resetForm();
});
txp.amount = toAmount;
}
});
}, 100);
txp.toAddress = toAddress;
// 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.100] creatingTx', wallet, txp); //TODO
walletService.createTx(wallet, txp, function(err, createdTxp) {
console.log('[confirm.js.102:createdTxp:]',err, createdTxp); //TODO
if (err) {
return setSendError(err);
}
$scope.fee = createdTxp.fee;
$scope.txp = createdTxp;
});
});
};
$scope.approve = function() {
var wallet = $scope.wallet;
var txp =$scope.txp;
if (!wallet) {
$log.error('No wallet selected')
return;
};
if (!txp) {
$log.error('No txp')
return;
};
if (!wallet.canSign() && !wallet.isPrivKeyExternal()) {
$log.info('No signing proposal: No private key');
// ongoingProcess.set('sendingTx', true);
walletService.publishTx(walelt, txp, function(err, publishedTxp) {
// ongoingProcess.set('sendingTx', false);
if (err) {
return setSendError(err);
}
// TODO
$state.transitionTo('tab.home');
// TODO
// var type = txStatus.notify(createdTxp);
// $scope.openStatusModal(type, createdTxp, function() {
// return $scope.$emit('Local/TxProposalAction');
// });
});
} else {
$rootScope.$emit('Local/NeedsConfirmation', txp, function(accept) {
if (accept) self.confirmTx(txp);
else self.resetForm();
});
}
};
function fromFiat(val) {
if (!rateService.isAvailable()) return;
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
};
function toFiat(val) {
if (!rateService.isAvailable()) return;
return parseFloat((rateService.toFiat(val * unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10);
};
@ -166,7 +214,10 @@ console.log('[confirm.js.23:$scope:]',$stateParams); //TODO
$scope.setWallets = function(network) {
$scope.wallets = profileService.getWallets({onlyComplete:true, network: network});
$scope.wallet = $scope.wallets[0];
};
});

View file

@ -1,11 +1,11 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesController',
function($scope, $rootScope, $timeout, $log, configService, profileService, fingerprintService, walletService) {
function($scope, $rootScope, $timeout, $log, $stateParams, configService, profileService, fingerprintService, walletService) {
var fc;
var config = configService.getSync();
console.log($stateParams);
var disableFocusListener = $rootScope.$on('Local/NewFocusedWalletReady', function() {
$scope.init();
});
@ -19,6 +19,11 @@ angular.module('copayApp.controllers').controller('preferencesController',
fc = profileService.focusedClient;
if (fc) {
$scope.backgroundColor = fc.color;
config.aliasFor = config.aliasFor || {};
$scope.walletName = fc.credentials.walletName;
$scope.alias = config.aliasFor[fc.credentials.walletId] || $scope.walletName;
$scope.encryptEnabled = walletService.isEncrypted(fc);
if (fc.isPrivKeyExternal)
$scope.externalSource = fc.getPrivKeyExternalSourceName() == 'ledger' ? 'Ledger' : 'Trezor';

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, lodash, profileService, walletService, configService ) {
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService ) {
var self = this;
@ -34,4 +34,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
self.setWallets();
self.updateAllClients();
$scope.bitpayCardEnabled = true; // TODO
$state.transitionTo('confirm', {toAmount:555500, toAddress: 'mvfAwUJohJWibGzBZgAUGsDarsr4Z4NovU', toName: 'bla bla'});
});

View file

@ -84,8 +84,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
var wallet = profileService.getWallet($stateParams.walletId);
$scope.wallet = wallet;
if (wallet) {
profileService.setAndStoreFocus(wallet.id, function() {});
walletService.updateStatus(wallet, {}, function(err, status) {
if (err) {} // TODO
});