mv blockUx to wds

reset index scope on change wallet

rm wds

rm newTx, better txhistory update

better history display while sync

show first TX will syncing from 0

add new tx anim

WIP mobile

fix mobile

fix mobile 2

keep vanilla state in walletHome
This commit is contained in:
Matias Alejo Garcia 2016-02-18 17:16:07 -03:00
parent 13996dc26a
commit e02d4cb00b
6 changed files with 226 additions and 207 deletions

View File

@ -13,7 +13,7 @@
"angular-gettext": "2.1.2", "angular-gettext": "2.1.2",
"angular-moment": "0.10.1", "angular-moment": "0.10.1",
"angular-qrcode": "monospaced/angular-qrcode#~6.0.3", "angular-qrcode": "monospaced/angular-qrcode#~6.0.3",
"angular-ui-router": "0.2.15", "angular-ui-router": "0.2.18",
"angular-ui-switch": "0.1.1", "angular-ui-switch": "0.1.1",
"animate.css": "3.4.0", "animate.css": "3.4.0",
"foundation": "5.5.2", "foundation": "5.5.2",

View File

@ -16,5 +16,5 @@ src="img/icon-ledger-white.svg">
<img style="height:0.6em; margin-right: 1px;" ng-show="index.usingCustomBWS" src="img/icon-bws-white.svg"> <img style="height:0.6em; margin-right: 1px;" ng-show="index.usingCustomBWS" src="img/icon-bws-white.svg">
<img style="height:0.6em" class="animated flash infinite" ng-show="index.loadingWallet || <img style="height:0.6em" class="animated flash infinite" ng-show="index.loadingWallet ||
index.updatingTxHistory[index.walletId]" src="img/icon-sync-white.svg"> index.updatingTxHistory" src="img/icon-sync-white.svg">

View File

