aboutsummaryrefslogtreecommitdiff
path: root/packages/anastasis-core
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-11-08 16:51:23 +0100
committerFlorian Dold <florian@dold.me>2021-11-08 16:51:23 +0100
commit6a0c5263bba435b3ab3a8cda335ceadf7cdd4664 (patch)
treed043fb1ceef7cbba9f28151a9117460f25706ab4 /packages/anastasis-core
parent16662b194d214fad6ccc244261ed1c02e197a390 (diff)
anastasis-webui: ui tweaks
Diffstat (limited to 'packages/anastasis-core')
-rw-r--r--packages/anastasis-core/src/index.ts41
1 files changed, 34 insertions, 7 deletions
diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts
index 3be0d7b76..f88e6e8bc 100644
--- a/packages/anastasis-core/src/index.ts
+++ b/packages/anastasis-core/src/index.ts
@@ -109,13 +109,23 @@ export * from "./challenge-feedback-types.js";
const logger = new Logger("anastasis-core:index.ts");
-function getContinents(): ContinentInfo[] {
+function getContinents(
+ opts: { requireProvider?: boolean } = {},
+): ContinentInfo[] {
+ const currenciesWithProvider = new Set<string>();
+ anastasisData.providersList.anastasis_provider.forEach((x) => {
+ currenciesWithProvider.add(x.currency);
+ });
const continentSet = new Set<string>();
const continents: ContinentInfo[] = [];
for (const country of anastasisData.countriesList.countries) {
if (continentSet.has(country.continent)) {
continue;
}
+ if (opts.requireProvider && !currenciesWithProvider.has(country.currency)) {
+ // Country's currency doesn't have any providers => skip
+ continue;
+ }
continentSet.add(country.continent);
continents.push({
...{ name_i18n: country.continent_i18n },
@@ -148,9 +158,18 @@ export class ReducerError extends Error {
* Get countries for a continent, abort with ReducerError
* exception when continent doesn't exist.
*/
-function getCountries(continent: string): CountryInfo[] {
+function getCountries(
+ continent: string,
+ opts: { requireProvider?: boolean } = {},
+): CountryInfo[] {
+ const currenciesWithProvider = new Set<string>();
+ anastasisData.providersList.anastasis_provider.forEach((x) => {
+ currenciesWithProvider.add(x.currency);
+ });
const countries = anastasisData.countriesList.countries.filter(
- (x) => x.continent === continent,
+ (x) =>
+ x.continent === continent &&
+ (!opts.requireProvider || currenciesWithProvider.has(x.currency)),
);
if (countries.length <= 0) {
throw new ReducerError({
@@ -164,14 +183,18 @@ function getCountries(continent: string): CountryInfo[] {
export async function getBackupStartState(): Promise<ReducerStateBackup> {
return {
backup_state: BackupStates.ContinentSelecting,
- continents: getContinents(),
+ continents: getContinents({
+ requireProvider: true,
+ }),
};
}
export async function getRecoveryStartState(): Promise<ReducerStateRecovery> {
return {
recovery_state: RecoveryStates.ContinentSelecting,
- continents: getContinents(),
+ continents: getContinents({
+ requireProvider: true,
+ }),
};
}
@@ -1073,7 +1096,9 @@ async function backupSelectContinent(
state: ReducerStateBackup,
args: ActionArgsSelectContinent,
): Promise<ReducerStateBackup | ReducerStateError> {
- const countries = getCountries(args.continent);
+ const countries = getCountries(args.continent, {
+ requireProvider: true,
+ });
if (countries.length <= 0) {
return {
code: TalerErrorCode.ANASTASIS_REDUCER_INPUT_INVALID,
@@ -1092,7 +1117,9 @@ async function recoverySelectContinent(
state: ReducerStateRecovery,
args: ActionArgsSelectContinent,
): Promise<ReducerStateRecovery | ReducerStateError> {
- const countries = getCountries(args.continent);
+ const countries = getCountries(args.continent, {
+ requireProvider: true,
+ });
return {
...state,
recovery_state: RecoveryStates.CountrySelecting,