rm focusedClient

This commit is contained in:
Matias Alejo Garcia 2016-08-22 14:42:43 -03:00
commit d4f39abc9a
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
9 changed files with 102 additions and 147 deletions

View file

@ -3,9 +3,9 @@
"//":" Modify it at app-template/",
"manifest_version": 2,
"name": "BitPay",
"description": "The BitPay Bitcoin Wallet",
"version": "0.2.0",
"name": "Copay",
"description": "A Secure Bitcoin Wallet",
"version": "2.5.0",
"permissions": [
"storage",
"unlimitedStorage",

View file

@ -3,10 +3,10 @@
"//":"PLEASE! Do not edit this file directly",
"//":" Modify it at app-template/",
"name": "bitpay",
"description": "The BitPay Bitcoin Wallet",
"name": "copay",
"description": "A Secure Bitcoin Wallet",
"author": "BitPay",
"version": "0.2.0",
"version": "2.5.0",
"keywords": [
"wallet",
"copay",

View file

@ -53,7 +53,6 @@ angular.module('copayApp.controllers').controller('copayersController',
};
$scope.deleteWallet = function() {
var wallet = profileService.focusedClient;
if ($scope.isCordova) {
navigator.notification.confirm(
delete_msg,

View file

@ -6,20 +6,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
self.glideraEnabled = configService.getSync().glidera.enabled;
// wallet list change
$rootScope.$on('Local/WalletListUpdated', function(event) {
self.walletSelection = false;
self.setWallets();
});
$rootScope.$on('Local/ColorUpdated', function(event) {
self.setWallets();
});
$rootScope.$on('Local/AliasUpdated', function(event) {
self.setWallets();
});
self.setWallets = function() {
$scope.wallets = profileService.getWallets();
};

View file

@ -24,9 +24,11 @@ angular.module('copayApp.directives')
var URI = bitcore.URI;
var Address = bitcore.Address
var validator = function(value) {
if (!profileService.focusedClient)
return;
var networkName = profileService.focusedClient.credentials.network;
var networkName = attrs.networkName;
if (!networkName)
throw 'validAddress should provide network name';
// Regular url
if (/^https?:\/\//.test(value)) {
ctrl.$setValidity('validAddress', true);

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout) {
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout, $rootScope) {
var root = {};
var defaultConfig = {
@ -115,6 +115,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
configCache.pushNotifications = defaultConfig.pushNotifications;
}
configCache.bwsFor = configCache.bwsFor || {};
configCache.colorFor = configCache.colorFor || {};
configCache.aliasFor = configCache.aliasFor || {};
} else {
configCache = lodash.clone(defaultConfig);
};
@ -158,6 +162,8 @@ angular.module('copayApp.services').factory('configService', function(storageSer
lodash.merge(config, oldOpts, newOpts);
configCache = config;
$rootScope.$emit('Local/SettingsUpdated');
storageService.storeConfig(JSON.stringify(config), cb);
});
};

View file

@ -16,118 +16,93 @@ angular.module('copayApp.services')
var BACKGROUND_UPDATE_PERIOD = 30;
root.profile = null;
root.focusedClient = null;
Object.defineProperty(root, "focusedClient", {
get: function () { throw "focusedClient is not used any more" },
set: function () { throw "focusedClient is not used any more" }
});
root.wallet = {}; // decorated version of client
root._setFocus = function(walletId, cb) {
$log.debug('Set focus:', walletId);
// Set local object
if (walletId)
root.focusedClient = root.wallet[walletId];
else
root.focusedClient = [];
if (lodash.isEmpty(root.focusedClient)) {
root.focusedClient = root.wallet[lodash.keys(root.wallet)[0]];
}
// Still nothing?
if (lodash.isEmpty(root.focusedClient)) {
$rootScope.$emit('Local/NoWallets');
} else {
$rootScope.$emit('Local/NewFocusedWallet');
// Set update period
lodash.each(root.wallet, function(client, id) {
client.setNotificationsInterval(BACKGROUND_UPDATE_PERIOD);
});
root.focusedClient.setNotificationsInterval(FOREGROUND_UPDATE_PERIOD);
}
return cb();
};
root.setAndStoreFocus = function(walletId, cb) {
root._setFocus(walletId, function() {
storageService.storeFocusedWalletId(walletId, cb);
});
};
root.setCustomBWSFlag = function(wallet) {
root.updateWalletSettings = function(wallet) {
var defaults = configService.getDefaults();
var config = configService.getSync();
wallet.usingCustomBWS = config.bwsFor && config.bwsFor[wallet.id] && (config.bwsFor[wallet.id] != defaults.bws.url);
};
wallet.usingCustomBWS = config.bwsFor[wallet.id] && (config.bwsFor[wallet.id] != defaults.bws.url);
wallet.name = config.aliasFor[wallet.id] || wallet.credentials.walletName;
wallet.color = config.colorFor[wallet.id] || '#4A90E2';
}
// Adds a wallet client to profileService
root.bindWalletClient = function(client, opts) {
root.bindWalletClient = function(wallet, opts) {
var opts = opts || {};
var walletId = client.credentials.walletId;
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
var walletId = wallet.credentials.walletId;
if ((root.wallet[walletId] && root.wallet[walletId].started) || opts.force) {
return false;
}
// INIT WALLET CLIENT VIEWMODEL
var c = client;
c.id = walletId;
c.started = true;
c.doNotVerifyPayPro = isChromeApp;
c.name = config.aliasFor[walletId] || client.credentials.walletName;
c.color = config.colorFor[walletId] || '#4A90E2';
c.network = client.credentials.network;
c.copayerId = client.credentials.copayerId;
c.m = client.credentials.m;
c.n = client.credentials.n;
// INIT WALLET VIEWMODEL
wallet.id = walletId;
wallet.started = true;
wallet.doNotVerifyPayPro = isChromeApp;
root.setCustomBWSFlag(c);
root.wallet[walletId] = c;
client.removeAllListeners();
client.on('report', function(n) {
wallet.network = wallet.credentials.network;
wallet.copayerId = wallet.credentials.copayerId;
wallet.m = wallet.credentials.m;
wallet.n = wallet.credentials.n;
root.updateWalletSettings(wallet);
root.wallet[walletId] = wallet;
wallet.removeAllListeners();
wallet.on('report', function(n) {
$log.info('BWC Report:' + n);
});
client.on('notification', function(n) {
wallet.on('notification', function(n) {
$log.debug('BWC Notification:', n);
$ionicHistory.clearCache();
notificationService.newBWCNotification(n,
walletId, client.credentials.walletName);
walletId, wallet.credentials.walletName);
if (root.focusedClient.credentials.walletId == walletId) {
$rootScope.$emit(n.type, n);
} else {
$rootScope.$apply();
}
$rootScope.$emit(n.type, n, wallet);
});
client.on('walletCompleted', function() {
wallet.on('walletCompleted', function() {
$log.debug('Wallet completed');
root.updateCredentials(JSON.parse(client.export()), function() {
root.updateCredentials(JSON.parse(wallet.export()), function() {
$rootScope.$emit('Local/WalletCompleted', walletId);
});
});
if (client.hasPrivKeyEncrypted() && !client.isPrivKeyEncrypted()) {
if (wallet.hasPrivKeyEncrypted() && !wallet.isPrivKeyEncrypted()) {
$log.warn('Auto locking unlocked wallet:' + walletId);
client.lock();
wallet.lock();
}
client.initialize({}, function(err) {
wallet.initialize({}, function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
return;
}
client.setNotificationsInterval(BACKGROUND_UPDATE_PERIOD);
wallet.setNotificationsInterval(BACKGROUND_UPDATE_PERIOD);
});
$rootScope.$on('Local/SettingsUpdated', function(e, walletId) {
if (!walletId || walletId == wallet.id) {
$log.debug('Updating settings for wallet:' + wallet.id);
root.updateWalletSettings(wallet);
}
});
return true;
@ -178,8 +153,7 @@ angular.module('copayApp.services')
if (!credentials.walletId || !credentials.m)
return cb('bindWallet should receive credentials JSON');
// Create the client
// Create the client
var getBWSURL = function(walletId) {
var config = configService.getSync();
var defaults = configService.getDefaults();
@ -228,24 +202,19 @@ angular.module('copayApp.services')
}
bindWallets(function() {
storageService.getFocusedWalletId(function(err, focusedWalletId) {
if (err) return cb(err);
root._setFocus(focusedWalletId, function() {
if (usePushNotifications)
root.pushNotificationsInit();
if (usePushNotifications)
root.pushNotificationsInit();
root.isBound = true;
$rootScope.$emit('Local/ProfileBound');
root.isBound = true;
$rootScope.$emit('Local/ProfileBound');
root.isDisclaimerAccepted(function(val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}
$rootScope.$emit('disclaimerAccepted');
return cb();
});
});
})
root.isDisclaimerAccepted(function(val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}
$rootScope.$emit('disclaimerAccepted');
return cb();
});
});
});
};
@ -267,7 +236,6 @@ angular.module('copayApp.services')
});
if (!walletFound) return $log.debug('Wallet not found');
root.setAndStoreFocus(walletFound.id, function() {});
}, 100);
}
});
@ -463,8 +431,6 @@ angular.module('copayApp.services')
root.profile.deleteWallet(walletId);
delete root.wallet[walletId];
root.focusedClient = null;
storageService.removeAllWalletData(walletId, function(err) {
if (err) $log.warn(err);
@ -474,11 +440,9 @@ angular.module('copayApp.services')
$timeout(function() {
$rootScope.$emit('Local/WalletListUpdated');
root.setAndStoreFocus(null, function() {
storageService.storeProfile(root.profile, function(err) {
if (err) return cb(err);
return cb();
});
storageService.storeProfile(root.profile, function(err) {
if (err) return cb(err);
return cb();
});
});
};
@ -535,13 +499,11 @@ angular.module('copayApp.services')
};
saveBwsUrl(function() {
root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) {
var config = configService.getSync();
if (config.pushNotifications.enabled)
pushNotificationsService.enableNotifications(root.wallet);
return cb(err, client);
});
storageService.storeProfile(root.profile, function(err) {
var config = configService.getSync();
if (config.pushNotifications.enabled)
pushNotificationsService.enableNotifications(root.wallet);
return cb(err, client);
});
});
};

View file

@ -1,9 +1,9 @@
[Desktop Entry]
Type=Application
Version=0.2.0
Name=BitPay
Comment=The BitPay Bitcoin Wallet
Exec=bitpay
Version=2.5.0
Name=Copay
Comment=A Secure Bitcoin Wallet
Exec=copay
Icon=icon-256.png
Terminal=false
Categories=Finance

View file

@ -1,10 +1,10 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "bitpay"
#define MyAppVersion "0.2.0"
#define MyAppName "copay"
#define MyAppVersion "2.5.0"
#define MyAppPublisher "BitPay"
#define MyAppURL "https://bitpay.com"
#define MyAppURL "https://copay.io"
#define MyAppExeName "*NAMECASENOSPACE.exe"
[Setup]
@ -18,7 +18,7 @@ AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=BitPay-win
OutputBaseFilename=Copay-win
OutputDir=./
Compression=lzma
SolidCompression=yes
@ -32,8 +32,8 @@ Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "BitPay\win64\bitpay.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "BitPay\win64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "Copay\win64\copay.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "Copay\win64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "../public/img/icons/favicon.ico"; DestDir: "{app}"; DestName: "icon.ico"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
@ -50,8 +50,8 @@ Root: HKCR; Subkey: "bitcoin"; ValueType: "string"; ValueName: "URL Protocol"; V
Root: HKCR; Subkey: "bitcoin\DefaultIcon"; ValueType: "string"; ValueData: "{app}\{#MyAppExeName},0"
Root: HKCR; Subkey: "bitcoin\shell\open\command"; ValueType: "string"; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKCR; Subkey: "bitpay"; ValueType: "string"; ValueData: "URL:BitPay Custom Protocol"; Flags: uninsdeletekey
Root: HKCR; Subkey: "bitpay"; ValueType: "string"; ValueName: "URL Protocol"; ValueData: ""
Root: HKCR; Subkey: "bitpay\DefaultIcon"; ValueType: "string"; ValueData: "{app}\{#MyAppExeName},0"
Root: HKCR; Subkey: "bitpay\shell\open\command"; ValueType: "string"; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKCR; Subkey: "copay"; ValueType: "string"; ValueData: "URL:Copay Custom Protocol"; Flags: uninsdeletekey
Root: HKCR; Subkey: "copay"; ValueType: "string"; ValueName: "URL Protocol"; ValueData: ""
Root: HKCR; Subkey: "copay\DefaultIcon"; ValueType: "string"; ValueData: "{app}\{#MyAppExeName},0"
Root: HKCR; Subkey: "copay\shell\open\command"; ValueType: "string"; ValueData: """{app}\{#MyAppExeName}"" ""%1"""