temp build
This commit is contained in:
@@ -1,41 +1,40 @@
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/type.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/providers/payment_methods.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
import 'package:pweb/services/amplitude.dart';
|
||||
import 'package:pweb/providers/recipient.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
|
||||
|
||||
class PageSelectorProvider extends ChangeNotifier {
|
||||
static final _logger = Logger('provider.page_selector');
|
||||
|
||||
PayoutDestination _selected = PayoutDestination.dashboard;
|
||||
PaymentType? _type;
|
||||
bool _cameFromRecipientList = false;
|
||||
PayoutDestination? _previousDestination;
|
||||
|
||||
RecipientProvider? recipientProvider;
|
||||
WalletsProvider? walletsProvider;
|
||||
PaymentMethodsProvider? methodsProvider;
|
||||
late RecipientsProvider recipientProvider;
|
||||
late WalletsProvider walletsProvider;
|
||||
late PaymentMethodsProvider methodsProvider;
|
||||
|
||||
PayoutDestination get selected => _selected;
|
||||
PaymentType? get type => _type;
|
||||
bool get cameFromRecipientList => _cameFromRecipientList;
|
||||
|
||||
PageSelectorProvider({
|
||||
this.recipientProvider,
|
||||
this.walletsProvider,
|
||||
this.methodsProvider,
|
||||
});
|
||||
PageSelectorProvider();
|
||||
|
||||
void update(
|
||||
RecipientProvider recipientProv,
|
||||
RecipientsProvider recipientProv,
|
||||
WalletsProvider walletsProv,
|
||||
PaymentMethodsProvider methodsProv,
|
||||
) {
|
||||
@@ -50,44 +49,30 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void selectRecipient(Recipient? recipient, {bool fromList = false}) {
|
||||
if (recipientProvider != null) {
|
||||
recipientProvider!.selectRecipient(recipient);
|
||||
_cameFromRecipientList = fromList;
|
||||
_setPreviousDestination();
|
||||
_selected = PayoutDestination.payment;
|
||||
notifyListeners();
|
||||
} else {
|
||||
debugPrint("RecipientProvider is null — cannot select recipient");
|
||||
}
|
||||
recipientProvider.setCurrentObject(recipient?.id);
|
||||
_cameFromRecipientList = fromList;
|
||||
_setPreviousDestination();
|
||||
_selected = PayoutDestination.payment;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void editRecipient(Recipient? recipient, {bool fromList = false}) {
|
||||
if (recipientProvider != null) {
|
||||
recipientProvider!.selectRecipient(recipient);
|
||||
_cameFromRecipientList = fromList;
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
notifyListeners();
|
||||
} else {
|
||||
debugPrint("RecipientProvider is null — cannot select recipient");
|
||||
}
|
||||
recipientProvider.setCurrentObject(recipient?.id);
|
||||
_cameFromRecipientList = fromList;
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void goToAddRecipient() {
|
||||
if (recipientProvider != null) {
|
||||
AmplitudeService.recipientAddStarted();
|
||||
recipientProvider!.selectRecipient(null);
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
_cameFromRecipientList = false;
|
||||
notifyListeners();
|
||||
} else {
|
||||
debugPrint("RecipientProvider is null — cannot go to add recipient");
|
||||
}
|
||||
AmplitudeService.recipientAddStarted();
|
||||
recipientProvider!.setCurrentObject(null);
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
_cameFromRecipientList = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void startPaymentWithoutRecipient(PaymentType type) {
|
||||
if (recipientProvider != null) {
|
||||
recipientProvider!.selectRecipient(null);
|
||||
}
|
||||
recipientProvider.setCurrentObject(null);
|
||||
_type = type;
|
||||
_cameFromRecipientList = false;
|
||||
_setPreviousDestination();
|
||||
@@ -111,13 +96,9 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void selectWallet(Wallet wallet) {
|
||||
if (walletsProvider != null) {
|
||||
walletsProvider!.selectWallet(wallet);
|
||||
_selected = PayoutDestination.editwallet;
|
||||
notifyListeners();
|
||||
} else {
|
||||
debugPrint("WalletsProvider is null — cannot select wallet");
|
||||
}
|
||||
walletsProvider.selectWallet(wallet);
|
||||
_selected = PayoutDestination.editwallet;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void startPaymentFromWallet(Wallet wallet) {
|
||||
@@ -129,26 +110,26 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
PaymentMethod? getPaymentMethodForWallet(Wallet wallet) {
|
||||
if (methodsProvider == null || methodsProvider!.methods.isEmpty) {
|
||||
if (methodsProvider.methods.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return methodsProvider!.methods.firstWhereOrNull(
|
||||
(method) => method.type == PaymentType.wallet &&
|
||||
method.details.contains(wallet.walletUserID)
|
||||
(method.description?.contains(wallet.walletUserID) ?? false),
|
||||
);
|
||||
}
|
||||
|
||||
Map<PaymentType, Object> getAvailablePaymentTypes() {
|
||||
final recipient = selectedRecipient;
|
||||
if (recipient == null) return {};
|
||||
if ((recipient == null) || !methodsProvider.isReady) return {};
|
||||
|
||||
final methodsForRecipient = methodsProvider.methods.where(
|
||||
(method) => !method.isArchived && method.recipientRef == recipient.id,
|
||||
);
|
||||
|
||||
return {
|
||||
if (recipient.card != null) PaymentType.card: recipient.card!,
|
||||
if (recipient.iban != null) PaymentType.iban: recipient.iban!,
|
||||
if (recipient.wallet != null) PaymentType.wallet: recipient.wallet!,
|
||||
if (recipient.bank != null) PaymentType.bankAccount: recipient.bank!,
|
||||
if (recipient.cryptoAddress != null) PaymentType.cryptoAddress: recipient.cryptoAddress!,
|
||||
for (final method in methodsForRecipient) method.type: method.data,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -158,11 +139,11 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
|
||||
if (availableTypes.containsKey(currentType)) {
|
||||
return currentType;
|
||||
} else if (availableTypes.isNotEmpty) {
|
||||
return availableTypes.keys.first;
|
||||
} else {
|
||||
return PaymentType.bankAccount;
|
||||
}
|
||||
if (availableTypes.isNotEmpty) {
|
||||
return availableTypes.keys.first;
|
||||
}
|
||||
return PaymentType.bankAccount;
|
||||
}
|
||||
|
||||
bool shouldShowPaymentForm() {
|
||||
@@ -170,11 +151,11 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void handleWalletAutoSelection() {
|
||||
if (selectedWallet != null && methodsProvider != null) {
|
||||
if (selectedWallet != null) {
|
||||
final wallet = selectedWallet!;
|
||||
final matchingMethod = getPaymentMethodForWallet(wallet);
|
||||
if (matchingMethod != null) {
|
||||
methodsProvider!.selectMethod(matchingMethod);
|
||||
methodsProvider.setCurrentObject(matchingMethod.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +166,6 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Recipient? get selectedRecipient => recipientProvider?.selectedRecipient;
|
||||
Wallet? get selectedWallet => walletsProvider?.selectedWallet;
|
||||
Recipient? get selectedRecipient => recipientProvider.currentObject;
|
||||
Wallet? get selectedWallet => walletsProvider.selectedWallet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user