mirror of https://github.com/BTCPrivate/copay.git
commit
5f959aa5d9
33
index.html
33
index.html
|
@ -17,7 +17,7 @@
|
|||
<img src="./img/logo-negative.svg" alt="" width="130">
|
||||
</figure>
|
||||
<div class="text-right" ng-show="$root.wallet">
|
||||
<h5>Company Funds</h5>
|
||||
<h5 ng-show="$root.wallet.id">Wallet ID:{{$root.wallet.id}}</h5>
|
||||
<p ng-show="totalBalance">{{totalBalance}} BTC</p>
|
||||
<p ng-show="!totalBalance">0 BTC</p>
|
||||
</div>
|
||||
|
@ -48,15 +48,22 @@
|
|||
<div ng-if='$root.flashMessage.message' class="panel callout radius" style="color:red" >
|
||||
{{$root.flashMessage.type}}:
|
||||
{{$root.flashMessage.message}}
|
||||
<a href="#" ng-click="clearFlashMessage()" class="button tiny">Dismiss</a>
|
||||
<a ng-click="clearFlashMessage()" class="button tiny">Dismiss</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div ng-if='$root.wallet && !$root.wallet.publicKeyRing.isComplete() && !loading' class="panel callout radius" >
|
||||
<div ng-if='$root.wallet && !$root.wallet.publicKeyRing.isComplete() && !loading' class="panel radius" >
|
||||
|
||||
<p class="panel panel-sign"> <i class="fi-alert size-40"></i>
|
||||
NOTE: Your wallet is not complete yet.
|
||||
{{$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers() }} keys are missing. Ask your copayers to join your session: <b>{{$root.wallet.network.peerId}}</b>
|
||||
<span ng-show="$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers()>1">
|
||||
{{$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers() }} keys are
|
||||
</span>
|
||||
<span ng-show="$root.wallet.publicKeyRing.totalCopayers - $root.wallet.publicKeyRing.registeredCopayers()==1">
|
||||
One key is
|
||||
</span>
|
||||
|
||||
missing. Ask your copayers to join your session: <b>{{$root.wallet.network.peerId}}</b>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
|
@ -203,6 +210,7 @@
|
|||
<!-- HOME -->
|
||||
<script type="text/ng-template" id="home.html">
|
||||
<div class="home" data-ng-controller="HomeController">
|
||||
<div ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||
<h3>Address</h3>
|
||||
|
||||
<div class="row">
|
||||
|
@ -219,6 +227,7 @@
|
|||
<button class="secondary round expand" ng-click="newAddr()"> Create </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
@ -226,8 +235,7 @@
|
|||
<!-- TRANSACTIONS -->
|
||||
<script type="text/ng-template" id="transactions.html">
|
||||
<div class="transactions" data-ng-controller="TransactionsController">
|
||||
|
||||
<div class="row">
|
||||
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||
<div class="large-12 columns">
|
||||
<h3>Pending Transactions <small>({{txsoutput.length}})</small></h3>
|
||||
<div class="panel pending" ng-repeat="txp in txsoutput">
|
||||
|
@ -290,8 +298,7 @@
|
|||
<!-- SEND -->
|
||||
<script type="text/ng-template" id="send.html">
|
||||
<div class="send" data-ng-controller="SendController">
|
||||
<h3>{{title}}</h3>
|
||||
<div class="row">
|
||||
<div class="row" ng-show='$root.wallet.publicKeyRing.isComplete()'>
|
||||
<div class="large-8 columns">
|
||||
<form>
|
||||
<label for="address">To
|
||||
|
@ -338,16 +345,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<div ng-show="$root.wallet" style="margin-top:200px">
|
||||
<hr>
|
||||
<p>
|
||||
[DEBUG] WalletId: {{$root.wallet.id}}
|
||||
<ul class="no-bullet">
|
||||
<li class="panel" style="word-wrap: break-word;" ng-repeat="pub in $root.wallet.publicKeyRing.copayersBIP32">
|
||||
${{pub.extendedPublicKeyString()}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- / <div class="large-4 columns box-backup">Backup to Dropbox</div>
|
||||
// <div class="large-4 columns box-backup">Backup to email</div> -->
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
var config = {
|
||||
networkName: 'testnet',
|
||||
network: {
|
||||
apiKey: 'lwjd5qra8257b9',
|
||||
key: 'lwjd5qra8257b9',
|
||||
// This is for running local peerJs with params: ./peerjs -p 10009 -k 'sdfjhwefh'
|
||||
// key: 'sdfjhwefh',
|
||||
// host: 'localhost',
|
||||
// port: 10009,
|
||||
// path: '/',
|
||||
maxPeers: 3,
|
||||
debug: 3,
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.header').controller('HeaderController',
|
||||
function($scope, $rootScope, $location, walletFactory) {
|
||||
function($scope, $rootScope, $location, walletFactory, controllerUtils) {
|
||||
$scope.menu = [{
|
||||
'title': 'Home',
|
||||
'icon': 'fi-home',
|
||||
|
@ -39,9 +39,7 @@ angular.module('copay.header').controller('HeaderController',
|
|||
var w = $rootScope.wallet;
|
||||
if (w) {
|
||||
w.disconnect();
|
||||
delete $rootScope['wallet'];
|
||||
$rootScope.totalBalance = 0;
|
||||
$location.path('signin');
|
||||
controllerUtils.logout();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ angular.module('copay.home').controller('HomeController',
|
|||
$scope.newAddr = function() {
|
||||
var a = $rootScope.wallet.generateAddress().toString();
|
||||
$scope.addrs.push(a);
|
||||
|
||||
_getBalance();
|
||||
var socket = Socket($scope);
|
||||
socket.on('connect', controllerUtils.handleTransactionByAddress($scope));
|
||||
|
|
|
@ -26,10 +26,12 @@ angular.module('copay.signin').controller('SigninController',
|
|||
};
|
||||
|
||||
$scope.join = function(cid) {
|
||||
console.log('[signin.js.42:join:]'); //TODO
|
||||
$scope.loading = true;
|
||||
walletFactory.network.on('openError', function() {
|
||||
controllerUtils.onError($scope);
|
||||
$rootScope.$digest();
|
||||
});
|
||||
walletFactory.connectTo(cid, function(w) {
|
||||
console.log('[signin.js.50]'); //TODO
|
||||
controllerUtils.setupUxHandlers(w);
|
||||
w.netStart();
|
||||
});
|
||||
|
|
|
@ -96,11 +96,12 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
|||
|
||||
Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
||||
|
||||
if (this.id !== data.walletId)
|
||||
throw new Error('wrong message received: Bad wallet ID');
|
||||
|
||||
if (this.id !== data.walletId) {
|
||||
this.emit('badMessage',senderId);
|
||||
this.log('badMessage FROM:', senderId); //TODO
|
||||
return;
|
||||
}
|
||||
this.log('[Wallet.js.98]' , data.type); //TODO
|
||||
|
||||
switch(data.type) {
|
||||
case 'publicKeyRing':
|
||||
this._handlePublicKeyRing(senderId, data, isInbound);
|
||||
|
@ -108,28 +109,33 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
case 'txProposals':
|
||||
this._handleTxProposals(senderId, data, isInbound);
|
||||
break;
|
||||
case 'abort':
|
||||
this.emit('abort');
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Wallet.prototype._handleNetworkChange = function(newPeer) {
|
||||
if (!newPeer) return;
|
||||
this.log('#### Setting new PEER:', newPeer);
|
||||
this.sendWalletId(newPeer);
|
||||
this.sendPublicKeyRing(newPeer);
|
||||
this.sendTxProposals(newPeer);
|
||||
if (newPeer) {
|
||||
this.log('#### Setting new PEER:', newPeer);
|
||||
this.sendWalletId(newPeer);
|
||||
this.sendPublicKeyRing(newPeer);
|
||||
this.sendTxProposals(newPeer);
|
||||
}
|
||||
this.emit('refresh');
|
||||
};
|
||||
|
||||
Wallet.prototype.netStart = function() {
|
||||
var self = this;
|
||||
var net = this.network;
|
||||
net.removeAllListeners();
|
||||
net.on('networkChange', self._handleNetworkChange.bind(self) );
|
||||
net.on('data', self._handleData.bind(self) );
|
||||
net.on('open', function() {}); // TODO
|
||||
net.on('close', function() {}); // TODO
|
||||
net.on('openError', function() {
|
||||
this.log('[Wallet.js.132:openError:] GOT openError'); //TODO
|
||||
self.emit('openError');
|
||||
});
|
||||
net.on('close', function() {
|
||||
self.emit('close');
|
||||
});
|
||||
net.start(function(peerId) {
|
||||
self.emit('created');
|
||||
});
|
||||
|
@ -185,6 +191,7 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
|||
this.emit('publicKeyRingUpdated', this.publicKeyRing);
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype.generateAddress = function() {
|
||||
var addr = this.publicKeyRing.generateAddress();
|
||||
this.store();
|
||||
|
|
|
@ -16,11 +16,18 @@ var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
|||
*/
|
||||
|
||||
function Network(opts) {
|
||||
var self = this;
|
||||
opts = opts || {};
|
||||
this.peerId = opts.peerId;
|
||||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 5;
|
||||
this.opts = { key: opts.key };
|
||||
|
||||
// For using your own peerJs server
|
||||
['port', 'host', 'path', 'debug'].forEach(function(k) {
|
||||
if (opts[k]) self.opts[k]=opts[k];
|
||||
});
|
||||
this.connectedPeers = [];
|
||||
}
|
||||
|
||||
|
@ -128,6 +135,13 @@ Network.prototype._addPeer = function(peerId, isInbound) {
|
|||
}
|
||||
};
|
||||
|
||||
Network.prototype._checkAnyPeer = function() {
|
||||
if (!this.connectedPeers.length) {
|
||||
console.log('EMIT openError: no more peers, not even you!');
|
||||
this.emit('openError');
|
||||
}
|
||||
}
|
||||
|
||||
Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
||||
|
||||
var self=this;
|
||||
|
@ -150,14 +164,14 @@ Network.prototype._setupConnectionHandlers = function(dataConn, isInbound) {
|
|||
|
||||
dataConn.on('error', function(e) {
|
||||
console.log('### DATA ERROR',e ); //TODO
|
||||
self.emit('dataError');
|
||||
});
|
||||
|
||||
dataConn.on('close', function() {
|
||||
if (self.closing) return;
|
||||
self.closing=1;
|
||||
console.log('### CLOSE RECV FROM:', dataConn.peer);
|
||||
self._onClose(dataConn.peer);
|
||||
this.emit('close');
|
||||
self._checkAnyPeer();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -182,7 +196,7 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
self.peer.disconnect();
|
||||
self.peer.destroy();
|
||||
self.peer = null;
|
||||
this.emit('abort');
|
||||
self._checkAnyPeer();
|
||||
});
|
||||
|
||||
p.on('connection', function(dataConn) {
|
||||
|
@ -205,11 +219,7 @@ Network.prototype.start = function(openCallback) {
|
|||
// Start PeerJS Peer
|
||||
if (this.peer) return openCallback(); // This is for connectTo-> peer is started before
|
||||
|
||||
this.peer = new Peer(this.peerId, {
|
||||
key: this.apiKey, // TODO: we need our own PeerServer KEY (http://peerjs.com/peerserver)
|
||||
debug: this.debug,
|
||||
});
|
||||
|
||||
this.peer = new Peer(this.peerId, this.opts);
|
||||
this._setupPeerHandlers(openCallback);
|
||||
};
|
||||
|
||||
|
@ -234,6 +244,7 @@ Network.prototype._sendToOne = function(peerId, data, cb) {
|
|||
|
||||
Network.prototype.send = function(peerIds, data, cb) {
|
||||
var self=this;
|
||||
console.log('[WebRTC.js.242] SENDING ', data.type); //TODO
|
||||
if (!peerIds) {
|
||||
peerIds = this.connectedPeers;
|
||||
data.isBroadcast = 1;
|
||||
|
@ -243,6 +254,7 @@ Network.prototype.send = function(peerIds, data, cb) {
|
|||
var l = peerIds.length;
|
||||
var i = 0;
|
||||
peerIds.forEach(function(peerId) {
|
||||
console.log('[WebRTC.js.258:peerId:]',peerId); //TODO
|
||||
self._sendToOne(peerId, data, function () {
|
||||
if (++i === l && typeof cb === 'function') cb();
|
||||
});
|
||||
|
@ -270,7 +282,6 @@ Network.prototype.connectTo = function(peerId) {
|
|||
Network.prototype.disconnect = function(cb) {
|
||||
var self = this;
|
||||
self.closing = 1;
|
||||
|
||||
this.send(null, { type: 'disconnect' }, function() {
|
||||
self.connectedPeers = [];
|
||||
self.peerId = null;
|
||||
|
|
|
@ -2,7 +2,32 @@
|
|||
|
||||
angular.module('copay.controllerUtils').factory('controllerUtils', function ($rootScope, $location, Socket) {
|
||||
var root = {};
|
||||
|
||||
root.logout = function(scope) {
|
||||
delete $rootScope['wallet'];
|
||||
$rootScope.totalBalance = 0;
|
||||
$location.path('signin');
|
||||
};
|
||||
|
||||
root.onError = function(scope) {
|
||||
if (scope) scope.loading = false;
|
||||
$rootScope.flashMessage = {type:'error', message: 'Could not connect to peer'};
|
||||
root.logout();
|
||||
}
|
||||
|
||||
|
||||
root.onErrorDigest = function(scope) {
|
||||
root.onError(scope);
|
||||
$rootScope.$digest();
|
||||
}
|
||||
|
||||
|
||||
root.setupUxHandlers = function(w) {
|
||||
|
||||
w.on('badMessage', function(peerId) {
|
||||
$rootScope.flashMessage = {type:'error', message: 'Received wrong message from peer id:' + peerId};
|
||||
});
|
||||
|
||||
w.on('created', function() {
|
||||
$location.path('peer');
|
||||
$rootScope.wallet = w;
|
||||
|
@ -14,14 +39,11 @@ angular.module('copay.controllerUtils').factory('controllerUtils', function ($ro
|
|||
});
|
||||
});
|
||||
w.on('refresh', function() {
|
||||
console.log('[controllerUtils.js] RECEIVED REFRESH'); //TODO
|
||||
});
|
||||
|
||||
w.on('openError', function(){
|
||||
$scope.loading = false;
|
||||
$rootScope.flashMessage = {type:'error', message: 'Wallet not found'};
|
||||
$location.path('signin');
|
||||
console.log('[controllerUtils.js] Refreshing'); //TODO
|
||||
$rootScope.$digest();
|
||||
});
|
||||
w.on('openError', root.onErrorDigest);
|
||||
w.on('close', root.onErrorDigest);
|
||||
};
|
||||
|
||||
root.handleTransactionByAddress = function(scope) {
|
||||
|
|
Loading…
Reference in New Issue