adding CityWallet functionality
This commit is contained in:
@@ -49,8 +49,9 @@ class GatewayController extends ChangeNotifier {
|
||||
Future<ApiResponse<Map<String, dynamic>>> poll(String uid) async {
|
||||
startLoading();
|
||||
try {
|
||||
dynamic workflowResponse =
|
||||
await http.get('/public/transaction/poll/$uid');
|
||||
dynamic workflowResponse = await http.get(
|
||||
'/public/transaction/poll/$uid',
|
||||
);
|
||||
|
||||
logger.i(workflowResponse.toString());
|
||||
|
||||
@@ -62,6 +63,10 @@ class GatewayController extends ChangeNotifier {
|
||||
finishLoading();
|
||||
if (model.status == 'SUCCESS') {
|
||||
transactionController.updateReceiptData(response);
|
||||
} else {
|
||||
model.status = 'FAILED';
|
||||
model.errorMessage = response['errorMessage'];
|
||||
return ApiResponse.failure(response['errorMessage']);
|
||||
}
|
||||
notifyListeners();
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
@@ -79,7 +84,7 @@ class GatewayController extends ChangeNotifier {
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> pollTransaction(String uid) async {
|
||||
// poll up to 30 times (~5 minutes at 10-second intervals)
|
||||
int maxAttempts = 30;
|
||||
int maxAttempts = 15;
|
||||
int attempt = 0;
|
||||
|
||||
while (!model.isCancelled && attempt < maxAttempts) {
|
||||
@@ -103,6 +108,9 @@ class GatewayController extends ChangeNotifier {
|
||||
// Otherwise (e.g. PENDING), continue polling
|
||||
} else {
|
||||
// Network error — show failure UI and stop
|
||||
model.isCancelled = true;
|
||||
model.status = 'FAILED';
|
||||
model.errorMessage = result.error;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +126,8 @@ class GatewayController extends ChangeNotifier {
|
||||
|
||||
// Alternative method using Timer instead of while loop
|
||||
Future<ApiResponse<Map<String, dynamic>>> pollTransactionWithTimer(
|
||||
String uid) async {
|
||||
String uid,
|
||||
) async {
|
||||
_pollTimer = Timer.periodic(const Duration(seconds: 5), (timer) async {
|
||||
if (model.isCancelled) {
|
||||
timer.cancel();
|
||||
@@ -145,7 +154,8 @@ class GatewayController extends ChangeNotifier {
|
||||
// This returns immediately; the caller should use the timer callback approach.
|
||||
// Consider refactoring this to use poll(String uid) directly for a consistent API.
|
||||
return ApiResponse.failure(
|
||||
"Polling via timer started; use a different flow for the result");
|
||||
"Polling via timer started; use a different flow for the result",
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -154,4 +164,4 @@ class GatewayController extends ChangeNotifier {
|
||||
_pollTimer?.cancel(); // Cancel timer if it exists
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user