@ -154,36 +154,34 @@
<div <div
class="oh pr m20t text-gray size-12 text-center" class="oh pr m20t text-gray size-12 text-center"
ng-show="!index.loadingWallet && !index.txHistory[0] && !index.updatingTxHistory[index.walletId] && ng-show="!index.loadingWallet && !index.txHistory[0] && !index.updatingTxHistory && !index.txHistoryError && !index.updateError" translate>
!index.txHistoryError && !index.updateError" translate>
No transactions yet No transactions yet
</div> </div>
<div ng-show="index.updatingTxHistory[index.walletId]
&& ( (index.txProgress > 6 && !index.txHistory[0]) || (index.txProgress > 50 ) )">
<div class="row p20 text-center">
<div class="columns large-12 medium-12 small-12 m10b">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
<div class="size-12 text-gray m20t">
<div translate>{{index.txProgress}} transactions downloaded</div>
<div translate>Updating transaction history. Please stand by.</div>
</div>
</div>
</div>
<div class="oh pr" ng-show="index.txHistory[0]"> <div class="oh pr" ng-show="index.txHistory[0] || index.txProgress > 5">
<h4 class="title m0"> <h4 class="title m0">
<span translate>Activity</span> <span translate>Activity</span>
</h4> </h4>
<div ng-show="index.updatingTxHistory && index.txProgress > 5">
<div class="row p20 text-center">
<div class="columns large-12 medium-12 small-12 m10b">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
<div class="size-12 text-gray m20t">
<div translate>{{index.txProgress}} transactions downloaded</div>
<div translate>Updating transaction history. Please stand by.</div>
</div>
</div>
</div>
<div ng-if="index.txHistory[0] && index.updatingTxHistory[index.walletId] && index.newTx" class="row collapse last-transactions-content animated fadeInDown"> <div ng-if="index.txHistory[0] && index.updatingTxHistory && index.newTx" class="row collapse last-transactions-content animated fadeInDown">
<div class="large-6 medium-6 small-6 columns size-14"> <div class="large-6 medium-6 small-6 columns size-14">
<div class="m10r left"> <div class="m10r left">
<img src="img/icon-new.svg" width="40"> <img src="img/icon-new.svg" width="40">
@ -194,11 +192,10 @@
<div style="margin-top:5px; background:#eee; width: 6em; margin-left: 52px; line-height:0.6em"> <div style="margin-top:5px; background:#eee; width: 6em; margin-left: 52px; line-height:0.6em">
<span>&nbsp;</span> <span>&nbsp;</span>
</div> </div>
</div>
</div>
</div> </div>
<div ng-repeat="btx in index.txHistory" <div ng-repeat="btx in index.txHistory track by btx.txid"
fast-click callback-fn="home.openTxModal(btx)" fast-click callback-fn="home.openTxModal(btx)"
class="row collapse last-transactions-content"> class="row collapse last-transactions-content">
<div class="large-6 medium-6 small-6 columns size-14"> <div class="large-6 medium-6 small-6 columns size-14">
@ -302,8 +299,8 @@
<!-- Address--> <!-- Address-->
<div class="large-12 columns"> <div class="large-12 columns">
<h2 class="text-center m10t" translate>My Bitcoin address</h2> <h2 class="text-center m10t" translate>My Bitcoin address</h2>
<div class="text-center" ng-click="home.copyToClipboard(home.getWalletData('addr'))" ng-show="home.getWalletData('addr') || home.generatingAddress"> <div class="text-center" ng-click="home.copyToClipboard(home.addr)" ng-show="home.addr || home.generatingAddress">
<qrcode size="220" data="bitcoin:{{home.getWalletData('addr')}}"></qrcode> <qrcode size="220" data="bitcoin:{{home.addr}}"></qrcode>
<div ng-show="home.generatingAddress" style="position:relative; top:-226px; height:0px"> <div ng-show="home.generatingAddress" style="position:relative; top:-226px; height:0px">
<div style="height:220px; width:220px; margin:auto; background: white"> <div style="height:220px; width:220px; margin:auto; background: white">
<div class="spinner" style="margin-top:85px"> <div class="spinner" style="margin-top:85px">
@ -317,29 +314,29 @@
</div> </div>
<div class="m10t" > <div class="m10t" >
<h4 ng-class="{'enable_text_select': !index.isCordova}" class="size-12"> <h4 ng-class="{'enable_text_select': !index.isCordova}" class="size-12">
{{home.generatingAddress ? '...' : home.getWalletData('addr')}} {{home.generatingAddress ? '...' : home.addr}}
</h4> </h4>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row m20t"> <div class="row m20t">
<div class="small-12 columns" ng-show="index.isCordova && home.getWalletData('addr')"> <div class="small-12 columns" ng-show="index.isCordova && home.addr">
<button class="button outline light-gray small round expand" <button class="button outline light-gray small round expand"
ng-click="home.shareAddress(home.getWalletData('addr'))" ng-click="home.shareAddress(home.addr)"
ng-disabled="home.generatingAddress"> ng-disabled="home.generatingAddress">
<span translate>Share address</span> <span translate>Share address</span>
</button> </button>
</div> </div>
<div class="small-12 columns" ng-show="home.getWalletData('addr')"> <div class="small-12 columns" ng-show="home.addr">
<button class="button expand small round m10b" ng-click="home.openCustomizedAmountModal(home.getWalletData('addr'))" <button class="button expand small round m10b" ng-click="home.openCustomizedAmountModal(home.addr)"
ng-style="{'background-color':index.backgroundColor}" ng-style="{'background-color':index.backgroundColor}"
ng-disabled="home.generatingAddress"> ng-disabled="home.generatingAddress">
<span translate>Request a specific amount</span> <span translate>Request a specific amount</span>
</button> </button>
</div> </div>
</div> </div>
<div class="row m10t" ng-show="home.getWalletData('addr')" > <div class="row m10t" ng-show="home.addr" >
<div class="large-12 columns"> <div class="large-12 columns">
<div class="line-t size-10 text-gray m10b p10t"> <div class="line-t size-10 text-gray m10b p10t">
<span translate> Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them.</span> <span translate> Share this wallet address to receive payments. To protect your privacy, new addresses are generated automatically once you use them.</span>
@ -361,8 +358,9 @@
<div class="pr p25b"> <div class="pr p25b">
<h4 class="title m0"> <h4 class="title m0">
<available-balance></available-balance> <available-balance></available-balance>
<a ng-show="!home.lockedCurrentFeePerKb && index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount" <a
ng-click="home.sendAll()" ng-show="!home.lockedCurrentFeePerKb && index.feeToSendMaxStr && index.availableBalanceSat > 0 && !home.blockUx && !home.lockAmount"
ng-click="home.sendAll()"
translate> Send All translate> Send All
</a> </a>
<div ng-show="!home.paymentExpired && home._paypro"> <div ng-show="!home.paymentExpired && home._paypro">

View File

