- 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>
89 lines
2.7 KiB
Dart
89 lines
2.7 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:dartz/dartz.dart';
|
|
import 'package:data_channel/data_channel.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:injectable/injectable.dart';
|
|
|
|
import '../../../common/api/api_client.dart';
|
|
import '../../../common/api/api_failure.dart';
|
|
import '../../../common/function/app_function.dart';
|
|
import '../../../common/url/api_path.dart';
|
|
import '../../../domain/wallet/wallet.dart';
|
|
import '../wallet_response.dart';
|
|
|
|
@injectable
|
|
class DeviceLocalDataProvider {
|
|
final FlutterSecureStorage _storage;
|
|
|
|
static const _deviceIdKey = 'device_id';
|
|
static const _registeredKey = 'device_registered';
|
|
|
|
DeviceLocalDataProvider(this._storage);
|
|
|
|
/// ID unik & stabil per instalasi; dibuat sekali lalu disimpan.
|
|
Future<String> deviceId() async {
|
|
final saved = await _storage.read(key: _deviceIdKey);
|
|
if (saved != null && saved.isNotEmpty) return saved;
|
|
|
|
final created = generateUuidV4();
|
|
await _storage.write(key: _deviceIdKey, value: created);
|
|
return created;
|
|
}
|
|
|
|
Future<bool> isRegistered() async =>
|
|
await _storage.read(key: _registeredKey) == 'true';
|
|
|
|
Future<void> setRegistered(bool value) =>
|
|
_storage.write(key: _registeredKey, value: value.toString());
|
|
}
|
|
|
|
@injectable
|
|
class DeviceRemoteDataProvider {
|
|
final ApiClient _apiClient;
|
|
final String _logName = 'DeviceRemoteDataProvider';
|
|
|
|
DeviceRemoteDataProvider(this._apiClient);
|
|
|
|
Future<DC<WalletFailure, Unit>> register({
|
|
required String deviceId,
|
|
required String fcmToken,
|
|
required String platform,
|
|
required String appVersion,
|
|
}) async {
|
|
try {
|
|
final response = await _apiClient.put(
|
|
ApiPath.devices,
|
|
headers: getAuthorizationHeader(),
|
|
data: {
|
|
'device_id': deviceId,
|
|
'fcm_token': fcmToken,
|
|
'platform': platform,
|
|
'app_version': appVersion,
|
|
},
|
|
);
|
|
final failure = parseWalletFailure(response);
|
|
if (failure != null) return DC.error(failure);
|
|
return DC.data(unit);
|
|
} on ApiFailure catch (e, s) {
|
|
log('register', name: _logName, error: e, stackTrace: s);
|
|
return DC.error(WalletFailure.serverError(e));
|
|
}
|
|
}
|
|
|
|
Future<DC<WalletFailure, Unit>> unregister({required String deviceId}) async {
|
|
try {
|
|
final response = await _apiClient.delete(
|
|
'${ApiPath.devices}/$deviceId',
|
|
headers: getAuthorizationHeader(),
|
|
);
|
|
final failure = parseWalletFailure(response);
|
|
if (failure != null) return DC.error(failure);
|
|
return DC.data(unit);
|
|
} on ApiFailure catch (e, s) {
|
|
log('unregister', name: _logName, error: e, stackTrace: s);
|
|
return DC.error(WalletFailure.serverError(e));
|
|
}
|
|
}
|
|
}
|