changing random uuid for wallet id

This commit is contained in:
Gabriel Bazán 2016-07-29 12:46:41 -03:00 committed by Gustavo Maximiliano Cortez
parent c099816e71
commit c474cca890
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
3 changed files with 31 additions and 65 deletions

View File

@ -17,7 +17,6 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
this.init = function() { this.init = function() {
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet'; var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
amazonService.setCredentials(network); amazonService.setCredentials(network);
amazonService.initAmazonUUID(network);
self.allWallets = profileService.getWallets(network, 1); self.allWallets = profileService.getWallets(network, 1);
client = profileService.focusedClient; client = profileService.focusedClient;
if (client && client.credentials.m == 1 && client.credentials.network == network) { if (client && client.credentials.m == 1 && client.credentials.network == network) {
@ -62,7 +61,8 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
var currency_code = configService.getSync().amazon.testnet ? window.amazon_sandbox_currency_code : window.amazon_currency_code; var currency_code = configService.getSync().amazon.testnet ? window.amazon_sandbox_currency_code : window.amazon_currency_code;
var dataSrc = { var dataSrc = {
currency: currency_code, currency: currency_code,
amount: $scope.fiat amount: $scope.fiat,
uuid: self.selectedWalletId
}; };
var outputs = []; var outputs = [];
var config = configService.getSync(); var config = configService.getSync();
@ -185,6 +185,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController',
newData['invoiceUrl'] = dataSrc.invoiceUrl; newData['invoiceUrl'] = dataSrc.invoiceUrl;
newData['amount'] = dataSrc.amount; newData['amount'] = dataSrc.amount;
newData['date'] = dataSrc.invoiceTime || now; newData['date'] = dataSrc.invoiceTime || now;
newData['uuid'] = dataSrc.uuid;
if (newData.status == 'expired') { if (newData.status == 'expired') {
amazonService.savePendingGiftCard(newData, { amazonService.savePendingGiftCard(newData, {

View File

@ -13,27 +13,6 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
}; };
root.initAmazonUUID = function(network) {
storageService.getAmazonUUID(network, function(err, uuid) {
if (err) $log.error(err);
if (uuid) return;
var now = moment().unix();
var random = Math.floor((Math.random() * 100) + 1);
var generateUUID = now + random;
storageService.setAmazonUUID(network, generateUUID, function(err) {
if (err) $log.error(err);
});
});
}
var _getUUID = function(cb) {
var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet';
storageService.getAmazonUUID(network, function(err, uuid) {
if (err) $log.error(err);
return cb(uuid);
});
};
var _getBitPay = function(endpoint) { var _getBitPay = function(endpoint) {
return { return {
method: 'GET', method: 'GET',
@ -90,22 +69,19 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}; };
root.createBitPayInvoice = function(data, cb) { root.createBitPayInvoice = function(data, cb) {
_getUUID(function(uuid) {
if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID');
var dataSrc = { var dataSrc = {
currency: data.currency, currency: data.currency,
amount: data.amount, amount: data.amount,
clientId: uuid clientId: data.uuid
}; };
$http(_postBitPay('/amazon-gift/pay', dataSrc)).then(function(data) { $http(_postBitPay('/amazon-gift/pay', dataSrc)).then(function(data) {
$log.info('BitPay Create Invoice: SUCCESS'); $log.info('BitPay Create Invoice: SUCCESS');
return cb(null, data.data); return cb(null, data.data);
}, function(data) { }, function(data) {
$log.error('BitPay Create Invoice: ERROR ' + data.data.message); $log.error('BitPay Create Invoice: ERROR ' + data.data.message);
return cb(data.data); return cb(data.data);
});
}); });
}; };
@ -119,28 +95,25 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo
}); });
}; };
root.createGiftCard = function(dataInvoice, cb) { root.createGiftCard = function(data, cb) {
_getUUID(function(uuid) {
if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID');
var dataSrc = { var dataSrc = {
"clientId": uuid, "clientId": data.uuid,
"invoiceId": dataInvoice.invoiceId, "invoiceId": data.invoiceId,
"accessKey": dataInvoice.accessKey "accessKey": data.accessKey
}; };
$http(_postBitPay('/amazon-gift/redeem', dataSrc)).then(function(data) { $http(_postBitPay('/amazon-gift/redeem', dataSrc)).then(function(data) {
var status = data.data.status == ('new' || 'paid') ? 'PENDING' : data.data.status; var status = data.data.status == ('new' || 'paid') ? 'PENDING' : data.data.status;
data.data.status = status; data.data.status = status;
data.data.clientId = uuid; $log.info('Amazon.com Gift Card Create/Update: ' + status);
$log.info('Amazon.com Gift Card Create/Update: ' + status); return cb(null, data.data);
return cb(null, data.data); }, function(data) {
}, function(data) { $log.error('Amazon.com Gift Card Create/Update: ' + data.data.message);
$log.error('Amazon.com Gift Card Create/Update: ' + data.data.message); return cb(data.data);
return cb(data.data);
});
}); });
}; };
return root; return root;
}); });

View File

@ -268,11 +268,11 @@ angular.module('copayApp.services')
root.checkQuota = function() { root.checkQuota = function() {
var block = ''; var block = '';
// 50MB // 50MB
for (var i = 0; i < 1024*1024; ++ i){ for (var i = 0; i < 1024 * 1024; ++i) {
block += '12345678901234567890123456789012345678901234567890'; block += '12345678901234567890123456789012345678901234567890';
} }
storage.set('test', block, function(err) { storage.set('test', block, function(err) {
$log.error('CheckQuota Return:'+ err); $log.error('CheckQuota Return:' + err);
}); });
}; };
@ -330,13 +330,5 @@ angular.module('copayApp.services')
storage.remove('amazonGiftCards-' + network, cb); storage.remove('amazonGiftCards-' + network, cb);
}; };
root.setAmazonUUID = function(network, uuid, cb) {
storage.set('amazonUUID-' + network, uuid, cb);
};
root.getAmazonUUID = function(network, cb) {
storage.get('amazonUUID-' + network, cb);
};
return root; return root;
}); });