Add saved payout destination UX and service contracts (#54)
This commit is contained in:
1 parent
a5689876ff
commit
24af794112
49 files changed
+4687
-62
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'models.dart';
|
||||
import 'service.dart';
|
||||
|
||||
class DestinationSelectionProvider extends ChangeNotifier {
|
||||
DestinationSelectionProvider(this.service, this.context);
|
||||
final DestinationService service;
|
||||
final PayoutContext context;
|
||||
final assessments = <String, PayoutEligibility>{};
|
||||
bool busy = false, _disposed = false;
|
||||
DestinationIssue? error;
|
||||
Future<void> assess(List<SavedDestination> methods) async {
|
||||
for (final d in methods) {
|
||||
try {
|
||||
final assessment = await service.assess(d.input, context);
|
||||
if (_disposed) return;
|
||||
assessments[d.id] = assessment;
|
||||
} on DestinationException catch (e) {
|
||||
if (_disposed) return;
|
||||
assessments[d.id] = PayoutEligibility(
|
||||
EligibilityState.requiresAction,
|
||||
reason: e.issue,
|
||||
);
|
||||
} catch (_) {
|
||||
if (_disposed) return;
|
||||
assessments[d.id] = const PayoutEligibility(
|
||||
EligibilityState.temporarilyUnavailable,
|
||||
reason: DestinationIssue.unavailable,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
Future<SavedReference?> select(SavedDestination d) async {
|
||||
if (busy) return null;
|
||||
busy = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
SavedReference? result;
|
||||
try {
|
||||
final current = await service.get(d.id);
|
||||
final a = await service.assess(current.input, context);
|
||||
if (_disposed) return null;
|
||||
assessments[d.id] = a;
|
||||
if (a.eligible) result = current.input;
|
||||
} on DestinationException catch (e) {
|
||||
error = e.issue;
|
||||
} catch (_) {
|
||||
error = DestinationIssue.unavailable;
|
||||
}
|
||||
if (_disposed) return null;
|
||||
busy = false;
|
||||
notifyListeners();
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user