Merge pull request #4348 from JDonadio/bug/select-unit
Fix unit selection
This commit is contained in:
commit
7c8b77413c
2 changed files with 49 additions and 74 deletions
|
|
@ -1,19 +1,11 @@
|
||||||
<div
|
<div class="topbar-container" ng-include="'views/includes/topbar.html'"
|
||||||
class="topbar-container"
|
|
||||||
ng-include="'views/includes/topbar.html'"
|
|
||||||
ng-init="titleSection='Unit'; goBackToState = 'preferencesGlobal'; noColor = true">
|
ng-init="titleSection='Unit'; goBackToState = 'preferencesGlobal'; noColor = true">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="content preferences" ng-controller="preferencesUnitController">
|
||||||
|
|
||||||
|
|
||||||
<div class="content preferences" ng-controller="preferencesUnitController as prefUnit">
|
|
||||||
<h4></h4>
|
<h4></h4>
|
||||||
<ul class="no-bullet m0 ">
|
|
||||||
<li ng-repeat="unit in prefUnit.unitOpts" ng-click="prefUnit.save(unit)" class="line-b p20 size-14">
|
<ion-radio class="line-b size-12" ng-repeat="unit in unitList" ng-value="unit.code" ng-model="currentUnit"
|
||||||
<span>{{unit.shortName}}</span>
|
ng-click="save(unit)">{{unit.shortName}}
|
||||||
<i class="fi-check size-16 right" ng-show="prefUnit.unitName == unit.shortName"></i>
|
</ion-radio>
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="extra-margin-bottom"></div>
|
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,49 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesUnitController',
|
angular.module('copayApp.controllers').controller('preferencesUnitController', function($scope, $log, configService, go, walletService, profileService) {
|
||||||
function($scope, $timeout, $log, configService, go, walletService, profileService) {
|
|
||||||
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 config = configService.getSync();
|
||||||
var opts = {
|
|
||||||
wallet: {
|
$scope.currentUnit = config.wallet.settings.unitCode;
|
||||||
settings: {
|
|
||||||
unitName: newUnit.shortName,
|
$scope.unitList = [
|
||||||
unitToSatoshi: newUnit.value,
|
{
|
||||||
unitDecimals: newUnit.decimals,
|
name: 'bits (1,000,000 bits = 1BTC)',
|
||||||
unitCode: newUnit.code,
|
shortName: 'bits',
|
||||||
}
|
value: 100,
|
||||||
|
decimals: 2,
|
||||||
|
code: 'bit',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'BTC',
|
||||||
|
shortName: 'BTC',
|
||||||
|
value: 100000000,
|
||||||
|
decimals: 8,
|
||||||
|
code: 'btc',
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
$scope.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) {
|
|
||||||
if (err) $log.warn(err);
|
|
||||||
go.preferencesGlobal();
|
|
||||||
$scope.$emit('Local/UnitSettingUpdated');
|
|
||||||
walletService.updateRemotePreferences(profileService.getClients(), {}, function() {
|
|
||||||
$log.debug('Remote preferences saved');
|
|
||||||
});
|
|
||||||
$timeout(function() {
|
|
||||||
$scope.$apply();
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.warn(err);
|
||||||
|
|
||||||
|
go.preferencesGlobal();
|
||||||
|
$scope.$emit('Local/UnitSettingUpdated');
|
||||||
|
|
||||||
|
walletService.updateRemotePreferences(profileService.getClients(), {}, function() {
|
||||||
|
$log.debug('Remote preferences saved');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue