diff --git a/public/views/disclaimer.html b/public/views/disclaimer.html index d0a02d7c8..f8e233397 100644 --- a/public/views/disclaimer.html +++ b/public/views/disclaimer.html @@ -25,14 +25,14 @@
-
+
Creating Wallet...
-
diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js index 9d56c1d26..c08afb327 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -4,45 +4,53 @@ angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, go) { var self = this; self.tries = 0; - $scope.creatingProfile = true; + self.creatingProfile = true; - var create = function(noWallet) { - profileService.create({ - noWallet: noWallet - }, function(err) { + var create = function(opts) { + opts = opts || {}; + $log.debug('Creating profile'); + profileService.create(opts, function(err) { + console.log('[disclaimer.js.13]', err); //TODO if (err) { $log.warn(err); $scope.error = err; $scope.$apply(); - $timeout(function() { + + return $timeout(function() { $log.warn('Retrying to create profile......'); if (self.tries == 3) { self.tries == 0; - create(true); + return create({ + noWallet: true + }); } else { self.tries += 1; - create(false); + return create(); } }, 3000); - } else { - $scope.error = ""; - $scope.creatingProfile = false; - } + }; + + $scope.error = ""; + self.creatingProfile = false; + + console.log('[disclaimer.js.33]'); //TODO }); }; - this.init = function() { - + this.init = function(opts) { $ionicSideMenuDelegate.canDragContent(false); self.lang = uxLanguage.currentLanguage; profileService.getProfile(function(err, profile) { if (!profile) { - create(false); + + console.log('[disclaimer.js.43]'); //TODO + create(opts); + console.log('[disclaimer.js.46]'); //TODO } else { - $log.debug('There is a profile already'); - $scope.creatingProfile = false; + $log.info('There is already a profile'); + self.creatingProfile = false; profileService.bindProfile(profile, function(err) { if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) { $log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.'); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index f14acff19..8dbfd9c1c 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -224,6 +224,7 @@ angular.module('copayApp.services') root._seedWallet = function(opts, cb) { opts = opts || {}; + $log.debug('seedWallet', opts); var walletClient = bwcService.getClient(null, opts); var network = opts.networkName || 'livenet'; @@ -291,13 +292,15 @@ angular.module('copayApp.services') return cb(null, Profile.create()); } - root._seedWallet({}, function(err, walletClient) { + root._seedWallet(opts, function(err, walletClient) { if (err) return cb(err); var walletName = gettextCatalog.getString('Personal Wallet'); var me = gettextCatalog.getString('me'); + walletClient.createWallet(walletName, me, 1, 1, { - network: 'livenet' + network: 'livenet', + walletPrivKey: opts.walletPrivKey, }, function(err) { if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); var p = Profile.create({ @@ -559,16 +562,24 @@ angular.module('copayApp.services') }; root.create = function(opts, cb) { - $log.info('Creating profile'); + $log.info('Creating profile', opts); var defaults = configService.getDefaults(); +console.log('[profileService.js.567]'); //TODO configService.get(function(err) { + +console.log('[profileService.js.570]'); //TODO root._createNewProfile(opts, function(err, p) { if (err) return cb(err); +console.log('[profileService.js.574]'); //TODO root.bindProfile(p, function(err) { + +console.log('[profileService.js.577]'); //TODO // ignore NONAGREEDDISCLAIMER storageService.storeNewProfile(p, function(err) { + +console.log('[profileService.js.581]'); //TODO return cb(err); }); }); diff --git a/test/controllers/disclaimer.test.js b/test/controllers/disclaimer.test.js new file mode 100644 index 000000000..78f7c4cbd --- /dev/null +++ b/test/controllers/disclaimer.test.js @@ -0,0 +1,78 @@ +describe.only('disclaimerController', function() { + var walletService; + var storeProfile; + + var fixtures = { + '8dc332881e99c908c655147dc6bc605e102b0bd3cf2dbee02ed2a0f4daf2925a': { + "walletId": "eddaef15-f412-462f-9d3e-a793a7f6f6ba" + }, + '654145bc3f15f03a8b1ccf55aa1bdcd1cfd5bbe3de90e909fd4e7f9f69ec4d79': { + "copayerId": "1a91ead1b6d13da882a25377a20e460df557e77008ea4f60eecbf984f786cf03", + "wallet": { + "version": "1.0.0", + "createdOn": 1465152783, + "id": "eddaef15-f412-462f-9d3e-a793a7f6f6ba", + "name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"/gaG7FIkhCiwsWKZUR0sL/cxH+zHMK0=\"}", + "m": 1, + "n": 1, + "status": "complete", + "publicKeyRing": [{ + "xPubKey": "xpub6Cb7MYAX7mJR28MfFueCsoDVVHhoWkQxRC4viAeHanYwRNgDo5xMF42xmAeExzfyPXX3GaALNA8hWFMekVYvDF2BALommUhMgZ52szh88fd", + "requestPubKey": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd" + }], + "copayers": [{ + "version": 2, + "createdOn": 1465152783, + "xPubKey": "xpub6Cb7MYAX7mJR28MfFueCsoDVVHhoWkQxRC4viAeHanYwRNgDo5xMF42xmAeExzfyPXX3GaALNA8hWFMekVYvDF2BALommUhMgZ52szh88fd", + "id": "1a91ead1b6d13da882a25377a20e460df557e77008ea4f60eecbf984f786cf03", + "name": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"wwZd+2LQgYR6cA==\"}", + "requestPubKey": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd", + "signature": "3045022100ac3f31ef145eabde6a125958aa9d63c2bd4aa27717d7f6905c3e3ff1e733ee8e02206a43200b775ee5c8f7a85c4d3309d155240d5de46a7d9c5e60045bf49779f40b", + "requestPubKeys": [{ + "key": "029a167eebe3ccd9987d41743477f8b75e1f3c30463187e1b106e0cc1155efa4dd", + "signature": "3045022100ac3f31ef145eabde6a125958aa9d63c2bd4aa27717d7f6905c3e3ff1e733ee8e02206a43200b775ee5c8f7a85c4d3309d155240d5de46a7d9c5e60045bf49779f40b" + }], + "customData": "{\"iv\":\"BZQVWAP6d1e4G8Fq1rQKbA==\",\"v\":1,\"iter\":1,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"ct\":\"9l63hoVnA71LshCC5xbOTHA+ivBzux7u8SAci56p4aaVIF4qzXQhQKFX+sAFGfBjULm/E1st6awdXnxbAgjbF7D0zsbBFLFOSCw+ko5Xc6o=\"}" + }], + "pubKey": "026d95bb5cc2a30c19e22379ae78b4757aaa2dd0ccbd15a1db054fb50cb98ed361", + "network": "livenet", + "derivationStrategy": "BIP44", + "addressType": "P2PKH", + "addressManager": { + "version": 2, + "derivationStrategy": "BIP44", + "receiveAddressIndex": 0, + "changeAddressIndex": 0, + "copayerIndex": 2147483647 + }, + "scanStatus": null + } + }, + }; // TODO: Read from file + + beforeEach(function(done) { + mocks.init(fixtures, 'disclaimerController', { + initController: true, + noDisclaimer: true, + }, done); + }) + + afterEach(function(done) { + mocks.clear({}, done); + }); + + // it('should be defined', function() { + // should.exist(ctrl); + // }); + + it('should create the initial profile', function(done) { + localStorage.clear(); + ctrl.init({ + walletPrivKey: 'Kz4CFSTgLzoYfMkt97BTBotUbZYXjMts6Ej9HbVfCf5oLmun1BXy', + mnemonic: 'tunnel fork scare industry noble snow tank bullet over gesture nuclear next', + }); + setTimeout(function() { + done(); + }, 1000); + }); +}); diff --git a/test/helpers.js b/test/helpers.js index 19c15b632..22fc6135c 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -220,6 +220,9 @@ mocks.init = function(fixtures, controllerName, opts, done) { noWallet: true }, function(err) { should.not.exist(err, err); + if (opts.noDisclaimer){ + return done(); + }; _profileService_.setDisclaimerAccepted(function() { if (!opts.initController) startController();