run js-beautify on everything
...with two spaces. Command: js-beautify -s 2 -r [filename]
This commit is contained in:
parent
da445e7c69
commit
ea2e2d4e19
49 changed files with 859 additions and 682 deletions
|
|
@ -19,7 +19,7 @@ var log = function() {
|
|||
// From the bundle
|
||||
var copay = require('copay');
|
||||
|
||||
var copayApp = window.copayApp = angular.module('copayApp',[
|
||||
var copayApp = window.copayApp = angular.module('copayApp', [
|
||||
'ngRoute',
|
||||
'angularMoment',
|
||||
'mm.foundation',
|
||||
|
|
@ -34,4 +34,3 @@ angular.module('copayApp.filters', []);
|
|||
angular.module('copayApp.services', []);
|
||||
angular.module('copayApp.controllers', []);
|
||||
angular.module('copayApp.directives', []);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,27 +12,27 @@ angular.module('copayApp.controllers').controller('AddressesController',
|
|||
controllerUtils.setSocketHandlers();
|
||||
controllerUtils.updateAddressList();
|
||||
$scope.loading = false;
|
||||
},1);
|
||||
}, 1);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.selectAddress = function (addr) {
|
||||
$scope.selectAddress = function(addr) {
|
||||
$scope.selectedAddr = addr;
|
||||
};
|
||||
|
||||
$rootScope.$watch('addrInfos', function() {
|
||||
$scope.addressList();
|
||||
});
|
||||
});
|
||||
|
||||
$scope.addressList = function () {
|
||||
$scope.addressList = function() {
|
||||
$scope.addresses = [];
|
||||
var addrInfos = $rootScope.addrInfos;
|
||||
if (addrInfos) {
|
||||
for(var i=0;i<addrInfos.length;i++) {
|
||||
for (var i = 0; i < addrInfos.length; i++) {
|
||||
var addrinfo = addrInfos[i];
|
||||
$scope.addresses.push({
|
||||
'address' : addrinfo.address.toString(),
|
||||
'balance' : $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.address.toString()] : 0,
|
||||
$scope.addresses.push({
|
||||
'address': addrinfo.address.toString(),
|
||||
'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.address.toString()] : 0,
|
||||
'isChange': addrinfo.isChange
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,35 +2,34 @@
|
|||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
$scope.themes = ['default'];
|
||||
if (config.themes && Array.isArray(config.themes) && config.themes[0]) {
|
||||
$scope.themes = config.themes;
|
||||
} else {
|
||||
$scope.themes = ['default'];
|
||||
}
|
||||
|
||||
$scope.theme = 'css/tpl-' + $scope.themes[0] + '.css';
|
||||
|
||||
$scope.change_theme = function(name) {
|
||||
$scope.theme = 'css/tpl-' + name + '.css';
|
||||
};
|
||||
$scope.version = copay.version;
|
||||
|
||||
$scope.getVideoURL = function(copayer) {
|
||||
if (config.disableVideo) return;
|
||||
|
||||
var vi = $rootScope.videoInfo[copayer]
|
||||
if (!vi) return;
|
||||
|
||||
if ($rootScope.wallet.getOnlinePeerIDs().indexOf(copayer) === -1) {
|
||||
// peer disconnected, remove his video
|
||||
delete $rootScope.videoInfo[copayer]
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.theme = 'css/tpl-' + $scope.themes[0] + '.css';
|
||||
|
||||
$scope.change_theme = function(name) {
|
||||
$scope.theme = 'css/tpl-' + name + '.css';
|
||||
};
|
||||
$scope.version = copay.version;
|
||||
|
||||
$scope.getVideoURL = function(copayer) {
|
||||
if (config.disableVideo) return;
|
||||
|
||||
var vi = $rootScope.videoInfo[copayer]
|
||||
if (!vi) return;
|
||||
|
||||
if ($rootScope.wallet.getOnlinePeerIDs().indexOf(copayer) === -1) {
|
||||
// peer disconnected, remove his video
|
||||
delete $rootScope.videoInfo[copayer]
|
||||
return;
|
||||
}
|
||||
|
||||
var encoded = vi.url;
|
||||
var url = decodeURI(encoded);
|
||||
var trusted = $sce.trustAsResourceUrl(url);
|
||||
return trusted;
|
||||
};
|
||||
});
|
||||
var encoded = vi.url;
|
||||
var url = decodeURI(encoded);
|
||||
var trusted = $sce.trustAsResourceUrl(url);
|
||||
return trusted;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('HeaderController',
|
||||
function($scope, $rootScope, $location, notification, $http, controllerUtils) {
|
||||
$scope.menu = [
|
||||
{
|
||||
$scope.menu = [{
|
||||
'title': 'Addresses',
|
||||
'icon': 'fi-address-book',
|
||||
'link': '#/addresses'
|
||||
|
|
@ -25,15 +24,23 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
return new Array(num);
|
||||
}
|
||||
|
||||
$http.get('https://api.github.com/repos/bitpay/copay/tags').success(function(data){
|
||||
var toInt = function (s) { return parseInt(s); };
|
||||
$http.get('https://api.github.com/repos/bitpay/copay/tags').success(function(data) {
|
||||
var toInt = function(s) {
|
||||
return parseInt(s);
|
||||
};
|
||||
var latestVersion = data[0].name.replace('v', '').split('.').map(toInt);
|
||||
var currentVersion = copay.version.split('.').map(toInt);
|
||||
if (currentVersion[0] < latestVersion[0]){
|
||||
$scope.updateVersion = {class: 'error', version:data[0].name};
|
||||
if (currentVersion[0] < latestVersion[0]) {
|
||||
$scope.updateVersion = {
|
||||
class: 'error',
|
||||
version: data[0].name
|
||||
};
|
||||
} else if (currentVersion[0] == latestVersion[0] && currentVersion[1] < latestVersion[1]) {
|
||||
$scope.updateVersion = {class: 'info', version:data[0].name};
|
||||
}
|
||||
$scope.updateVersion = {
|
||||
class: 'info',
|
||||
version: data[0].name
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
$rootScope.unitName = config.unitName;
|
||||
|
|
@ -59,7 +66,7 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
$rootScope.$watch('receivedFund', function(receivedFund) {
|
||||
if (receivedFund) {
|
||||
var currentAddr;
|
||||
for(var i=0;i<$rootScope.addrInfos.length;i++) {
|
||||
for (var i = 0; i < $rootScope.addrInfos.length; i++) {
|
||||
var addrinfo = $rootScope.addrInfos[i];
|
||||
if (addrinfo.address.toString() == receivedFund[1] && !addrinfo.isChange) {
|
||||
currentAddr = addrinfo.address.toString();
|
||||
|
|
@ -83,12 +90,12 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
|
||||
|
||||
$scope.isActive = function(item) {
|
||||
if (item.link && item.link.replace('#','') == $location.path()) {
|
||||
if (item.link && item.link.replace('#', '') == $location.path()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
$scope.signout = function() {
|
||||
logout();
|
||||
$scope.clearFlashMessage();
|
||||
|
|
@ -97,7 +104,7 @@ angular.module('copayApp.controllers').controller('HeaderController',
|
|||
$scope.refresh = function() {
|
||||
var w = $rootScope.wallet;
|
||||
w.connectToAll();
|
||||
if ($rootScope.addrInfos.length > 0 ) {
|
||||
if ($rootScope.addrInfos.length > 0) {
|
||||
controllerUtils.updateBalance(function() {
|
||||
$rootScope.$digest();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
$scope.title = 'Import a backup';
|
||||
var reader = new FileReader();
|
||||
var _importBackup = function(encryptedObj) {
|
||||
Passphrase.getBase64Async($scope.password, function(passphrase){
|
||||
Passphrase.getBase64Async($scope.password, function(passphrase) {
|
||||
walletFactory.import(encryptedObj, passphrase, function(err, w) {
|
||||
if (err) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: err.errMsg || 'Wrong password', type: 'error'};
|
||||
$rootScope.$flashMessage = {
|
||||
message: err.errMsg || 'Wrong password',
|
||||
type: 'error'
|
||||
};
|
||||
$rootScope.$digest();
|
||||
return;
|
||||
}
|
||||
|
|
@ -43,7 +46,10 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
$scope.import = function(form) {
|
||||
if (form.$invalid) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'There is an error in the form. Please, try again', type: 'error'};
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'There is an error in the form. Please, try again',
|
||||
type: 'error'
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +59,10 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (!backupFile && !backupText) {
|
||||
$scope.loading = false;
|
||||
$rootScope.$flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'};
|
||||
$rootScope.$flashMessage = {
|
||||
message: 'Please, select your backup file or paste the text',
|
||||
type: 'error'
|
||||
};
|
||||
$scope.loading = false;
|
||||
return;
|
||||
}
|
||||
|
|
@ -62,8 +71,7 @@ angular.module('copayApp.controllers').controller('ImportController',
|
|||
|
||||
if (backupFile) {
|
||||
reader.readAsBinaryString(backupFile);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_importBackup(backupText);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
templateUrl: 'addressBookModal.html',
|
||||
windowClass: 'tiny',
|
||||
controller: function($scope, $modalInstance) {
|
||||
|
||||
|
||||
$scope.submitAddressBook = function(form) {
|
||||
if (form.$invalid) {
|
||||
$rootScope.$flashMessage = {
|
||||
|
|
@ -255,8 +255,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
};
|
||||
|
||||
$scope.topAmount = function() {
|
||||
var maxSat = ($rootScope.availableBalance * config.unitToSatoshi).toFixed(0)
|
||||
- bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
|
||||
var maxSat = ($rootScope.availableBalance * config.unitToSatoshi).toFixed(0) - bitcore.TransactionBuilder.FEE_PER_1000B_SAT;
|
||||
$scope.amount = maxSat / config.unitToSatoshi;
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ angular.module('copayApp.controllers').controller('SetupController',
|
|||
|
||||
var updateRCSelect = function(n) {
|
||||
$scope.requiredCopayers = (valid_pairs[[parseInt(n / 2 + 1), n]] > 0 || config.networkName === 'testnet') ?
|
||||
parseInt(n / 2 + 1) : 1;
|
||||
parseInt(n / 2 + 1) : 1;
|
||||
$scope.RCValues = [];
|
||||
for (var m = 1; m <= n; m++) {
|
||||
if (valid_pairs[[m, n]] > 0 || config.networkName === 'testnet') {
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ angular.module('copayApp.directives')
|
|||
.directive('contact', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
link:function(scope, element, attrs) {
|
||||
link: function(scope, element, attrs) {
|
||||
if (!scope.wallet) return;
|
||||
|
||||
var address = attrs.address;
|
||||
|
|
@ -137,7 +137,7 @@ angular.module('copayApp.directives')
|
|||
element.append(address);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.directive('highlightOnChange', function() {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.filters', [])
|
||||
.filter('amTimeAgo', ['amMoment', function(amMoment) {
|
||||
return function(input) {
|
||||
return amMoment.preprocessDate(input).fromNow();
|
||||
};
|
||||
}])
|
||||
.filter('amTimeAgo', ['amMoment',
|
||||
function(amMoment) {
|
||||
return function(input) {
|
||||
return amMoment.preprocessDate(input).fromNow();
|
||||
};
|
||||
}
|
||||
])
|
||||
.filter('paged', function() {
|
||||
return function(elements) {
|
||||
if (elements) {
|
||||
|
|
@ -28,5 +30,4 @@ angular.module('copayApp.filters', [])
|
|||
|
||||
return addrs;
|
||||
};
|
||||
})
|
||||
;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -168,15 +168,29 @@ Insight.prototype.checkActivity = function(addresses, cb) {
|
|||
if (!addresses) throw new Error('address must be set');
|
||||
|
||||
this.getTransactions(addresses, function onResult(txs) {
|
||||
var flatArray = function (xss) { return xss.reduce(function(r, xs) { return r.concat(xs); }, []); };
|
||||
var getInputs = function (t) { return t.vin.map(function (vin) { return vin.addr }); };
|
||||
var getOutputs = function (t) { return flatArray(
|
||||
t.vout.map(function (vout) { return vout.scriptPubKey.addresses; })
|
||||
);};
|
||||
var flatArray = function(xss) {
|
||||
return xss.reduce(function(r, xs) {
|
||||
return r.concat(xs);
|
||||
}, []);
|
||||
};
|
||||
var getInputs = function(t) {
|
||||
return t.vin.map(function(vin) {
|
||||
return vin.addr
|
||||
});
|
||||
};
|
||||
var getOutputs = function(t) {
|
||||
return flatArray(
|
||||
t.vout.map(function(vout) {
|
||||
return vout.scriptPubKey.addresses;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
var activityMap = new Array(addresses.length);
|
||||
var activeAddress = flatArray(txs.map(function(t) { return getInputs(t).concat(getOutputs(t)); }));
|
||||
activeAddress.forEach(function (addr) {
|
||||
var activeAddress = flatArray(txs.map(function(t) {
|
||||
return getInputs(t).concat(getOutputs(t));
|
||||
}));
|
||||
activeAddress.forEach(function(addr) {
|
||||
var index = addresses.indexOf(addr);
|
||||
if (index != -1) activityMap[index] = true;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var bitcore = require('bitcore');
|
||||
var HK = bitcore.HierarchicalKey;
|
||||
var WalletKey = bitcore.WalletKey;
|
||||
var networks = bitcore.networks;
|
||||
var util = bitcore.util;
|
||||
var Structure = require('./Structure');
|
||||
var imports = require('soop').imports();
|
||||
var bitcore = require('bitcore');
|
||||
var HK = bitcore.HierarchicalKey;
|
||||
var WalletKey = bitcore.WalletKey;
|
||||
var networks = bitcore.networks;
|
||||
var util = bitcore.util;
|
||||
var Structure = require('./Structure');
|
||||
|
||||
function PrivateKey(opts) {
|
||||
opts = opts || {};
|
||||
this.network = opts.networkName === 'testnet' ?
|
||||
this.network = opts.networkName === 'testnet' ?
|
||||
networks.testnet : networks.livenet;
|
||||
var init = opts.extendedPrivateKeyString || this.network.name;
|
||||
this.bip = opts.HK || new HK(init);
|
||||
|
|
@ -81,15 +81,19 @@ PrivateKey.prototype.getForPaths = function(paths) {
|
|||
PrivateKey.prototype.getForPath = function(path) {
|
||||
var pk = this.privateKeyCache[path];
|
||||
if (!pk) {
|
||||
var derivedHK = this._getHK(path);
|
||||
var derivedHK = this._getHK(path);
|
||||
pk = this.privateKeyCache[path] = derivedHK.eckey.private.toString('hex');
|
||||
}
|
||||
var wk = new WalletKey({network: this.network});
|
||||
wk.fromObj({priv: pk});
|
||||
var wk = new WalletKey({
|
||||
network: this.network
|
||||
});
|
||||
wk.fromObj({
|
||||
priv: pk
|
||||
});
|
||||
return wk;
|
||||
};
|
||||
|
||||
PrivateKey.prototype.get = function(index,isChange) {
|
||||
PrivateKey.prototype.get = function(index, isChange) {
|
||||
var path = Structure.FullBranch(index, isChange);
|
||||
return this.getForPath(path);
|
||||
};
|
||||
|
|
@ -99,11 +103,11 @@ PrivateKey.prototype.getAll = function(receiveIndex, changeIndex) {
|
|||
throw new Error('Invalid parameters');
|
||||
|
||||
var ret = [];
|
||||
for(var i=0;i<receiveIndex; i++) {
|
||||
ret.push(this.get(i,false));
|
||||
for (var i = 0; i < receiveIndex; i++) {
|
||||
ret.push(this.get(i, false));
|
||||
}
|
||||
for(var i=0; i<changeIndex; i++) {
|
||||
ret.push(this.get(i,true));
|
||||
for (var i = 0; i < changeIndex; i++) {
|
||||
ret.push(this.get(i, true));
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var imports = require('soop').imports();
|
||||
var preconditions = require('preconditions').instance();
|
||||
var bitcore = require('bitcore');
|
||||
var HK = bitcore.HierarchicalKey;
|
||||
var PrivateKey = require('./PrivateKey');
|
||||
var Structure = require('./Structure');
|
||||
var AddressIndex= require('./AddressIndex');
|
||||
var Address = bitcore.Address;
|
||||
var Script = bitcore.Script;
|
||||
var bitcore = require('bitcore');
|
||||
var HK = bitcore.HierarchicalKey;
|
||||
var PrivateKey = require('./PrivateKey');
|
||||
var Structure = require('./Structure');
|
||||
var AddressIndex = require('./AddressIndex');
|
||||
var Address = bitcore.Address;
|
||||
var Script = bitcore.Script;
|
||||
|
||||
function PublicKeyRing(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
this.walletId = opts.walletId;
|
||||
|
||||
this.network = opts.networkName === 'livenet' ?
|
||||
bitcore.networks.livenet : bitcore.networks.testnet;
|
||||
this.network = opts.networkName === 'livenet' ?
|
||||
bitcore.networks.livenet : bitcore.networks.testnet;
|
||||
|
||||
this.requiredCopayers = opts.requiredCopayers || 3;
|
||||
this.totalCopayers = opts.totalCopayers || 5;
|
||||
|
|
@ -33,11 +32,11 @@ function PublicKeyRing(opts) {
|
|||
this.addressToPath = {};
|
||||
}
|
||||
|
||||
PublicKeyRing.fromObj = function (data) {
|
||||
PublicKeyRing.fromObj = function(data) {
|
||||
if (data instanceof PublicKeyRing) {
|
||||
throw new Error('bad data format: Did you use .toObj()?');
|
||||
}
|
||||
var ret = new PublicKeyRing(data);
|
||||
var ret = new PublicKeyRing(data);
|
||||
|
||||
for (var k in data.copayersExtPubKeys) {
|
||||
ret.addCopayer(data.copayersExtPubKeys[k]);
|
||||
|
|
@ -54,8 +53,8 @@ PublicKeyRing.prototype.toObj = function() {
|
|||
totalCopayers: this.totalCopayers,
|
||||
indexes: this.indexes.toObj(),
|
||||
|
||||
copayersExtPubKeys: this.copayersHK.map( function (b) {
|
||||
return b.extendedPublicKeyString();
|
||||
copayersExtPubKeys: this.copayersHK.map(function(b) {
|
||||
return b.extendedPublicKeyString();
|
||||
}),
|
||||
nicknameFor: this.nicknameFor,
|
||||
publicKeysCache: this.publicKeysCache
|
||||
|
|
@ -67,11 +66,11 @@ PublicKeyRing.prototype.getCopayerId = function(i) {
|
|||
return this.copayerIds[i];
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.registeredCopayers = function () {
|
||||
PublicKeyRing.prototype.registeredCopayers = function() {
|
||||
return this.copayersHK.length;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.isComplete = function () {
|
||||
PublicKeyRing.prototype.isComplete = function() {
|
||||
return this.registeredCopayers() === this.totalCopayers;
|
||||
};
|
||||
|
||||
|
|
@ -86,21 +85,23 @@ PublicKeyRing.prototype.myCopayerId = function(i) {
|
|||
PublicKeyRing.prototype._checkKeys = function() {
|
||||
|
||||
if (!this.isComplete())
|
||||
throw new Error('dont have required keys yet');
|
||||
throw new Error('dont have required keys yet');
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._newExtendedPublicKey = function () {
|
||||
return new PrivateKey({networkName: this.network.name})
|
||||
PublicKeyRing.prototype._newExtendedPublicKey = function() {
|
||||
return new PrivateKey({
|
||||
networkName: this.network.name
|
||||
})
|
||||
.deriveBIP45Branch()
|
||||
.extendedPublicKeyString();
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._updateBip = function (index) {
|
||||
PublicKeyRing.prototype._updateBip = function(index) {
|
||||
var hk = this.copayersHK[index].derive(Structure.IdBranch);
|
||||
this.copayerIds[index]= hk.eckey.public.toString('hex');
|
||||
this.copayerIds[index] = hk.eckey.public.toString('hex');
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._setNicknameForIndex = function (index, nickname) {
|
||||
PublicKeyRing.prototype._setNicknameForIndex = function(index, nickname) {
|
||||
this.nicknameFor[this.copayerIds[index]] = nickname;
|
||||
};
|
||||
|
||||
|
|
@ -114,9 +115,9 @@ PublicKeyRing.prototype.nicknameForCopayer = function(copayerId) {
|
|||
|
||||
PublicKeyRing.prototype.addCopayer = function(newEpk, nickname) {
|
||||
if (this.isComplete())
|
||||
throw new Error('PKR already has all required key:' + this.totalCopayers);
|
||||
throw new Error('PKR already has all required key:' + this.totalCopayers);
|
||||
|
||||
this.copayersHK.forEach(function(b){
|
||||
this.copayersHK.forEach(function(b) {
|
||||
if (b.extendedPublicKeyString() === newEpk)
|
||||
throw new Error('PKR already has that key');
|
||||
});
|
||||
|
|
@ -129,7 +130,7 @@ PublicKeyRing.prototype.addCopayer = function(newEpk, nickname) {
|
|||
var bip = new HK(newEpk);
|
||||
this.copayersHK.push(bip);
|
||||
this._updateBip(i);
|
||||
if (nickname) {
|
||||
if (nickname) {
|
||||
this._setNicknameForIndex(i, nickname);
|
||||
}
|
||||
return newEpk;
|
||||
|
|
@ -138,19 +139,22 @@ PublicKeyRing.prototype.addCopayer = function(newEpk, nickname) {
|
|||
PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
||||
this._checkKeys();
|
||||
|
||||
var path = Structure.Branch(index, isChange);
|
||||
var path = Structure.Branch(index, isChange);
|
||||
var pubKeys = this.publicKeysCache[path];
|
||||
if (!pubKeys) {
|
||||
pubKeys = [];
|
||||
var l = this.copayersHK.length;
|
||||
for(var i=0; i<l; i++) {
|
||||
for (var i = 0; i < l; i++) {
|
||||
var hk = this.copayersHK[i].derive(path);
|
||||
pubKeys[i] = hk.eckey.public;
|
||||
}
|
||||
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex');});
|
||||
}
|
||||
else {
|
||||
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex');});
|
||||
this.publicKeysCache[path] = pubKeys.map(function(pk) {
|
||||
return pk.toString('hex');
|
||||
});
|
||||
} else {
|
||||
pubKeys = pubKeys.map(function(s) {
|
||||
return new Buffer(s, 'hex');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -158,15 +162,15 @@ PublicKeyRing.prototype.getPubKeys = function(index, isChange) {
|
|||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getRedeemScript = function (index, isChange) {
|
||||
PublicKeyRing.prototype.getRedeemScript = function(index, isChange) {
|
||||
var pubKeys = this.getPubKeys(index, isChange);
|
||||
var script = Script.createMultisig(this.requiredCopayers, pubKeys);
|
||||
var script = Script.createMultisig(this.requiredCopayers, pubKeys);
|
||||
return script;
|
||||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getAddress = function (index, isChange) {
|
||||
var script = this.getRedeemScript(index,isChange);
|
||||
PublicKeyRing.prototype.getAddress = function(index, isChange) {
|
||||
var script = this.getRedeemScript(index, isChange);
|
||||
var address = Address.fromScript(script, this.network.name);
|
||||
this.addressToPath[address.toString()] = Structure.FullBranch(index, isChange);
|
||||
return address;
|
||||
|
|
@ -174,13 +178,13 @@ PublicKeyRing.prototype.getAddress = function (index, isChange) {
|
|||
|
||||
PublicKeyRing.prototype.pathForAddress = function(address) {
|
||||
var path = this.addressToPath[address];
|
||||
if (!path) throw new Error('Couldn\'t find path for address '+address);
|
||||
if (!path) throw new Error('Couldn\'t find path for address ' + address);
|
||||
return path;
|
||||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
|
||||
var addr = this.getAddress(index,isChange);
|
||||
PublicKeyRing.prototype.getScriptPubKeyHex = function(index, isChange) {
|
||||
var addr = this.getAddress(index, isChange);
|
||||
return Script.createP2SH(addr.payload()).getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
|
|
@ -204,18 +208,18 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
|
||||
var ret = [];
|
||||
if (!opts.excludeChange) {
|
||||
for (var i=0; i<this.indexes.getChangeIndex(); i++) {
|
||||
for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
|
||||
ret.unshift({
|
||||
address: this.getAddress(i,true),
|
||||
address: this.getAddress(i, true),
|
||||
isChange: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!opts.excludeMain) {
|
||||
for (var i=0; i<this.indexes.getReceiveIndex(); i++) {
|
||||
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
|
||||
ret.unshift({
|
||||
address: this.getAddress(i,false),
|
||||
address: this.getAddress(i, false),
|
||||
isChange: false
|
||||
});
|
||||
}
|
||||
|
|
@ -225,59 +229,59 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
|
|||
};
|
||||
|
||||
// TODO this could be cached
|
||||
PublicKeyRing.prototype._addScriptMap = function (map, index, isChange) {
|
||||
var script = this.getRedeemScript(index,isChange);
|
||||
PublicKeyRing.prototype._addScriptMap = function(map, index, isChange) {
|
||||
var script = this.getRedeemScript(index, isChange);
|
||||
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype.getRedeemScriptMap = function () {
|
||||
PublicKeyRing.prototype.getRedeemScriptMap = function() {
|
||||
var ret = {};
|
||||
|
||||
for (var i=0; i<this.indexes.getChangeIndex(); i++) {
|
||||
this._addScriptMap(ret,i,true);
|
||||
for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
|
||||
this._addScriptMap(ret, i, true);
|
||||
}
|
||||
for (var i=0; i<this.indexes.getReceiveIndex(); i++) {
|
||||
this._addScriptMap(ret,i,false);
|
||||
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
|
||||
this._addScriptMap(ret, i, false);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
|
||||
|
||||
if (!ignoreId && this.walletId !== inPKR.walletId) {
|
||||
if (!ignoreId && this.walletId !== inPKR.walletId) {
|
||||
throw new Error('inPKR walletId mismatch');
|
||||
}
|
||||
|
||||
if (this.network.name !== inPKR.network.name) {
|
||||
throw new Error('Network mismatch. Should be '+this.network.name +
|
||||
' and found '+inPKR.network.name);
|
||||
throw new Error('Network mismatch. Should be ' + this.network.name +
|
||||
' and found ' + inPKR.network.name);
|
||||
}
|
||||
|
||||
if (
|
||||
this.requiredCopayers && inPKR.requiredCopayers &&
|
||||
(this.requiredCopayers !== inPKR.requiredCopayers))
|
||||
throw new Error('inPKR requiredCopayers mismatch '+this.requiredCopayers+'!='+inPKR.requiredCopayers);
|
||||
throw new Error('inPKR requiredCopayers mismatch ' + this.requiredCopayers + '!=' + inPKR.requiredCopayers);
|
||||
|
||||
if (
|
||||
this.totalCopayers && inPKR.totalCopayers &&
|
||||
(this.totalCopayers !== inPKR.totalCopayers))
|
||||
throw new Error('inPKR totalCopayers mismatch'+this.totalCopayers+'!='+inPKR.requiredCopayers);
|
||||
throw new Error('inPKR totalCopayers mismatch' + this.totalCopayers + '!=' + inPKR.requiredCopayers);
|
||||
};
|
||||
|
||||
|
||||
PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
||||
var self = this;
|
||||
var hasChanged = false;
|
||||
var l= self.copayersHK.length;
|
||||
if (self.isComplete())
|
||||
var l = self.copayersHK.length;
|
||||
if (self.isComplete())
|
||||
return;
|
||||
|
||||
inPKR.copayersHK.forEach( function(b) {
|
||||
inPKR.copayersHK.forEach(function(b) {
|
||||
var haveIt = false;
|
||||
var epk = b.extendedPublicKeyString();
|
||||
for(var j=0; j<l; j++) {
|
||||
var epk = b.extendedPublicKeyString();
|
||||
for (var j = 0; j < l; j++) {
|
||||
if (self.copayersHK[j].extendedPublicKeyString() === epk) {
|
||||
haveIt=true;
|
||||
haveIt = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -289,8 +293,8 @@ PublicKeyRing.prototype._mergePubkeys = function(inPKR) {
|
|||
self.copayersHK.push(new HK(epk));
|
||||
self._updateBip(l2);
|
||||
if (inPKR.nicknameFor[self.getCopayerId(l2)])
|
||||
self._setNicknameForIndex(l2,inPKR.nicknameFor[self.getCopayerId(l2)]);
|
||||
hasChanged=true;
|
||||
self._setNicknameForIndex(l2, inPKR.nicknameFor[self.getCopayerId(l2)]);
|
||||
hasChanged = true;
|
||||
}
|
||||
});
|
||||
return hasChanged;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ TxProposal.prototype.mergeMetadata = function(v1, author) {
|
|||
|
||||
Object.keys(v1.seenBy).forEach(function(k) {
|
||||
if (!v0.seenBy[k]) {
|
||||
if (k != author) throw new Error('Non authoritative seenBy change by '+author);
|
||||
if (k != author) throw new Error('Non authoritative seenBy change by ' + author);
|
||||
v0.seenBy[k] = v1.seenBy[k];
|
||||
events.push({
|
||||
type: 'seen',
|
||||
|
|
@ -89,7 +89,7 @@ TxProposal.prototype.mergeMetadata = function(v1, author) {
|
|||
|
||||
Object.keys(v1.signedBy).forEach(function(k) {
|
||||
if (!v0.signedBy[k]) {
|
||||
if (k != author) throw new Error('Non authoritative signedBy change by '+author);
|
||||
if (k != author) throw new Error('Non authoritative signedBy change by ' + author);
|
||||
v0.signedBy[k] = v1.signedBy[k];
|
||||
events.push({
|
||||
type: 'signed',
|
||||
|
|
@ -101,7 +101,7 @@ TxProposal.prototype.mergeMetadata = function(v1, author) {
|
|||
|
||||
Object.keys(v1.rejectedBy).forEach(function(k) {
|
||||
if (!v0.rejectedBy[k]) {
|
||||
if (k != author) throw new Error('Non authoritative rejectedBy change by '+author);
|
||||
if (k != author) throw new Error('Non authoritative rejectedBy change by ' + author);
|
||||
v0.rejectedBy[k] = v1.rejectedBy[k];
|
||||
events.push({
|
||||
type: 'rejected',
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function Wallet(opts) {
|
|||
this.token = opts.token;
|
||||
this.tokenTime = opts.tokenTime;
|
||||
}
|
||||
|
||||
|
||||
this.verbose = opts.verbose;
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
|
|
@ -142,12 +142,11 @@ Wallet.prototype._handleAddressBook = function(senderId, data, isInbound) {
|
|||
this.log('RECV ADDRESSBOOK:', data);
|
||||
var rcv = data.addressBook;
|
||||
var hasChange;
|
||||
for(var key in rcv) {
|
||||
for (var key in rcv) {
|
||||
if (!this.addressBook[key]) {
|
||||
this.addressBook[key] = rcv[key];
|
||||
hasChange = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (rcv[key].createdTs > this.addressBook[key].createdTs) {
|
||||
this.addressBook[key] = rcv[key];
|
||||
hasChange = true;
|
||||
|
|
@ -395,7 +394,7 @@ Wallet.prototype.sendAllTxProposals = function(recipients) {
|
|||
Wallet.prototype.sendTxProposal = function(ntxid, recipients) {
|
||||
preconditions.checkArgument(ntxid);
|
||||
preconditions.checkState(this.txProposals.txps[ntxid]);
|
||||
this.log('### SENDING txProposal '+ntxid+' TO:', recipients || 'All', this.txProposals);
|
||||
this.log('### SENDING txProposal ' + ntxid + ' TO:', recipients || 'All', this.txProposals);
|
||||
this.network.send(recipients, {
|
||||
type: 'txProposal',
|
||||
txProposal: this.txProposals.txps[ntxid].toObj(),
|
||||
|
|
@ -771,7 +770,7 @@ Wallet.prototype.updateIndexes = function(callback) {
|
|||
|
||||
Wallet.prototype.deriveAddresses = function(index, amout, isChange) {
|
||||
var ret = new Array(amout);
|
||||
for(var i = 0; i < amout; i++) {
|
||||
for (var i = 0; i < amout; i++) {
|
||||
ret[i] = this.publicKeyRing.getAddress(index + i, isChange).toString();
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -791,7 +790,7 @@ Wallet.prototype.indexDiscovery = function(start, change, gap, cb) {
|
|||
// Optimize window to minimize the derivations.
|
||||
var scanWindow = (lastActive == -1) ? gap : gap - (scanIndex - lastActive) + 1;
|
||||
var addresses = self.deriveAddresses(scanIndex, scanWindow, change);
|
||||
self.blockchain.checkActivity(addresses, function(err, actives){
|
||||
self.blockchain.checkActivity(addresses, function(err, actives) {
|
||||
if (err) throw err;
|
||||
|
||||
// Check for new activities in the newlly scanned addresses
|
||||
|
|
@ -804,7 +803,9 @@ Wallet.prototype.indexDiscovery = function(start, change, gap, cb) {
|
|||
next();
|
||||
});
|
||||
},
|
||||
function _while() { return hasActivity; },
|
||||
function _while() {
|
||||
return hasActivity;
|
||||
},
|
||||
function _finnaly(err) {
|
||||
if (err) return cb(err);
|
||||
cb(null, lastActive);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||
var bitcore = require('bitcore');
|
||||
var util = bitcore.util;
|
||||
var extend = require('util')._extend;
|
||||
var imports = require('soop').imports();
|
||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||
var bitcore = require('bitcore');
|
||||
var util = bitcore.util;
|
||||
var extend = require('util')._extend;
|
||||
/*
|
||||
* Emits
|
||||
* 'connect'
|
||||
|
|
@ -19,17 +19,17 @@ var extend = require('util')._extend;
|
|||
*/
|
||||
|
||||
function Network(opts) {
|
||||
var self = this;
|
||||
opts = opts || {};
|
||||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 10;
|
||||
var self = this;
|
||||
opts = opts || {};
|
||||
this.apiKey = opts.apiKey || 'lwjd5qra8257b9';
|
||||
this.debug = opts.debug || 3;
|
||||
this.maxPeers = opts.maxPeers || 10;
|
||||
this.reconnectAttempts = opts.reconnectAttempts || 3;
|
||||
this.sjclParams = opts.sjclParams || {
|
||||
salt: 'f28bfb49ef70573c',
|
||||
iter:500,
|
||||
mode:'ccm',
|
||||
ts:parseInt(64),
|
||||
this.sjclParams = opts.sjclParams || {
|
||||
salt: 'f28bfb49ef70573c',
|
||||
iter: 500,
|
||||
mode: 'ccm',
|
||||
ts: parseInt(64),
|
||||
};
|
||||
this.opts = {};
|
||||
['config', 'port', 'host', 'path', 'debug', 'key', 'secure'].forEach(function(k) {
|
||||
|
|
@ -47,11 +47,11 @@ Network.prototype.cleanUp = function() {
|
|||
this.privkey = null; //TODO: hide privkey in a closure
|
||||
this.copayerId = null;
|
||||
this.signingKey = null;
|
||||
this.allowedCopayerIds=null;
|
||||
this.isInboundPeerAuth=[];
|
||||
this.copayerForPeer={};
|
||||
this.connections={};
|
||||
this.criticalErr='';
|
||||
this.allowedCopayerIds = null;
|
||||
this.isInboundPeerAuth = [];
|
||||
this.copayerForPeer = {};
|
||||
this.connections = {};
|
||||
this.criticalErr = '';
|
||||
if (this.peer) {
|
||||
this.peer.disconnect();
|
||||
this.peer.destroy();
|
||||
|
|
@ -62,7 +62,7 @@ Network.prototype.cleanUp = function() {
|
|||
this.tries = 0;
|
||||
};
|
||||
|
||||
Network.parent=EventEmitter;
|
||||
Network.parent = EventEmitter;
|
||||
|
||||
// Array helpers
|
||||
Network._arrayDiff = function(a, b) {
|
||||
|
|
@ -99,9 +99,9 @@ Network._arrayRemove = function(el, array) {
|
|||
};
|
||||
|
||||
Network.prototype.connectedCopayers = function() {
|
||||
var ret =[];
|
||||
for(var i in this.connectedPeers){
|
||||
var copayerId =this.copayerForPeer[this.connectedPeers[i]];
|
||||
var ret = [];
|
||||
for (var i in this.connectedPeers) {
|
||||
var copayerId = this.copayerForPeer[this.connectedPeers[i]];
|
||||
if (copayerId) ret.push(copayerId);
|
||||
}
|
||||
return ret;
|
||||
|
|
@ -126,7 +126,7 @@ Network.prototype._onClose = function(peerID) {
|
|||
|
||||
Network.prototype.connectToCopayers = function(copayerIds) {
|
||||
var self = this;
|
||||
var arrayDiff= Network._arrayDiff(copayerIds, self.connectedCopayers());
|
||||
var arrayDiff = Network._arrayDiff(copayerIds, self.connectedCopayers());
|
||||
|
||||
arrayDiff.forEach(function(copayerId) {
|
||||
if (self.allowedCopayerIds && !self.allowedCopayerIds[copayerId]) {
|
||||
|
|
@ -146,7 +146,7 @@ Network.prototype._sendHello = function(copayerId) {
|
|||
|
||||
Network.prototype._addConnectedCopayer = function(copayerId, isInbound) {
|
||||
var peerId = this.peerFromCopayer(copayerId);
|
||||
this._addCopayerMap(peerId,copayerId);
|
||||
this._addCopayerMap(peerId, copayerId);
|
||||
Network._arrayPushOnce(peerId, this.connectedPeers);
|
||||
this.emit('connect', copayerId);
|
||||
};
|
||||
|
|
@ -158,15 +158,15 @@ Network.prototype._onData = function(enchex, isInbound, peerId) {
|
|||
|
||||
var privkey = this.privkey;
|
||||
|
||||
try {
|
||||
try {
|
||||
var data = this._decrypt(privkey, encbuf);
|
||||
payload= JSON.parse(data);
|
||||
payload = JSON.parse(data);
|
||||
} catch (e) {
|
||||
this._deletePeer(peerId);
|
||||
return;
|
||||
}
|
||||
|
||||
if(isInbound && payload.type === 'hello') {
|
||||
if (isInbound && payload.type === 'hello') {
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
|
||||
if (this.allowedCopayerIds && !this.allowedCopayerIds[payload.copayerId]) {
|
||||
|
|
@ -179,13 +179,13 @@ Network.prototype._onData = function(enchex, isInbound, peerId) {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( !this.copayerForPeer[peerId] || (isInbound && !this.isInboundPeerAuth[peerId]) ) {
|
||||
if (!this.copayerForPeer[peerId] || (isInbound && !this.isInboundPeerAuth[peerId])) {
|
||||
this._deletePeer(peerId);
|
||||
return;
|
||||
}
|
||||
|
||||
var self=this;
|
||||
switch(payload.type) {
|
||||
var self = this;
|
||||
switch (payload.type) {
|
||||
case 'disconnect':
|
||||
this._onClose(peerId);
|
||||
break;
|
||||
|
|
@ -206,21 +206,21 @@ Network.prototype._setupConnectionHandlers = function(dataConn, toCopayerId) {
|
|||
var isInbound = toCopayerId ? false : true;
|
||||
|
||||
dataConn.on('open', function() {
|
||||
if (!Network._inArray(dataConn.peer, self.connectedPeers) &&
|
||||
!self.connections[dataConn.peer]) {
|
||||
if (!Network._inArray(dataConn.peer, self.connectedPeers) &&
|
||||
!self.connections[dataConn.peer]) {
|
||||
|
||||
self.connections[dataConn.peer] = dataConn;
|
||||
|
||||
// The connecting peer send hello
|
||||
if(toCopayerId) {
|
||||
if (toCopayerId) {
|
||||
self.emit('connected');
|
||||
self._sendHello(toCopayerId);
|
||||
self._sendHello(toCopayerId);
|
||||
self._addConnectedCopayer(toCopayerId);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dataConn.on('data', function(data) {
|
||||
dataConn.on('data', function(data) {
|
||||
self._onData(data, isInbound, dataConn.peer);
|
||||
});
|
||||
|
||||
|
|
@ -244,14 +244,14 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
|
||||
p.on('open', function() {
|
||||
self.connectedPeers = [self.peerId];
|
||||
self.copayerForPeer[self.peerId]= self.copayerId;
|
||||
self.copayerForPeer[self.peerId] = self.copayerId;
|
||||
return openCallback();
|
||||
});
|
||||
|
||||
p.on('error', function(err) {
|
||||
console.log('RECV ERROR: ', err); //TODO
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/) ) {
|
||||
self.criticalError=err.message;
|
||||
if (!err.message.match(/Could\snot\sconnect\sto peer/)) {
|
||||
self.criticalError = err.message;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -270,11 +270,9 @@ Network.prototype._setupPeerHandlers = function(openCallback) {
|
|||
|
||||
Network.prototype._addCopayerMap = function(peerId, copayerId) {
|
||||
if (!this.copayerForPeer[peerId]) {
|
||||
if(Object.keys(this.copayerForPeer).length < this.maxPeers) {
|
||||
this.copayerForPeer[peerId]=copayerId;
|
||||
}
|
||||
else {
|
||||
}
|
||||
if (Object.keys(this.copayerForPeer).length < this.maxPeers) {
|
||||
this.copayerForPeer[peerId] = copayerId;
|
||||
} else {}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -288,16 +286,16 @@ Network.prototype.setCopayerId = function(copayerId) {
|
|||
throw new Error('network already started: can not change peerId')
|
||||
}
|
||||
this.copayerId = copayerId;
|
||||
this.copayerIdBuf = new Buffer(copayerId,'hex');
|
||||
this.copayerIdBuf = new Buffer(copayerId, 'hex');
|
||||
this.peerId = this.peerFromCopayer(this.copayerId);
|
||||
this._addCopayerMap(this.peerId,copayerId);
|
||||
this._addCopayerMap(this.peerId, copayerId);
|
||||
};
|
||||
|
||||
|
||||
// TODO cache this.
|
||||
Network.prototype.peerFromCopayer = function(hex) {
|
||||
var SIN = bitcore.SIN;
|
||||
return new SIN(new Buffer(hex,'hex')).toString();
|
||||
return new SIN(new Buffer(hex, 'hex')).toString();
|
||||
};
|
||||
|
||||
Network.prototype.start = function(opts, openCallback) {
|
||||
|
|
@ -317,7 +315,7 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
this.setCopayerId(opts.copayerId);
|
||||
|
||||
var self = this;
|
||||
var setupPeer = function () {
|
||||
var setupPeer = function() {
|
||||
if (self.connectedPeers.length > 0) return; // Already connected!
|
||||
if (self.peer) {
|
||||
self.peer.destroy();
|
||||
|
|
@ -333,7 +331,7 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
return;
|
||||
}
|
||||
if (self.criticalError && self.criticalError.match(/taken/)) {
|
||||
self.criticalError=' Looks like you are already connected to this wallet please close all other Copay Wallets '
|
||||
self.criticalError = ' Looks like you are already connected to this wallet please close all other Copay Wallets '
|
||||
}
|
||||
self.emit('serverError', self.criticalError);
|
||||
self.cleanUp();
|
||||
|
|
@ -376,7 +374,7 @@ Network.prototype._sendToOne = function(copayerId, payload, sig, cb) {
|
|||
Network.prototype.send = function(copayerIds, payload, cb) {
|
||||
if (!payload) return cb();
|
||||
|
||||
var self=this;
|
||||
var self = this;
|
||||
if (!copayerIds) {
|
||||
copayerIds = this.connectedCopayers();
|
||||
payload.isBroadcast = 1;
|
||||
|
|
@ -394,7 +392,7 @@ Network.prototype.send = function(copayerIds, payload, cb) {
|
|||
copayerIds.forEach(function(copayerId) {
|
||||
var copayerIdBuf = new Buffer(copayerId, 'hex');
|
||||
var encPayload = self._encrypt(copayerIdBuf, payloadBuf);
|
||||
self._sendToOne(copayerId, encPayload, sig, function () {
|
||||
self._sendToOne(copayerId, encPayload, sig, function() {
|
||||
if (++i === l && typeof cb === 'function') cb();
|
||||
});
|
||||
});
|
||||
|
|
@ -417,16 +415,18 @@ Network.prototype.connectTo = function(copayerId) {
|
|||
};
|
||||
|
||||
Network.prototype.lockIncommingConnections = function(allowedCopayerIdsArray) {
|
||||
this.allowedCopayerIds={};
|
||||
for(var i in allowedCopayerIdsArray) {
|
||||
this.allowedCopayerIds[ allowedCopayerIdsArray[i] ] = true;
|
||||
this.allowedCopayerIds = {};
|
||||
for (var i in allowedCopayerIdsArray) {
|
||||
this.allowedCopayerIds[allowedCopayerIdsArray[i]] = true;
|
||||
}
|
||||
};
|
||||
|
||||
Network.prototype.disconnect = function(cb, forced) {
|
||||
var self = this;
|
||||
self.closing = 1;
|
||||
self.send(null, { type: 'disconnect' }, function(){
|
||||
self.send(null, {
|
||||
type: 'disconnect'
|
||||
}, function() {
|
||||
self.cleanUp();
|
||||
if (typeof cb === 'function') cb();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ Storage.prototype.get = function(walletId, k) {
|
|||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(walletId, k, v, callback) {
|
||||
this.setGlobal(this._key(walletId,k), v, callback);
|
||||
this.setGlobal(this._key(walletId, k), v, callback);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
|
|
@ -143,6 +143,6 @@ Storage.prototype.getEncryptedObj = function(walletId) {
|
|||
Storage.prototype.clearAll = function(callback) {
|
||||
this.data = {};
|
||||
this.save(callback);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Storage);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
|
||||
var imports = require('soop').imports();
|
||||
|
||||
function Storage() {
|
||||
}
|
||||
function Storage() {}
|
||||
|
||||
Storage.prototype._read = function(k) {
|
||||
var ret;
|
||||
|
|
@ -13,7 +12,7 @@ Storage.prototype._read = function(k) {
|
|||
return ret;
|
||||
};
|
||||
|
||||
Storage.prototype._write = function(k,v) {
|
||||
Storage.prototype._write = function(k, v) {
|
||||
localStorage.setItem(k, JSON.stringify(v));
|
||||
};
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ Storage.prototype._getWalletKeys = function(walletId) {
|
|||
if (walletId = split[0])
|
||||
keys.push(split[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
};
|
||||
|
|
@ -38,8 +37,8 @@ Storage.prototype.getGlobal = function(k) {
|
|||
};
|
||||
|
||||
// set value for key
|
||||
Storage.prototype.setGlobal = function(k,v) {
|
||||
this._write(k,v);
|
||||
Storage.prototype.setGlobal = function(k, v) {
|
||||
this._write(k, v);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
|
|
@ -54,44 +53,44 @@ Storage.prototype._key = function(walletId, k) {
|
|||
};
|
||||
// get value by key
|
||||
Storage.prototype.get = function(walletId, k) {
|
||||
return this.getGlobal(this._key(walletId,k));
|
||||
return this.getGlobal(this._key(walletId, k));
|
||||
};
|
||||
|
||||
// set value for key
|
||||
Storage.prototype.set = function(walletId, k,v) {
|
||||
this.setGlobal(this._key(walletId,k), v);
|
||||
Storage.prototype.set = function(walletId, k, v) {
|
||||
this.setGlobal(this._key(walletId, k), v);
|
||||
};
|
||||
|
||||
// remove value for key
|
||||
Storage.prototype.remove = function(walletId, k) {
|
||||
this.removeGlobal(this._key(walletId,k));
|
||||
this.removeGlobal(this._key(walletId, k));
|
||||
};
|
||||
|
||||
Storage.prototype.setName = function(walletId, name) {
|
||||
this.setGlobal('nameFor::'+walletId, name);
|
||||
this.setGlobal('nameFor::' + walletId, name);
|
||||
};
|
||||
|
||||
Storage.prototype.getName = function(walletId) {
|
||||
return this.getGlobal('nameFor::'+walletId);
|
||||
return this.getGlobal('nameFor::' + walletId);
|
||||
};
|
||||
|
||||
Storage.prototype.getWalletIds = function() {
|
||||
var walletIds = [];
|
||||
var uniq = {};
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var key = localStorage.key(i);
|
||||
var split = key.split('::');
|
||||
if (split.length == 2) {
|
||||
var key = localStorage.key(i);
|
||||
var split = key.split('::');
|
||||
if (split.length == 2) {
|
||||
var walletId = split[0];
|
||||
|
||||
if (walletId === 'nameFor') continue;
|
||||
|
||||
if (typeof uniq[walletId] === 'undefined' ) {
|
||||
if (typeof uniq[walletId] === 'undefined') {
|
||||
walletIds.push(walletId);
|
||||
uniq[walletId] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return walletIds;
|
||||
};
|
||||
|
||||
|
|
@ -100,9 +99,9 @@ Storage.prototype.getWallets = function() {
|
|||
var uniq = {};
|
||||
var ids = this.getWalletIds();
|
||||
|
||||
for (var i in ids){
|
||||
for (var i in ids) {
|
||||
wallets.push({
|
||||
id:ids[i],
|
||||
id: ids[i],
|
||||
name: this.getName(ids[i]),
|
||||
});
|
||||
}
|
||||
|
|
@ -120,6 +119,6 @@ Storage.prototype.setFromObj = function(walletId, obj) {
|
|||
// remove all values
|
||||
Storage.prototype.clearAll = function() {
|
||||
localStorage.clear();
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Storage);
|
||||
|
|
|
|||
|
|
@ -60,15 +60,14 @@ angular
|
|||
.config(function($locationProvider) {
|
||||
$locationProvider
|
||||
.html5Mode(false);
|
||||
//.hashPrefix('!');
|
||||
//.hashPrefix('!');
|
||||
})
|
||||
.run(function($rootScope, $location) {
|
||||
$rootScope.$on('$routeChangeStart', function(event, next, current) {
|
||||
|
||||
if (!util.supports.data) {
|
||||
$location.path('unsupported');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((!$rootScope.wallet || !$rootScope.wallet.id) && next.validate) {
|
||||
$location.path('signin');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ var BackupService = function(notification) {
|
|||
};
|
||||
|
||||
BackupService.prototype.getName = function(wallet) {
|
||||
return (wallet.name ? (wallet.name+'-') : '') + wallet.id;
|
||||
return (wallet.name ? (wallet.name + '-') : '') + wallet.id;
|
||||
};
|
||||
|
||||
BackupService.prototype.download = function(wallet) {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
}, 3000);
|
||||
});
|
||||
w.on('txProposalEvent', function(e){
|
||||
w.on('txProposalEvent', function(e) {
|
||||
switch (e.type) {
|
||||
case 'signed':
|
||||
var user = w.publicKeyRing.nicknameForCopayer(e.cId);
|
||||
|
|
@ -297,7 +297,7 @@ angular.module('copayApp.services')
|
|||
Socket.emit('subscribe', 'inv');
|
||||
Socket.on('block', function(block) {
|
||||
root.updateBalance(function() {
|
||||
$rootScope.$digest();
|
||||
$rootScope.$digest();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@
|
|||
// Detect mobile devices
|
||||
var isMobile = {
|
||||
Android: function() {
|
||||
return !! navigator.userAgent.match(/Android/i);
|
||||
return !!navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
BlackBerry: function() {
|
||||
return !! navigator.userAgent.match(/BlackBerry/i);
|
||||
return !!navigator.userAgent.match(/BlackBerry/i);
|
||||
},
|
||||
iOS: function() {
|
||||
return !! navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
return !!navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
},
|
||||
Opera: function() {
|
||||
return !! navigator.userAgent.match(/Opera Mini/i);
|
||||
return !!navigator.userAgent.match(/Opera Mini/i);
|
||||
},
|
||||
Windows: function() {
|
||||
return !! navigator.userAgent.match(/IEMobile/i);
|
||||
return !!navigator.userAgent.match(/IEMobile/i);
|
||||
},
|
||||
any: function() {
|
||||
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
||||
|
|
|
|||
|
|
@ -1,40 +1,61 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').
|
||||
factory('notification', ['$timeout',function($timeout){
|
||||
factory('notification', ['$timeout',
|
||||
function($timeout) {
|
||||
|
||||
var notifications = JSON.parse(localStorage.getItem('notifications')) || [],
|
||||
queue = [];
|
||||
queue = [];
|
||||
|
||||
var settings = {
|
||||
info: { duration: 5000, enabled: true },
|
||||
funds: { duration: 5000, enabled: true },
|
||||
warning: { duration: 5000, enabled: true },
|
||||
error: { duration: 1e10, enabled: true },
|
||||
success: { duration: 5000, enabled: true },
|
||||
progress: { duration: 0, enabled: true },
|
||||
custom: { duration: 35000, enabled: true },
|
||||
info: {
|
||||
duration: 5000,
|
||||
enabled: true
|
||||
},
|
||||
funds: {
|
||||
duration: 5000,
|
||||
enabled: true
|
||||
},
|
||||
warning: {
|
||||
duration: 5000,
|
||||
enabled: true
|
||||
},
|
||||
error: {
|
||||
duration: 1e10,
|
||||
enabled: true
|
||||
},
|
||||
success: {
|
||||
duration: 5000,
|
||||
enabled: true
|
||||
},
|
||||
progress: {
|
||||
duration: 0,
|
||||
enabled: true
|
||||
},
|
||||
custom: {
|
||||
duration: 35000,
|
||||
enabled: true
|
||||
},
|
||||
details: true,
|
||||
localStorage: false,
|
||||
html5Mode: false,
|
||||
html5DefaultIcon: 'img/favicon.ico'
|
||||
};
|
||||
|
||||
function html5Notify(icon, title, content, ondisplay, onclose){
|
||||
if(window.webkitNotifications.checkPermission() === 0){
|
||||
if(!icon){
|
||||
function html5Notify(icon, title, content, ondisplay, onclose) {
|
||||
if (window.webkitNotifications.checkPermission() === 0) {
|
||||
if (!icon) {
|
||||
icon = 'img/favicon.ico';
|
||||
}
|
||||
var noti = window.webkitNotifications.createNotification(icon, title, content);
|
||||
if(typeof ondisplay === 'function'){
|
||||
if (typeof ondisplay === 'function') {
|
||||
noti.ondisplay = ondisplay;
|
||||
}
|
||||
if(typeof onclose === 'function'){
|
||||
if (typeof onclose === 'function') {
|
||||
noti.onclose = onclose;
|
||||
}
|
||||
noti.show();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
settings.html5Mode = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,53 +65,50 @@ angular.module('copayApp.services').
|
|||
|
||||
/* ========== SETTINGS RELATED METHODS =============*/
|
||||
|
||||
disableHtml5Mode: function(){
|
||||
disableHtml5Mode: function() {
|
||||
settings.html5Mode = false;
|
||||
},
|
||||
|
||||
disableType: function(notificationType){
|
||||
disableType: function(notificationType) {
|
||||
settings[notificationType].enabled = false;
|
||||
},
|
||||
|
||||
enableHtml5Mode: function(){
|
||||
enableHtml5Mode: function() {
|
||||
// settings.html5Mode = true;
|
||||
settings.html5Mode = this.requestHtml5ModePermissions();
|
||||
},
|
||||
|
||||
enableType: function(notificationType){
|
||||
enableType: function(notificationType) {
|
||||
settings[notificationType].enabled = true;
|
||||
},
|
||||
|
||||
getSettings: function(){
|
||||
getSettings: function() {
|
||||
return settings;
|
||||
},
|
||||
|
||||
toggleType: function(notificationType){
|
||||
toggleType: function(notificationType) {
|
||||
settings[notificationType].enabled = !settings[notificationType].enabled;
|
||||
},
|
||||
|
||||
toggleHtml5Mode: function(){
|
||||
toggleHtml5Mode: function() {
|
||||
settings.html5Mode = !settings.html5Mode;
|
||||
},
|
||||
|
||||
requestHtml5ModePermissions: function(){
|
||||
if (window.webkitNotifications){
|
||||
requestHtml5ModePermissions: function() {
|
||||
if (window.webkitNotifications) {
|
||||
if (window.webkitNotifications.checkPermission() === 0) {
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
window.webkitNotifications.requestPermission(function(){
|
||||
if(window.webkitNotifications.checkPermission() === 0){
|
||||
} else {
|
||||
window.webkitNotifications.requestPermission(function() {
|
||||
if (window.webkitNotifications.checkPermission() === 0) {
|
||||
settings.html5Mode = true;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
settings.html5Mode = false;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
|
@ -98,38 +116,38 @@ angular.module('copayApp.services').
|
|||
|
||||
/* ============ QUERYING RELATED METHODS ============*/
|
||||
|
||||
getAll: function(){
|
||||
getAll: function() {
|
||||
// Returns all notifications that are currently stored
|
||||
return notifications;
|
||||
},
|
||||
|
||||
getQueue: function(){
|
||||
getQueue: function() {
|
||||
return queue;
|
||||
},
|
||||
|
||||
/* ============== NOTIFICATION METHODS ==============*/
|
||||
|
||||
info: function(title, content, userData){
|
||||
info: function(title, content, userData) {
|
||||
return this.awesomeNotify('info', 'info', title, content, userData);
|
||||
},
|
||||
|
||||
funds: function(title, content, userData){
|
||||
|
||||
funds: function(title, content, userData) {
|
||||
return this.awesomeNotify('funds', 'bitcoin', title, content, userData);
|
||||
},
|
||||
|
||||
error: function(title, content, userData){
|
||||
error: function(title, content, userData) {
|
||||
return this.awesomeNotify('error', 'x', title, content, userData);
|
||||
},
|
||||
|
||||
success: function(title, content, userData){
|
||||
success: function(title, content, userData) {
|
||||
return this.awesomeNotify('success', 'check', title, content, userData);
|
||||
},
|
||||
|
||||
warning: function(title, content, userData){
|
||||
warning: function(title, content, userData) {
|
||||
return this.awesomeNotify('warning', 'alert', title, content, userData);
|
||||
},
|
||||
|
||||
awesomeNotify: function(type, icon, title, content, userData){
|
||||
awesomeNotify: function(type, icon, title, content, userData) {
|
||||
/**
|
||||
* Supposed to wrap the makeNotification method for drawing icons using font-awesome
|
||||
* rather than an image.
|
||||
|
|
@ -143,13 +161,13 @@ angular.module('copayApp.services').
|
|||
return this.makeNotification(type, false, icon, title, content, userData);
|
||||
},
|
||||
|
||||
notify: function(image, title, content, userData){
|
||||
notify: function(image, title, content, userData) {
|
||||
// Wraps the makeNotification method for displaying notifications with images
|
||||
// rather than icons
|
||||
return this.makeNotification('custom', image, true, title, content, userData);
|
||||
},
|
||||
|
||||
makeNotification: function(type, image, icon, title, content, userData){
|
||||
makeNotification: function(type, image, icon, title, content, userData) {
|
||||
var notification = {
|
||||
'type': type,
|
||||
'image': image,
|
||||
|
|
@ -161,16 +179,15 @@ angular.module('copayApp.services').
|
|||
};
|
||||
notifications.push(notification);
|
||||
|
||||
if(settings.html5Mode){
|
||||
html5Notify(image, title, content, function(){
|
||||
if (settings.html5Mode) {
|
||||
html5Notify(image, title, content, function() {
|
||||
// inner on display function
|
||||
}, function(){
|
||||
}, function() {
|
||||
// inner on close function
|
||||
});
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
queue.push(notification);
|
||||
$timeout(function removeFromQueueTimeout(){
|
||||
$timeout(function removeFromQueueTimeout() {
|
||||
queue.splice(queue.indexOf(notification), 1);
|
||||
}, settings[type].duration);
|
||||
|
||||
|
|
@ -183,80 +200,77 @@ angular.module('copayApp.services').
|
|||
|
||||
/* ============ PERSISTENCE METHODS ============ */
|
||||
|
||||
save: function(){
|
||||
save: function() {
|
||||
// Save all the notifications into localStorage
|
||||
if(settings.localStorage){
|
||||
if (settings.localStorage) {
|
||||
localStorage.setItem('notifications', JSON.stringify(notifications));
|
||||
}
|
||||
},
|
||||
|
||||
restore: function(){
|
||||
restore: function() {
|
||||
// Load all notifications from localStorage
|
||||
},
|
||||
|
||||
clear: function(){
|
||||
clear: function() {
|
||||
notifications = [];
|
||||
this.save();
|
||||
}
|
||||
|
||||
};
|
||||
}]).
|
||||
directive('notifications', function(notification, $compile){
|
||||
/**
|
||||
*
|
||||
* It should also parse the arguments passed to it that specify
|
||||
* its position on the screen like "bottom right" and apply those
|
||||
* positions as a class to the container element
|
||||
*
|
||||
* Finally, the directive should have its own controller for
|
||||
* handling all of the notifications from the notification service
|
||||
*/
|
||||
var html =
|
||||
'<div class="dr-notification-wrapper" ng-repeat="noti in queue">' +
|
||||
'<div class="dr-notification-close-btn" ng-click="removeNotification(noti)">' +
|
||||
'<i class="fi-x"></i>' +
|
||||
'</div>' +
|
||||
'<div class="dr-notification">' +
|
||||
'<div class="dr-notification-image dr-notification-type-{{noti.type}}" ng-switch on="noti.image">' +
|
||||
'<i class="fi-{{noti.icon}}" ng-switch-when="false"></i>' +
|
||||
'<img ng-src="{{noti.image}}" ng-switch-default />' +
|
||||
'</div>' +
|
||||
'<div class="dr-notification-content">' +
|
||||
'<h3 class="dr-notification-title">{{noti.title}}</h3>' +
|
||||
'<p class="dr-notification-text">{{noti.content}}</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
}
|
||||
]).
|
||||
directive('notifications', function(notification, $compile) {
|
||||
/**
|
||||
*
|
||||
* It should also parse the arguments passed to it that specify
|
||||
* its position on the screen like "bottom right" and apply those
|
||||
* positions as a class to the container element
|
||||
*
|
||||
* Finally, the directive should have its own controller for
|
||||
* handling all of the notifications from the notification service
|
||||
*/
|
||||
var html =
|
||||
'<div class="dr-notification-wrapper" ng-repeat="noti in queue">' +
|
||||
'<div class="dr-notification-close-btn" ng-click="removeNotification(noti)">' +
|
||||
'<i class="fi-x"></i>' +
|
||||
'</div>' +
|
||||
'<div class="dr-notification">' +
|
||||
'<div class="dr-notification-image dr-notification-type-{{noti.type}}" ng-switch on="noti.image">' +
|
||||
'<i class="fi-{{noti.icon}}" ng-switch-when="false"></i>' +
|
||||
'<img ng-src="{{noti.image}}" ng-switch-default />' +
|
||||
'</div>' +
|
||||
'<div class="dr-notification-content">' +
|
||||
'<h3 class="dr-notification-title">{{noti.title}}</h3>' +
|
||||
'<p class="dr-notification-text">{{noti.content}}</p>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
|
||||
function link(scope, element, attrs){
|
||||
var position = attrs.notifications;
|
||||
position = position.split(' ');
|
||||
element.addClass('dr-notification-container');
|
||||
for(var i = 0; i < position.length ; i++){
|
||||
element.addClass(position[i]);
|
||||
}
|
||||
function link(scope, element, attrs) {
|
||||
var position = attrs.notifications;
|
||||
position = position.split(' ');
|
||||
element.addClass('dr-notification-container');
|
||||
for (var i = 0; i < position.length; i++) {
|
||||
element.addClass(position[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
template: html,
|
||||
link: link,
|
||||
controller: ['$scope', function NotificationsCtrl( $scope ){
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {},
|
||||
template: html,
|
||||
link: link,
|
||||
controller: ['$scope',
|
||||
function NotificationsCtrl($scope) {
|
||||
$scope.queue = notification.getQueue();
|
||||
|
||||
$scope.removeNotification = function(noti){
|
||||
$scope.removeNotification = function(noti) {
|
||||
$scope.queue.splice($scope.queue.indexOf(noti), 1);
|
||||
};
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,8 +38,12 @@ angular.module('copayApp.services').factory('Socket',
|
|||
var ret = {};
|
||||
|
||||
var addrList = listeners
|
||||
.filter(function(i) { return i.event != 'block'; })
|
||||
.map(function(i) {return i.event;});
|
||||
.filter(function(i) {
|
||||
return i.event != 'block';
|
||||
})
|
||||
.map(function(i) {
|
||||
return i.event;
|
||||
});
|
||||
|
||||
for (var i in addrList) {
|
||||
ret[addrList[i]] = 1;
|
||||
|
|
@ -47,7 +51,9 @@ angular.module('copayApp.services').factory('Socket',
|
|||
return ret;
|
||||
},
|
||||
isListeningBlocks: function() {
|
||||
return listeners.filter(function(i) { return i.event == 'block'; }).length > 0;
|
||||
return listeners.filter(function(i) {
|
||||
return i.event == 'block';
|
||||
}).length > 0;
|
||||
},
|
||||
emit: function(event, data, callback) {
|
||||
socket.emit(event, data, function() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').value('walletFactory', new copay.WalletFactory(config, copay.version));
|
||||
|
||||
|
|
|
|||
33
js/shell.js
33
js/shell.js
|
|
@ -1,23 +1,24 @@
|
|||
/*
|
||||
** copay-shell integration
|
||||
*/
|
||||
** copay-shell integration
|
||||
*/
|
||||
(function() {
|
||||
/*
|
||||
** This is a monkey patch for when Copay is running from
|
||||
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
|
||||
** receives context from Node.js, we get a `module.exports` contruct
|
||||
** available to us. Because of this, some libs (specifically Moment.js)
|
||||
** attempt to assume their CommonJS form and bind to this. This causes
|
||||
** there to be no references in the window to these libs, so let's trick
|
||||
** the renderer into thinking that we are _not_ in a CommonJS environment.
|
||||
*/
|
||||
if (typeof module !== 'undefined') module = { exports: null };
|
||||
** This is a monkey patch for when Copay is running from
|
||||
** within Copay-Shell (atom-shell). Since the renderer (the frontend)
|
||||
** receives context from Node.js, we get a `module.exports` contruct
|
||||
** available to us. Because of this, some libs (specifically Moment.js)
|
||||
** attempt to assume their CommonJS form and bind to this. This causes
|
||||
** there to be no references in the window to these libs, so let's trick
|
||||
** the renderer into thinking that we are _not_ in a CommonJS environment.
|
||||
*/
|
||||
if (typeof module !== 'undefined') module = {
|
||||
exports: null
|
||||
};
|
||||
|
||||
// are we running in copay shell?
|
||||
if (window.process && process.type === 'renderer') {
|
||||
window.cshell = initCopayShellBindings();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -35,12 +36,14 @@
|
|||
|
||||
function initCopayShellBindings() {
|
||||
|
||||
var ipc = require('ipc');
|
||||
var ipc = require('ipc');
|
||||
var clipb = require('clipboard');
|
||||
|
||||
// atom shell forces to implement the clipboard on our own - thanks obama.
|
||||
|
||||
Mousetrap.stopCallback = function() { return false };
|
||||
Mousetrap.stopCallback = function() {
|
||||
return false
|
||||
};
|
||||
|
||||
Mousetrap.bind('ctrl+c', function(e) {
|
||||
clipb.writeText(window.getSelection().toString());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue