Skip to content

Commit

Permalink
fix: manual backup flow (#663)
Browse files Browse the repository at this point in the history
* fix: manual backup flow

* chore: fix format & analyze

---------

Co-authored-by: Egor Komarov <egor.komarov@bf.rocks>
  • Loading branch information
Odrin and Egor Komarov authored Dec 3, 2024
1 parent eb6c13b commit 351a575
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,14 @@ class ManageSeedsAccountsCubit extends Cubit<ManageSeedsAccountsState> {
final list = seeds.seeds;
list.sort((a, b) => a.addedAt.compareTo(b.addedAt));
if (list.isNotEmpty && list.first.addedAt != 0) {
final masterPublicKey = list.last.masterKey.publicKey;

final isShowBackup = storageService.getValue<bool>(
StorageKey.showingManualBackupBadge(masterPublicKey.publicKey),
final seed = list.last;
final key = StorageKey.showingManualBackupBadge(
seed.masterKey.publicKey.publicKey,
);
final isShowBackup = storageService.getValue<bool>(key);

if (isShowBackup ?? false) {
storageService.addValue(
StorageKey.showingManualBackupBadge(masterPublicKey.publicKey),
list.last.addType == SeedAddType.create,
);
if (isShowBackup == null) {
storageService.addValue(key, seed.addType == SeedAddType.create);
}

emit(
Expand Down
14 changes: 7 additions & 7 deletions lib/feature/wallet/view/wallet_page_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class WalletPageModel extends ElementaryModel {
Stream<TransportStrategy> get transportStrategy =>
_nekotonRepository.currentTransportStream;

Future<bool?> isNewUser() async {
bool? isNewUser() {
return _storageService.getValue(StorageKey.userWithNewWallet());
}

Future<void> resetValueNewUser() async {
return _storageService.delete(StorageKey.userWithNewWallet());
void resetValueNewUser() {
_storageService.delete(StorageKey.userWithNewWallet());
}

Future<bool?> isShowingBadge(KeyAccount account) async {
bool? isShowingBadge(KeyAccount account) {
final masterPublicKey = _nekotonRepository.seedList
.findSeedByAnyPublicKey(account.publicKey)
?.masterPublicKey;
Expand All @@ -40,15 +40,15 @@ class WalletPageModel extends ElementaryModel {
);
}

Future<bool?> isShowingNewTokens(KeyAccount account) async {
bool? isShowingNewTokens(KeyAccount account) {
final address = account.address;

return _storageService.getValue(
StorageKey.showingNewTokensLabel(address.address),
);
}

Future<void> hideShowingBadge(KeyAccount account) async {
void hideShowingBadge(KeyAccount account) {
final masterPublicKey = _nekotonRepository.seedList
.findSeedByAnyPublicKey(account.publicKey)
?.masterPublicKey;
Expand All @@ -61,7 +61,7 @@ class WalletPageModel extends ElementaryModel {
);
}

Future<void> hideNewTokenLabels(KeyAccount account) async {
void hideNewTokenLabels(KeyAccount account) {
final address = account.address;

return _storageService.addValue(
Expand Down
44 changes: 21 additions & 23 deletions lib/feature/wallet/view/wallet_page_widget.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:app/feature/wallet/view/wallet_page_wm.dart';
import 'package:app/feature/wallet/wallet.dart';
import 'package:app/utils/utils.dart';
import 'package:elementary/elementary.dart';
import 'package:elementary_helper/elementary_helper.dart';
import 'package:flutter/material.dart';
import 'package:nekoton_repository/nekoton_repository.dart';

class WalletPageWidget extends ElementaryWidget<WalletPageWidgetModel> {
const WalletPageWidget({
Expand All @@ -15,27 +13,27 @@ class WalletPageWidget extends ElementaryWidget<WalletPageWidgetModel> {
@override
Widget build(WalletPageWidgetModel wm) {
return Scaffold(
body: TripleSourceBuilder<KeyAccount?, bool, TransportStrategy>(
firstSource: wm.currentAccount,
secondSource: wm.isShowingNewTokens,
thirdSource: wm.transportStrategy,
builder: (_, currentAccount, isShowingNewTokens, transport) {
return currentAccount?.let(
(value) => StateNotifierBuilder(
listenableState: wm.isShowingBadge,
builder: (_, isShowingBadge) => WalletView(
key: ValueKey(value),
currentAccount: value,
scrollController: wm.scrollController,
isShowingBadge: isShowingBadge ?? false,
isShowingNewTokens: isShowingNewTokens ?? false,
finishedBackupCallback: wm.hideShowingBadge,
confirmImportCallback: wm.hideNewTokensLabel,
manifestUrl: transport?.manifestUrl ?? '',
),
),
) ??
const SizedBox.shrink();
body: StateNotifierBuilder(
listenableState: wm.currentAccount,
builder: (_, account) {
if (account == null) return const SizedBox.shrink();
return TripleSourceBuilder(
firstSource: wm.isShowingBadge,
secondSource: wm.isShowingNewTokens,
thirdSource: wm.transportStrategy,
builder: (_, isShowingBadge, isShowingNewTokens, transport) {
return WalletView(
key: ValueKey(account),
currentAccount: account,
scrollController: wm.scrollController,
isShowingBadge: isShowingBadge ?? false,
isShowingNewTokens: isShowingNewTokens ?? false,
finishedBackupCallback: wm.hideShowingBadge,
confirmImportCallback: wm.hideNewTokensLabel,
manifestUrl: transport?.manifestUrl ?? '',
);
},
);
},
),
);
Expand Down
29 changes: 14 additions & 15 deletions lib/feature/wallet/view/wallet_page_wm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,29 @@ class WalletPageWidgetModel
_checkBadge();
}

Future<void> _checkBadge() async {
void _checkBadge() {
//check user create new wallet or login
final account = _currentAccount.value;
final isNewUser = await model.isNewUser();
if (isNewUser != null && account != null) {
final isNewUser = model.isNewUser();

if (account == null) return;

if (isNewUser != null) {
if (isNewUser) {
_isShowingNewTokensNotifier.accept(true);
_isShowingBadgeNotifier.accept(true);
} else {
_isShowingBadgeNotifier.accept(false);
unawaited(model.hideShowingBadge(account));
model.hideShowingBadge(account);
}
unawaited(model.resetValueNewUser());

model.resetValueNewUser();
return;
}
if (account != null) {
_isShowingBadgeNotifier.accept(
await model.isShowingBadge(account) ?? true,
);
_isShowingNewTokensNotifier
.accept(await model.isShowingNewTokens(account) ?? true);
} else {
_isShowingBadgeNotifier.accept(true);
_isShowingNewTokensNotifier.accept(true);
}

_isShowingBadgeNotifier.accept(model.isShowingBadge(account) ?? true);
_isShowingNewTokensNotifier.accept(
model.isShowingNewTokens(account) ?? true,
);
}
}

0 comments on commit 351a575

Please sign in to comment.