From dd0dc9c6ad1c4c3dcd3acd703377bf4accc68ab5 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 11 Oct 2014 14:33:45 -0300 Subject: [PATCH] add warning for old wallets --- js/controllers/createProfile.js | 20 +++++++++++++++++++- js/models/Identity.js | 13 +++++++++++-- js/models/Wallet.js | 19 ++++++++++++++++--- views/createProfile.html | 11 ++++++++++- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index fc72460b9..eec5e786d 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -2,6 +2,24 @@ angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager) { controllerUtils.redirIfLogged(); + $scope.retreiving = true; + + + copay.Identity.anyProfile({ + pluginManager: pluginManager, + }, function(anyProfile) { + copay.Identity.anyWallet({ + pluginManager: pluginManager, + }, function(anyWallet) { + $scope.retreiving = false; + $scope.anyProfile = anyProfile; +console.log('[createProfile.js.15:anyProfile:]',anyProfile); //TODO + $scope.anyWallet = anyWallet; +console.log('[createProfile.js.17:anyWallet:]',anyWallet); //TODO + }); + + }); + $scope.createProfile = function(form) { if (form && form.$invalid) { @@ -15,7 +33,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', fun networkName: config.networkName, walletDefaults: config.wallet, passphrase: config.passphrase, - }, function(err, iden , firstWallet) { + }, function(err, iden, firstWallet) { controllerUtils.bindProfile($scope, iden, firstWallet); }); } diff --git a/js/models/Identity.js b/js/models/Identity.js index fc9987cb6..303298343 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -105,13 +105,22 @@ Identity._getStorage = function(opts, password) { * @param opts.storageOpts * @param cb */ - - Identity.anyProfile = function(opts, cb) { var storage = Identity._getStorage(opts); Profile.any(storage,cb); }; +/** + * check if any wallet exists on storage + * + * @param opts.storageOpts + * @param cb + */ +Identity.anyWallet = function(opts, cb) { + var storage = Identity._getStorage(opts); + Wallet.any(storage,cb); +}; + /** * creates and Identity * diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 4344e6a36..92a25ad3f 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -166,6 +166,19 @@ Wallet.COPAYER_PAIR_LIMITS = { 12: 1, }; + + +Wallet.key = function(str) { + return 'wallet::' + str; +}; + + +Wallet.any = function(storage, cb) { + storage.getFirst(Wallet.key(''), function(err, val) { + return cb(val ? true : false); + }); +}; + /* for stubbing */ Wallet._newInsight = function(opts) { return new Insight(opts); @@ -217,7 +230,7 @@ Wallet.getMaxRequiredCopayers = function(totalCopayers) { Wallet.delete = function(walletId, storage, cb) { preconditions.checkArgument(cb); - storage.deletePrefix('wallet::' + walletId, function(err) { + storage.deletePrefix(Wallet.key(walletId), function(err) { if (err) return cb(err); storage.deletePrefix(walletId + '::', function(err) { return cb(err); @@ -245,7 +258,7 @@ Wallet.read = function(walletId, readOpts, cb) { err; var obj = {}; - storage.getFirst('wallet::' + walletId, function(err, ret) { + storage.getFirst(Wallet.key(walletId), function(err, ret) { if (err) return cb(err); if (!ret) @@ -1023,7 +1036,7 @@ Wallet.prototype.store = function(cb) { this.keepAlive(); var val = this.toObj(); - var key = 'wallet::' + this.id + ((val.opts && val.opts.name) ? '_' + val.opts.name : ''); + var key = Wallet.key(this.id + ((val.opts && val.opts.name) ? '_' + val.opts.name : '')); this.storage.set(key, val, function(err) { log.debug('Wallet:' + self.id + ' stored'); if (cb) diff --git a/views/createProfile.html b/views/createProfile.html index 84063cd0c..4623f4bfd 100644 --- a/views/createProfile.html +++ b/views/createProfile.html @@ -1,6 +1,15 @@
+
+
+ +
+
+ Copay now needs a profile to access your wallets.
+ You can import current your wallets after creating your profile. +
+
+ -

( TODO2: if user has wallets (wallet::) show message: Copay now needs a profile to ... , you can import your wallets after creating your profile )

Retreiving information from storage...