feat: integrate enakgame and voucher
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
|
||||
part 'voucher_loader_event.dart';
|
||||
part 'voucher_loader_state.dart';
|
||||
part 'voucher_loader_bloc.freezed.dart';
|
||||
|
||||
/// Katalog voucher yang bisa ditukar (§9.1).
|
||||
@injectable
|
||||
class VoucherLoaderBloc extends Bloc<VoucherLoaderEvent, VoucherLoaderState> {
|
||||
final IVoucherRepository _repository;
|
||||
|
||||
VoucherLoaderBloc(this._repository) : super(VoucherLoaderState.initial()) {
|
||||
on<VoucherLoaderEvent>(_onVoucherLoaderEvent);
|
||||
}
|
||||
|
||||
Future<void> _onVoucherLoaderEvent(
|
||||
VoucherLoaderEvent event,
|
||||
Emitter<VoucherLoaderState> emit,
|
||||
) {
|
||||
return event.map(
|
||||
fetched: (e) async {
|
||||
emit(state.copyWith(isFetching: true, failureOption: none()));
|
||||
|
||||
final result = await _repository.getVouchers();
|
||||
|
||||
final data = result.fold(
|
||||
(f) => state.copyWith(failureOption: optionOf(f)),
|
||||
(vouchers) => state.copyWith(vouchers: vouchers, hasLoaded: true),
|
||||
);
|
||||
|
||||
emit(data.copyWith(isFetching: false));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user