improving polling logic
This commit is contained in:
@@ -242,7 +242,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget>
|
||||
),
|
||||
child: ClipOval(
|
||||
child: Image.asset(
|
||||
flagAsset,
|
||||
'assets/$flagAsset',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => Icon(
|
||||
Icons.monetization_on_outlined,
|
||||
|
||||
@@ -90,12 +90,6 @@ class GatewayController extends ChangeNotifier {
|
||||
while (!model.isCancelled && attempt < maxAttempts) {
|
||||
attempt++;
|
||||
|
||||
// Wait 10 seconds before each poll request
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
|
||||
// Check again after delay in case it was cancelled during the delay
|
||||
if (model.isCancelled) break;
|
||||
|
||||
ApiResponse<Map<String, dynamic>> result = await poll(uid);
|
||||
|
||||
// Only stop on success or failure
|
||||
@@ -105,8 +99,15 @@ class GatewayController extends ChangeNotifier {
|
||||
if (status == 'SUCCESS') {
|
||||
return result;
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
if (model.isCancelled) break;
|
||||
|
||||
// Otherwise (e.g. PENDING), continue polling
|
||||
} else {
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
if (model.isCancelled) break;
|
||||
|
||||
// Network error — show failure UI and stop
|
||||
model.isCancelled = true;
|
||||
model.status = 'FAILED';
|
||||
|
||||
Reference in New Issue
Block a user