EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -0,0 +1,128 @@
|
||||
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/wallet_remote_data_provider.dart';
|
||||
|
||||
@Injectable(as: IWalletRepository)
|
||||
class WalletRepository implements IWalletRepository {
|
||||
final WalletRemoteDataProvider _remoteDataProvider;
|
||||
|
||||
final String _logName = 'WalletRepository';
|
||||
|
||||
WalletRepository(this._remoteDataProvider);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, WalletSummary>> getWallet() => _run(
|
||||
'getWallet',
|
||||
_remoteDataProvider.fetchWallet,
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, WalletTransactionPage>> getTransactions({
|
||||
required int page,
|
||||
int limit = 20,
|
||||
WalletCurrency? currency,
|
||||
List<WalletTransactionType> types = const [],
|
||||
DateTime? from,
|
||||
DateTime? to,
|
||||
}) => _run(
|
||||
'getTransactions',
|
||||
() => _remoteDataProvider.fetchTransactions(
|
||||
page: page,
|
||||
limit: limit,
|
||||
currency: currency,
|
||||
types: types,
|
||||
from: from,
|
||||
to: to,
|
||||
),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, WalletExpiring>> getExpiring() => _run(
|
||||
'getExpiring',
|
||||
_remoteDataProvider.fetchExpiring,
|
||||
(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,
|
||||
}) => _run(
|
||||
'previewExchange',
|
||||
() => _remoteDataProvider.previewExchange(coins: coins),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, ExchangeResult>> exchange({
|
||||
required int coins,
|
||||
required String pin,
|
||||
required String idempotencyKey,
|
||||
}) => _run(
|
||||
'exchange',
|
||||
() => _remoteDataProvider.exchange(
|
||||
coins: coins,
|
||||
pin: pin,
|
||||
idempotencyKey: idempotencyKey,
|
||||
),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, TransferRecipient>> checkRecipient({
|
||||
required String phone,
|
||||
}) => _run(
|
||||
'checkRecipient',
|
||||
() => _remoteDataProvider.checkRecipient(phone: phone),
|
||||
(dto) => dto.toDomain(),
|
||||
);
|
||||
|
||||
@override
|
||||
Future<Either<WalletFailure, TransferResult>> transfer({
|
||||
required WalletCurrency currency,
|
||||
required int amount,
|
||||
required String recipientPhone,
|
||||
required String pin,
|
||||
required String idempotencyKey,
|
||||
}) => _run(
|
||||
'transfer',
|
||||
() => _remoteDataProvider.transfer(
|
||||
currency: currency,
|
||||
amount: amount,
|
||||
recipientPhone: recipientPhone,
|
||||
pin: pin,
|
||||
idempotencyKey: idempotencyKey,
|
||||
),
|
||||
(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user