Connect customer quotations and payment execution to Sendico (#50)

This commit is contained in:
Stephan D committed 2026-10-16 09:57:28 +02:00
1 parent 5d67c25c8e
commit 7a6510d1a8
45 files changed
+2696 -45

No files matched your search

@@ -19,6 +19,8 @@ class TransferProvider extends ChangeNotifier {
.firstOrNull
?.id ??
'usd';
wallet.addListener(_walletChanged);
_syncAccounts();
final op = recorder.begin(
journey,
JourneyStep.transferDraft,
@@ -26,6 +28,30 @@ class TransferProvider extends ChangeNotifier {
);
recorder.finish(op, simulated: wallet.service.isSimulated);
}
void _syncAccounts() {
final accounts = wallet.data?.accounts;
if (accounts == null ||
accounts.isEmpty ||
busy ||
uncertain ||
quote != null)
return;
if (!accounts.any((a) => a.id == source)) source = accounts.first.id;
if (!accounts.any((a) => a.id == destination) || destination == source) {
destination = accounts.where((a) => a.id != source).firstOrNull?.id;
}
if (!wallet.service.isSimulated && kind == TransferKind.payout) {
recipient = wallet.account(source)?.payoutMethod ?? '';
}
}
void _walletChanged() {
if (_disposed) return;
final previous = source;
_syncAccounts();
if (source != previous) notifyListeners();
}
final WalletProvider wallet;
final TransferKind kind;
final JourneyRecorder recorder;
@@ -45,7 +71,8 @@ class TransferProvider extends ChangeNotifier {
TransferKind.exchange => JourneyKind.exchange,
TransferKind.payout => JourneyKind.payout,
};
bool get hasDraft => amount.isNotEmpty || recipient.isNotEmpty;
bool get hasDraft =>
amount.isNotEmpty || (wallet.service.isSimulated && recipient.isNotEmpty);
bool get expired =>
quote != null && !DateTime.now().isBefore(quote!.expiresAt);
void change({
@@ -59,6 +86,7 @@ class TransferProvider extends ChangeNotifier {
this.destination = destination ?? this.destination;
this.amount = amount ?? this.amount;
this.recipient = recipient ?? this.recipient;
if (source != null) _syncAccounts();
quote = null;
noSubmission = false;
error = null;
@@ -171,6 +199,7 @@ class TransferProvider extends ChangeNotifier {
error = null;
factorError = null;
notifyListeners();
_key ??= approval?.token;
_key ??= List.generate(
16,
(_) => Random.secure().nextInt(256).toRadixString(16).padLeft(2, '0'),
@@ -266,6 +295,7 @@ class TransferProvider extends ChangeNotifier {
@override
void dispose() {
_disposed = true;
wallet.removeListener(_walletChanged);
recipient = '';
if (!_handedOff) recorder.dispose();
super.dispose();