Improvement - 247 - Wallet should default currency based on language selected

This commit is contained in:
Jean-Baptiste Dominguez 2018-04-25 13:56:54 +09:00
commit 463eed2583
2 changed files with 62 additions and 7 deletions

View file

@ -1199,11 +1199,46 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
}); });
}) })
.run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService) { .run(function($rootScope, $state, $location, $log, $timeout, startupService, ionicToast, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, emailService, /* plugins START HERE => */ buydotbitcoindotcomService, glideraService, amazonService, bitpayCardService, applicationService, mercadoLibreService, rateService) {
$ionicPlatform.ready(function() {
// Init language
uxLanguage.init(function (lang) {
uxLanguage.init(); // Try to load the profile
profileService.loadAndBindProfile(function(err) {
// If err, first time so I define the currency rate by language
if (err) {
var rateCode = uxLanguage.getRateCode(lang);
$ionicPlatform.ready(function() { rateService.whenAvailable(function() {
var alternatives = rateService.listAlternatives(true);
var newAltCurrency = lodash.find(alternatives, {
'isoCode': rateCode
});
configService.whenAvailable(function(config) {
var opts = {
wallet: {
settings: {
alternativeName: newAltCurrency.name,
alternativeIsoCode: newAltCurrency.isoCode,
}
}
};
configService.set(opts, function(err) {
if (err) $log.warn(err);
});
});
$log.debug('Setting default currency : ' + newAltCurrency);
});
};
});
});
if (screen.width < 768 && platformInfo.isCordova) if (screen.width < 768 && platformInfo.isCordova)
screen.lockOrientation('portrait'); screen.lockOrientation('portrait');
@ -1278,6 +1313,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
$log.debug('No profile... redirecting'); $log.debug('No profile... redirecting');
$state.go('onboarding.tour'); $state.go('onboarding.tour');
} else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) { } else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) {
$scope.setRateByLanguage();
if (lodash.isEmpty(profileService.getWallets())) { if (lodash.isEmpty(profileService.getWallets())) {
$log.debug('No wallets and no disclaimer... redirecting'); $log.debug('No wallets and no disclaimer... redirecting');
$state.go('onboarding.tour'); $state.go('onboarding.tour');

View file

@ -8,41 +8,53 @@ angular.module('copayApp.services')
root.availableLanguages = [{ root.availableLanguages = [{
name: 'English', name: 'English',
isoCode: 'en', isoCode: 'en',
rateCode: 'USD'
}, { }, {
name: 'Español', name: 'Español',
isoCode: 'es', isoCode: 'es',
rateCode: 'EUR'
}, { }, {
name: 'Français', name: 'Français',
isoCode: 'fr', isoCode: 'fr',
rateCode: 'EUR'
}, { }, {
name: 'Italiano', name: 'Italiano',
isoCode: 'it', isoCode: 'it',
rateCode: 'EUR'
}, { }, {
name: 'Nederlands', name: 'Nederlands',
isoCode: 'nl', isoCode: 'nl',
rateCode: 'EUR'
}, { }, {
name: 'Polski', name: 'Polski',
isoCode: 'pl', isoCode: 'pl',
rateCode: 'EUR'
}, { }, {
name: 'Deutsch', name: 'Deutsch',
isoCode: 'de', isoCode: 'de',
rateCode: 'EUR'
}, { }, {
name: '日本語', name: '日本語',
isoCode: 'ja', isoCode: 'ja',
useIdeograms: true, useIdeograms: true,
rateCode: 'JPY'
}, { }, {
name: '中文(简体)', name: '中文(简体)',
isoCode: 'zh', isoCode: 'zh',
useIdeograms: true, useIdeograms: true,
rateCode: 'CNY'
}, { }, {
name: 'Pусский', name: 'Pусский',
isoCode: 'ru', isoCode: 'ru',
rateCode: 'RUB'
}, { }, {
name: 'Português', name: 'Português',
isoCode: 'pt', isoCode: 'pt',
rateCode: 'EUR'
}, { }, {
name: '한국어', name: '한국어',
isoCode: 'ko' isoCode: 'ko',
rateCode: 'KRW'
}]; }];
// }, { // }, {
@ -105,18 +117,19 @@ angular.module('copayApp.services')
return root.availableLanguages; return root.availableLanguages;
}; };
root.init = function(cb) { root.init = function(cb, cbSuccess) {
configService.whenAvailable(function(config) { configService.whenAvailable(function(config) {
var userLang = config.wallet.settings.defaultLanguage; var userLang = config.wallet.settings.defaultLanguage;
if (userLang && userLang != root.currentLanguage) { if (userLang && userLang != root.currentLanguage) {
root._set(userLang); root._set(userLang);
if (cb) return cb(userLang);
} else { } else {
root._detect(function(lang) { root._detect(function(lang) {
root._set(lang); root._set(lang);
if (cb) return cb(lang);
}); });
} }
if (cb) return cb();
}); });
}; };
@ -126,5 +139,11 @@ angular.module('copayApp.services')
}), 'name'); }), 'name');
}; };
root.getRateCode = function(lang) {
return lodash.result(lodash.find(root.availableLanguages, {
'isoCode': lang
}), 'rateCode');
};
return root; return root;
}); });