Fixed Conflicts:

index.html
This commit is contained in:
Gustavo Cortez 2014-06-03 18:49:25 -03:00
commit 5a0c1e235b
33 changed files with 322 additions and 202 deletions

View file

@ -16,46 +16,23 @@ var log = function() {
if (config.verbose) console.log(arguments);
}
// From the bundle
var copay = require('copay');
var copayApp = window.copayApp = angular.module('copay',[
var copayApp = window.copayApp = angular.module('copayApp',[
'ngRoute',
'angularMoment',
'mm.foundation',
'monospaced.qrcode',
'notifications',
'copay.filters',
'copay.header',
'copay.footer',
'copay.addresses',
'copay.transactions',
'copay.send',
'copay.backup',
'copay.walletFactory',
'copay.signin',
'copay.socket',
'copay.controllerUtils',
'copay.setup',
'copay.directives',
'copay.video',
'copay.import',
'copay.passphrase',
'copay.settings'
'copayApp.filters',
'copayApp.controllers',
'copayApp.directives',
'copayApp.services',
]);
angular.module('copay.header', []);
angular.module('copay.footer', []);
angular.module('copay.addresses', []);
angular.module('copay.transactions', []);
angular.module('copay.send', []);
angular.module('copay.backup', []);
angular.module('copay.walletFactory', []);
angular.module('copay.controllerUtils', []);
angular.module('copay.signin', []);
angular.module('copay.setup', []);
angular.module('copay.socket', []);
angular.module('copay.directives', []);
angular.module('copay.video', []);
angular.module('copay.import', []);
angular.module('copay.passphrase', []);
angular.module('copay.settings', []);
angular.module('copayApp.filters', []);
angular.module('copayApp.controllers', []);
angular.module('copayApp.directives', []);
angular.module('copayApp.services', []);

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.addresses').controller('AddressesController',
angular.module('copayApp.controllers').controller('AddressesController',
function($scope, $rootScope, $timeout, controllerUtils) {
$scope.loading = false;
var w = $rootScope.wallet;

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copay.backup').controller('BackupController',
function($scope, $rootScope, $location, $window, $timeout) {
angular.module('copayApp.controllers').controller('BackupController',
function($scope, $rootScope, $location, $window, $timeout, $modal) {
$scope.title = 'Backup';
var _getEncryptedWallet = function() {
@ -18,29 +18,40 @@ angular.module('copay.backup').controller('BackupController',
saveAs(blob, filename);
};
$scope.email = function() {
var email = prompt('Please enter your email addres.');
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (email && email !== '') {
if (!email.match(mailformat)) {
alert('Enter a valid email address');
} else {
var body = _getEncryptedWallet();
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
var href = 'mailto:' + email + '?'
+ 'subject=[Copay Backup] ' + subject + '&'
+ 'body=' + body;
$scope.openModal = function () {
var modalInstance = $modal.open({
templateUrl: 'backupModal.html',
controller: ModalInstanceCtrl,
});
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
modalInstance.result.then(sendEmail);
};
if (newWin) {
$timeout(function() {
newWin.close();
}, 1000);
}
}
}
};
});
var sendEmail = function(email) {
var body = _getEncryptedWallet();
var subject = ($rootScope.wallet.name ? $rootScope.wallet.name + ' - ' : '') + $rootScope.wallet.id;
var href = 'mailto:' + email + '?'
+ 'subject=[Copay Backup] ' + subject + '&'
+ 'body=' + body;
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
if (newWin) {
$timeout(function() {
newWin.close();
}, 1000);
}
};
});
var ModalInstanceCtrl = function ($scope, $modalInstance) {
$scope.submit = function (form) {
$modalInstance.close($scope.email);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.footer').controller('FooterController', function($rootScope, $sce, $scope, $http) {
angular.module('copayApp.controllers').controller('FooterController', function($rootScope, $sce, $scope, $http) {
if (config.themes && Array.isArray(config.themes) && config.themes[0]) {
$scope.themes = config.themes;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.header').controller('HeaderController',
angular.module('copayApp.controllers').controller('HeaderController',
function($scope, $rootScope, $location, $notification, $http, walletFactory, controllerUtils) {
$scope.menu = [
{

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.import').controller('ImportController',
angular.module('copayApp.controllers').controller('ImportController',
function($scope, $rootScope, walletFactory, controllerUtils, Passphrase) {
$scope.title = 'Import a backup';
var reader = new FileReader();

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.send').controller('SendController',
angular.module('copayApp.controllers').controller('SendController',
function($scope, $rootScope, $window, $location, $timeout) {
$scope.title = 'Send';
$scope.loading = false;

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.settings').controller('SettingsController',
angular.module('copayApp.controllers').controller('SettingsController',
function($scope, $rootScope, $window, $location) {
$scope.title = 'Settings';

View file

@ -32,7 +32,7 @@ var valid_pairs = {
'1,12': 489
};
angular.module('copay.setup').controller('SetupController',
angular.module('copayApp.controllers').controller('SetupController',
function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) {
$rootScope.videoInfo = {};

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.signin').controller('SigninController',
angular.module('copayApp.controllers').controller('SigninController',
function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase) {
var cmp = function(o1, o2){
var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase();
@ -24,10 +24,16 @@ angular.module('copay.signin').controller('SigninController',
console.log('## Obtaining passphrase...');
Passphrase.getBase64Async(password, function(passphrase){
console.log('## Passphrase obtained');
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
var w, errMsg;
try{
var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase});
} catch (e){
errMsg = e.message;
};
if (!w) {
$scope.loading = $scope.failure = false;
$rootScope.$flashMessage = { message: 'Wrong password', type: 'error'};
$rootScope.$flashMessage = { message: errMsg || 'Wrong password', type: 'error'};
$rootScope.$digest();
return;
}

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.transactions').controller('TransactionsController',
angular.module('copayApp.controllers').controller('TransactionsController',
function($scope, $rootScope, $timeout, controllerUtils) {
$scope.title = 'Transactions';

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.directives')
angular.module('copayApp.directives')
.directive('validAddress', [
function() {

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.filters', [])
angular.module('copayApp.filters', [])
.filter('amTimeAgo', ['amMoment', function(amMoment) {
return function(input) {
return amMoment.preprocessDate(input).fromNow();

View file

@ -2,5 +2,5 @@
angular.element(document).ready(function() {
// Init the app
angular.bootstrap(document, ['copay']);
angular.bootstrap(document, ['copayApp']);
});

View file

@ -19,7 +19,8 @@ function Wallet(opts) {
//required params
['storage', 'network', 'blockchain',
'requiredCopayers', 'totalCopayers', 'spendUnconfirmed',
'publicKeyRing', 'txProposals', 'privateKey', 'version'
'publicKeyRing', 'txProposals', 'privateKey', 'version',
'reconnectDelay'
].forEach(function(k) {
if (typeof opts[k] === 'undefined')
throw new Error('missing required option for Wallet: ' + k);
@ -64,7 +65,6 @@ Wallet.prototype.seedCopayer = function(pubKey) {
Wallet.prototype.connectToAll = function() {
var all = this.publicKeyRing.getAllCopayerIds();
console.log('[Wallet.js.58] connecting'); //TODO
this.network.connectToCopayers(all);
if (this.seededCopayerId) {
this.sendWalletReady(this.seededCopayerId);
@ -100,7 +100,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
var inTxp = copay.TxProposals.fromObj(data.txProposals);
var ids = inTxp.getNtxids();
if (ids.lenght>1) {
if (ids.lenght > 1) {
this.emit('badMessage', senderId);
this.log('Received BAD TxProposal messsage FROM:', senderId); //TODO
return;
@ -164,12 +164,13 @@ Wallet.prototype._optsToObj = function() {
spendUnconfirmed: this.spendUnconfirmed,
requiredCopayers: this.requiredCopayers,
totalCopayers: this.totalCopayers,
reconnectDelay: this.reconnectDelay,
name: this.name,
netKey: this.netKey,
version: this.version,
};
if (this.token){
if (this.token) {
obj.token = this.token;
obj.tokenTime = new Date().getTime();
}
@ -243,18 +244,26 @@ Wallet.prototype.netStart = function() {
net.start(startOpts, function() {
self.emit('ready', net.getPeer());
self.token = net.peer.options.token;
setTimeout(function(){
setTimeout(function() {
console.log('[EMIT publicKeyRingUpdated:]'); //TODO
self.emit('publicKeyRingUpdated', true);
console.log('[CONNECT:]'); //TODO
self.connectToAll();
self.scheduleConnect();
console.log('[EMIT TxProposal]'); //TODO
self.emit('txProposalsUpdated');
self.store();
},10);
}, 10);
});
};
Wallet.prototype.scheduleConnect = function() {
var self = this;
if (self.network.isOnline()) {
self.connectToAll();
setTimeout(self.scheduleConnect.bind(self), self.reconnectDelay);
}
}
Wallet.prototype.getOnlinePeerIDs = function() {
return this.network.getOnlinePeerIDs();
};
@ -331,7 +340,7 @@ Wallet.prototype.sendTxProposals = function(recipients, ntxid) {
var last = toSend[toSend];
for(var i in toSend) {
for (var i in toSend) {
var id = toSend[i];
var lastInBatch = (i == toSend.length - 1);
this.network.send(recipients, {
@ -445,7 +454,7 @@ Wallet.prototype.sign = function(ntxid, cb) {
ret = true;
}
if (cb) return cb(ret);
},10);
}, 10);
};
Wallet.prototype.sendTx = function(ntxid, cb) {
@ -625,7 +634,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
}]);
var selectedUtxos = b.getSelectedUnspent();
var inputChainPaths = selectedUtxos.map(function(utxo) {
return pkr.pathForAddress(utxo.address);
});

View file

@ -115,6 +115,7 @@ WalletFactory.prototype.create = function(opts) {
opts.verbose = this.verbose;
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers;
opts.version = opts.version || this.version;
@ -146,7 +147,6 @@ WalletFactory.prototype.open = function(walletId, opts) {
this.storage._setPassphrase(opts.passphrase);
var w = this.read(walletId);
if (w) {
this._checkVersion(w.version);
w.store();

View file

@ -313,8 +313,8 @@ Network.prototype.setCopayerId = function(copayerId) {
};
// TODO cache this.
Network.prototype.peerFromCopayer = function(hex) {
// TODO cache this.
var SIN = bitcore.SIN;
return new SIN(new Buffer(hex,'hex')).toString();
};
@ -409,6 +409,10 @@ Network.prototype.send = function(copayerIds, payload, cb) {
};
Network.prototype.isOnline = function() {
return !!this.peer;
};
Network.prototype.connectTo = function(copayerId) {
var self = this;

View file

@ -2,7 +2,7 @@
//Setting up route
angular
.module('copay')
.module('copayApp')
.config(function($routeProvider) {
$routeProvider
@ -56,7 +56,7 @@ angular
//Setting HTML5 Location Mode
angular
.module('copay')
.module('copayApp')
.config(function($locationProvider) {
$locationProvider
.html5Mode(false);

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.controllerUtils')
angular.module('copayApp.services')
.factory('controllerUtils', function($rootScope, $sce, $location, $notification, Socket, video) {
var root = {};
var bitcore = require('bitcore');

View file

@ -1,3 +1,4 @@
'use strict';
angular.module('copay.passphrase').value('Passphrase', new copay.Passphrase(config.passphrase));
angular.module('copayApp.services')
.value('Passphrase', new copay.Passphrase(config.passphrase));

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copay.socket').factory('Socket',
angular.module('copayApp.services').factory('Socket',
function($rootScope) {
var listeners = [];
var url = 'http://' + config.socket.host + ':' + config.socket.port;

View file

@ -93,4 +93,4 @@ Video.prototype.close = function() {
this.mediaConnections = {};
};
angular.module('copay.video').value('video', new Video());
angular.module('copayApp.services').value('video', new Video());

View file

@ -1,4 +1,4 @@
'use strict';
angular.module('copay.walletFactory').value('walletFactory', new copay.WalletFactory(config, copay.version));
angular.module('copayApp.services').value('walletFactory', new copay.WalletFactory(config, copay.version));