fix tx details

This commit is contained in:
Matias Alejo Garcia 2016-08-18 17:56:04 -03:00
commit 8fff3da3c7
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
12 changed files with 1721 additions and 404 deletions

View File

@ -535,14 +535,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
};
self.removeAndMarkSoftConfirmedTx = function(txs) {
return lodash.filter(txs, function(tx) {
if (tx.confirmations >= SOFT_CONFIRMATION_LIMIT)
return tx;
tx.recent = true;
});
}
self.showMore = function() {
$timeout(function() {
@ -1188,9 +1180,9 @@ console.log('[index.js:1063] walletImported'); //TODO
});
$rootScope.$on('Local/NewFocusedWallet', function() {
console.log('[index.js.1200:NewFocusedWallet:] TODO'); //TODO
console.log('[index.js.1200:NewFocusedWallet:] TODO'); //TODO
return;
return;
uxLanguage.update();

View File

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

View File

@ -149,11 +149,11 @@
<div ng-show="btx.txid" class="tx-details-blockchain">
<div class="text-center m20t">
<button class="button outline round dark-gray tiny" ng-click="$root.openExternalLink('https://' +
<button class="button button-positive" ng-click="$root.openExternalLink('https://' +
(getShortNetworkName() == 'test' ? 'test-' : '') + 'insight.bitpay.com/tx/' + btx.txid)">
<span class="text-gray" translate>See it on the blockchain</span>
</button>
<button class="button outline round dark-gray tiny" ng-click="showCommentPopup()">
<button class="button button-positive" ng-click="showCommentPopup()">
<span class="text-gray" translate ng-show="!btx.note">Add comment</i></span>
<span class="text-gray" translate ng-show="btx.note">Edit comment</span>
</button>

View File

@ -3,9 +3,9 @@
<ion-nav-bar class="bar-stable">
<ion-nav-title>Home</ion-nav-title>
</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" ng-if="txps[0]" translate>Payment Proposals</h2>
<div class="list card" ng-if="txps[0]">
<ul>
<li ng-repeat="tx in txps" class="item item-icon-left"
@ -46,8 +46,9 @@
<h2>Wallets
<a href="#/add"><i class="ion-ios-plus-outline right"></i></a>
<h2>Wallets </h2>
</h2>
<div class="list card">
<ul class="pr">
@ -64,7 +65,7 @@
Incomplete
</span>
<span class="item-note" ng-show="item.isComplete()">
{{item.availableBalanceStr}}
{{item.status.availableBalanceStr}}
</span>
</li>
</ul>

View File

@ -1,6 +1,6 @@
<ion-view ng-controller="walletDetailsController">
<ion-view>
<ion-nav-bar class="bar-stable">
<ion-nav-title>{{wallet.name}}</ion-nav-title>
@ -14,7 +14,7 @@
</ion-nav-buttons>
</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">
No Wallet
<a href ui-sref="tabs.home" class="button">
@ -33,35 +33,35 @@
<div class="oh pr" ng-show="wallet && wallet.isComplete()">
<div ng-style="{'background-color':wallet.color}" class="amount">
<div ng-if="!wallet.notAuthorized && !wallet.updating">
<div ng-if="!notAuthorized && !updatingStatus">
<div class="m20t" ng-show="wallet.updateError" ng-click='update()'>
<span class="size-12 db m10b">{{wallet.updateError|translate}}</span>
<div class="m20t" ng-show="updateStatusError" ng-click='update()'>
<span class="size-12 db m10b">{{updateStatusError|translate}}</span>
<button class="outline white tiny round" translate>Tap to retry</button>
</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>
<br><span translate>Tap to retry</span>
</div>
<div ng-click='wallet.updateAll({triggerTxUpdate: true})' ng-show="!wallet.updateError && wallet.walletScanStatus != 'error' && !wallet.hideBalance" on-hold="hideToggle()">
<strong class="size-36">{{wallet.totalBalanceStr}}</strong>
<div class="size-14" ng-if="wallet.totalBalanceAlternative">{{wallet.totalBalanceAlternative}} {{wallet.alternativeIsoCode}}</div>
<div class="size-14" ng-if="wallet.pendingAmount">
<span translate>Pending Confirmation</span>: {{wallet.pendingAmountStr}}
<div ng-click='updateAll()' ng-show="!updateStatusError && wallet.walletScanStatus != 'error' && !hideBalance" on-hold="hideToggle()">
<strong class="size-36">{{status.totalBalanceStr}}</strong>
<div class="size-14" ng-if="status.totalBalanceAlternative">{{status.totalBalanceAlternative}} {{status.alternativeIsoCode}}</div>
<div class="size-14" ng-if="status.pendingAmount">
<span translate>Pending Confirmation</span>: {{status.pendingAmountStr}}
</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>
<div class="size-14" translate>
Tap and hold to show
</div>
</div>
</div>
<div ng-if="wallet.updating">
<div ng-if="updatingStatus">
<div class="size-36">
<strong>...</strong>
</div>
@ -82,7 +82,7 @@
</span>
</div>
</div>
<div class="oh pr m20t" ng-show="wallet.notAuthorized && !wallet.updating">
<div class="oh pr m20t" ng-show="notAuthorized && !updatingStatus">
<div class="text-center text-warning">
<i class="fi-alert"></i>
<span translate>
@ -94,7 +94,7 @@
</div>
<div class="text-center m10t ">
<span class="button outline round dark-gray tiny"
ng-click="wallet.recreate()">
ng-click="recreate()">
<span translate>Recreate</span>
</span>
</div>
@ -105,65 +105,65 @@
</div>
<div ng-if="wallet.txps[0]">
<h4 ng-show="wallet.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>Payment Proposals</h4>
<h4 ng-show="!requiresMultipleSignatures" class="title m0" translate>Unsent transactions</h4>
<div ng-repeat="tx in wallet.txps">
<div ng-include="wallet.txTemplateUrl"></div>
</div>
<div class="text-gray text-center size-12 p10t"
ng-show="wallet.lockedBalanceSat">
ng-show="status.lockedBalanceSat">
<span translate>Total Locked Balance</span>:
<b>{{wallet.lockedBalanceStr}} </b>
<span> {{wallet.lockedBalanceAlternative}}
{{wallet.alternativeIsoCode}} </span>
<b>{{status.lockedBalanceStr}} </b>
<span> {{status.lockedBalanceAlternative}}
{{status.alternativeIsoCode}} </span>
</div>
</div>
<!-- Activity -->
<h4 class="title" ng-click="wallet.startSearch(); openSearchModal()" ng-show="!wallet.notAuthorized">
<!-- Transactions -->
<h4 class="title" ng-click="startSearch(); openSearchModal()" ng-show="!notAuthorized">
<span translate>Activity</span>
<i class="dib m5l size-16 pointer fi-magnifying-glass"></i>
</h4>
<div class="oh pr m20t text-gray size-12 text-center"
ng-show="!wallet.loadingWallet && !wallet.txHistory[0] && !wallet.updatingTxHistory && !wallet.txHistoryError && !wallet.updateError && !wallet.notAuthorized"
translate>No transactions yet ZZZZ {{wallet.totalBalanceStr}}
ng-show="!txHistory[0] && !updatingTxHistory && !txHistoryError && !updateStatusError && !notAuthorized"
translate>No transactions yet {{status.totalBalanceStr}}
</div>
<div class="oh pr" ng-show="(wallet.txHistory[0] || wallet.txProgress > 5) && !wallet.notAuthorized">
<div ng-show="wallet.updatingTxHistory && wallet.txProgress > 5">
<div class="row p20 text-center">
<div class="columns large-12 medium-12 small-12 m10b">
<ion-spinner class="spinner-dark" icon="lines"></ion-spinner>
</div>
<div class="size-12 text-gray m20t">
<div translate>{{wallet.txProgress}} transactions downloaded</div>
<div translate>Updating transaction history. Please stand by.</div>
</div>
<div ng-show="updatingTxHistory">
<div class="row p20 text-center">
<div class="columns large-12 medium-12 small-12 m10b">
<ion-spinner class="spinner-dark" icon="lines"></ion-spinner>
</div>
<div class="size-12 text-gray m20t">
<div translate>{{updatingTxHistoryProgress}} transactions downloaded</div>
<div translate>Updating transaction history. Please stand by.</div>
</div>
</div>
</div>
<div ng-if="wallet.txHistory[0] && wallet.updatingTxHistory && wallet.newTx" class="row collapse last-transactions-content animated fadeInDown">
<div class="large-6 medium-6 small-6 columns size-14">
<div class="m10r left">
<img src="img/icon-new.svg" width="40">
</div>
<div class="m10t" style="background:#eee; width: 8em; margin-left: 52px; line-height:0.6em">
<span>&nbsp;</span>
</div>
<div style="margin-top:5px; background:#eee; width: 6em; margin-left: 52px; line-height:0.6em">
<span>&nbsp;</span>
</div>
<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="m10r left">
<img src="img/icon-new.svg" width="40">
</div>
<div class="m10t" style="background:#eee; width: 8em; margin-left: 52px; line-height:0.6em">
<span>&nbsp;</span>
</div>
<div style="margin-top:5px; background:#eee; width: 6em; margin-left: 52px; line-height:0.6em">
<span>&nbsp;</span>
</div>
</div>
</div>
<div ng-repeat="btx in wallet.txHistory track by btx.txid"
ng-click="openTxModal(btx)"
class="row collapse last-transactions-content">
<div class="large-6 medium-6 small-6 columns size-14">
<div class="list card">
<ul>
<li ng-repeat="btx in txHistory track by btx.txid" class="item"
ng-click="openTxModal(btx)">
<div class="row">
<div class="col col-50">
<div class="m10r left">
<img src="img/icon-receive-history.svg" alt="sync" width="40" ng-show="btx.action == 'received'">
<img src="img/icon-sent-history.svg" alt="sync" width="40" ng-show="btx.action == 'sent'">
@ -195,7 +195,7 @@
</div>
</div>
<div class="large-5 medium-5 small-5 columns text-right" >
<div class="col" >
<span class="size-16" ng-class="{'text-bold': btx.recent}">
<span ng-if="btx.action == 'received'">+</span>
<span ng-if="btx.action == 'sent'">-</span>
@ -206,31 +206,29 @@
{{btx.amountStr}}
</span>
</span>
<div class="size-12 text-gray">
<p>
<time ng-if="btx.time">{{btx.time * 1000 | amTimeAgo}}</time>
<span translate class="text-warning"
ng-show="!btx.time && (!btx.confirmations || btx.confirmations == 0)">
Unconfirmed
</span>
</div>
</p>
</div>
<div class="large-1 medium-1 small-1 columns text-right m10t">
<i class="icon-arrow-right3 size-18"></i>
<div class="col">
<i class="icon ion-chevron-right"></i>
</div>
</div>
<div class="row m20t text-center" ng-show="wallet.historyRendering && !wallet.ching">
<div class="columns large-12 medium-12 small-12">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
</div>
</div>
</li>
<li class="item" ng-show="updatingTxHistory && !isSearching">
Updating...
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
</li>
<ion-infinite-scroll
ng-if="historyShowMore"
ng-if="txHistoryShowMore"
on-infinite="showMore()"
distance="1%">
</ion-infinite-scroll>
</div>
</ul>
</div>
</ion-content>

1334
src/js/controllers/index.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
$scope.externalSource = null;
if (wallet) {
walletService.updateStatus(wallet, {}, function(err, status) {});
walletService.getStatus(wallet, {}, function(err, status) {});
var config = configService.getSync();
config.aliasFor = config.aliasFor || {};
$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.unitList = [
{
name: 'bits (1,000,000 bits = 1BTC)',
shortName: 'bits',
value: 100,
decimals: 2,
code: 'bit',
},
{
name: 'BTC',
shortName: 'BTC',
value: 100000000,
decimals: 8,
code: 'btc',
}
];
$scope.unitList = [{
name: 'bits (1,000,000 bits = 1BTC)',
shortName: 'bits',
value: 100,
decimals: 2,
code: 'bit',
}, {
name: 'BTC',
shortName: 'BTC',
value: 100000000,
decimals: 8,
code: 'btc',
}];
$scope.save = function(newUnit) {
var opts = {

View File

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

View File

@ -1,36 +1,16 @@
'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 isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid;
var isChromeApp = platformInfo.isChromeApp;
var self = this;
$rootScope.shouldHideMenuBar = false;
$rootScope.wpInputFocused = false;
var config = configService.getSync();
var configWallet = config.wallet;
var walletSettings = configWallet.settings;
var ret = {};
var errorPopup;
var HISTORY_SHOW_LIMIT = 10;
// 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() {
var fc = profileService.focusedClient;
@ -46,7 +26,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
};
this.openTxModal = function(btx) {
$scope.openTxModal = function(btx) {
var self = this;
$scope.btx = lodash.cloneDeep(btx);
@ -61,32 +41,100 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
};
$scope.update = function() {
walletService.updateStatus(wallet, {
force: true
}, function(err, status) {
if (err) {} // TODO
$scope.recreate = function() {
walletService.recreate();
};
$scope.updateStatus = function(force) {
$scope.updatingStatus = true;
$scope.updateStatusError = false;
$timeout(function() {
walletService.getStatus(wallet, {
force: !!force,
}, function(err, status) {
$scope.updatingStatus = false;
if (err) {
$scope.status = null;
$scope.updateStatusError = true;
return;
}
$scope.status = status;
});
})
};
$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() {
console.log('[walletDetails.js.70:hideToogle:] TODO'); //TODO
};
if (!$stateParams.walletId) {
$log.debug('No wallet provided... using the first one');
$stateParams.walletId = profileService.getWallets({
onlyComplete: true
})[0].id;
}
var currentTxHistoryPage;
var completeTxHistory;
var wallet;
$scope.init = function() {
currentTxHistoryPage = 0;
completeTxHistory = [];
var wallet = profileService.getWallet($stateParams.walletId);
$scope.wallet = wallet;
wallet = profileService.getWallet($stateParams.walletId);
$scope.wallet = wallet;
$scope.requiresMultipleSignatures = wallet.credentials.m > 1;
$scope.newTx = false;
$scope.updateAll();
};
if (wallet) {
walletService.updateStatus(wallet, {}, function(err, status) {
if (err) {} // TODO
});
}
});

View File

@ -3,17 +3,6 @@
angular.module('copayApp.services').factory('txFormatService', function(bwcService, rateService, configService, lodash) {
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();
@ -57,8 +46,8 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
};
root.processTx = function(tx) {
if (!tx || tx.action == 'invalid')
return tx;
if (!tx || tx.action == 'invalid')
return tx;
// New transaction output format
if (tx.outputs && tx.outputs.length) {
@ -77,7 +66,7 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
}, 0);
}
tx.toAddress = tx.outputs[0].toAddress;
}
}
tx.amountStr = root.formatAmountStr(tx.amount);
tx.alternativeAmountStr = root.formatAlternativeStr(tx.amount);

View File

@ -1,7 +1,7 @@
'use strict';
// 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 ^^
//
//
@ -9,6 +9,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
var root = {};
root.WALLET_STATUS_MAX_TRIES = 7;
root.WALLET_STATUS_DELAY_BETWEEN_TRIES = 1.4 * 1000;
root.SOFT_CONFIRMATION_LIMIT = 12;
root.SAFE_CONFIRMATIONS = 6;
// UI Related
root.openStatusModal = function(type, txp, cb) {
@ -27,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) {
$log.info('Requesting Ledger Chrome app to sign the transaction');
@ -78,16 +89,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
var _walletStatusHash = function(walletStatus) {
var bal;
if (walletStatus) {
bal = walletStatus.balance.totalAmount;
} else {
bal = self.totalBalanceSat;
}
return bal;
};
// TODO
// This handles errors from BWS/index which normally
@ -102,7 +103,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
console.log('[walletService.js.93] TODO NOT AUTH'); //TODO
// TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
self.notAuthorized = true;
wallet.notAuthorized = true;
go.walletHome();
} else if (err instanceof errors.NOT_FOUND) {
root.showErrorPopup(gettext('Could not access Wallet Service: Not found'));
@ -115,170 +116,127 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
root.handleError = lodash.debounce(_handleError, 1000);
root.setBalance = function(wallet, balance) {
if (!balance) return;
var config = configService.getSync().wallet.settings;
var COIN = 1e8;
// Address with Balance
wallet.balanceByAddress = balance.byAddress;
// Spend unconfirmed funds
if (wallet.spendUnconfirmed) {
wallet.totalBalanceSat = balance.totalAmount;
wallet.lockedBalanceSat = balance.lockedAmount;
wallet.availableBalanceSat = balance.availableAmount;
wallet.totalBytesToSendMax = balance.totalBytesToSendMax;
wallet.pendingAmount = null;
} else {
wallet.totalBalanceSat = balance.totalConfirmedAmount;
wallet.lockedBalanceSat = balance.lockedConfirmedAmount;
wallet.availableBalanceSat = balance.availableConfirmedAmount;
wallet.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
wallet.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
}
// Selected unit
wallet.unitToSatoshi = config.unitToSatoshi;
wallet.satToUnit = 1 / wallet.unitToSatoshi;
wallet.unitName = config.unitName;
//STR
wallet.totalBalanceStr = txFormatService.formatAmount(wallet.totalBalanceSat) + ' ' + wallet.unitName;
wallet.lockedBalanceStr = txFormatService.formatAmount(wallet.lockedBalanceSat) + ' ' + wallet.unitName;
wallet.availableBalanceStr = txFormatService.formatAmount(wallet.availableBalanceSat) + ' ' + wallet.unitName;
if (wallet.pendingAmount) {
wallet.pendingAmountStr = txFormatService.formatAmount(wallet.pendingAmount) + ' ' + wallet.unitName;
} else {
wallet.pendingAmountStr = null;
}
wallet.alternativeName = config.alternativeName;
wallet.alternativeIsoCode = config.alternativeIsoCode;
rateService.whenAvailable(function() {
var totalBalanceAlternative = rateService.toFiat(wallet.totalBalanceSat, wallet.alternativeIsoCode);
var lockedBalanceAlternative = rateService.toFiat(wallet.lockedBalanceSat, wallet.alternativeIsoCode);
var alternativeConversionRate = rateService.toFiat(100000000, wallet.alternativeIsoCode);
wallet.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
wallet.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
wallet.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
wallet.alternativeBalanceAvailable = true;
wallet.isRateAvailable = true;
});
};
root.setStatus = function(wallet, status) {
wallet.status = status;
wallet.statusUpdatedOn = Date.now();
wallet.isValid = true;
root.setBalance(wallet, status.balance);
wallet.email = status.preferences.email;
wallet.copayers = status.wallet.copayers;
};
root.updateStatus = function(wallet, opts, cb, initStatusHash, tries) {
tries = tries || 0;
root.getStatus = function(wallet, opts, cb) {
opts = opts || {};
if (wallet.isValid && !opts.force)
return;
var walletId = wallet.id;
if (opts.untilItChanges && lodash.isUndefined(initStatusHash)) {
initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
}
var get = function(cb) {
if (opts.walletStatus)
return cb(null, opts.walletStatus);
else {
return wallet.getStatus({
twoStep: true
}, function(err, ret) {
if (err)
return cb(bwcError.msg(err, gettext('Could not update Wallet')));
// TODO??
// self.isSingleAddress = !!ret.wallet.singleAddress;
// self.updating = ret.wallet.scanStatus == 'running';
return cb(null, ret);
});
}
function get(cb) {
wallet.getStatus({
twoStep: true
}, function(err, ret) {
if (err) {
return cb(bwcError.msg(err, gettext('Could not update Wallet')));
}
return cb(null, ret);
});
};
// If not untilItChanges...trigger history update now
if (opts.triggerTxUpdate && !opts.untilItChanges) {
$timeout(function() {
root.debounceUpdateHistory();
}, 1);
}
function cacheBalance(wallet, balance) {
if (!balance) return;
$timeout(function() {
var config = configService.getSync().wallet.settings;
// if (!opts.quiet)
// self.updating = true;
var cache = wallet.cachedStatus;
// Address with Balance
cache.balanceByAddress = balance.byAddress;
// Spend unconfirmed funds
if (cache.spendUnconfirmed) {
cache.totalBalanceSat = balance.totalAmount;
cache.lockedBalanceSat = balance.lockedAmount;
cache.availableBalanceSat = balance.availableAmount;
cache.totalBytesToSendMax = balance.totalBytesToSendMax;
cache.pendingAmount = null;
} else {
cache.totalBalanceSat = balance.totalConfirmedAmount;
cache.lockedBalanceSat = balance.lockedConfirmedAmount;
cache.availableBalanceSat = balance.availableConfirmedAmount;
cache.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
cache.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
}
// Selected unit
cache.unitToSatoshi = config.unitToSatoshi;
cache.satToUnit = 1 / cache.unitToSatoshi;
cache.unitName = config.unitName;
//STR
cache.totalBalanceStr = txFormatService.formatAmount(cache.totalBalanceSat) + ' ' + cache.unitName;
cache.lockedBalanceStr = txFormatService.formatAmount(cache.lockedBalanceSat) + ' ' + cache.unitName;
cache.availableBalanceStr = txFormatService.formatAmount(cache.availableBalanceSat) + ' ' + cache.unitName;
if (cache.pendingAmount) {
cache.pendingAmountStr = txFormatService.formatAmount(cache.pendingAmount) + ' ' + cache.unitName;
} else {
cache.pendingAmountStr = null;
}
cache.alternativeName = config.alternativeName;
cache.alternativeIsoCode = config.alternativeIsoCode;
rateService.whenAvailable(function() {
var totalBalanceAlternative = rateService.toFiat(cache.totalBalanceSat, cache.alternativeIsoCode);
var lockedBalanceAlternative = rateService.toFiat(cache.lockedBalanceSat, cache.alternativeIsoCode);
var alternativeConversionRate = rateService.toFiat(100000000, cache.alternativeIsoCode);
cache.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
cache.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
cache.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
cache.alternativeBalanceAvailable = true;
cache.isRateAvailable = true;
});
};
function isStatusCached() {
return wallet.cachedStatus && wallet.cachedStatus.isValid;
};
function cacheStatus(status) {
wallet.cachedStatus = status ||  {};
var cache = wallet.cachedStatus;
cache.statusUpdatedOn = Date.now();
cache.isValid = true;
cache.email = status.preferences ? status.preferences.email : null;
cacheBalance(wallet, status.balance);
};
function walletStatusHash(status) {
return status ? status.balance.totalAmount : wallet.totalBalanceSat;
};
function _getStatus(initStatusHash, tries, cb) {
if (isStatusCached() && !opts.force) return cb(null, wallet.cachedStatus);
tries = tries || 0;
$log.debug('Updating Status:', wallet.credentials.walletName, tries);
get(function(err, walletStatus) {
var currentStatusHash = _walletStatusHash(walletStatus);
get(function(err, status) {
if (err) return cb(err);
var currentStatusHash = walletStatusHash(status);
$log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries);
if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7 && walletId == profileService.focusedClient.credentials.walletId) {
if (opts.untilItChanges &&
initStatusHash == currentStatusHash &&
tries < root.WALLET_STATUS_MAX_TRIES &&
walletId == wallet.credentials.walletId) {
return $timeout(function() {
$log.debug('Retrying update... ' + walletId + ' Try:' + tries)
return root.updateStatus(wallet, {
walletStatus: null,
untilItChanges: true,
triggerTxUpdate: opts.triggerTxUpdate,
}, cb, initStatusHash, ++tries);
}, 1400 * tries);
return _getStatus(initStatusHash, ++tries, cb);
}, root.WALLET_STATUS_DELAY_BETWEEN_TRIES * tries);
}
if (err) {
root.handleError(err);
return cb(err);
}
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
root.setStatus(wallet, walletStatus);
cacheStatus(status);
// self.setPendingTxps(walletStatus.pendingTxps);
//
// // Status Shortcuts
// self.lastUpdate = Date.now();
// self.walletName = walletStatus.wallet.name;
// self.walletSecret = walletStatus.wallet.secret;
// self.walletStatus = walletStatus.wallet.status;
// self.walletScanStatus = walletStatus.wallet.scanStatus;
// self.copayers = walletStatus.wallet.copayers;
// self.preferences = walletStatus.preferences;
// self.setBalance(walletStatus.balance);
// self.otherWallets = lodash.filter(profileService.getWallets(self.network), function(w) {
// return w.id != self.walletId;
// });
//
// Notify external addons or plugins
// TODO
if (opts.triggerTxUpdate && opts.untilItChanges) {
$timeout(function() {
root.debounceUpdateHistory();
}, 1);
}
return cb();
// } else {
// self.loadingWallet = false;
// }
// wallet.setPendingTxps(status.pendingTxps);
return cb(null, status);
});
});
};
_getStatus(walletStatusHash(), 0, cb);
};
var getSavedTxs = function(walletId, cb) {
@ -321,14 +279,60 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
var removeAndMarkSoftConfirmedTx = function(txs) {
return lodash.filter(txs, function(tx) {
if (tx.confirmations >= root.SOFT_CONFIRMATION_LIMIT)
return tx;
tx.recent = true;
});
}
var updateLocalTxHistory = function(wallet, cb) {
var processNewTxs = function(wallet, txs) {
var config = configService.getSync().wallet.settings;
var now = Math.floor(Date.now() / 1000);
var txHistoryUnique = {};
var ret = [];
wallet.hasUnsafeConfirmed = false;
lodash.each(txs, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.time > now)
tx.time = now;
if (tx.confirmations >= root.SAFE_CONFIRMATIONS) {
tx.safeConfirmed = root.SAFE_CONFIRMATIONS + '+';
} else {
tx.safeConfirmed = false;
wallet.hasUnsafeConfirmed = true;
}
if (tx.note) {
delete tx.note.encryptedEditedByName;
delete tx.note.encryptedBody;
}
if (!txHistoryUnique[tx.txid]) {
ret.push(tx);
txHistoryUnique[tx.txid] = true;
} else {
$log.debug('Ignoring duplicate TX in history: ' + tx.txid)
}
});
return ret;
};
var updateLocalTxHistory = function(wallet, progressFn, cb) {
var FIRST_LIMIT = 5;
var LIMIT = 50;
var requestLimit = FIRST_LIMIT;
var walletId = wallet.credentials.walletId;
var config = configService.getSync().wallet.settings;
progressFn = progressFn || function() {};
var fixTxsUnit = function(txs) {
if (!txs || !txs[0] || !txs[0].amountStr) return;
@ -342,7 +346,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Fixing Tx Cache Unit to:' + name)
lodash.each(txs, function(tx) {
tx.amountStr = txFormatService.formatAmount(tx.amount) + name;
tx.amountStr = txFormatService.formatAmount(tx.amount) + name;
tx.feeStr = txFormatService.formatAmount(tx.fees) + name;
});
};
@ -352,54 +356,33 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
fixTxsUnit(txsFromLocal);
var confirmedTxs = self.removeAndMarkSoftConfirmedTx(txsFromLocal);
var confirmedTxs = removeAndMarkSoftConfirmedTx(txsFromLocal);
var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null;
var endingTs = confirmedTxs[0] ? confirmedTxs[0].time : null;
// First update
if (walletId == profileService.focusedClient.credentials.walletId) {
self.completeHistory = txsFromLocal;
setCompactTxHistory();
}
wallet.completeHistory = txsFromLocal;
if (historyUpdateInProgress[walletId])
return;
historyUpdateInProgress[walletId] = true;
function getNewTxs(newTxs, skip, i_cb) {
function getNewTxs(newTxs, skip, cb) {
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;
$log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue);
if (!shouldContinue) {
newTxs = self.processNewTxs(newTxs);
$log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length);
return i_cb(null, newTxs);
return cb(null, newTxs);
}
requestLimit = LIMIT;
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;
setCompactTxHistory();
}
$timeout(function() {
$rootScope.$apply();
});
}
getNewTxs(newTxs, skip, cb);
});
};
@ -445,9 +428,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Tx History synced. Total Txs: ' + newHistory.length);
// Final update
if (walletId == profileService.focusedClient.credentials.walletId) {
self.completeHistory = newHistory;
setCompactTxHistory();
if (walletId == wallet.credentials.walletId) {
wallet.completeHistory = newHistory;
}
return storageService.setTxHistory(historyToSave, walletId, function() {
@ -461,30 +443,18 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
};
root.updateHistory = function(wallet) {
root.getTxHistory = function(wallet, opts, cb) {
opts = opts || {};
var walletId = wallet.credentials.walletId;
if (!wallet.isComplete()) return;
if (!wallet.isComplete()) return cb();
$log.debug('Updating Transaction History');
self.txHistoryError = false;
self.updatingTxHistory = true;
$timeout(function() {
updateLocalTxHistory(wallet, function(err) {
historyUpdateInProgress[walletId] = self.updatingTxHistory = false;
self.loadingWallet = false;
self.txProgress = 0;
if (err)
self.txHistoryError = true;
$timeout(function() {
self.newTx = false
}, 1000);
$rootScope.$apply();
});
updateLocalTxHistory(wallet, opts.progressFn, function(err) {
if (err) return cb(err);
return cb(err, wallet.completeHistory);
});
};
@ -673,20 +643,11 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
});
};
var setCompactTxHistory = function() {
// TODO
self.isSearching = false;
self.nextTxHistory = self.historyShowMoreLimit;
self.txHistory = self.completeHistory ? self.completeHistory.slice(0, self.historyShowLimit) : null;
self.historyShowMore = self.completeHistory ? self.completeHistory.length > self.historyShowLimit : null;
};
root.debounceUpdateHistory = lodash.debounce(function() {
root.updateHistory();
}, 1000);
self.throttledUpdateHistory = lodash.throttle(function() {
root.throttledUpdateHistory = lodash.throttle(function() {
root.updateHistory();
}, 5000);
@ -707,19 +668,18 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.recreate = function(wallet, cb) {
ongoingProcess.set('recreating', true);
wallet.recreateWallet(function(err) {
self.notAuthorized = false;
wallet.notAuthorized = false;
ongoingProcess.set('recreating', false);
if (err) {
self.handleError(err);
$rootScope.$apply();
wallet.handleError(err);
return;
}
profileService.bindWalletClient(wallet, {
force: true
});
self.startScan(wallet);
wallet.startScan(wallet);
});
};
@ -727,16 +687,16 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
$log.debug('Scanning wallet ' + wallet.credentials.walletId);
if (!wallet.isComplete()) return;
// self.updating = true;
// wallet.updating = true;
wallet.startScan({
includeCopayerBranches: true,
}, function(err) {
// TODO
// if (err && self.walletId == walletId) {
// self.updating = false;
// self.handleError(err);
// if (err && wallet.walletId == walletId) {
// wallet.updating = false;
// wallet.handleError(err);
// $rootScope.$apply();
// }
});
@ -911,14 +871,14 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (err) return cb(err);
ongoingProcess.set('signingTx', true);
root.signTx(wallet, publishedTxp, function(err, signedTxp) {
root.signTx(wallet, publishedTxp, function(err, signedTxp) {
ongoingProcess.set('signingTx', false);
root.lock(wallet);
if (err) {
// TODO?
//$scope.$emit('Local/TxProposalAction');
var msg = err.message ?
var msg = err.message ?
err.message :
gettext('The payment was created but could not be completed. Please try again from home screen');
return cb(err);