2015-08-31 18:12:04 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('buyGlideraController',
|
2015-09-01 18:53:47 -03:00
|
|
|
function($scope, $timeout, profileService, addressService, glideraService) {
|
|
|
|
|
|
|
|
|
|
this.addr = {};
|
2015-09-02 19:16:59 -03:00
|
|
|
this.show2faCodeInput = null;
|
|
|
|
|
this.error = null;
|
|
|
|
|
this.success = null;
|
2015-09-01 18:53:47 -03:00
|
|
|
|
2015-08-31 18:12:04 -03:00
|
|
|
this.getBuyPrice = function(token, price) {
|
|
|
|
|
var self = this;
|
2015-09-02 19:16:59 -03:00
|
|
|
if (!price || (price && !price.qty && !price.fiat)) {
|
|
|
|
|
this.buyPrice = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-01 18:53:47 -03:00
|
|
|
glideraService.buyPrice(token, price, function(error, buyPrice) {
|
|
|
|
|
self.buyPrice = buyPrice;
|
2015-08-31 18:12:04 -03:00
|
|
|
});
|
2015-09-01 18:53:47 -03:00
|
|
|
};
|
|
|
|
|
|
2015-09-02 19:16:59 -03:00
|
|
|
this.get2faCode = function(token) {
|
2015-09-01 18:53:47 -03:00
|
|
|
var self = this;
|
2015-09-02 19:16:59 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
glideraService.get2faCode(token, function(error, sent) {
|
|
|
|
|
self.show2faCodeInput = sent;
|
|
|
|
|
});
|
|
|
|
|
}, 100);
|
2015-09-01 18:53:47 -03:00
|
|
|
};
|
|
|
|
|
|
2015-09-02 19:16:59 -03:00
|
|
|
this.sendRequest = function(token, twoFaCode) {
|
2015-09-01 18:53:47 -03:00
|
|
|
var fc = profileService.focusedClient;
|
2015-09-02 19:16:59 -03:00
|
|
|
if (!fc) return;
|
|
|
|
|
this.loading = true;
|
2015-09-01 18:53:47 -03:00
|
|
|
var self = this;
|
2015-09-02 19:16:59 -03:00
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
glideraService.buy(token, twoFaCode, data, function(error, data) {
|
|
|
|
|
self.loading = false;
|
|
|
|
|
if (error) {
|
|
|
|
|
self.error = error;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self.success = data
|
|
|
|
|
}
|
2015-09-01 18:53:47 -03:00
|
|
|
});
|
2015-09-02 19:16:59 -03:00
|
|
|
}
|
|
|
|
|
});
|
2015-09-01 18:53:47 -03:00
|
|
|
};
|
2015-08-31 18:12:04 -03:00
|
|
|
|
|
|
|
|
});
|