Skip to content

Commit

Permalink
Fixing bug in load ussd codes first time
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Ciber committed Oct 9, 2021
1 parent 2457137 commit 44725de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ generate:
run:
flutter run --flavor development --target lib/main_development.dart

.PHONY: run-prod
run-prod:
flutter run --flavor production --target lib/main_production.dart

.PHONY: build
build:
flutter build apk --flavor production --target lib/main_production.dart --target-platform=android-arm

.PHONY: run-prod
run-prod:
flutter run --flavor production --target lib/main_production.dart
.PHONY: build-stg
build-stg:
flutter build apk --flavor staging --target lib/main_staging.dart --target-platform=android-arm

.PHONY: build-dev
build-dev:
Expand Down
45 changes: 26 additions & 19 deletions lib/app/data/repositories/ussd_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,37 @@ class UssdRepository {
final actualDay = DateTime.now().day;

if (lastDay != actualDay) {
return getUssdCodesRemote();
final result = await getUssdCodesRemote();

return result.when(
success: (data) {
return Result.success(data: data);
},
error: (error) async {
try {
final ussdItems = await _localDatasource.getUssdCodes();

return Result.success(data: ussdItems);
} on UssdCodesCacheException {
try {
final ussdItems = await _assetsDatasource.getUssdCodes();

await _localDatasource.saveUssdCodes(ussdItems, '');

return Result.success(data: ussdItems);
} on Exception {
return const Result.error(
message: 'Error al cargar los códigos ussd',
);
}
}
},
);
} else {
final ussdItems = await _localDatasource.getUssdCodes();

return Result.success(data: ussdItems);
}
} on UssdCodesServerException {
try {
final ussdItems = await _localDatasource.getUssdCodes();

return Result.success(data: ussdItems);
} on UssdCodesCacheException {
try {
final ussdItems = await _assetsDatasource.getUssdCodes();

await _localDatasource.saveUssdCodes(ussdItems, '');

return Result.success(data: ussdItems);
} on Exception {
return const Result.error(
message: 'Error al cargar los códigos ussd',
);
}
}
} on UssdCodesCacheException {
try {
final ussdItems = await _assetsDatasource.getUssdCodes();
Expand Down

0 comments on commit 44725de

Please sign in to comment.