Buy flow completed

This commit is contained in:
Gustavo Maximiliano Cortez 2015-09-02 19:16:59 -03:00
commit ada933d49c
5 changed files with 103 additions and 68 deletions

View file

@ -4,6 +4,9 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
function($scope, $timeout, profileService, addressService, glideraService) {
this.addr = {};
this.show2faCodeInput = null;
this.error = null;
this.success = null;
this.setDestinationAddress = function() {
var self = this;
@ -14,7 +17,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
$timeout(function() {
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
if (err) {
self.addrError = err;
return;
} else {
if (addr) self.addr[fc.credentials.walletId] = addr;
}
@ -25,36 +28,51 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.getBuyPrice = function(token, price) {
var self = this;
this.buyAmount = price.qty;
if (!price || (price && !price.qty && !price.fiat)) {
this.buyPrice = null;
return;
}
glideraService.buyPrice(token, price, function(error, buyPrice) {
self.buyPrice = buyPrice;
self.setDestinationAddress();
});
};
this.get2faCode = function(token, cb) {
this.get2faCode = function(token) {
var self = this;
glideraService.get2faCode(token, function(error, sent) {
self.show2faCodeInput = sent;
$timeout(function() {
glideraService.get2faCode(token, function(error, sent) {
self.show2faCodeInput = sent;
});
}, 100);
};
this.sendRequest = function(token, twoFaCode) {
var fc = profileService.focusedClient;
if (!fc) return;
this.loading = true;
var self = this;
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
if (addr) {
var data = {
destinationAddress: addr,
qty: self.buyPrice.qty,
priceUuid: self.buyPrice.priceUuid,
useCurrentPrice: false,
ip: null
};
console.log('[sellGlidera.js:128]',token, twoFaCode, addr, data); //TODO
glideraService.buy(token, twoFaCode, data, function(error, data) {
console.log('[sellGlidera.js:116]', error, data); //TODO
self.loading = false;
if (error) {
self.error = error;
}
else {
self.success = data
}
});
}
});
};
this.send = function(token, twoFaCode) {
var fc = profileService.focusedClient;
var self = this;
var data = {
destinationAddress: self.addr[fc.credentials.walletId],
qty: self.buyPrice.qty,
priceUuid: self.buyPrice.priceUuid,
useCurrentPrice: false,
ip: null
};
console.log('[sellGlidera.js:128]',token, twoFaCode, data); //TODO
glideraService.buy(token, twoFaCode, data, function(error, data) {
console.log('[sellGlidera.js:116]',data); //TODO
});
};
});