- 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>
97 lines
2.3 KiB
Dart
97 lines
2.3 KiB
Dart
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/pin_remote_data_provider.dart';
|
|
|
|
@Injectable(as: IPinRepository)
|
|
class PinRepository implements IPinRepository {
|
|
final PinRemoteDataProvider _remoteDataProvider;
|
|
|
|
final String _logName = 'PinRepository';
|
|
|
|
PinRepository(this._remoteDataProvider);
|
|
|
|
@override
|
|
Future<Either<WalletFailure, PinStatus>> getStatus() => _run(
|
|
'getStatus',
|
|
_remoteDataProvider.fetchStatus,
|
|
(dto) => dto.toDomain(),
|
|
);
|
|
|
|
@override
|
|
Future<Either<WalletFailure, PinOtp>> requestOtp(PinOtpPurpose purpose) =>
|
|
_run(
|
|
'requestOtp',
|
|
() => _remoteDataProvider.requestOtp(purpose),
|
|
(dto) => dto.toDomain(),
|
|
);
|
|
|
|
@override
|
|
Future<Either<WalletFailure, PinStatus>> setup({
|
|
required String otpToken,
|
|
required String otpCode,
|
|
required String pin,
|
|
required String confirmPin,
|
|
}) => _run(
|
|
'setup',
|
|
() => _remoteDataProvider.setup(
|
|
otpToken: otpToken,
|
|
otpCode: otpCode,
|
|
pin: pin,
|
|
confirmPin: confirmPin,
|
|
),
|
|
(dto) => dto.toDomain(),
|
|
);
|
|
|
|
@override
|
|
Future<Either<WalletFailure, Unit>> change({
|
|
required String oldPin,
|
|
required String pin,
|
|
required String confirmPin,
|
|
}) => _run(
|
|
'change',
|
|
() => _remoteDataProvider.change(
|
|
oldPin: oldPin,
|
|
pin: pin,
|
|
confirmPin: confirmPin,
|
|
),
|
|
(value) => value,
|
|
);
|
|
|
|
@override
|
|
Future<Either<WalletFailure, Unit>> reset({
|
|
required String otpToken,
|
|
required String otpCode,
|
|
required String pin,
|
|
required String confirmPin,
|
|
}) => _run(
|
|
'reset',
|
|
() => _remoteDataProvider.reset(
|
|
otpToken: otpToken,
|
|
otpCode: otpCode,
|
|
pin: pin,
|
|
confirmPin: confirmPin,
|
|
),
|
|
(value) => value,
|
|
);
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|