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/", "//":" Modify it at app-template/",
"manifest_version": 2, "manifest_version": 2,
"name": "BitPay", "name": "Copay",
"description": "The BitPay Bitcoin Wallet", "description": "A Secure Bitcoin Wallet",
"version": "0.2.0", "version": "2.5.0",
"permissions": [ "permissions": [
"storage", "storage",
"unlimitedStorage", "unlimitedStorage",

View file

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

View file

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

View file

@ -6,20 +6,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
self.glideraEnabled = configService.getSync().glidera.enabled; 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() { self.setWallets = function() {
$scope.wallets = profileService.getWallets(); $scope.wallets = profileService.getWallets();
}; };

View file

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

View file

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

View file

@ -16,118 +16,93 @@ angular.module('copayApp.services')
var BACKGROUND_UPDATE_PERIOD = 30; var BACKGROUND_UPDATE_PERIOD = 30;
root.profile = null; 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.wallet = {}; // decorated version of client
root._setFocus = function(walletId, cb) { root.updateWalletSettings = function(wallet) {
$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) {
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
var config = configService.getSync(); 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 // Adds a wallet client to profileService
root.bindWalletClient = function(client, opts) { root.bindWalletClient = function(wallet, opts) {
var opts = opts || {}; var opts = opts || {};
var walletId = client.credentials.walletId; var walletId = wallet.credentials.walletId;
var config = configService.getSync();
config.colorFor = config.colorFor || {};
config.aliasFor = config.aliasFor || {};
if ((root.wallet[walletId] && root.wallet[walletId].started) || opts.force) { if ((root.wallet[walletId] && root.wallet[walletId].started) || opts.force) {
return false; return false;
} }
// INIT WALLET CLIENT VIEWMODEL // INIT WALLET VIEWMODEL
var c = client; wallet.id = walletId;
c.id = walletId; wallet.started = true;
c.started = true; wallet.doNotVerifyPayPro = isChromeApp;
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;
root.setCustomBWSFlag(c);
root.wallet[walletId] = c;
client.removeAllListeners(); wallet.network = wallet.credentials.network;
client.on('report', function(n) { 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); $log.info('BWC Report:' + n);
}); });
client.on('notification', function(n) { wallet.on('notification', function(n) {
$log.debug('BWC Notification:', n); $log.debug('BWC Notification:', n);
$ionicHistory.clearCache(); $ionicHistory.clearCache();
notificationService.newBWCNotification(n, notificationService.newBWCNotification(n,
walletId, client.credentials.walletName); walletId, wallet.credentials.walletName);
if (root.focusedClient.credentials.walletId == walletId) { $rootScope.$emit(n.type, n, wallet);
$rootScope.$emit(n.type, n);
} else {
$rootScope.$apply();
}
}); });
client.on('walletCompleted', function() { wallet.on('walletCompleted', function() {
$log.debug('Wallet completed'); $log.debug('Wallet completed');
root.updateCredentials(JSON.parse(client.export()), function() { root.updateCredentials(JSON.parse(wallet.export()), function() {
$rootScope.$emit('Local/WalletCompleted', walletId); $rootScope.$emit('Local/WalletCompleted', walletId);
}); });
}); });
if (client.hasPrivKeyEncrypted() && !client.isPrivKeyEncrypted()) { if (wallet.hasPrivKeyEncrypted() && !wallet.isPrivKeyEncrypted()) {
$log.warn('Auto locking unlocked wallet:' + walletId); $log.warn('Auto locking unlocked wallet:' + walletId);
client.lock(); wallet.lock();
} }
client.initialize({}, function(err) { wallet.initialize({}, function(err) {
if (err) { if (err) {
$log.error('Could not init notifications err:', err); $log.error('Could not init notifications err:', err);
return; 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; return true;
@ -178,8 +153,7 @@ angular.module('copayApp.services')
if (!credentials.walletId || !credentials.m) if (!credentials.walletId || !credentials.m)
return cb('bindWallet should receive credentials JSON'); return cb('bindWallet should receive credentials JSON');
// Create the client
// Create the client
var getBWSURL = function(walletId) { var getBWSURL = function(walletId) {
var config = configService.getSync(); var config = configService.getSync();
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
@ -228,24 +202,19 @@ angular.module('copayApp.services')
} }
bindWallets(function() { bindWallets(function() {
storageService.getFocusedWalletId(function(err, focusedWalletId) { if (usePushNotifications)
if (err) return cb(err); root.pushNotificationsInit();
root._setFocus(focusedWalletId, function() {
if (usePushNotifications)
root.pushNotificationsInit();
root.isBound = true; root.isBound = true;
$rootScope.$emit('Local/ProfileBound'); $rootScope.$emit('Local/ProfileBound');
root.isDisclaimerAccepted(function(val) { root.isDisclaimerAccepted(function(val) {
if (!val) { if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
} }
$rootScope.$emit('disclaimerAccepted'); $rootScope.$emit('disclaimerAccepted');
return cb(); return cb();
}); });
});
})
}); });
}); });
}; };
@ -267,7 +236,6 @@ angular.module('copayApp.services')
}); });
if (!walletFound) return $log.debug('Wallet not found'); if (!walletFound) return $log.debug('Wallet not found');
root.setAndStoreFocus(walletFound.id, function() {});
}, 100); }, 100);
} }
}); });
@ -463,8 +431,6 @@ angular.module('copayApp.services')
root.profile.deleteWallet(walletId); root.profile.deleteWallet(walletId);
delete root.wallet[walletId]; delete root.wallet[walletId];
root.focusedClient = null;
storageService.removeAllWalletData(walletId, function(err) { storageService.removeAllWalletData(walletId, function(err) {
if (err) $log.warn(err); if (err) $log.warn(err);
@ -474,11 +440,9 @@ angular.module('copayApp.services')
$timeout(function() { $timeout(function() {
$rootScope.$emit('Local/WalletListUpdated'); $rootScope.$emit('Local/WalletListUpdated');
root.setAndStoreFocus(null, function() { storageService.storeProfile(root.profile, function(err) {
storageService.storeProfile(root.profile, function(err) { if (err) return cb(err);
if (err) return cb(err); return cb();
return cb();
});
}); });
}); });
}; };
@ -535,13 +499,11 @@ angular.module('copayApp.services')
}; };
saveBwsUrl(function() { saveBwsUrl(function() {
root.setAndStoreFocus(walletId, function() { storageService.storeProfile(root.profile, function(err) {
storageService.storeProfile(root.profile, function(err) { var config = configService.getSync();
var config = configService.getSync(); if (config.pushNotifications.enabled)
if (config.pushNotifications.enabled) pushNotificationsService.enableNotifications(root.wallet);
pushNotificationsService.enableNotifications(root.wallet); return cb(err, client);
return cb(err, client);
});
}); });
}); });
}; };

View file

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

View file

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