Improvement - 247 - Wallet should default currency based on language selected
This commit is contained in:
parent
eba2a19ca2
commit
463eed2583
2 changed files with 62 additions and 7 deletions
|
|
@ -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)
|
||||
screen.lockOrientation('portrait');
|
||||
|
||||
|
|
@ -1278,6 +1313,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
$log.debug('No profile... redirecting');
|
||||
$state.go('onboarding.tour');
|
||||
} else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) {
|
||||
$scope.setRateByLanguage();
|
||||
if (lodash.isEmpty(profileService.getWallets())) {
|
||||
$log.debug('No wallets and no disclaimer... redirecting');
|
||||
$state.go('onboarding.tour');
|
||||
|
|
|
|||
|
|
@ -8,41 +8,53 @@ angular.module('copayApp.services')
|
|||
root.availableLanguages = [{
|
||||
name: 'English',
|
||||
isoCode: 'en',
|
||||
rateCode: 'USD'
|
||||
}, {
|
||||
name: 'Español',
|
||||
isoCode: 'es',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: 'Français',
|
||||
isoCode: 'fr',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: 'Italiano',
|
||||
isoCode: 'it',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: 'Nederlands',
|
||||
isoCode: 'nl',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: 'Polski',
|
||||
isoCode: 'pl',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: 'Deutsch',
|
||||
isoCode: 'de',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: '日本語',
|
||||
isoCode: 'ja',
|
||||
useIdeograms: true,
|
||||
rateCode: 'JPY'
|
||||
}, {
|
||||
name: '中文(简体)',
|
||||
isoCode: 'zh',
|
||||
useIdeograms: true,
|
||||
rateCode: 'CNY'
|
||||
}, {
|
||||
name: 'Pусский',
|
||||
isoCode: 'ru',
|
||||
rateCode: 'RUB'
|
||||
}, {
|
||||
name: 'Português',
|
||||
isoCode: 'pt',
|
||||
rateCode: 'EUR'
|
||||
}, {
|
||||
name: '한국어',
|
||||
isoCode: 'ko'
|
||||
isoCode: 'ko',
|
||||
rateCode: 'KRW'
|
||||
}];
|
||||
|
||||
// }, {
|
||||
|
|
@ -105,18 +117,19 @@ angular.module('copayApp.services')
|
|||
return root.availableLanguages;
|
||||
};
|
||||
|
||||
root.init = function(cb) {
|
||||
root.init = function(cb, cbSuccess) {
|
||||
configService.whenAvailable(function(config) {
|
||||
var userLang = config.wallet.settings.defaultLanguage;
|
||||
|
||||
if (userLang && userLang != root.currentLanguage) {
|
||||
root._set(userLang);
|
||||
if (cb) return cb(userLang);
|
||||
} else {
|
||||
root._detect(function(lang) {
|
||||
root._set(lang);
|
||||
if (cb) return cb(lang);
|
||||
});
|
||||
}
|
||||
if (cb) return cb();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -126,5 +139,11 @@ angular.module('copayApp.services')
|
|||
}), 'name');
|
||||
};
|
||||
|
||||
root.getRateCode = function(lang) {
|
||||
return lodash.result(lodash.find(root.availableLanguages, {
|
||||
'isoCode': lang
|
||||
}), 'rateCode');
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue