Skip to content

Commit 1aa1954

Browse files
committed
refactor: improve UI layout and loading state management for BIP85 derivations
1 parent 4514aa4 commit 1aa1954

4 files changed

Lines changed: 54 additions & 34 deletions

File tree

lib/core/widgets/bip85_derivation_widget.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ class _Bip85DerivationWidgetState extends State<Bip85DerivationWidget> {
7272
final isRevoked = widget.derivation.status == Bip85Status.revoked;
7373

7474
return Container(
75-
padding: const EdgeInsets.all(16),
75+
padding: const EdgeInsets.all(8),
7676
decoration: BoxDecoration(
7777
border: Border.all(color: context.appColors.border),
78+
borderRadius: BorderRadius.circular(8),
79+
color: context.appColors.surface,
7880
),
81+
7982
child: Column(
8083
crossAxisAlignment: .start,
8184
children: [

lib/features/bip85_entropy/bip85_home_page.dart

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:bb_mobile/core/utils/build_context_x.dart';
33
import 'package:bb_mobile/core/widgets/bip85_derivation_widget.dart';
44
import 'package:bb_mobile/core/widgets/buttons/button.dart';
55
import 'package:bb_mobile/core/widgets/loading/fading_linear_progress.dart';
6-
import 'package:bb_mobile/core/widgets/scrollable_column.dart';
76
import 'package:bb_mobile/features/bip85_entropy/presentation/cubit.dart';
87
import 'package:bb_mobile/features/bip85_entropy/presentation/state.dart';
98
import 'package:flutter/material.dart';
@@ -23,9 +22,11 @@ class Bip85HomePage extends StatelessWidget {
2322

2423
return Padding(
2524
padding: const EdgeInsets.symmetric(vertical: 16),
26-
child: ScrollableColumn(
25+
child: Column(
2726
children: [
28-
FadingLinearProgress(trigger: state.xprvBase58.isEmpty),
27+
FadingLinearProgress(
28+
trigger: state.xprvBase58.isEmpty || state.isLoading,
29+
),
2930
Container(
3031
margin: const EdgeInsets.all(16),
3132
padding: const EdgeInsets.all(12),
@@ -48,36 +49,44 @@ class Bip85HomePage extends StatelessWidget {
4849
),
4950
const Gap(16),
5051
if (state.derivations.isNotEmpty && state.xprvBase58.isNotEmpty)
51-
...List.generate(state.derivations.length, (index) {
52-
final derivation = state.derivations[index];
53-
return Padding(
54-
padding: const EdgeInsets.symmetric(vertical: 2),
55-
child: Bip85DerivationWidget(
56-
xprvBase58: state.xprvBase58,
57-
derivation: derivation,
58-
onAliasChanged: cubit.aliasDerivation,
59-
onDerivationRevoked: cubit.revokeDerivation,
60-
onDerivationActivated: cubit.activateDerivation,
61-
),
62-
);
63-
}),
64-
const Gap(16),
65-
Row(
66-
mainAxisAlignment: .spaceBetween,
67-
children: [
68-
BBButton.small(
69-
onPressed: () => cubit.deriveNextMnemonic(),
70-
label: context.loc.bip85NextMnemonic,
71-
bgColor: context.appColors.onSurface,
72-
textColor: context.appColors.surface,
52+
Expanded(
53+
child: ListView.builder(
54+
itemCount: state.derivations.length,
55+
itemBuilder: (context, index) {
56+
final derivation = state.derivations[index];
57+
return Padding(
58+
padding: const EdgeInsets.all(8),
59+
child: Bip85DerivationWidget(
60+
xprvBase58: state.xprvBase58,
61+
derivation: derivation,
62+
onAliasChanged: cubit.aliasDerivation,
63+
onDerivationRevoked: cubit.revokeDerivation,
64+
onDerivationActivated: cubit.activateDerivation,
65+
),
66+
);
67+
},
7368
),
74-
BBButton.small(
75-
onPressed: () => cubit.deriveNextHex(),
76-
label: context.loc.bip85NextHex,
77-
bgColor: context.appColors.onSurface,
78-
textColor: context.appColors.surface,
79-
),
80-
],
69+
),
70+
const Gap(16),
71+
Padding(
72+
padding: const EdgeInsets.symmetric(horizontal: 16),
73+
child: Row(
74+
mainAxisAlignment: .spaceBetween,
75+
children: [
76+
BBButton.small(
77+
onPressed: () => cubit.deriveNextMnemonic(),
78+
label: context.loc.bip85NextMnemonic,
79+
bgColor: context.appColors.onSurface,
80+
textColor: context.appColors.surface,
81+
),
82+
BBButton.small(
83+
onPressed: () => cubit.deriveNextHex(),
84+
label: context.loc.bip85NextHex,
85+
bgColor: context.appColors.onSurface,
86+
textColor: context.appColors.surface,
87+
),
88+
],
89+
),
8190
),
8291
],
8392
),

lib/features/bip85_entropy/presentation/cubit.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ class Bip85EntropyCubit extends Cubit<Bip85EntropyState> {
4848

4949
Future<void> init() async {
5050
try {
51+
emit(state.copyWith(isLoading: true));
5152
await fetchXprvBase58();
5253
await fetchAllDerivations();
54+
emit(state.copyWith(isLoading: false));
5355
} catch (e) {
5456
emit(state.copyWith(error: Bip85EntropyError(e.toString())));
5557
}
5658
}
5759

5860
Future<void> fetchAllDerivations() async {
61+
emit(state.copyWith(isLoading: true));
5962
final derivations = await _fetchAllBip85DerivationsUsecase.execute();
60-
emit(state.copyWith(derivations: derivations));
63+
emit(state.copyWith(derivations: derivations, isLoading: false));
6164
}
6265

6366
Future<void> fetchXprvBase58() async {
@@ -71,17 +74,21 @@ class Bip85EntropyCubit extends Cubit<Bip85EntropyState> {
7174

7275
Future<void> deriveNextMnemonic() async {
7376
try {
77+
emit(state.copyWith(isLoading: true));
7478
await _deriveNextBip85MnemonicFromDefaultWalletUsecase.execute();
7579
await fetchAllDerivations();
80+
emit(state.copyWith(isLoading: false));
7681
} catch (e) {
7782
emit(state.copyWith(error: Bip85EntropyError(e.toString())));
7883
}
7984
}
8085

8186
Future<void> deriveNextHex() async {
8287
try {
88+
emit(state.copyWith(isLoading: true));
8389
await _deriveNextBip85HexFromDefaultWalletUsecase.execute(length: 30);
8490
await fetchAllDerivations();
91+
emit(state.copyWith(isLoading: false));
8592
} catch (e) {
8693
emit(state.copyWith(error: Bip85EntropyError(e.toString())));
8794
}

lib/features/bip85_entropy/presentation/state.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ sealed class Bip85EntropyState with _$Bip85EntropyState {
1010
Bip85EntropyError? error,
1111
@Default([]) List<Bip85DerivationEntity> derivations,
1212
@Default('') String xprvBase58,
13+
@Default(false) bool isLoading,
1314
}) = _Bip85EntropyState;
1415
}

0 commit comments

Comments
 (0)