improving polling logic

This commit is contained in:
Prince
2026-06-12 23:48:21 +02:00
parent 202756a6bb
commit 77236a11d9
2 changed files with 8 additions and 7 deletions

View File

@@ -242,7 +242,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget>
), ),
child: ClipOval( child: ClipOval(
child: Image.asset( child: Image.asset(
flagAsset, 'assets/$flagAsset',
fit: BoxFit.cover, fit: BoxFit.cover,
errorBuilder: (_, __, ___) => Icon( errorBuilder: (_, __, ___) => Icon(
Icons.monetization_on_outlined, Icons.monetization_on_outlined,

View File

@@ -90,12 +90,6 @@ class GatewayController extends ChangeNotifier {
while (!model.isCancelled && attempt < maxAttempts) { while (!model.isCancelled && attempt < maxAttempts) {
attempt++; 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); ApiResponse<Map<String, dynamic>> result = await poll(uid);
// Only stop on success or failure // Only stop on success or failure
@@ -105,8 +99,15 @@ class GatewayController extends ChangeNotifier {
if (status == 'SUCCESS') { if (status == 'SUCCESS') {
return result; return result;
} }
await Future.delayed(const Duration(seconds: 10));
if (model.isCancelled) break;
// Otherwise (e.g. PENDING), continue polling // Otherwise (e.g. PENDING), continue polling
} else { } else {
await Future.delayed(const Duration(seconds: 10));
if (model.isCancelled) break;
// Network error — show failure UI and stop // Network error — show failure UI and stop
model.isCancelled = true; model.isCancelled = true;
model.status = 'FAILED'; model.status = 'FAILED';