wallet details refactor

This commit is contained in:
Ivan Socolsky 2016-08-18 10:37:08 -03:00
commit 8aefbe25b3
No known key found for this signature in database
GPG key ID: FAECE6A05FAA4F56
9 changed files with 703 additions and 706 deletions

View file

@ -3,7 +3,7 @@
<ion-nav-bar class="bar-stable"> <ion-nav-bar class="bar-stable">
<ion-nav-title>Home</ion-nav-title> <ion-nav-title>Home</ion-nav-title>
</ion-nav-bar> </ion-nav-bar>
<ion-content class="padding home" ng-controller="tabHomeController"> <ion-content class="padding home" ng-controller="tabHomeController" cache-view="false">
<h2 class="title m0" translate>Payment Proposals</h2> <h2 class="title m0" translate>Payment Proposals</h2>
<div class="list card" ng-if="txps[0]"> <div class="list card" ng-if="txps[0]">
@ -64,7 +64,7 @@
Incomplete Incomplete
</span> </span>
<span class="item-note" ng-show="item.isComplete()"> <span class="item-note" ng-show="item.isComplete()">
{{item.availableBalanceStr}} {{item.status.availableBalanceStr}}
</span> </span>
</li> </li>
</ul> </ul>

View file

@ -1,6 +1,6 @@
<ion-view ng-controller="walletDetailsController"> <ion-view>
<ion-nav-bar class="bar-stable"> <ion-nav-bar class="bar-stable">
<ion-nav-title>{{wallet.name}}</ion-nav-title> <ion-nav-title>{{wallet.name}}</ion-nav-title>
@ -14,7 +14,7 @@
</ion-nav-buttons> </ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-content class="has-header" delegate-handle="my-handle" overflow-scroll="true"> <ion-content ng-controller="walletDetailsController" ng-init="init()" cache-view="false" class="has-header" delegate-handle="my-handle" overflow-scroll="true">
<div ng-show="!wallet"> <div ng-show="!wallet">
No Wallet No Wallet
<a href ui-sref="tabs.home" class="button"> <a href ui-sref="tabs.home" class="button">
@ -33,35 +33,35 @@
<div class="oh pr" ng-show="wallet && wallet.isComplete()"> <div class="oh pr" ng-show="wallet && wallet.isComplete()">
<div ng-style="{'background-color':wallet.color}" class="amount"> <div ng-style="{'background-color':wallet.color}" class="amount">
<div ng-if="!wallet.notAuthorized && !updating"> <div ng-if="!notAuthorized && !updatingStatus">
<div class="m20t" ng-show="wallet.updateError" ng-click='update()'> <div class="m20t" ng-show="updateStatusError" ng-click='update()'>
<span class="size-12 db m10b">{{wallet.updateError|translate}}</span> <span class="size-12 db m10b">{{updateStatusError|translate}}</span>
<button class="outline white tiny round" translate>Tap to retry</button> <button class="outline white tiny round" translate>Tap to retry</button>
</div> </div>
<div ng-show="wallet.walletScanStatus == 'error'" ng-click='wallet.retryScan()'> <div ng-show="wallet.walletScanStatus == 'error'" ng-click='retryScan()'>
<span translate>Scan status finished with error</span> <span translate>Scan status finished with error</span>
<br><span translate>Tap to retry</span> <br><span translate>Tap to retry</span>
</div> </div>
<div ng-click='updateAll({triggerTxUpdate: true})' ng-show="!updateError && wallet.walletScanStatus != 'error' && !hideBalance" on-hold="hideToggle()"> <div ng-click='updateAll()' ng-show="!updateStatusError && wallet.walletScanStatus != 'error' && !hideBalance" on-hold="hideToggle()">
<strong class="size-36">{{status.totalBalanceStr}}</strong> <strong class="size-36">{{status.totalBalanceStr}}</strong>
<div class="size-14" ng-if="wallet.totalBalanceAlternative">{{status.totalBalanceAlternative}} {{status.alternativeIsoCode}}</div> <div class="size-14" ng-if="status.totalBalanceAlternative">{{status.totalBalanceAlternative}} {{status.alternativeIsoCode}}</div>
<div class="size-14" ng-if="wallet.pendingAmount"> <div class="size-14" ng-if="status.pendingAmount">
<span translate>Pending Confirmation</span>: {{status.pendingAmountStr}} <span translate>Pending Confirmation</span>: {{status.pendingAmountStr}}
</div> </div>
</div> </div>
<div ng-show="!wallet.updateError && wallet.walletScanStatus != 'error' && wallet.shouldHideBalance" on-hold="wallet.hideToggle()"> <div ng-show="!updateStatusError && wallet.walletScanStatus != 'error' && shouldHideBalance" on-hold="hideToggle()">
<strong class="size-24" translate>[Balance Hidden]</strong> <strong class="size-24" translate>[Balance Hidden]</strong>
<div class="size-14" translate> <div class="size-14" translate>
Tap and hold to show Tap and hold to show
</div> </div>
</div> </div>
</div> </div>
<div ng-if="updating"> <div ng-if="updatingStatus">
<div class="size-36"> <div class="size-36">
<strong>...</strong> <strong>...</strong>
</div> </div>
@ -82,7 +82,7 @@
</span> </span>
</div> </div>
</div> </div>
<div class="oh pr m20t" ng-show="wallet.notAuthorized && !updating"> <div class="oh pr m20t" ng-show="notAuthorized && !updatingStatus">
<div class="text-center text-warning"> <div class="text-center text-warning">
<i class="fi-alert"></i> <i class="fi-alert"></i>
<span translate> <span translate>
@ -94,7 +94,7 @@
</div> </div>
<div class="text-center m10t "> <div class="text-center m10t ">
<span class="button outline round dark-gray tiny" <span class="button outline round dark-gray tiny"
ng-click="wallet.recreate()"> ng-click="recreate()">
<span translate>Recreate</span> <span translate>Recreate</span>
</span> </span>
</div> </div>
@ -105,48 +105,46 @@
</div> </div>
<div ng-if="wallet.txps[0]"> <div ng-if="wallet.txps[0]">
<h4 ng-show="wallet.requiresMultipleSignatures" class="title m0" translate>Payment Proposals</h4> <h4 ng-show="requiresMultipleSignatures" class="title m0" translate>Payment Proposals</h4>
<h4 ng-show="!wallet.requiresMultipleSignatures" class="title m0" translate>Unsent transactions</h4> <h4 ng-show="!requiresMultipleSignatures" class="title m0" translate>Unsent transactions</h4>
<div ng-repeat="tx in wallet.txps"> <div ng-repeat="tx in wallet.txps">
<div ng-include="wallet.txTemplateUrl"></div> <div ng-include="wallet.txTemplateUrl"></div>
</div> </div>
<div class="text-gray text-center size-12 p10t" <div class="text-gray text-center size-12 p10t"
ng-show="wallet.lockedBalanceSat"> ng-show="status.lockedBalanceSat">
<span translate>Total Locked Balance</span>: <span translate>Total Locked Balance</span>:
<b>{{wallet.lockedBalanceStr}} </b> <b>{{status.lockedBalanceStr}} </b>
<span> {{wallet.lockedBalanceAlternative}} <span> {{status.lockedBalanceAlternative}}
{{wallet.alternativeIsoCode}} </span> {{status.alternativeIsoCode}} </span>
</div> </div>
</div> </div>
<!-- Activity --> <!-- Transactions -->
<h4 class="title" ng-click="startSearch(); openSearchModal()" ng-show="!notAuthorized">
<h4 class="title" ng-click="wallet.startSearch(); openSearchModal()" ng-show="!wallet.notAuthorized">
<span translate>Activity</span> <span translate>Activity</span>
<i class="dib m5l size-16 pointer fi-magnifying-glass"></i> <i class="dib m5l size-16 pointer fi-magnifying-glass"></i>
</h4> </h4>
<div class="oh pr m20t text-gray size-12 text-center" <div class="oh pr m20t text-gray size-12 text-center"
ng-show="!wallet.loadingWallet && !txHistory[0] && !wallet.updatingTxHistory && !wallet.txHistoryError && !wallet.updateError && !wallet.notAuthorized" ng-show="!txHistory[0] && !updatingTxHistory && !txHistoryError && !updateStatusError && !notAuthorized"
translate>No transactions yet ZZZZ {{wallet.totalBalanceStr}} translate>No transactions yet {{status.totalBalanceStr}}
</div> </div>
<div class="oh pr" ng-show="(txHistory[0] || updatingTxHistoryProgress > 5) && !notAuthorized">
<div class="oh pr" ng-show="(txHistory[0] || wallet.txProgress > 5) && !wallet.notAuthorized"> <div ng-show="updatingTxHistory">
<div ng-show="wallet.updatingTxHistory && wallet.txProgress > 5">
<div class="row p20 text-center"> <div class="row p20 text-center">
<div class="columns large-12 medium-12 small-12 m10b"> <div class="columns large-12 medium-12 small-12 m10b">
<ion-spinner class="spinner-dark" icon="lines"></ion-spinner> <ion-spinner class="spinner-dark" icon="lines"></ion-spinner>
</div> </div>
<div class="size-12 text-gray m20t"> <div class="size-12 text-gray m20t">
<div translate>{{wallet.txProgress}} transactions downloaded</div> <div translate>{{updatingTxHistoryProgress}} transactions downloaded</div>
<div translate>Updating transaction history. Please stand by.</div> <div translate>Updating transaction history. Please stand by.</div>
</div> </div>
</div> </div>
</div> </div>
<div ng-if="txHistory[0] && wallet.updatingTxHistory && wallet.newTx" class="row collapse last-transactions-content animated fadeInDown"> <div ng-if="txHistory[0] && updatingTxHistory && 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">
@ -219,14 +217,12 @@
</div> </div>
</div> </div>
<div class="row m20t text-center" ng-show="wallet.historyRendering && !wallet.ching"> <div class="text-center" ng-show="updatingTxHistory && !isSearching">
<div class="columns large-12 medium-12 small-12"> <ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
</div>
</div> </div>
<ion-infinite-scroll <ion-infinite-scroll
ng-if="wallet.historyShowMore" ng-if="txHistoryShowMore"
on-infinite="showMore()" on-infinite="showMore()"
distance="1%"> distance="1%">
</ion-infinite-scroll> </ion-infinite-scroll>

