This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-07 17:43:55 -03:00
commit 40113052f4
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
6 changed files with 139 additions and 79 deletions

View file

@ -7,6 +7,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.show2faCodeInput = null;
this.error = null;
this.success = null;
this.loading = null;
this.getBuyPrice = function(token, price) {
var self = this;
@ -26,14 +27,15 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.get2faCode = function(token) {
var self = this;
this.loading = true;
this.loading = gettext('Sending 2FA code...');
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
self.loading = false;
self.loading = null;
if (err) {
self.error = gettext('Glidera could not the 2FA code to your phone');
self.error = gettext('Glidera could not send the 2FA code to your phone');
}
else {
self.error = null;
self.show2faCodeInput = sent;
}
});
@ -51,7 +53,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
$scope.$apply();
}
else {
self.loading = true;
self.loading = gettext('Buying bitcoin...');
var data = {
destinationAddress: addr,
qty: self.buyPrice.qty,
@ -61,7 +63,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
};
$timeout(function() {
glideraService.buy(token, twoFaCode, data, function(err, data) {
self.loading = false;
self.loading = null;
if (err) {
self.error = gettext('Could not buy bitcoin');
}

View file

@ -393,6 +393,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setOngoingProcess('updatingPendingTxps', true);
$log.debug('Updating PendingTxps');
fc.getTxProposals({}, function(err, txps) {
console.log('[index.js:395]',txps); //TODO
self.setOngoingProcess('updatingPendingTxps', false);
if (err) {
self.handleError(err);
@ -950,6 +951,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateGlidera(accessToken, permissions);
});
$rootScope.$on('Local/GlideraError', function(event) {
self.debouncedUpdate();
});
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
self.updateAll();
self.updateTxHistory();

View file

@ -7,38 +7,64 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
this.data = {};
this.show2faCodeInput = null;
this.success = null;
this.error = null;
this.loading = null;
this.currentSpendUnconfirmed = config.wallet.spendUnconfirmed;
this.currentFeeLevel = config.wallet.settings.feeLevel || 'normal';
this.getSellPrice = function(token, price) {
var self = this;
if (!price || (price && !price.qty && !price.fiat)) {
this.error = null;
this.sellPrice = null;
return;
}
glideraService.sellPrice(token, price, function(error, sellPrice) {
self.sellPrice = sellPrice;
glideraService.sellPrice(token, price, function(err, sellPrice) {
if (err) {
self.error = gettext('Glidera could not get pricing to sell bitcoin');
}
else {
self.error = null;
self.sellPrice = sellPrice;
}
});
};
this.get2faCode = function(token) {
var self = this;
this.loading = gettext('Sending 2FA code...');
$timeout(function() {
glideraService.get2faCode(token, function(error, sent) {
self.show2faCodeInput = sent;
glideraService.get2faCode(token, function(err, sent) {
self.loading = null;
if (err) {
self.error = gettext('Glidera could not send the 2FA code to your phone');
}
else {
self.show2faCodeInput = sent;
}
});
}, 100);
};
this.createTx = function(token, twoFaCode) {
this.createTx = function(token, permissions, twoFaCode) {
var self = this;
var fc = profileService.focusedClient;
self.error = null;
this.loading = gettext('Selling Bitcoin...');
$timeout(function() {
addressService.getAddress(fc.credentials.walletId, null, function(err, refundAddress) {
if (!refundAddress) return;
if (!refundAddress) {
self.loading = null;
self.error = gettext('Could not get the bitcoin address');
return;
}
glideraService.getSellAddress(token, function(error, sellAddress) {
if (!sellAddress) return;
if (!sellAddress) {
self.loading = null;
self.error = gettext('Could not get the destination bitcoin address');
return;
}
var amount = parseInt((self.sellPrice.qty * 100000000).toFixed(0));
feeService.getCurrentFeeValue(self.currentFeeLevel, function(err, feePerKb) {
@ -47,6 +73,7 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
toAddress: sellAddress,
amount: amount,
message: 'Glidera',
customData: {'glideraToken': token},
payProUrl: null,
feePerKb: feePerKb,
excludeUnconfirmedUtxos: self.currentSpendUnconfirmed ? false : true
@ -54,32 +81,48 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
if (err) {
profileService.lockFC();
$log.error(err);
$timeout(function() {
self.loading = null;
self.error = gettext('Could not create transaction');
}, 1);
return;
}
if (!fc.canSign()) {
self.loading = null;
$log.info('No signing proposal: No private key');
return;
}
_signTx(txp, function(err, rawTx) {
_signTx(txp, function(err, txp, rawTx) {
profileService.lockFC();
if (err) {
self.error = err.message ? err.message : gettext('The payment was created but could not be completed. Please try again from home screen');
$timeout(function() {
$scope.$digest();
}, 1);
self.loading = null;
self.error = err;
$scope.$apply();
}
else {
var data = {
refundAddress: refundAddress,
signedTransaction: rawTx,
priceUuid: self.sellPrice.priceUuid,
useCurrentPrice: false,
useCurrentPrice: self.sellPrice.priceUuid ? false : true,
ip: null
};
glideraService.sell(token, twoFaCode, data, function(error, data) {
self.success = data
glideraService.sell(token, twoFaCode, data, function(err, data) {
self.loading = null;
if (err) {
self.error = gettext('Could not sell bitcoin');
fc.removeTxProposal(txp, function(err, txpb) {
$timeout(function() {
$scope.$emit('Local/GlideraError');
}, 100);
});
}
else {
self.success = data;
$scope.$emit('Local/GlideraUpdated', token, permissions);
}
});
}
});
@ -98,16 +141,16 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
fc.signTxProposal(txp, function(err, signedTx) {
profileService.lockFC();
if (err) {
err.message = bwsError.msg(err, gettextCatalog.getString('The payment was created but could not be signed. Please try again from home screen'));
err = gettext('The payment was created but could not be signed');
return cb(err);
}
else {
if (signedTx.status == 'accepted') {
return cb(null, txp, signedTx.raw);
if (signedTx.status == 'accepted') {
return cb(null, signedTx.raw);
} else {
return cb(true);
console.log('NO ACCEPTED TX');
} else {
return cb(gettext('The transaction could not be signed'));
}
}
});
};