diff --git a/Gruntfile.js b/Gruntfile.js index f43f545f5..2c729ea30 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -108,7 +108,6 @@ module.exports = function(grunt) { 'bower_components/angular-sanitize/angular-sanitize.js', 'bower_components/ng-csv/build/ng-csv.js', 'bower_components/angular-mocks/angular-mocks.js', - 'bower_components/crypto-js/crypto-js.js', 'angular-bitcore-wallet-client/angular-bitcore-wallet-client.js' ], dest: 'public/lib/angular.js' diff --git a/bower.json b/bower.json index 212561382..871393726 100644 --- a/bower.json +++ b/bower.json @@ -20,8 +20,7 @@ "ng-lodash": "0.2.3", "qrcode-decoder-js": "*", "trezor-connect": "~1.0.1", - "ng-csv": "~0.3.6", - "crypto-js": "^3.1.6" + "ng-csv": "~0.3.6" }, "resolutions": { "angular": "1.5.3" diff --git a/src/js/controllers/buyAmazon.js b/src/js/controllers/buyAmazon.js index c843137c9..777ee3a93 100644 --- a/src/js/controllers/buyAmazon.js +++ b/src/js/controllers/buyAmazon.js @@ -17,6 +17,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', this.init = function() { var network = configService.getSync().amazon.testnet ? 'testnet' : 'livenet'; amazonService.setCredentials(network); + amazonService.initAmazonUUID(network); self.allWallets = profileService.getWallets(network, 1); client = profileService.focusedClient; if (client && client.credentials.m == 1 && client.credentials.network == network) { @@ -176,7 +177,7 @@ angular.module('copayApp.controllers').controller('buyAmazonController', return; } - var now = moment().unix(); + var now = moment().unix() * 1000; var newData = giftCard; newData['invoiceId'] = dataSrc.invoiceId; diff --git a/src/js/services/amazonService.js b/src/js/services/amazonService.js index 38a229e8e..959aab0e8 100644 --- a/src/js/services/amazonService.js +++ b/src/js/services/amazonService.js @@ -1,5 +1,4 @@ 'use strict'; - angular.module('copayApp.services').factory('amazonService', function($http, $log, lodash, moment, storageService, configService, platformInfo) { var root = {}; var credentials = {}; @@ -14,19 +13,25 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo }; }; - var _getUuid = function(cb) { - var isCordova = platformInfo.isCordova; - - if (isCordova) { - window.plugins.uniqueDeviceID.get(function(uuid) { - return cb(uuid); - }, function(err) { - $log.error(err); - return cb(); + 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); }); - } else { - return cb('XXX'); // Test purpose - } + }); + } + + 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) { @@ -85,8 +90,9 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo }; root.createBitPayInvoice = function(data, cb) { - _getUuid(function(uuid) { + _getUUID(function(uuid) { if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID'); + var dataSrc = { currency: data.currency, amount: data.amount, @@ -114,7 +120,9 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo }; root.createGiftCard = function(dataInvoice, cb) { - _getUuid(function(uuid) { + _getUUID(function(uuid) { + if (lodash.isEmpty(uuid)) return cb('CAN_NOT_GET_UUID'); + var dataSrc = { "clientId": uuid, "invoiceId": dataInvoice.invoiceId, @@ -131,8 +139,7 @@ angular.module('copayApp.services').factory('amazonService', function($http, $lo $log.error('Amazon.com Gift Card Create/Update: ' + data.data.message); return cb(data.data); }); - }) - + }); }; return root; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 7c6fa4010..3b2334fdd 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -330,5 +330,13 @@ angular.module('copayApp.services') 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; });