updateStatus -> getStatus
This commit is contained in:
parent
9423de7179
commit
5656caaa5a
4 changed files with 1428 additions and 124 deletions
|
|
@ -226,7 +226,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ion-infinite-scroll
|
<ion-infinite-scroll
|
||||||
ng-if="historyShowMore"
|
ng-if="wallet.historyShowMore"
|
||||||
on-infinite="showMore()"
|
on-infinite="showMore()"
|
||||||
distance="1%">
|
distance="1%">
|
||||||
</ion-infinite-scroll>
|
</ion-infinite-scroll>
|
||||||
|
|
|
||||||
1334
src/js/controllers/index.js
Normal file
1334
src/js/controllers/index.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -85,9 +85,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
||||||
$scope.wallet = wallet;
|
$scope.wallet = wallet;
|
||||||
|
|
||||||
if (wallet) {
|
if (wallet) {
|
||||||
walletService.updateStatus(wallet, {
|
walletService.updateStatus(wallet, {}, function(err, status) {
|
||||||
triggerTxUpdate: true
|
|
||||||
}, function(err, status) {
|
|
||||||
console.log(status);
|
console.log(status);
|
||||||
if (err) {} // TODO
|
if (err) {} // TODO
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
|
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
|
root.WALLET_STATUS_MAX_TRIES = 7;
|
||||||
|
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.HISTORY_SHOW_LIMIT = 10;
|
||||||
|
|
||||||
|
|
@ -107,90 +109,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
};
|
};
|
||||||
root.handleError = lodash.debounce(_handleError, 1000);
|
root.handleError = lodash.debounce(_handleError, 1000);
|
||||||
|
|
||||||
|
root.getStatus = function(wallet, opts, cb) {
|
||||||
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) {
|
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
function updateBalance(cb) {
|
function get(cb) {
|
||||||
if (wallet.isValid && !opts.force)
|
|
||||||
return cb();
|
|
||||||
};
|
|
||||||
|
|
||||||
function updateHistory() {
|
|
||||||
if (!opts.triggerTxUpdate) return;
|
|
||||||
$timeout(function() {
|
|
||||||
root.updateHistory(wallet);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function getStatus(cb) {
|
|
||||||
wallet.getStatus({
|
wallet.getStatus({
|
||||||
twoStep: true
|
twoStep: true
|
||||||
}, function(err, ret) {
|
}, function(err, ret) {
|
||||||
|
|
@ -201,61 +123,112 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function walletStatusHash(walletStatus) {
|
function cacheBalance(wallet, balance) {
|
||||||
var bal;
|
if (!balance) return;
|
||||||
if (walletStatus) {
|
|
||||||
bal = walletStatus.balance.totalAmount;
|
var config = configService.getSync().wallet.settings;
|
||||||
|
|
||||||
|
// 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 {
|
} else {
|
||||||
bal = wallet.totalBalanceSat;
|
wallet.totalBalanceSat = balance.totalConfirmedAmount;
|
||||||
|
wallet.lockedBalanceSat = balance.lockedConfirmedAmount;
|
||||||
|
wallet.availableBalanceSat = balance.availableConfirmedAmount;
|
||||||
|
wallet.totalBytesToSendMax = balance.totalBytesToSendConfirmedMax;
|
||||||
|
wallet.pendingAmount = balance.totalAmount - balance.totalConfirmedAmount;
|
||||||
}
|
}
|
||||||
return bal;
|
|
||||||
};
|
|
||||||
|
|
||||||
function doUpdate(initStatusHash, tries) {
|
// Selected unit
|
||||||
if (wallet.isValid && !opts.force) return cb();
|
wallet.unitToSatoshi = config.unitToSatoshi;
|
||||||
|
wallet.satToUnit = 1 / wallet.unitToSatoshi;
|
||||||
|
wallet.unitName = config.unitName;
|
||||||
|
|
||||||
tries = tries || 0;
|
//STR
|
||||||
|
wallet.totalBalanceStr = root.formatAmount(wallet.totalBalanceSat) + ' ' + wallet.unitName;
|
||||||
|
wallet.lockedBalanceStr = root.formatAmount(wallet.lockedBalanceSat) + ' ' + wallet.unitName;
|
||||||
|
wallet.availableBalanceStr = root.formatAmount(wallet.availableBalanceSat) + ' ' + wallet.unitName;
|
||||||
|
|
||||||
$timeout(function() {
|
if (wallet.pendingAmount) {
|
||||||
$log.debug('Updating Status:', wallet.credentials.walletName, tries);
|
wallet.pendingAmountStr = root.formatAmount(wallet.pendingAmount) + ' ' + wallet.unitName;
|
||||||
getStatus(function(err, walletStatus) {
|
} else {
|
||||||
if (err) return cb(err);
|
wallet.pendingAmountStr = null;
|
||||||
|
}
|
||||||
|
|
||||||
var currentStatusHash = walletStatusHash(walletStatus);
|
wallet.alternativeName = config.alternativeName;
|
||||||
$log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries);
|
wallet.alternativeIsoCode = config.alternativeIsoCode;
|
||||||
if (opts.untilItChanges &&
|
|
||||||
initStatusHash == currentStatusHash &&
|
|
||||||
tries < 7 &&
|
|
||||||
walletId == wallet.credentials.walletId) {
|
|
||||||
return $timeout(function() {
|
|
||||||
$log.debug('Retrying update... ' + walletId + ' Try:' + tries)
|
|
||||||
return root.doUpdate(initStatusHash, ++tries, cb);
|
|
||||||
}, 1400 * tries);
|
|
||||||
}
|
|
||||||
|
|
||||||
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
|
rateService.whenAvailable(function() {
|
||||||
|
|
||||||
root.setStatus(wallet, walletStatus);
|
var totalBalanceAlternative = rateService.toFiat(wallet.totalBalanceSat, wallet.alternativeIsoCode);
|
||||||
|
var lockedBalanceAlternative = rateService.toFiat(wallet.lockedBalanceSat, wallet.alternativeIsoCode);
|
||||||
|
var alternativeConversionRate = rateService.toFiat(100000000, wallet.alternativeIsoCode);
|
||||||
|
|
||||||
// wallet.setPendingTxps(walletStatus.pendingTxps);
|
wallet.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
|
||||||
return cb();
|
wallet.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
|
||||||
});
|
wallet.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
|
||||||
|
|
||||||
|
wallet.alternativeBalanceAvailable = true;
|
||||||
|
wallet.isRateAvailable = true;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// trigger history update now?
|
function cacheStatus = (status) {
|
||||||
if (!opts.untilItChanges) updateHistory();
|
wallet.status = status;
|
||||||
|
wallet.statusUpdatedOn = Date.now();
|
||||||
|
wallet.isValid = true;
|
||||||
|
cacheBalance(wallet, status.balance);
|
||||||
|
wallet.email = status.preferences.email;
|
||||||
|
};
|
||||||
|
|
||||||
doUpdate(walletStatusHash(), 0, function(err) {
|
function walletStatusHash(status) {
|
||||||
|
return status ? status.balance.totalAmount : wallet.totalBalanceSat;
|
||||||
|
};
|
||||||
|
|
||||||
|
function _getStatus(initStatusHash, tries, cb) {
|
||||||
|
if (wallet.isValid && !opts.force) return cb(null, wallet.status);
|
||||||
|
|
||||||
|
tries = tries || 0;
|
||||||
|
|
||||||
|
$log.debug('Updating Status:', wallet.credentials.walletName, tries);
|
||||||
|
get(function(err, status) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
var currentStatusHash = walletStatusHash(status);
|
||||||
|
$log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries);
|
||||||
|
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 _getStatus(initStatusHash, ++tries, cb);
|
||||||
|
}, root.WALLET_STATUS_DELAY_BETWEEN_TRIES * tries);
|
||||||
|
}
|
||||||
|
|
||||||
|
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
|
||||||
|
|
||||||
|
root.cacheStatus(wallet, status);
|
||||||
|
|
||||||
|
// wallet.setPendingTxps(status.pendingTxps);
|
||||||
|
return cb(null, status);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_getStatus(walletStatusHash(), 0, function(err, status) {
|
||||||
if (err) {
|
if (err) {
|
||||||
root.handleError(err);
|
root.handleError(err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
return cb(null, status);
|
||||||
if (opts.untilItChanges) updateHistory();
|
|
||||||
return cb();
|
|
||||||
})
|
})
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var getSavedTxs = function(walletId, cb) {
|
var getSavedTxs = function(walletId, cb) {
|
||||||
|
|
@ -363,7 +336,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
$log.debug('Fixing Tx Cache Unit to:' + name)
|
$log.debug('Fixing Tx Cache Unit to:' + name)
|
||||||
lodash.each(txs, function(tx) {
|
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;
|
tx.feeStr = txFormatService.formatAmount(tx.fees) + name;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -479,11 +452,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root.updateHistory = function(wallet) {
|
root.updateHistory = function(wallet, cb) {
|
||||||
var walletId = wallet.credentials.walletId;
|
var walletId = wallet.credentials.walletId;
|
||||||
|
|
||||||
if (!wallet.isComplete()) return;
|
if (!wallet.isComplete()) return cb();
|
||||||
|
|
||||||
|
|
||||||
$log.debug('Updating Transaction History');
|
$log.debug('Updating Transaction History');
|
||||||
wallet.txHistoryError = false;
|
wallet.txHistoryError = false;
|
||||||
|
|
@ -499,7 +471,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
wallet.newTx = false
|
wallet.newTx = false
|
||||||
}, 1000);
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -927,7 +899,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
ongoingProcess.set('signingTx', true);
|
ongoingProcess.set('signingTx', true);
|
||||||
root.signTx(wallet, publishedTxp, function(err, signedTxp) {
|
root.signTx(wallet, publishedTxp, function(err, signedTxp) {
|
||||||
ongoingProcess.set('signingTx', false);
|
ongoingProcess.set('signingTx', false);
|
||||||
root.lock(wallet);
|
root.lock(wallet);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue