wallet details refactor
This commit is contained in:
parent
e3076d18ab
commit
8aefbe25b3
9 changed files with 703 additions and 706 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -88,11 +88,9 @@ 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) {
|
||||
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
|
||||
|
|
@ -101,9 +99,10 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
if (status.pendingTxps && status.pendingTxps[0]) {
|
||||
txps = txps.concat(status.pendingTxps);
|
||||
}
|
||||
if (++i == l) {
|
||||
if (--i == 0) {
|
||||
setPendingTxps(txps);
|
||||
}
|
||||
wallet.status = status;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -61,48 +41,100 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
});
|
||||
};
|
||||
|
||||
$scope.updateAll = function() {
|
||||
$scope.update();
|
||||
}
|
||||
$scope.recreate = function() {
|
||||
walletService.recreate();
|
||||
};
|
||||
|
||||
$scope.update = function() {
|
||||
$scope.updating = true;
|
||||
$scope.updateStatus = function(force) {
|
||||
$scope.updatingStatus = true;
|
||||
$scope.updateStatusError = false;
|
||||
$timeout(function() {
|
||||
walletService.getStatus(wallet, {
|
||||
force: true
|
||||
force: !!force,
|
||||
}, function(err, status) {
|
||||
if (err) {} // TODO
|
||||
$scope.updatingStatus = false;
|
||||
if (err) {
|
||||
$scope.status = null;
|
||||
$scope.updateStatusError = true;
|
||||
return;
|
||||
}
|
||||
$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() {
|
||||
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.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;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
1072
src/js/routes.js
1072
src/js/routes.js
File diff suppressed because it is too large
Load diff
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ^^
|
||||
//
|
||||
//
|
||||
|
|
@ -12,7 +12,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
root.WALLET_STATUS_MAX_TRIES = 7;
|
||||
root.WALLET_STATUS_DELAY_BETWEEN_TRIES = 1.4 * 1000;
|
||||
root.SOFT_CONFIRMATION_LIMIT = 12;
|
||||
root.HISTORY_SHOW_LIMIT = 10;
|
||||
root.SAFE_CONFIRMATIONS = 6;
|
||||
|
||||
// UI Related
|
||||
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) {
|
||||
$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;
|
||||
|
||||
//STR
|
||||
cache.totalBalanceStr = root.formatAmount(cache.totalBalanceSat) + ' ' + cache.unitName;
|
||||
cache.lockedBalanceStr = root.formatAmount(cache.lockedBalanceSat) + ' ' + cache.unitName;
|
||||
cache.availableBalanceStr = root.formatAmount(cache.availableBalanceSat) + ' ' + cache.unitName;
|
||||
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 = root.formatAmount(cache.pendingAmount) + ' ' + cache.unitName;
|
||||
cache.pendingAmountStr = txFormatService.formatAmount(cache.pendingAmount) + ' ' + cache.unitName;
|
||||
} else {
|
||||
cache.pendingAmountStr = null;
|
||||
}
|
||||
|
|
@ -229,13 +236,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
});
|
||||
};
|
||||
|
||||
_getStatus(walletStatusHash(), 0, function(err, status) {
|
||||
if (err) {
|
||||
root.handleError(err);
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, status);
|
||||
})
|
||||
_getStatus(walletStatusHash(), 0, cb);
|
||||
};
|
||||
|
||||
var getSavedTxs = function(walletId, cb) {
|
||||
|
|
@ -300,8 +301,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
if (tx.time > now)
|
||||
tx.time = now;
|
||||
|
||||
if (tx.confirmations >= SAFE_CONFIRMATIONS) {
|
||||
tx.safeConfirmed = SAFE_CONFIRMATIONS + '+';
|
||||
if (tx.confirmations >= root.SAFE_CONFIRMATIONS) {
|
||||
tx.safeConfirmed = root.SAFE_CONFIRMATIONS + '+';
|
||||
} else {
|
||||
tx.safeConfirmed = false;
|
||||
wallet.hasUnsafeConfirmed = true;
|
||||
|
|
@ -323,13 +324,15 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
return ret;
|
||||
};
|
||||
|
||||
var updateLocalTxHistory = function(wallet, cb) {
|
||||
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;
|
||||
|
||||
|
|
@ -359,43 +362,27 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
|
||||
|
||||
// First update
|
||||
if (walletId == wallet.credentials.walletId) {
|
||||
wallet.completeHistory = txsFromLocal;
|
||||
}
|
||||
wallet.completeHistory = txsFromLocal;
|
||||
|
||||
if (wallet.historyUpdateInProgress)
|
||||
return;
|
||||
|
||||
wallet.historyUpdateInProgress = 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 = processNewTxs(wallet, 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 == 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;
|
||||
}
|
||||
}
|
||||
getNewTxs(newTxs, skip, cb);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -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.skip = opts.skip || 0;
|
||||
opts.limit = opts.limit || root.HISTORY_SHOW_LIMIT;
|
||||
|
||||
var walletId = wallet.credentials.walletId;
|
||||
|
||||
|
|
@ -467,10 +452,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
|||
|
||||
$log.debug('Updating Transaction History');
|
||||
|
||||
updateLocalTxHistory(wallet, function(err) {
|
||||
updateLocalTxHistory(wallet, opts.progressFn, function(err) {
|
||||
if (err) return cb(err);
|
||||
var txs = wallet.completeHistory ? wallet.completeHistory.slice(opts.skip, opts.limit) : null;
|
||||
return cb(err, txs);
|
||||
return cb(err, wallet.completeHistory);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue