From 5d30a6abea0f56e7e6fde6efcf68f18e24f45d14 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 24 Apr 2014 16:35:52 -0300 Subject: [PATCH] add wallets nicknames, handle error messages --- index.html | 25 +++++++++++++----- js/controllers/setup.js | 5 ++-- js/controllers/signin.js | 9 +++---- js/models/core/Wallet.js | 5 ++++ js/models/core/WalletFactory.js | 12 ++++++--- js/models/network/WebRTC.js | 46 ++++++++++++++++++--------------- js/models/storage/LocalPlain.js | 42 +++++++++++++++++++++++------- js/services/controllerUtils.js | 2 ++ 8 files changed, 98 insertions(+), 48 deletions(-) diff --git a/index.html b/index.html index d863c928f..5da820527 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,13 @@ Copay
-
Wallet ID: {{$root.wallet.id}}
+
+
Wallet: {{$root.wallet.name}} <{{$root.wallet.id}}>
+

+

+
+
Wallet ID: {{$root.wallet.id}}
+

Balance: {{totalBalance || 0}}
Available to Spend: {{availableBalance || 0}} @@ -98,7 +104,7 @@ Connecting to wallet...

-
+

Create a New Wallet

@@ -109,12 +115,12 @@

-
+

Open Wallet

@@ -141,7 +147,7 @@
-
+ Import from file @@ -176,10 +182,15 @@ ng-options="requiredCopayers as requiredCopayers for requiredCopayers in RCValues">
-
+
+
Wallet name (optional)
+ +
+ +

diff --git a/js/controllers/setup.js b/js/controllers/setup.js index 1feaa1a77..a5fa11814 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -26,11 +26,12 @@ angular.module('copay.setup').controller('SetupController', updateRCSelect(tc); }); - $scope.create = function(totalCopayers, requiredCopayers) { + $scope.create = function(totalCopayers, requiredCopayers, walletName) { $scope.loading = true; var opts = { requiredCopayers: requiredCopayers, - totalCopayers: totalCopayers + totalCopayers: totalCopayers, + name: walletName, }; var w = walletFactory.create(opts); controllerUtils.setupUxHandlers(w); diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 67db9c1a7..0a0c80070 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -3,8 +3,8 @@ angular.module('copay.signin').controller('SigninController', function($scope, $rootScope, $location, walletFactory, controllerUtils) { $scope.loading = false; - $scope.walletIds = walletFactory.getWalletIds(); - $scope.selectedWalletId = $scope.walletIds.length ? $scope.walletIds[0]:null; + $scope.wallets = walletFactory.getWallets(); + $scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null; $scope.create = function() { $location.path('setup'); @@ -12,14 +12,13 @@ angular.module('copay.signin').controller('SigninController', $scope.open = function(walletId, opts) { $scope.loading = true; - -console.log('[signin.js.23:walletId:]',walletId); //TODO var w = walletFactory.open(walletId, opts); controllerUtils.setupUxHandlers(w); }; $scope.join = function(secret) { - if (!secret || !secret.length) { + if (!secret || secret.length !==66 || !secret.match(/^[0-9a-f]*$/) ) { + $rootScope.flashMessage = { message: 'Bad secret secret string', type: 'error'}; return; } $scope.loading = true; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 975a98314..95d0c0f98 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -25,6 +25,7 @@ function Wallet(opts) { this.log('creating '+opts.requiredCopayers+' of '+opts.totalCopayers+' wallet'); this.id = opts.id || Wallet.getRandomId(); + this.name = opts.name; this.verbose = opts.verbose; this.publicKeyRing.walletId = this.id; this.txProposals.walletId = this.id; @@ -137,6 +138,7 @@ Wallet.prototype._optsToObj = function () { spendUnconfirmed: this.spendUnconfirmed, requiredCopayers: this.requiredCopayers, totalCopayers: this.totalCopayers, + name: this.name, }; return obj; @@ -172,6 +174,7 @@ Wallet.prototype.netStart = function() { copayerId: myId, signingKeyHex: self.privateKey.getSigningKey(), }; + net.start(startOpts, function() { self.emit('created'); for (var i=0; i') ) : i.id; + }); + return ret; +}; WalletFactory.prototype.remove = function(walletId) { // TODO remove wallet contents diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index a5569c52b..2f0aec30b 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -192,6 +192,7 @@ Network.prototype._onData = function(data, isInbound, peerId) { Network.prototype._checkAnyPeer = function() { if (!this.connectedPeers.length) { console.log('EMIT openError: no more peers, not even you!'); + this._cleanUp(); this.emit('openError'); } } @@ -251,8 +252,9 @@ Network.prototype._setupPeerHandlers = function(openCallback) { }); p.on('error', function(err) { - console.log('### PEER ERROR:', err); - //self.disconnect(null, true); // force disconnect + if (!err.message.match(/Could\snot\sconnect\sto peer/)) { + console.log('### PEER ERROR:', err); + } self._checkAnyPeer(); }); @@ -311,11 +313,12 @@ Network.prototype.start = function(opts, openCallback) { if (this.started) return openCallback(); opts.connectedPeers = opts.connectedPeers || []; - if (!this.copayerId) + if (!this.copayerId) this.setCopayerId(opts.copayerId); - if (!this.signingKey) + if (!this.signingKey) this.setSigningKey(opts.signingKeyHex); + console.log('CREATING PEER INSTANCE:', this.peerId); //TODO this.peer = new Peer(this.peerId, this.opts); this._setupPeerHandlers(openCallback); for (var i = 0; i