Improvement - 172 - Make default price display in fiat

This commit is contained in:
Jean-Baptiste Dominguez 2018-04-25 13:59:25 +09:00
commit 12f1c2e28a
9 changed files with 118 additions and 2 deletions

View file

@ -0,0 +1,42 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesPriceDisplayController', function($scope, $q, $timeout, configService, $ionicNavBarDelegate) {
$scope.save = function(priceDisplay) {
if ($scope.noSave) return;
var opts = {
wallet: {
settings: {
priceDisplay: priceDisplay
}
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
$timeout(function() {
$scope.$apply();
});
});
};
$scope.$on("$ionicView.enter", function(event, data) {
$ionicNavBarDelegate.showBar(true);
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
$scope.init();
});
$scope.init = function () {
configService.whenAvailable(function(config) {
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
$timeout(function() {
$scope.$apply();
});
});
};
});

View file

@ -16,6 +16,8 @@ angular.module('copayApp.controllers').controller('tabSettingsController', funct
isoCode: config.wallet.settings.alternativeIsoCode
};
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
// TODO move this to a generic service
bitpayAccountService.getAccounts(function(err, data) {
if (err) $log.error(err);

View file

@ -367,6 +367,15 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
configService.whenAvailable(function (config) {
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
$timeout(function () {
$scope.apply();
});
});
$scope.walletId = data.stateParams.walletId;
$scope.wallet = profileService.getWallet($scope.walletId);
if (!$scope.wallet) return;

View file

@ -413,6 +413,15 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
}
})
.state('tabs.priceDisplay', {
url: '/priceDisplay',
views: {
'tab-settings@tabs': {
controller: 'preferencesPriceDisplayController',
templateUrl: 'views/preferencesPriceDisplay.html'
}
}
})
.state('tabs.about', {
url: '/about',
views: {

View file

@ -69,6 +69,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
unitCode: 'btc',
alternativeName: 'US Dollar',
alternativeIsoCode: 'USD',
priceDisplay: 'fiat', // 'fiat' || 'crypto'
}
},
@ -181,6 +182,11 @@ angular.module('copayApp.services').factory('configService', function(storageSer
configCache.wallet.settings.unitCode = defaultConfig.wallet.settings.unitCode;
}
// If display is not configure, take the default value
if (!configCache.wallet.settings.priceDisplay) {
configCache.wallet.settings.display = defaultConfig.wallet.settings.priceDisplay;
}
// Convert tarascash wallet to new style cash wallet
if (configCache.bwsbcc && configCache.bwsbcc.url && configCache.bwsbcc.url.indexOf('bwsbcc') >= 0) {
configCache.bwsbcc = defaultConfig.bwscash.url;