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 = {};
|
|
|
|
|
|
|
|
|
|
this.setDestinationAddress = function() {
|
|
|
|
|
var self = this;
|
|
|
|
|
this.addrError = null;
|
|
|
|
|
var fc = profileService.focusedClient;
|
|
|
|
|
if (!fc) return;
|
|
|
|
|
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
addressService.getAddress(fc.credentials.walletId, null, function(err, addr) {
|
|
|
|
|
if (err) {
|
|
|
|
|
self.addrError = err;
|
|
|
|
|
} else {
|
|
|
|
|
if (addr) self.addr[fc.credentials.walletId] = addr;
|
|
|
|
|
}
|
|
|
|
|
$scope.$digest();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
2015-08-31 18:12:04 -03:00
|
|
|
|
|
|
|
|
this.getBuyPrice = function(token, price) {
|
|
|
|
|
var self = this;
|
2015-09-01 18:53:47 -03:00
|
|
|
this.buyAmount = price.qty;
|
|
|
|
|
glideraService.buyPrice(token, price, function(error, buyPrice) {
|
|
|
|
|
self.buyPrice = buyPrice;
|
|
|
|
|
self.setDestinationAddress();
|
2015-08-31 18:12:04 -03:00
|
|
|
});
|
2015-09-01 18:53:47 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.get2faCode = function(token, cb) {
|
|
|
|
|
var self = this;
|
|
|
|
|
glideraService.get2faCode(token, function(error, sent) {
|
|
|
|
|
self.show2faCodeInput = sent;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
2015-08-31 18:12:04 -03:00
|
|
|
|
|
|
|
|
});
|