Wallet/js/controllers/more.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-03-26 09:18:42 -03:00
'use strict';
2014-08-21 11:04:19 -04:00
angular.module('copayApp.controllers').controller('MoreController',
function($scope, $rootScope, $location, $filter, backupService, walletFactory, controllerUtils, notification, rateService) {
2014-08-21 14:57:50 -04:00
var w = $rootScope.wallet;
2014-08-21 11:02:07 -04:00
2014-09-03 11:33:45 -03:00
$scope.unitOpts = [{
name: 'Satoshis (100,000,000 satoshis = 1BTC)',
shortName: 'SAT',
value: 1,
decimals: 0
}, {
name: 'bits (1,000,000 bits = 1BTC)',
shortName: 'bits',
value: 100,
decimals: 2
}, {
name: 'mBTC (1,000 mBTC = 1BTC)',
shortName: 'mBTC',
value: 100000,
decimals: 5
}, {
name: 'BTC',
shortName: 'BTC',
value: 100000000,
decimals: 8
}];
2014-09-18 19:34:27 -03:00
2014-09-03 11:33:45 -03:00
$scope.selectedAlternative = {
name: w.settings.alternativeName,
isoCode: w.settings.alternativeIsoCode
2014-09-03 11:33:45 -03:00
};
$scope.alternativeOpts = rateService.isAvailable ?
rateService.listAlternatives() : [$scope.selectedAlternative];
rateService.whenAvailable(function() {
$scope.alternativeOpts = rateService.listAlternatives();
for (var ii in $scope.alternativeOpts) {
if (w.settings.alternativeIsoCode === $scope.alternativeOpts[ii].isoCode) {
2014-09-03 11:33:45 -03:00
$scope.selectedAlternative = $scope.alternativeOpts[ii];
}
}
});
for (var ii in $scope.unitOpts) {
if (w.settings.unitName === $scope.unitOpts[ii].shortName) {
2014-09-03 11:33:45 -03:00
$scope.selectedUnit = $scope.unitOpts[ii];
break;
}
}
2014-09-03 13:11:32 -03:00
$scope.save = function() {
w.changeSettings({
unitName: $scope.selectedUnit.shortName,
unitToSatoshi: $scope.selectedUnit.value,
unitDecimals: $scope.selectedUnit.decimals,
alternativeName: $scope.selectedAlternative.name,
alternativeIsoCode: $scope.selectedAlternative.isoCode,
});
2014-09-26 17:52:35 -03:00
notification.success('Success', $filter('translate')('settings successfully updated'));
2014-09-04 16:57:07 -03:00
controllerUtils.updateBalance();
2014-09-03 13:11:32 -03:00
};
2014-09-03 11:33:45 -03:00
2014-09-03 11:27:31 -03:00
$scope.hideAdv = true;
$scope.hidePriv = true;
2014-08-21 16:50:32 -04:00
if (w)
$scope.priv = w.privateKey.toObj().extendedPrivateKeyString;
2014-08-20 14:06:37 -04:00
2014-07-16 19:00:34 -03:00
$scope.downloadBackup = function() {
backupService.download(w);
}
2014-06-16 15:51:19 -03:00
$scope.deleteWallet = function() {
2014-06-16 17:37:33 -03:00
walletFactory.delete(w.id, function() {
2014-06-16 15:51:19 -03:00
controllerUtils.logout();
});
};
2014-08-20 20:52:31 -04:00
2014-08-21 13:12:55 -04:00
$scope.purge = function(deleteAll) {
var removed = w.purgeTxProposals(deleteAll);
2014-09-03 11:27:31 -03:00
if (removed) {
2014-08-21 14:28:02 -04:00
controllerUtils.updateBalance();
}
notification.info('Transactions Proposals Purged', removed + ' ' + $filter('translate')('transaction proposal purged'));
2014-08-21 13:12:55 -04:00
};
2014-08-20 20:52:31 -04:00
$scope.updateIndexes = function() {
2014-09-03 11:27:31 -03:00
notification.info('Scaning for transactions', 'Using derived addresses from your wallet');
2014-08-20 20:52:31 -04:00
w.updateIndexes(function(err) {
notification.info('Scan Ended', 'Updating balance');
if (err) {
notification.error('Error', $filter('translate')('Error updating indexes: ') + err);
2014-08-20 20:52:31 -04:00
}
controllerUtils.updateAddressList();
2014-09-03 11:27:31 -03:00
controllerUtils.updateBalance(function() {
2014-08-20 20:52:31 -04:00
notification.info('Finished', 'The balance is updated using the derived addresses');
2014-08-20 21:29:01 -04:00
w.sendIndexes();
2014-08-20 20:52:31 -04:00
});
});
};
2014-06-16 15:51:19 -03:00
});