2014-03-26 05:18:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-21 08:04:19 -07:00
|
|
|
angular.module('copayApp.controllers').controller('MoreController',
|
2014-11-29 13:35:48 -08:00
|
|
|
function($scope, $rootScope, $location, $filter, balanceService, notification, rateService) {
|
2014-08-21 11:57:50 -07:00
|
|
|
var w = $rootScope.wallet;
|
2014-10-09 06:37:00 -07:00
|
|
|
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
2014-08-21 08:02:07 -07:00
|
|
|
|
2014-10-27 12:13:06 -07:00
|
|
|
$rootScope.title = 'Settings';
|
2014-10-10 13:58:19 -07:00
|
|
|
|
2014-09-03 07:33:45 -07: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 15:34:27 -07:00
|
|
|
|
2014-09-03 07:33:45 -07:00
|
|
|
$scope.selectedAlternative = {
|
2014-09-03 09:28:14 -07:00
|
|
|
name: w.settings.alternativeName,
|
|
|
|
isoCode: w.settings.alternativeIsoCode
|
2014-09-03 07:33:45 -07:00
|
|
|
};
|
2014-11-07 08:00:40 -08:00
|
|
|
$scope.alternativeOpts = rateService.isAvailable() ?
|
2014-09-03 07:33:45 -07:00
|
|
|
rateService.listAlternatives() : [$scope.selectedAlternative];
|
|
|
|
|
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
$scope.alternativeOpts = rateService.listAlternatives();
|
|
|
|
for (var ii in $scope.alternativeOpts) {
|
2014-09-03 09:28:14 -07:00
|
|
|
if (w.settings.alternativeIsoCode === $scope.alternativeOpts[ii].isoCode) {
|
2014-09-03 07:33:45 -07:00
|
|
|
$scope.selectedAlternative = $scope.alternativeOpts[ii];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for (var ii in $scope.unitOpts) {
|
2014-09-03 09:28:14 -07:00
|
|
|
if (w.settings.unitName === $scope.unitOpts[ii].shortName) {
|
2014-09-03 07:33:45 -07:00
|
|
|
$scope.selectedUnit = $scope.unitOpts[ii];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 10:26:58 -07:00
|
|
|
|
2014-09-03 07:27:31 -07:00
|
|
|
$scope.hideAdv = true;
|
|
|
|
$scope.hidePriv = true;
|
2014-10-04 07:30:08 -07:00
|
|
|
$scope.hideSecret = true;
|
|
|
|
if (w) {
|
2014-08-21 13:50:32 -07:00
|
|
|
$scope.priv = w.privateKey.toObj().extendedPrivateKeyString;
|
2014-10-04 07:30:08 -07:00
|
|
|
$scope.secret = w.getSecret();
|
|
|
|
}
|
2014-08-20 11:06:37 -07:00
|
|
|
|
2014-10-30 07:07:15 -07:00
|
|
|
setTimeout(function() {
|
|
|
|
$scope.$digest();
|
|
|
|
}, 1);
|
|
|
|
|
2014-10-30 07:34:40 -07:00
|
|
|
$scope.save = function() {
|
2014-11-12 09:18:19 -08:00
|
|
|
var w = $rootScope.wallet;
|
2014-10-30 07:34:40 -07:00
|
|
|
w.changeSettings({
|
|
|
|
unitName: $scope.selectedUnit.shortName,
|
|
|
|
unitToSatoshi: $scope.selectedUnit.value,
|
|
|
|
unitDecimals: $scope.selectedUnit.decimals,
|
|
|
|
alternativeName: $scope.selectedAlternative.name,
|
|
|
|
alternativeIsoCode: $scope.selectedAlternative.isoCode,
|
|
|
|
});
|
|
|
|
notification.success('Success', $filter('translate')('settings successfully updated'));
|
2014-11-29 13:35:48 -08:00
|
|
|
balanceService.update(w, function() {
|
2014-11-12 09:18:19 -08:00
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
2014-11-11 11:53:57 -08:00
|
|
|
};
|
2014-08-20 17:52:31 -07:00
|
|
|
|
2014-08-21 10:12:55 -07:00
|
|
|
$scope.purge = function(deleteAll) {
|
|
|
|
var removed = w.purgeTxProposals(deleteAll);
|
2014-09-03 07:27:31 -07:00
|
|
|
if (removed) {
|
2014-11-29 13:35:48 -08:00
|
|
|
balanceService.update(w, function() {
|
2014-11-12 09:18:19 -08:00
|
|
|
$rootScope.$digest();
|
2014-11-29 13:35:48 -08:00
|
|
|
}, true);
|
2014-08-21 11:28:02 -07:00
|
|
|
}
|
2014-09-16 13:30:30 -07:00
|
|
|
notification.info('Transactions Proposals Purged', removed + ' ' + $filter('translate')('transaction proposal purged'));
|
2014-08-21 10:12:55 -07:00
|
|
|
};
|
|
|
|
|
2014-08-20 17:52:31 -07:00
|
|
|
$scope.updateIndexes = function() {
|
2014-11-12 09:18:19 -08:00
|
|
|
var w = $rootScope.wallet;
|
2014-09-03 07:27:31 -07:00
|
|
|
notification.info('Scaning for transactions', 'Using derived addresses from your wallet');
|
2014-08-20 17:52:31 -07:00
|
|
|
w.updateIndexes(function(err) {
|
|
|
|
notification.info('Scan Ended', 'Updating balance');
|
|
|
|
if (err) {
|
2014-09-16 13:30:30 -07:00
|
|
|
notification.error('Error', $filter('translate')('Error updating indexes: ') + err);
|
2014-08-20 17:52:31 -07:00
|
|
|
}
|
2014-11-29 13:35:48 -08:00
|
|
|
balanceService.update(w, function() {
|
2014-08-20 17:52:31 -07:00
|
|
|
notification.info('Finished', 'The balance is updated using the derived addresses');
|
2014-08-20 18:29:01 -07:00
|
|
|
w.sendIndexes();
|
2014-11-12 09:18:19 -08:00
|
|
|
$rootScope.$digest();
|
2014-11-29 13:35:48 -08:00
|
|
|
}, true);
|
2014-08-20 17:52:31 -07:00
|
|
|
});
|
|
|
|
};
|
2014-06-16 11:51:19 -07:00
|
|
|
});
|