View file

@ -11,7 +11,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
$scope.externalSource = null; $scope.externalSource = null;
if (wallet) { if (wallet) {
walletService.updateStatus(wallet, {}, function(err, status) {}); walletService.getStatus(wallet, {}, function(err, status) {});
var config = configService.getSync(); var config = configService.getSync();
config.aliasFor = config.aliasFor || {}; config.aliasFor = config.aliasFor || {};
$scope.alias = config.aliasFor[walletId] || wallet.credentials.walletName; $scope.alias = config.aliasFor[walletId] || wallet.credentials.walletName;

View file

@ -7,22 +7,19 @@ angular.module('copayApp.controllers').controller('preferencesUnitController', f
$scope.currentUnit = config.wallet.settings.unitCode; $scope.currentUnit = config.wallet.settings.unitCode;
} }
$scope.unitList = [ $scope.unitList = [{
{ name: 'bits (1,000,000 bits = 1BTC)',
name: 'bits (1,000,000 bits = 1BTC)', shortName: 'bits',
shortName: 'bits', value: 100,
value: 100, decimals: 2,
decimals: 2, code: 'bit',
code: 'bit', }, {
}, name: 'BTC',
{ shortName: 'BTC',
name: 'BTC', value: 100000000,
shortName: 'BTC', decimals: 8,
value: 100000000, code: 'btc',
decimals: 8, }];
code: 'btc',
}
];
$scope.save = function(newUnit) { $scope.save = function(newUnit) {
var opts = { var opts = {

View file

@ -88,11 +88,9 @@ angular.module('copayApp.controllers').controller('tabHomeController',
self.updateAllClients = function() { self.updateAllClients = function() {
var txps = []; var txps = [];
var wallets = profileService.getWallets(); var i = $scope.wallets.length;
var l = wallets.length,
i = 0;
lodash.each(wallets, function(wallet) { lodash.each($scope.wallets, function(wallet) {
walletService.getStatus(wallet, {}, function(err, status) { walletService.getStatus(wallet, {}, function(err, status) {
if (err) { if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
@ -101,9 +99,10 @@ angular.module('copayApp.controllers').controller('tabHomeController',
if (status.pendingTxps && status.pendingTxps[0]) { if (status.pendingTxps && status.pendingTxps[0]) {
txps = txps.concat(status.pendingTxps); txps = txps.concat(status.pendingTxps);
} }
if (++i == l) { if (--i == 0) {
setPendingTxps(txps); setPendingTxps(txps);
} }
wallet.status = status;
}); });
}); });
} }

View file

@ -1,36 +1,16 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, profileService, lodash, configService, gettext, gettextCatalog, platformInfo, go, walletService) { angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, bwcError, profileService, lodash, configService, gettext, gettextCatalog, platformInfo, go, walletService) {
var isCordova = platformInfo.isCordova; var isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid; var isAndroid = platformInfo.isAndroid;
var isChromeApp = platformInfo.isChromeApp; var isChromeApp = platformInfo.isChromeApp;
var self = this; var errorPopup;
$rootScope.shouldHideMenuBar = false;
$rootScope.wpInputFocused = false; var HISTORY_SHOW_LIMIT = 10;
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
var ret = {};
// INIT. Global value
ret.unitToSatoshi = walletSettings.unitToSatoshi;
ret.satToUnit = 1 / ret.unitToSatoshi;
ret.unitName = walletSettings.unitName;
ret.alternativeIsoCode = walletSettings.alternativeIsoCode;
ret.alternativeName = walletSettings.alternativeName;
ret.alternativeAmount = 0;
ret.unitDecimals = walletSettings.unitDecimals;
ret.isCordova = isCordova;
ret.addresses = [];
ret.isMobile = platformInfo.isMobile;
ret.isWindowsPhoneApp = platformInfo.isWP;
ret.countDown = null;
ret.sendMaxInfo = {};
ret.showAlternative = false;
$scope.openSearchModal = function() { $scope.openSearchModal = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
@ -61,48 +41,100 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
}); });
}; };
$scope.updateAll = function()  { $scope.recreate = function() {
$scope.update(); walletService.recreate();
} };
$scope.update = function() { $scope.updateStatus = function(force) {
$scope.updating = true; $scope.updatingStatus = true;
$scope.updateStatusError = false;
$timeout(function() { $timeout(function() {
walletService.getStatus(wallet, { walletService.getStatus(wallet, {
force: true force: !!force,
}, function(err, status) { }, function(err, status) {
if (err) {} // TODO $scope.updatingStatus = false;
if (err) {
$scope.status = null;
$scope.updateStatusError = true;
return;
}
$scope.status = status; $scope.status = status;
$scope.updating = false;
}); });
}) })
}; };
$scope.updateTxHistory = function() {
if ($scope.updatingTxHistory) return;
$scope.updatingTxHistory = true;
$scope.updateTxHistoryError = false;
$scope.updatingTxHistoryProgress = null;
var progressFn = function(txs) {
$scope.updatingTxHistoryProgress = txs ? txs.length : 0;
completeTxHistory = txs;
$scope.showHistory();
$scope.$digest();
};
$timeout(function() {
walletService.getTxHistory(wallet, {
progressFn: progressFn,
}, function(err, txHistory) {
$scope.updatingTxHistory = false;
if (err) {
$scope.txHistory = null;
$scope.updateTxHistoryError = true;
return;
}
completeTxHistory = txHistory;
$scope.showHistory();
$scope.$apply();
});
});
};
$scope.showHistory = function() {
if ($scope.isSearching) {
$scope.txHistorySearchResults = filteredTxHistory ? filteredTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT) : [];
$scope.txHistoryShowMore = filteredTxHistory.length > $scope.txHistorySearchResults.length;
} else {
$scope.txHistory = completeTxHistory ? completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT) : [];
$scope.txHistoryShowMore = completeTxHistory.length > $scope.txHistory.length;
}
};
$scope.showMore = function() {
currentTxHistoryPage++;
$scope.showHistory();
$scope.$broadcast('scroll.infiniteScrollComplete');
};
$scope.updateAll = function()  {
$scope.updateStatus(false);
$scope.updateTxHistory();
}
$scope.hideToggle = function() { $scope.hideToggle = function() {
console.log('[walletDetails.js.70:hideToogle:] TODO'); //TODO console.log('[walletDetails.js.70:hideToogle:] TODO'); //TODO
}; };
if (!$stateParams.walletId) { var currentTxHistoryPage;
$log.debug('No wallet provided... using the first one'); var completeTxHistory;
$stateParams.walletId = profileService.getWallets({ var wallet;
onlyComplete: true
})[0].id;
}
$scope.init = function() {
currentTxHistoryPage = 0;
completeTxHistory = [];
var wallet = profileService.getWallet($stateParams.walletId); wallet = profileService.getWallet($stateParams.walletId);
$scope.wallet = wallet; $scope.wallet = wallet;
$scope.requiresMultipleSignatures = wallet.credentials.m > 1;
$scope.newTx = false;
$scope.updateAll();
};
if (wallet) {
walletService.getStatus(wallet, {}, function(err, status) {
console.log('*** [walletDetails.js ln89] status:', status); // TODO
if (err) {} // TODO
$scope.status = status;
});
walletService.getHistory(wallet, {}, function(err, txHistory) {
console.log('*** [walletDetails.js ln93] txHistory:', txHistory); // TODO
if (err) {} // TODO
$scope.txHistory = txHistory;
});
}
}); });

