Skip to content

Commit

Permalink
Merge pull request #390 from kumulynja/fix-amount-change-send-button-…
Browse files Browse the repository at this point in the history
…issue

fix: check balance on amount change
  • Loading branch information
i5hi authored Dec 24, 2024
2 parents 37e7c97 + 03344eb commit 697d3f0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/send/bloc/send_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ class SendCubit extends Cubit<SendState> {
if (changeWallet == true) {
selectWallets();
}
if (_currencyCubit.state.amount != 0) {
_checkBalance();
}
}

void selectWallets({bool fromStart = false}) {
Expand Down Expand Up @@ -365,7 +362,7 @@ class SendCubit extends Cubit<SendState> {
if (amt == 0) {
emit(state.copyWith(showSendButton: false));
} else {
_checkBalance();
checkBalance();
}
// emit(state.copyWith(showSendButton: true));

Expand Down Expand Up @@ -408,7 +405,7 @@ class SendCubit extends Cubit<SendState> {
if (amt == 0) {
emit(state.copyWith(showSendButton: false));
} else {
_checkBalance();
checkBalance();
}

// emit(state.copyWith(showSendButton: true));
Expand Down Expand Up @@ -456,7 +453,7 @@ class SendCubit extends Cubit<SendState> {
if (amount == 0) {
emit(state.copyWith(showSendButton: false));
} else {
_checkBalance();
checkBalance();
}

// emit(state.copyWith(showSendButton: true));
Expand Down Expand Up @@ -492,15 +489,20 @@ class SendCubit extends Cubit<SendState> {
if (amount == 0) {
emit(state.copyWith(showSendButton: false));
} else {
_checkBalance();
checkBalance();
}
// emit(state.copyWith(showSendButton: true));
}

void _checkBalance() {
void checkBalance() {
final balance = state.selectedWalletBloc?.state.balanceSats() ?? 0;
final amount = _currencyCubit.state.amount;

if (amount == 0) {
emit(state.copyWith(showSendButton: false));
return;
}

if (balance < amount) {
emit(
state.copyWith(
Expand Down Expand Up @@ -544,7 +546,7 @@ class SendCubit extends Cubit<SendState> {
void updateWalletBloc(WalletBloc walletBloc) {
emit(state.copyWith(selectedWalletBloc: walletBloc));
sendAllCoin(false);
_checkBalance();
checkBalance();
}

void disabledDropdownClicked() {
Expand Down Expand Up @@ -601,7 +603,7 @@ class SendCubit extends Cubit<SendState> {
_currencyCubit.updateAmountDirect(amount);
_currencyCubit.updateAmount(amount == 0 ? '' : amount.toString());

_checkBalance();
checkBalance();
}

void togglePayjoin(bool toggle) {
Expand Down
6 changes: 6 additions & 0 deletions lib/send/listeners.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class SendListeners extends StatelessWidget {
Widget build(BuildContext context) {
return MultiBlocListener(
listeners: [
BlocListener<CurrencyCubit, CurrencyState>(
listenWhen: (previous, current) => previous.amount != current.amount,
listener: (context, state) {
context.read<SendCubit>().checkBalance();
},
),
BlocListener<CreateSwapCubit, SwapState>(
listenWhen: (previous, current) => previous.swapTx != current.swapTx,
listener: (context, state) async {
Expand Down

0 comments on commit 697d3f0

Please sign in to comment.