mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-28 06:28:41 +01:00
* add ability to hide accounts * remove import * merge * merge * fix loading accounts when styleSettings are not saved yet * merge * auto-reformat * small fixes * proper reload on card unhide * block hiding last card * fixup * revert formatting-only changes * liner fixes * fix overflows * card layout as separate class to prevent index errors * fix mini card on addresses page * block opening customizers if wallet is syncing * switch to BlocProvider.value to prevent auto dispose * imports * fix fiat balance * Improve homescreen layout and account access * Add homescreen layout regression tests * improve account management w/ education + archival flows * reorganize wallet-specific settings * preserve account archival during dismissal * fix: align account visuals with design feedback * minor account & archival visual corrections * simplify wallet settings + account UI state * generalise education carousel & dismissal tracking * refactor account UI flows + minor improvements * minor refactors and improvement * pass account balances as Money and format at display * use fresh full balance for account archival check * refactor BalanceCard w/ MoneyText + cleanup * minor card_customizer cleanup * rework card customizer flow --------- Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
126 lines
3.5 KiB
Dart
126 lines
3.5 KiB
Dart
import "package:cw_core/balance_card_style_settings.dart";
|
|
|
|
class BalanceCardLayout {
|
|
BalanceCardLayout._(
|
|
this._settings, {
|
|
required List<int> visible,
|
|
required List<int> hidden,
|
|
required this.needsRepair,
|
|
}) : visible = List<int>.unmodifiable(visible),
|
|
hidden = List<int>.unmodifiable(hidden);
|
|
|
|
factory BalanceCardLayout.resolve({
|
|
required List<int> accountIndices,
|
|
required List<BalanceCardStyleSettings> settings,
|
|
}) {
|
|
final List<int> accounts = [];
|
|
for (final accountIndex in accountIndices) {
|
|
if (!accounts.contains(accountIndex)) {
|
|
accounts.add(accountIndex);
|
|
}
|
|
}
|
|
|
|
final settingsByAccount = <int, BalanceCardStyleSettings>{};
|
|
for (final setting in settings) {
|
|
if (accounts.contains(setting.accountIndex)) {
|
|
settingsByAccount.putIfAbsent(setting.accountIndex, () => setting);
|
|
}
|
|
}
|
|
|
|
final hidden = [
|
|
for (final accountIndex in accounts)
|
|
if (settingsByAccount[accountIndex]?.hidden ?? false) accountIndex,
|
|
]..sort();
|
|
|
|
final visible = [
|
|
for (final accountIndex in accounts)
|
|
if (!hidden.contains(accountIndex)) accountIndex,
|
|
];
|
|
|
|
visible.sort((a, b) => _compareStackPosition(a, b, settingsByAccount));
|
|
|
|
var needsRepair = false;
|
|
for (var position = 0; position < visible.length; position++) {
|
|
final stored = settingsByAccount[visible[position]];
|
|
if (stored != null && stored.cardOrder != position) {
|
|
needsRepair = true;
|
|
}
|
|
}
|
|
|
|
return BalanceCardLayout._(
|
|
settingsByAccount,
|
|
visible: visible,
|
|
hidden: hidden,
|
|
needsRepair: needsRepair,
|
|
);
|
|
}
|
|
|
|
final Map<int, BalanceCardStyleSettings> _settings;
|
|
|
|
final List<int> visible;
|
|
final List<int> hidden;
|
|
|
|
// flag when db order is broken
|
|
final bool needsRepair;
|
|
|
|
List<int> get designOrder => designOrderOf(visible);
|
|
|
|
static List<int> stackFromOrder(Map<int, int> cardOrder, {bool forceSingleCard = false}) {
|
|
final positions = cardOrder.keys.toList()..sort();
|
|
final accountIndices = [for (final position in positions) cardOrder[position]!];
|
|
|
|
if (accountIndices.isEmpty || !forceSingleCard) {
|
|
return accountIndices;
|
|
}
|
|
return [accountIndices.first];
|
|
}
|
|
|
|
static List<int> designOrderOf(Iterable<int> accountIndices) =>
|
|
List<int>.of(accountIndices)..sort();
|
|
|
|
Map<int, int> get orders =>
|
|
{for (var position = 0; position < visible.length; position++) visible[position]: position};
|
|
|
|
BalanceCardStyleSettings? settingFor(int accountIndex) => _settings[accountIndex];
|
|
|
|
BalanceCardLayout unhiding(int accountIndex) {
|
|
if (!hidden.contains(accountIndex)) {
|
|
return this;
|
|
}
|
|
|
|
return BalanceCardLayout._(
|
|
_settings,
|
|
visible: [...visible, accountIndex],
|
|
hidden: [
|
|
for (final hiddenAccount in hidden)
|
|
if (hiddenAccount != accountIndex) hiddenAccount,
|
|
],
|
|
needsRepair: true,
|
|
);
|
|
}
|
|
|
|
static int _compareStackPosition(
|
|
int a,
|
|
int b,
|
|
Map<int, BalanceCardStyleSettings> settingsByAccount,
|
|
) {
|
|
final orderA = _storedOrder(settingsByAccount[a]);
|
|
final orderB = _storedOrder(settingsByAccount[b]);
|
|
|
|
if (orderA != orderB) {
|
|
if (orderA == null) {
|
|
return 1;
|
|
}
|
|
if (orderB == null) {
|
|
return -1;
|
|
}
|
|
return orderA.compareTo(orderB);
|
|
}
|
|
|
|
return a.compareTo(b);
|
|
}
|
|
|
|
static int? _storedOrder(BalanceCardStyleSettings? setting) =>
|
|
setting == null || setting.cardOrder < 0 ? null : setting.cardOrder;
|
|
}
|