File diff suppressed because it is too large Load diff

View file

@ -3,17 +3,6 @@
angular.module('copayApp.services').factory('txFormatService', function(bwcService, rateService, configService, lodash) { angular.module('copayApp.services').factory('txFormatService', function(bwcService, rateService, configService, lodash) {
var root = {}; var root = {};
// // RECEIVE
// // Check address
// root.isUsed(wallet.walletId, balance.byAddress, function(err, used) {
// if (used) {
// $log.debug('Address used. Creating new');
// $rootScope.$emit('Local/AddressIsUsed');
// }
// });
//
root.Utils = bwcService.getUtils(); root.Utils = bwcService.getUtils();
@ -57,8 +46,8 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
}; };
root.processTx = function(tx) { root.processTx = function(tx) {
if (!tx || tx.action == 'invalid') if (!tx || tx.action == 'invalid')
return tx; return tx;
// New transaction output format // New transaction output format
if (tx.outputs && tx.outputs.length) { if (tx.outputs && tx.outputs.length) {
@ -77,7 +66,7 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
}, 0); }, 0);
} }
tx.toAddress = tx.outputs[0].toAddress; tx.toAddress = tx.outputs[0].toAddress;
} }
tx.amountStr = root.formatAmountStr(tx.amount); tx.amountStr = root.formatAmountStr(tx.amount);
tx.alternativeAmountStr = root.formatAlternativeStr(tx.amount); tx.alternativeAmountStr = root.formatAlternativeStr(tx.amount);

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
// DO NOT INCLUDE STORAGE HERE \/ \/ // DO NOT INCLUDE STORAGE HERE \/ \/
angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, bwcService, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus, txFormatService, $ionicModal) { angular.module('copayApp.services').factory('walletService', function($log, $timeout, lodash, trezor, ledger, storageService, configService, rateService, uxLanguage, $filter, gettextCatalog, bwcError, $ionicPopup, fingerprintService, ongoingProcess, gettext, $rootScope, txStatus, txFormatService, $ionicModal) {
// DO NOT INCLUDE STORAGE HERE ^^ // DO NOT INCLUDE STORAGE HERE ^^
// //
// //
@ -12,7 +12,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.WALLET_STATUS_MAX_TRIES = 7; root.WALLET_STATUS_MAX_TRIES = 7;
root.WALLET_STATUS_DELAY_BETWEEN_TRIES = 1.4 * 1000; root.WALLET_STATUS_DELAY_BETWEEN_TRIES = 1.4 * 1000;
root.SOFT_CONFIRMATION_LIMIT = 12; root.SOFT_CONFIRMATION_LIMIT = 12;
root.HISTORY_SHOW_LIMIT = 10; root.SAFE_CONFIRMATIONS = 6;
// UI Related // UI Related
root.openStatusModal = function(type, txp, cb) { root.openStatusModal = function(type, txp, cb) {
@ -31,8 +31,15 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
// // RECEIVE
// // Check address
// root.isUsed(wallet.walletId, balance.byAddress, function(err, used) {
// if (used) {
// $log.debug('Address used. Creating new');
// $rootScope.$emit('Local/AddressIsUsed');
// }
// });
//
var _signWithLedger = function(wallet, txp, cb) { var _signWithLedger = function(wallet, txp, cb) {
$log.info('Requesting Ledger Chrome app to sign the transaction'); $log.info('Requesting Ledger Chrome app to sign the transaction');
@ -154,12 +161,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
cache.unitName = config.unitName; cache.unitName = config.unitName;
//STR //STR
cache.totalBalanceStr = root.formatAmount(cache.totalBalanceSat) + ' ' + cache.unitName; cache.totalBalanceStr = txFormatService.formatAmount(cache.totalBalanceSat) + ' ' + cache.unitName;
cache.lockedBalanceStr = root.formatAmount(cache.lockedBalanceSat) + ' ' + cache.unitName; cache.lockedBalanceStr = txFormatService.formatAmount(cache.lockedBalanceSat) + ' ' + cache.unitName;
cache.availableBalanceStr = root.formatAmount(cache.availableBalanceSat) + ' ' + cache.unitName; cache.availableBalanceStr = txFormatService.formatAmount(cache.availableBalanceSat) + ' ' + cache.unitName;
if (cache.pendingAmount) { if (cache.pendingAmount) {
cache.pendingAmountStr = root.formatAmount(cache.pendingAmount) + ' ' + cache.unitName; cache.pendingAmountStr = txFormatService.formatAmount(cache.pendingAmount) + ' ' + cache.unitName;
} else { } else {
cache.pendingAmountStr = null; cache.pendingAmountStr = null;
} }
@ -229,13 +236,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
_getStatus(walletStatusHash(), 0, function(err, status) { _getStatus(walletStatusHash(), 0, cb);
if (err) {
root.handleError(err);
return cb(err);
}
return cb(null, status);
})
}; };
var getSavedTxs = function(walletId, cb) { var getSavedTxs = function(walletId, cb) {
@ -300,8 +301,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (tx.time > now) if (tx.time > now)
tx.time = now; tx.time = now;
if (tx.confirmations >= SAFE_CONFIRMATIONS) { if (tx.confirmations >= root.SAFE_CONFIRMATIONS) {
tx.safeConfirmed = SAFE_CONFIRMATIONS + '+'; tx.safeConfirmed = root.SAFE_CONFIRMATIONS + '+';
} else { } else {
tx.safeConfirmed = false; tx.safeConfirmed = false;
wallet.hasUnsafeConfirmed = true; wallet.hasUnsafeConfirmed = true;
@ -323,13 +324,15 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
return ret; return ret;
}; };
var updateLocalTxHistory = function(wallet, cb) { var updateLocalTxHistory = function(wallet, progressFn, cb) {
var FIRST_LIMIT = 5; var FIRST_LIMIT = 5;
var LIMIT = 50; var LIMIT = 50;
var requestLimit = FIRST_LIMIT; var requestLimit = FIRST_LIMIT;
var walletId = wallet.credentials.walletId; var walletId = wallet.credentials.walletId;
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
progressFn = progressFn || function() {};
var fixTxsUnit = function(txs) { var fixTxsUnit = function(txs) {
if (!txs || !txs[0] || !txs[0].amountStr) return; if (!txs || !txs[0] || !txs[0].amountStr) return;
@ -359,43 +362,27 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
// First update // First update
if (walletId == wallet.credentials.walletId) { wallet.completeHistory = txsFromLocal;
wallet.completeHistory = txsFromLocal;
}
if (wallet.historyUpdateInProgress) function getNewTxs(newTxs, skip, cb) {
return;
wallet.historyUpdateInProgress = true;
function getNewTxs(newTxs, skip, i_cb) {
getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
if (err) return i_cb(err); if (err) return cb(err);
newTxs = newTxs.concat(processNewTxs(wallet, lodash.compact(res)));
progressFn(newTxs);
newTxs = newTxs.concat(lodash.compact(res));
skip = skip + requestLimit; skip = skip + requestLimit;
$log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue);
if (!shouldContinue) { if (!shouldContinue) {
newTxs = processNewTxs(wallet, newTxs);
$log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length); $log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length);
return i_cb(null, newTxs); return cb(null, newTxs);
} }
requestLimit = LIMIT; requestLimit = LIMIT;
getNewTxs(newTxs, skip, i_cb); getNewTxs(newTxs, skip, cb);
// Progress update
if (walletId == wallet.credentials.walletId) {
wallet.txProgress = newTxs.length;
if (wallet.completeHistory < FIRST_LIMIT && txsFromLocal.length == 0) {
$log.debug('Showing partial history');
var newHistory = processNewTxs(wallet, newTxs);
newHistory = lodash.compact(newHistory.concat(confirmedTxs));
wallet.completeHistory = newHistory;
}
}
}); });
}; };
@ -456,10 +443,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}; };
root.getHistory = function(wallet, opts, cb) { root.getTxHistory = function(wallet, opts, cb) {
opts = opts || {}; opts = opts || {};
opts.skip = opts.skip || 0;
opts.limit = opts.limit || root.HISTORY_SHOW_LIMIT;
var walletId = wallet.credentials.walletId; var walletId = wallet.credentials.walletId;
@ -467,10 +452,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
updateLocalTxHistory(wallet, function(err) { updateLocalTxHistory(wallet, opts.progressFn, function(err) {
if (err) return cb(err); if (err) return cb(err);
var txs = wallet.completeHistory ? wallet.completeHistory.slice(opts.skip, opts.limit) : null; return cb(err, wallet.completeHistory);
return cb(err, txs);
}); });
}; };