@ -4,25 +4,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var self = this; var self = this;
var SOFT_CONFIRMATION_LIMIT = 12; var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors(); var errors = bwcService.getErrors();
self.isCordova = isCordova; var historyUpdateInProgress = {};
self.isChromeApp = isChromeApp;
self.isSafari = isMobile.Safari();
self.isWindowsPhoneApp = isMobile.Windows() && isCordova;
self.usePushNotifications = self.isCordova && !isMobile.Windows();
self.onGoingProcess = {};
self.historyShowLimit = 10;
self.updatingTxHistory = {};
self.prevState = 'walletHome';
function strip(number) { var ret = {};
return (parseFloat(number.toPrecision(12))); ret.isCordova = isCordova;
}; ret.isChromeApp = isChromeApp;
ret.isSafari = isMobile.Safari();
ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
ret.usePushNotifications = ret.isCordova && !isMobile.Windows();
ret.onGoingProcess = {};
ret.historyShowLimit = 10;
ret.prevState = 'walletHome';
self.goHome = function() { ret.menu = [{
go.walletHome();
};
self.menu = [{
'title': gettext('Receive'), 'title': gettext('Receive'),
'icon': { 'icon': {
false: 'icon-receive', false: 'icon-receive',
@ -45,14 +39,23 @@ angular.module('copayApp.controllers').controller('indexController', function($r
'link': 'send' 'link': 'send'
}]; }];
self.addonViews = addonManager.addonViews(); ret.addonViews = addonManager.addonViews();
self.menu = self.menu.concat(addonManager.addonMenuItems()); ret.menu = ret.menu.concat(addonManager.addonMenuItems());
self.menuItemSize = self.menu.length > 4 ? 2 : 4; ret.menuItemSize = ret.menu.length > 4 ? 2 : 4;
self.txTemplateUrl = addonManager.txTemplateUrl() || 'views/includes/transaction.html'; ret.txTemplateUrl = addonManager.txTemplateUrl() || 'views/includes/transaction.html';
self.tab = 'walletHome'; ret.tab = 'walletHome';
ret.feeOpts = feeService.feeOpts;
var vanillaScope = ret;
self.feeOpts = feeService.feeOpts;
function strip(number) {
return (parseFloat(number.toPrecision(12)));
};
self.goHome = function() {
go.walletHome();
};
self.setOngoingProcess = function(processName, isOn) { self.setOngoingProcess = function(processName, isOn) {
$log.debug('onGoingProcess', processName, isOn); $log.debug('onGoingProcess', processName, isOn);
@ -72,35 +75,31 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.cleanInstance = function() {
$log.debug('Cleaning Index Instance');
lodash.each(self, function(v, k) {
if (lodash.isFunction(v)) return;
if (vanillaScope[k]) return;
// This are to prevent flicker in mobile:
if (k == 'hasProfile') return;
if (k == 'noFocusedWallet') return;
if (k == 'backgroundColor') return;
if (k == 'loadingWallet') {
self.loadingWallet = true;
return;
}
delete self[k];
});
};
self.setFocusedWallet = function() { self.setFocusedWallet = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc) return; if (!fc) return;
// loading full wallet self.cleanInstance();
self.loadingWallet = true; self.loadingWallet = true;
// Clean status
self.totalBalanceSat = null;
self.lockedBalanceSat = null;
self.availableBalanceSat = null;
self.pendingAmount = null;
self.spendUnconfirmed = null;
self.totalBalanceStr = null;
self.availableBalanceStr = null;
self.lockedBalanceStr = null;
self.alternativeBalanceAvailable = false;
self.totalBalanceAlternative = null;
self.currentFeeLevel = null;
self.notAuthorized = false;
self.txHistory = [];
self.completeHistory = [];
self.txProgress = 0;
self.historyShowShowAll = false;
self.balanceByAddress = null;
self.pendingTxProposalsCountForUs = null;
self.setSpendUnconfirmed(); self.setSpendUnconfirmed();
$timeout(function() { $timeout(function() {
@ -138,6 +137,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera(); self.initGlidera();
self.setCustomBWSFlag(); self.setCustomBWSFlag();
$rootScope.$apply();
if (fc.isPrivKeyExternal()) { if (fc.isPrivKeyExternal()) {
self.needsBackup = false; self.needsBackup = false;
self.openWallet(); self.openWallet();
@ -373,7 +374,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
// Notify external addons or plugins // Notify external addons or plugins
$rootScope.$emit('Local/BalanceUpdated', walletStatus.balance); $rootScope.$emit('Local/BalanceUpdated', walletStatus.balance);
$rootScope.$apply(); $rootScope.$apply();
if (opts.triggerTxUpdate) { if (opts.triggerTxUpdate) {
@ -668,7 +668,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
addressService.isUsed(self.walletId, balance.byAddress, function(err, used) { addressService.isUsed(self.walletId, balance.byAddress, function(err, used) {
if (used) { if (used) {
$log.debug('Address used. Creating new'); $log.debug('Address used. Creating new');
$rootScope.$emit('Local/NeedNewAddress'); $rootScope.$emit('Local/AddressIsUsed');
} }
}); });
@ -693,7 +693,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} }
}; };
this.csvHistory = function() { self.csvHistory = function() {
function saveFile(name, data) { function saveFile(name, data) {
var chooser = document.querySelector(name); var chooser = document.querySelector(name);
@ -768,82 +768,82 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$log.debug('Generating CSV from History'); $log.debug('Generating CSV from History');
self.setOngoingProcess('generatingCSV', true); self.setOngoingProcess('generatingCSV', true);
getHistory(function(err, txs) { getHistory(function(err, txs) {
self.setOngoingProcess('generatingCSV', false); self.setOngoingProcess('generatingCSV', false);
if (err) { if (err) {
self.handleError(err); self.handleError(err);
} else { } else {
$log.debug('Wallet Transaction History:', txs); $log.debug('Wallet Transaction History:', txs);
self.satToUnit = 1 / self.unitToSatoshi; self.satToUnit = 1 / self.unitToSatoshi;
var data = txs; var data = txs;
var satToBtc = 1 / 100000000; var satToBtc = 1 / 100000000;
self.csvContent = []; self.csvContent = [];
self.csvFilename = 'Copay-' + (self.alias || self.walletName) + '.csv'; self.csvFilename = 'Copay-' + (self.alias || self.walletName) + '.csv';
self.csvHeader = ['Date', 'Destination', 'Note', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers']; self.csvHeader = ['Date', 'Destination', 'Note', 'Amount', 'Currency', 'Txid', 'Creator', 'Copayers'];
var _amount, _note, _copayers, _creator; var _amount, _note, _copayers, _creator;
data.forEach(function(it, index) { data.forEach(function(it, index) {
var amount = it.amount; var amount = it.amount;
if (it.action == 'moved') if (it.action == 'moved')
amount = 0; amount = 0;
_copayers = ''; _copayers = '';
_creator = ''; _creator = '';
if (it.actions && it.actions.length > 1) { if (it.actions && it.actions.length > 1) {
for (var i = 0; i < it.actions.length; i++) { for (var i = 0; i < it.actions.length; i++) {
_copayers += it.actions[i].copayerName + ':' + it.actions[i].type + ' - '; _copayers += it.actions[i].copayerName + ':' + it.actions[i].type + ' - ';
}
_creator = (it.creatorName && it.creatorName != 'undefined') ? it.creatorName : '';
} }
_copayers = formatString(_copayers); _creator = (it.creatorName && it.creatorName != 'undefined') ? it.creatorName : '';
_creator = formatString(_creator); }
_amount = (it.action == 'sent' ? '-' : '') + (amount * satToBtc).toFixed(8); _copayers = formatString(_copayers);
_note = formatString((it.message ? it.message : '')); _creator = formatString(_creator);
_amount = (it.action == 'sent' ? '-' : '') + (amount * satToBtc).toFixed(8);
_note = formatString((it.message ? it.message : ''));
if (it.action == 'moved') if (it.action == 'moved')
_note += ' Moved:' + (it.amount * satToBtc).toFixed(8) _note += ' Moved:' + (it.amount * satToBtc).toFixed(8)
self.csvContent.push({
'Date': formatDate(it.time * 1000),
'Destination': formatString(it.addressTo),
'Note': _note,
'Amount': _amount,
'Currency': 'BTC',
'Txid': it.txid,
'Creator': _creator,
'Copayers': _copayers
});
if (it.fees && (it.action == 'moved' || it.action == 'sent')) {
var _fee = (it.fees * satToBtc).toFixed(8)
self.csvContent.push({ self.csvContent.push({
'Date': formatDate(it.time * 1000), 'Date': formatDate(it.time * 1000),
'Destination': formatString(it.addressTo), 'Destination': 'Bitcoin Network Fees',
'Note': _note, 'Note': '',
'Amount': _amount, 'Amount': '-' + _fee,
'Currency': 'BTC', 'Currency': 'BTC',
'Txid': it.txid, 'Txid': '',
'Creator': _creator, 'Creator': '',
'Copayers': _copayers 'Copayers': ''
}); });
}
if (it.fees && (it.action == 'moved' || it.action == 'sent')) { });
var _fee = (it.fees * satToBtc).toFixed(8) return;
self.csvContent.push({ }
'Date': formatDate(it.time * 1000), });
'Destination': 'Bitcoin Network Fees',
'Note': '',
'Amount': '-'+_fee,
'Currency': 'BTC',
'Txid': '',
'Creator': '',
'Copayers': ''
});
}
});
return;
}
});
}; };
self.removeSoftConfirmedTx = function(txs) { self.removeSoftConfirmedTx = function(txs) {
return lodash.map(txs, function(tx) { return lodash.filter(txs, function(tx) {
if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT) if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT)
return tx; return tx;
}); });
} }
self.getConfirmedTxs = function(walletId, cb) { self.getSavedTxs = function(walletId, cb) {
storageService.getTxHistory(walletId, function(err, txs) { storageService.getTxHistory(walletId, function(err, txs) {
if (err) return cb(err); if (err) return cb(err);
@ -859,12 +859,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
} catch (ex) { } catch (ex) {
$log.warn(ex); $log.warn(ex);
} }
return cb(null, lodash.compact(self.removeSoftConfirmedTx(localTxs))); return cb(null, lodash.compact(localTxs));
}); });
} }
self.updateLocalTxHistory = function(client, cb) { self.updateLocalTxHistory = function(client, cb) {
var requestLimit = 5; var FIRST_LIMIT = 5;
var LIMIT = 50;
var requestLimit = FIRST_LIMIT;
var walletId = client.credentials.walletId; var walletId = client.credentials.walletId;
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
@ -886,12 +888,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.getConfirmedTxs(walletId, function(err, txsFromLocal) { self.getSavedTxs(walletId, function(err, txsFromLocal) {
if (err) return cb(err); if (err) return cb(err);
var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null;
fixTxsUnit(txsFromLocal); fixTxsUnit(txsFromLocal);
var confirmedTxs = self.removeSoftConfirmedTx(txsFromLocal);
var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null;
// First update
if (walletId == profileService.focusedClient.credentials.walletId) {
self.completeHistory = txsFromLocal;
self.setCompactTxHistory();
}
function getNewTxs(newTxs, skip, i_cb) { function getNewTxs(newTxs, skip, i_cb) {
self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
if (err) return i_cb(err); if (err) return i_cb(err);
@ -907,30 +918,41 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return i_cb(null, newTxs); return i_cb(null, newTxs);
} }
if (walletId == profileService.focusedClient.credentials.walletId) requestLimit = LIMIT;
self.txProgress = newTxs.length;
$timeout(function() {
$rootScope.$apply();
});
requestLimit = 50;
getNewTxs(newTxs, skip, i_cb); getNewTxs(newTxs, skip, i_cb);
// Progress update
if (walletId == profileService.focusedClient.credentials.walletId) {
self.txProgress = newTxs.length;
if (self.completeHistory < FIRST_LIMIT && txsFromLocal.length == 0) {
$log.debug('Showing partial history');
var newHistory = self.processNewTxs(newTxs);
newHistory = lodash.compact(newHistory.concat(confirmedTxs));
self.completeHistory = newHistory;
self.setCompactTxHistory();
}
$timeout(function() {
$rootScope.$apply();
});
}
}); });
}; };
getNewTxs([], 0, function(err, txs) { getNewTxs([], 0, function(err, txs) {
if (err) return cb(err); if (err) return cb(err);
var newHistory = lodash.compact(txs.concat(txsFromLocal)); var newHistory = lodash.compact(txs.concat(confirmedTxs));
$log.debug('Tx History synced. Total Txs: ' + newHistory.length); $log.debug('Tx History synced. Total Txs: ' + newHistory.length);
// Final update
if (walletId == profileService.focusedClient.credentials.walletId) { if (walletId == profileService.focusedClient.credentials.walletId) {
self.completeHistory = newHistory; self.completeHistory = newHistory;
self.txHistory = newHistory.slice(0, self.historyShowLimit); self.setCompactTxHistory();
self.historyShowShowAll = newHistory.length > self.historyShowLimit;
} }
return storageService.setTxHistory(JSON.stringify(newHistory), walletId, function() { return storageService.setTxHistory(JSON.stringify(newHistory), walletId, function() {
$log.debug('Tx History saved.');
return cb(); return cb();
}); });
}); });
@ -974,15 +996,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (!fc) return; if (!fc) return;
var walletId = fc.credentials.walletId; var walletId = fc.credentials.walletId;
if (!fc.isComplete() || self.updatingTxHistory[walletId]) return; if (!fc.isComplete() || historyUpdateInProgress[walletId]) {
self.updatingTxHistory = historyUpdateInProgress[walletId];
return;
}
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
self.txHistoryError = false; self.txHistoryError = false;
self.updatingTxHistory[walletId] = true; historyUpdateInProgress[walletId] = self.updatingTxHistory = true;
$timeout(function() { $timeout(function() {
self.updateLocalTxHistory(fc, function(err) { self.updateLocalTxHistory(fc, function(err) {
self.updatingTxHistory[walletId] = false; historyUpdateInProgress[walletId] = self.updatingTxHistory = false;
self.loadingWallet = false; self.loadingWallet = false;
self.txProgress = 0; self.txProgress = 0;
if (err) if (err)
@ -999,8 +1024,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setCompactTxHistory = function() { self.setCompactTxHistory = function() {
self.txHistory = self.completeHistory.slice(0, self.historyShowLimit); self.txHistory = self.completeHistory.slice(0, self.historyShowLimit);
if (self.completeHistory.length > self.historyShowLimit) self.historyShowShowAll = self.completeHistory.length > self.historyShowLimit;
self.historyShowShowAll = true;
}; };
self.debounceUpdateHistory = lodash.debounce(function() { self.debounceUpdateHistory = lodash.debounce(function() {
@ -1470,7 +1494,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) { $rootScope.$on('Local/NeedsConfirmation', function(event, txp, cb) {
self.confirmTx = { self.confirmTx = {
txp : txFormatService.processTx(txp), txp: txFormatService.processTx(txp),
callback: function(accept) { callback: function(accept) {
self.confirmTx = null; self.confirmTx = null;
return cb(accept); return cb(accept);
@ -1509,4 +1533,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}); });
/* Start setup */
lodash.assign(self, vanillaScope);
}); });

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txService) { angular.module('copayApp.controllers').controller('walletHomeController', function($scope, $rootScope, $interval, $timeout, $filter, $modal, $log, notification, txStatus, isCordova, isMobile, profileService, lodash, configService, rateService, storageService, bitcore, isChromeApp, gettext, gettextCatalog, nodeWebkit, addressService, ledger, bwsError, confirmDialog, txFormatService, animationService, addressbookService, go, feeService, txService){
var self = this; var self = this;
window.ignoreMobilePause = false; window.ignoreMobilePause = false;
@ -8,25 +8,23 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$rootScope.wpInputFocused = false; $rootScope.wpInputFocused = false;
var config = configService.getSync(); var config = configService.getSync();
var configWallet = config.wallet; var configWallet = config.wallet;
// INIT
var walletSettings = configWallet.settings; var walletSettings = configWallet.settings;
this.unitToSatoshi = walletSettings.unitToSatoshi; var ret = {};
this.satToUnit = 1 / this.unitToSatoshi;
this.unitName = walletSettings.unitName; // INIT. Global value
this.alternativeIsoCode = walletSettings.alternativeIsoCode; ret.unitToSatoshi = walletSettings.unitToSatoshi;
this.alternativeName = walletSettings.alternativeName; ret.satToUnit = 1 / ret.unitToSatoshi;
this.alternativeAmount = 0; ret.unitName = walletSettings.unitName;
this.unitDecimals = walletSettings.unitDecimals; ret.alternativeIsoCode = walletSettings.alternativeIsoCode;
this.isCordova = isCordova; ret.alternativeName = walletSettings.alternativeName;
this.addresses = []; ret.alternativeAmount = 0;
this.isMobile = isMobile.any(); ret.unitDecimals = walletSettings.unitDecimals;
this.isWindowsPhoneApp = isMobile.Windows() && isCordova; ret.isCordova = isCordova;
this.blockUx = false; ret.addresses = [];
this.isRateAvailable = false; ret.isMobile = isMobile.any();
this.showScanner = false; ret.isWindowsPhoneApp = isMobile.Windows() && isCordova;
this.lockedCurrentFeePerKb = null; var vanillaScope = ret;
this.paymentExpired = false;
var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) { var disableScannerListener = $rootScope.$on('dataScanned', function(event, data) {
@ -47,12 +45,23 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}, 100); }, 100);
}); });
var disableAddrListener = $rootScope.$on('Local/NeedNewAddress', function() { var disableAddrListener = $rootScope.$on('Local/AddressIsUsed', function() {
self.setAddress(true); self.setAddress(true);
}); });
var disableFocusListener = $rootScope.$on('Local/NewFocusedWallet', function() { var disableFocusListener = $rootScope.$on('Local/NewFocusedWallet', function() {
self.addr = null;
self.resetForm(); self.resetForm();
self.kk=1;
$log.debug('Cleaning WalletHome Instance');
lodash.each(self, function(v, k) {
if (lodash.isFunction(v)) return;
if (vanillaScope[k]) return;
delete self[k];
});
}); });
var disableResumeListener = $rootScope.$on('Local/Resume', function() { var disableResumeListener = $rootScope.$on('Local/Resume', function() {
@ -88,24 +97,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}); });
this.walletData = {};
this.getWalletData = function(key) {
var fc = profileService.focusedClient;
if (!fc) return;
if (!this.walletData[fc.credentials.walletId]) return;
return this.walletData[fc.credentials.walletId][key];
};
this.setWalletData = function(key,val) {
var fc = profileService.focusedClient;
if (!fc) return;
if (!this.walletData[fc.credentials.walletId] )
this.walletData[fc.credentials.walletId] = {};
this.walletData[fc.credentials.walletId][key] = val;
};
this.onQrCodeScanned = function(data) { this.onQrCodeScanned = function(data) {
if (data) go.send(); if (data) go.send();
@ -523,13 +514,14 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
this.setAddress = function(forceNew) { this.setAddress = function(forceNew) {
console.log('[walletHome.js.795] KK', self.kk); //TODO
self.addrError = null; self.addrError = null;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc) if (!fc)
return; return;
// Address already set? // Address already set?
if (!forceNew && self.getWalletData('addr')) { if (!forceNew && self.addr) {
return; return;
} }
@ -542,7 +534,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
self.addrError = err; self.addrError = err;
} else { } else {
if (addr) if (addr)
self.setWalletData('addr',addr);; self.addr = addr;
} }
$scope.$digest(); $scope.$digest();
@ -839,6 +831,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var self = this; var self = this;
self.blockUx = !!name; self.blockUx = !!name;
console.log('[walletHome.js.795] KK', self.kk); //TODO
if (isCordova) { if (isCordova) {
if (name) { if (name) {
window.plugins.spinnerDialog.hide(); window.plugins.spinnerDialog.hide();
@ -892,7 +885,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0)); amount = parseInt((form.amount.$modelValue * unitToSat).toFixed(0));
outputs.push({ outputs.push({
'toAddress' : address, 'toAddress': address,
'amount': amount, 'amount': amount,
'message': comment 'message': comment
}); });
@ -922,7 +915,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}); });
return; return;
} else { } else {
$rootScope.$emit('Local/NeedsConfirmation', txp, function(accept) { $rootScope.$emit('Local/NeedsConfirmation', txp, function(accept) {
if (accept) self.acceptTx(txp); if (accept) self.acceptTx(txp);
else self.resetForm(); else self.resetForm();
}); });
@ -1269,10 +1262,12 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
}; };
/* Start setup */ /* Start setup */
lodash.assign(self, vanillaScope);
this.bindTouchDown(); this.bindTouchDown();
if (profileService.focusedClient) { if (profileService.focusedClient) {
this.setAddress(); this.setAddress();
this.setSendFormInputs(); this.setSendFormInputs();
} }
}); });

View File

@ -52,7 +52,7 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
toggleSidebar(invert); toggleSidebar(invert);
}; };
root.walletHome = function(delayed) { root.walletHome = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (fc && !fc.isComplete()) { if (fc && !fc.isComplete()) {
root.path('copayers'); root.path('copayers');
@ -63,7 +63,6 @@ angular.module('copayApp.services').factory('go', function($window, $rootScope,
} }
}; };
root.send = function() { root.send = function() {
root.path('walletHome', function() { root.path('walletHome', function() {
$rootScope.$emit('Local/SetTab', 'send'); $rootScope.$emit('Local/SetTab', 'send');