2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesUnitController',
|
2016-06-06 18:26:45 -03:00
|
|
|
function($scope, $timeout, $log, configService, go, walletService, profileService) {
|
2015-03-06 12:00:10 -03:00
|
|
|
var config = configService.getSync();
|
|
|
|
|
this.unitName = config.wallet.settings.unitName;
|
|
|
|
|
this.unitOpts = [
|
|
|
|
|
// TODO : add Satoshis to bitcore-wallet-client formatAmount()
|
|
|
|
|
// {
|
|
|
|
|
// name: 'Satoshis (100,000,000 satoshis = 1BTC)',
|
|
|
|
|
// shortName: 'SAT',
|
|
|
|
|
// value: 1,
|
|
|
|
|
// decimals: 0,
|
|
|
|
|
// code: 'sat',
|
|
|
|
|
// },
|
|
|
|
|
{
|
|
|
|
|
name: 'bits (1,000,000 bits = 1BTC)',
|
|
|
|
|
shortName: 'bits',
|
|
|
|
|
value: 100,
|
|
|
|
|
decimals: 2,
|
|
|
|
|
code: 'bit',
|
|
|
|
|
}
|
|
|
|
|
// TODO : add mBTC to bitcore-wallet-client formatAmount()
|
|
|
|
|
// ,{
|
|
|
|
|
// name: 'mBTC (1,000 mBTC = 1BTC)',
|
|
|
|
|
// shortName: 'mBTC',
|
|
|
|
|
// value: 100000,
|
|
|
|
|
// decimals: 5,
|
|
|
|
|
// code: 'mbtc',
|
|
|
|
|
// }
|
|
|
|
|
, {
|
|
|
|
|
name: 'BTC',
|
|
|
|
|
shortName: 'BTC',
|
|
|
|
|
value: 100000000,
|
|
|
|
|
decimals: 8,
|
|
|
|
|
code: 'btc',
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
this.save = function(newUnit) {
|
|
|
|
|
var opts = {
|
|
|
|
|
wallet: {
|
|
|
|
|
settings: {
|
|
|
|
|
unitName: newUnit.shortName,
|
|
|
|
|
unitToSatoshi: newUnit.value,
|
|
|
|
|
unitDecimals: newUnit.decimals,
|
|
|
|
|
unitCode: newUnit.code,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.unitName = newUnit.shortName;
|
|
|
|
|
|
|
|
|
|
configService.set(opts, function(err) {
|
2015-06-29 21:46:34 -03:00
|
|
|
if (err) $log.warn(err);
|
2015-11-13 16:00:28 -03:00
|
|
|
go.preferencesGlobal();
|
2015-04-25 12:37:04 -03:00
|
|
|
$scope.$emit('Local/UnitSettingUpdated');
|
2016-06-06 18:26:45 -03:00
|
|
|
walletService.updateRemotePreferences(profileService.getClients(), {}, function() {
|
2016-06-07 10:37:39 -03:00
|
|
|
$log.debug('Remote preferences saved');
|
2016-06-06 18:26:45 -03:00
|
|
|
});
|
2015-11-13 16:00:28 -03:00
|
|
|
$timeout(function() {
|
|
|
|
|
$scope.$apply();
|
|
|
|
|
}, 100);
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
});
|