feat: integrate enakgame and voucher
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/wallet/wallet.dart';
|
||||
import '../datasources/voucher_remote_data_provider.dart';
|
||||
|
||||
@Injectable(as: IVoucherRepository)
|
||||
class VoucherRepository implements IVoucherRepository {
|
||||
final VoucherRemoteDataProvider _remoteDataProvider;
|
||||
|
||||
final String _logName = 'VoucherRepository';
|
||||
|
||||
VoucherRepository(this._remoteDataProvider);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, List<Voucher>>> getVouchers() => _run(
|
||||
'getVouchers',
|
||||
_remoteDataProvider.fetchVouchers,
|
||||
(dtos) => dtos.map((e) => e.toDomain()).toList(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, VoucherRedeemResult>> redeem({
|
||||
required String voucherId,
|
||||
required String pin,
|
||||
required String idempotencyKey,
|
||||
}) => _run(
|
||||
'redeem',
|
||||
() => _remoteDataProvider.redeem(
|
||||
voucherId: voucherId,
|
||||
pin: pin,
|
||||
idempotencyKey: idempotencyKey,
|
||||
),
|
||||
(dto) => dto.toRedeemResult(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, VoucherRedemptionPage>> getRedemptions({
|
||||
required int page,
|
||||
int limit = 20,
|
||||
}) => _run(
|
||||
'getRedemptions',
|
||||
() => _remoteDataProvider.fetchRedemptions(page: page, limit: limit),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
Future<Either<WalletFailure, R>> _run<D, R>(
|
||||
String name,
|
||||
Future<DC<WalletFailure, D>> Function() call,
|
||||
R Function(D dto) toDomain,
|
||||
) async {
|
||||
try {
|
||||
final result = await call();
|
||||
if (result.hasError) return left(result.error!);
|
||||
return right(toDomain(result.data as D));
|
||||
} catch (e, s) {
|
||||
log(name, name: _logName, error: e, stackTrace: s);
|
||||
return left(const WalletFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,15 +50,6 @@ class WalletRepository implements IWalletRepository {
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, PaymentCode>> createPaymentCode({
|
||||
required String pin,
|
||||
}) => _run(
|
||||
'createPaymentCode',
|
||||
() => _remoteDataProvider.createPaymentCode(pin: pin),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, ExchangePreview>> previewExchange({
|
||||
required int coins,
|
||||
|
||||
Reference in New Issue
Block a user