Top Up Balance logic and Added fixes for routing
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:pshared/provider/recipient/provider.dart';
|
||||
import 'package:pweb/models/wallet.dart';
|
||||
import 'package:pweb/providers/wallets.dart';
|
||||
//import 'package:pweb/services/amplitude.dart';
|
||||
import 'package:pweb/app/router/payout_routes.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
|
||||
|
||||
@@ -41,44 +42,93 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
methodsProvider = methodsProv;
|
||||
}
|
||||
|
||||
void selectPage(PayoutDestination dest) {
|
||||
_selected = dest;
|
||||
void syncDestination(PayoutDestination destination) {
|
||||
if (_selected == destination) return;
|
||||
_selected = destination;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void selectRecipient(Recipient? recipient, {bool fromList = false}) {
|
||||
void selectPage(
|
||||
BuildContext context,
|
||||
PayoutDestination dest, {
|
||||
bool replace = true,
|
||||
}) {
|
||||
_selected = dest;
|
||||
notifyListeners();
|
||||
_navigateTo(context, dest, replace: replace);
|
||||
}
|
||||
|
||||
void selectRecipient(
|
||||
BuildContext context,
|
||||
Recipient? recipient, {
|
||||
bool fromList = false,
|
||||
}) {
|
||||
final previousDestination = _selected;
|
||||
recipientProvider.setCurrentObject(recipient?.id);
|
||||
_cameFromRecipientList = fromList;
|
||||
_setPreviousDestination();
|
||||
_selected = PayoutDestination.payment;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.payment) {
|
||||
_navigateTo(context, PayoutDestination.payment, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void editRecipient(Recipient? recipient, {bool fromList = false}) {
|
||||
void editRecipient(
|
||||
BuildContext context,
|
||||
Recipient? recipient, {
|
||||
bool fromList = false,
|
||||
}) {
|
||||
final previousDestination = _selected;
|
||||
recipientProvider.setCurrentObject(recipient?.id);
|
||||
_cameFromRecipientList = fromList;
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.addrecipient) {
|
||||
_navigateTo(context, PayoutDestination.addrecipient, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void goToAddRecipient() {
|
||||
void goToAddRecipient(BuildContext context) {
|
||||
// AmplitudeService.recipientAddStarted();
|
||||
final previousDestination = _selected;
|
||||
recipientProvider.setCurrentObject(null);
|
||||
_selected = PayoutDestination.addrecipient;
|
||||
_cameFromRecipientList = false;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.addrecipient) {
|
||||
_navigateTo(context, PayoutDestination.addrecipient, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void startPaymentWithoutRecipient(PaymentType type) {
|
||||
void startPaymentWithoutRecipient(
|
||||
BuildContext context,
|
||||
PaymentType type,
|
||||
) {
|
||||
final previousDestination = _selected;
|
||||
recipientProvider.setCurrentObject(null);
|
||||
_type = type;
|
||||
_cameFromRecipientList = false;
|
||||
_setPreviousDestination();
|
||||
_selected = PayoutDestination.payment;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.payment) {
|
||||
_navigateTo(context, PayoutDestination.payment, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void goBackFromPayment() {
|
||||
void goBackFromPayment(BuildContext context) {
|
||||
if (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
_navigateTo(
|
||||
context,
|
||||
_previousDestination ??
|
||||
(_cameFromRecipientList
|
||||
? PayoutDestination.recipients
|
||||
: PayoutDestination.dashboard),
|
||||
);
|
||||
}
|
||||
_selected = _previousDestination ??
|
||||
(_cameFromRecipientList
|
||||
? PayoutDestination.recipients
|
||||
@@ -89,22 +139,55 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void goBackFromWalletEdit() {
|
||||
selectPage(PayoutDestination.methods);
|
||||
void goBackFromWalletEdit(BuildContext context) {
|
||||
selectPage(context, PayoutDestination.methods);
|
||||
}
|
||||
|
||||
void selectWallet(Wallet wallet) {
|
||||
void selectWallet(BuildContext context, Wallet wallet) {
|
||||
final previousDestination = _selected;
|
||||
walletsProvider.selectWallet(wallet);
|
||||
_selected = PayoutDestination.editwallet;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.editwallet) {
|
||||
_navigateTo(context, PayoutDestination.editwallet, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void startPaymentFromWallet(Wallet wallet) {
|
||||
void startPaymentFromWallet(BuildContext context, Wallet wallet) {
|
||||
final previousDestination = _selected;
|
||||
_type = PaymentType.wallet;
|
||||
_cameFromRecipientList = false;
|
||||
_setPreviousDestination();
|
||||
_selected = PayoutDestination.payment;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.payment) {
|
||||
_navigateTo(context, PayoutDestination.payment, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void openWalletTopUp(BuildContext context, Wallet wallet) {
|
||||
final previousDestination = _selected;
|
||||
_setPreviousDestination();
|
||||
walletsProvider.selectWallet(wallet);
|
||||
_selected = PayoutDestination.walletTopUp;
|
||||
notifyListeners();
|
||||
if (previousDestination != PayoutDestination.walletTopUp) {
|
||||
_navigateTo(context, PayoutDestination.walletTopUp, replace: false);
|
||||
}
|
||||
}
|
||||
|
||||
void goBackFromWalletTopUp(BuildContext context) {
|
||||
if (Navigator.of(context).canPop()) {
|
||||
Navigator.of(context).pop();
|
||||
} else {
|
||||
_navigateTo(
|
||||
context,
|
||||
_previousDestination ?? PayoutDestination.dashboard,
|
||||
);
|
||||
}
|
||||
_selected = _previousDestination ?? PayoutDestination.dashboard;
|
||||
_previousDestination = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
PaymentMethod? getPaymentMethodForWallet(Wallet wallet) {
|
||||
@@ -113,8 +196,7 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
return methodsProvider.methods.firstWhereOrNull(
|
||||
(method) => method.type == PaymentType.wallet &&
|
||||
(method.description?.contains(wallet.walletUserID) ?? false),
|
||||
(method) => method.type == PaymentType.wallet && (method.description?.contains(wallet.walletUserID) ?? false),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,11 +241,24 @@ class PageSelectorProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void _setPreviousDestination() {
|
||||
if (_selected != PayoutDestination.payment) {
|
||||
if (_selected != PayoutDestination.payment &&
|
||||
_selected != PayoutDestination.walletTopUp) {
|
||||
_previousDestination = _selected;
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateTo(
|
||||
BuildContext context,
|
||||
PayoutDestination destination, {
|
||||
bool replace = true,
|
||||
}) {
|
||||
if (replace) {
|
||||
context.goToPayout(destination);
|
||||
} else {
|
||||
context.pushToPayout(destination);
|
||||
}
|
||||
}
|
||||
|
||||
Recipient? get selectedRecipient => recipientProvider.currentObject;
|
||||
Wallet? get selectedWallet => walletsProvider.selectedWallet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user