Skip to content

Commit

Permalink
Merge pull request #409 from kumulynja/loader-on-pj-uri-generation
Browse files Browse the repository at this point in the history
show spinner while loading payjoin address
  • Loading branch information
ethicnology authored Dec 31, 2024
2 parents 16199d1 + c5a697c commit 3b67f26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
17 changes: 12 additions & 5 deletions lib/receive/bloc/receive_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ class ReceiveCubit extends Cubit<ReceiveState> {
await isPayjoinEnabled();
await loadAddress();

payjoinInit();
await payjoinInit();
}

void payjoinInit() {
Future<void> payjoinInit() async {
final baseType = state.walletBloc!.state.wallet!.baseWalletType;

if (state.paymentNetwork == PaymentNetwork.bitcoin &&
state.defaultAddress != null &&
state.isPayjoin &&
baseType == BaseWalletType.Bitcoin) {
receivePayjoin(
await receivePayjoin(
state.walletBloc!.state.wallet!.isTestnet(),
state.defaultAddress!.address,
);
Expand Down Expand Up @@ -203,7 +203,8 @@ class ReceiveCubit extends Cubit<ReceiveState> {

emit(
state.copyWith(
loadingAddress: false,
loadingAddress: state
.isPayjoin, // Keep loading while the payjoin receiver is being initialized, if it's enabled.
errLoadingAddress: '',
),
);
Expand Down Expand Up @@ -357,7 +358,13 @@ class ReceiveCubit extends Cubit<ReceiveState> {

Future<void> receivePayjoin(bool isTestnet, String address) async {
final receiver = await _payjoinManager.initReceiver(isTestnet, address);
emit(state.copyWith(payjoinReceiver: receiver));
emit(
state.copyWith(
payjoinReceiver: receiver,
loadingAddress:
false, // Stop loading now that the receiver is initialized.
),
);
_payjoinManager.spawnNewReceiver(
isTestnet: isTestnet,
receiver: receiver,
Expand Down
21 changes: 15 additions & 6 deletions lib/receive/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class _Screen extends StatelessWidget {
final showQR = context.select(
(ReceiveCubit x) => x.state.showQR(swapTx, isChainSwap: isChainSwap),
);
final loadingAddress =
context.select((ReceiveCubit x) => x.state.loadingAddress);

final watchOnly =
context.select((WalletBloc x) => x.state.wallet!.watchOnly());
Expand Down Expand Up @@ -222,12 +224,19 @@ class _Screen extends StatelessWidget {
const SwapFeesDetails(),
],
if (isChainSwap == false && showQR) ...[
const ReceiveQR(),
const Gap(8),
ReceiveAddress(
swapTx: swapTx,
addressQr: addressQr,
),
if (loadingAddress)
const Center(child: CircularProgressIndicator())
else
Column(
children: [
const ReceiveQR(),
const Gap(8),
ReceiveAddress(
swapTx: swapTx,
addressQr: addressQr,
),
],
),
const Gap(8),
if (shouldShowForm) const BitcoinReceiveForm(),
if (paymentNetwork == PaymentNetwork.lightning || formSubmitted)
Expand Down

0 comments on commit 3b67f26

Please sign in to comment.