Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 14, 2025
1 parent 8916972 commit c000bca
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 61 deletions.
34 changes: 16 additions & 18 deletions lib/application/account/account_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import 'dart:async';

import 'package:aewallet/application/account/selected_account.dart';
import 'package:aewallet/application/app_service.dart';
import 'package:aewallet/application/nft/nft.dart';
import 'package:aewallet/application/refresh_in_progress.dart';
Expand All @@ -13,7 +12,6 @@ import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/model/data/account_balance.dart';
import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart';
import 'package:aewallet/modules/aeswap/application/session/provider.dart';
import 'package:aewallet/util/account_formatters.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'
as aedappfm;
import 'package:archethic_lib_dart/archethic_lib_dart.dart';
Expand Down Expand Up @@ -58,17 +56,9 @@ class AccountNotifier extends _$AccountNotifier {
Future<void> refreshRecentTransactions() async {
await _refresh([
(account) async {
_logger.fine(
'Start method refreshRecentTransactions for ${account.nameDisplayed}',
);
await updateRecentTransactions();
_logger.fine(
'End method refreshRecentTransactions for ${account.nameDisplayed}',
);
},
]);

ref.invalidate(selectedAccountRecentTransactionsProvider);
}

Future<void> refreshFungibleTokens() async {
Expand All @@ -79,6 +69,14 @@ class AccountNotifier extends _$AccountNotifier {
]);
}

Future<void> refreshNFT() async {
await _refresh([
(account) async {
await updateNFT();
},
]);
}

Future<void> refreshBalance() async {
await _refresh([
(account) async {
Expand All @@ -91,30 +89,23 @@ class AccountNotifier extends _$AccountNotifier {
await _refresh(
[
(account) async {
_logger.fine('RefreshAll - Start Balance refresh');
await updateBalance();
_logger.fine('RefreshAll - End Balance refresh');
},
(account) async {
_logger.fine('RefreshAll - Start recent transactions refresh');
await updateRecentTransactions();
_logger.fine('RefreshAll - End recent transactions refresh');
},
(account) async {
_logger.fine('RefreshAll - Start Fungible Tokens refresh');
await updateFungiblesTokens();
_logger.fine('RefreshAll - End Fungible Tokens refresh');
},
(account) async {
_logger.fine('RefreshAll - Start NFT refresh');
await updateNFT();
_logger.fine('RefreshAll - End NFT refresh');
},
],
);
}

Future<void> updateBalance() async {
_logger.fine('RefreshAll - Start Balance refresh');
await _update((account) async {
var totalUSD = 0.0;

Expand Down Expand Up @@ -179,9 +170,11 @@ class AccountNotifier extends _$AccountNotifier {

return account.copyWith(balance: accountBalance);
});
_logger.fine('RefreshAll - End Balance refresh');
}

Future<void> updateFungiblesTokens() async {
_logger.fine('RefreshAll - Start Fungible Tokens refresh');
await _update((account) async {
final appService = ref.read(appServiceProvider);
final poolsListRaw =
Expand All @@ -194,9 +187,11 @@ class AccountNotifier extends _$AccountNotifier {
),
);
});
_logger.fine('RefreshAll - End Fungible Tokens refresh');
}

Future<void> updateRecentTransactions() async {
_logger.fine('RefreshAll - Start recent transactions refresh');
await _update((account) async {
final session = ref.read(sessionNotifierProvider).loggedIn!;
final appService = ref.read(appServiceProvider);
Expand All @@ -212,6 +207,7 @@ class AccountNotifier extends _$AccountNotifier {
Duration.millisecondsPerSecond,
);
});
_logger.fine('RefreshAll - End recent transactions refresh');
}

Future<void> addCustomTokenAddress(String tokenAddress) async {
Expand Down Expand Up @@ -254,6 +250,7 @@ class AccountNotifier extends _$AccountNotifier {
}

Future<void> updateNFT() async {
_logger.fine('RefreshAll - Start NFT refresh');
await _update(
(account) async {
final session = ref.read(sessionNotifierProvider).loggedIn!;
Expand All @@ -271,6 +268,7 @@ class AccountNotifier extends _$AccountNotifier {
);
},
);
_logger.fine('RefreshAll - End NFT refresh');
}

Future<void> clearRecentTransactionsFromCache() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/application/account/account_notifier.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions lib/application/account/selected_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:async';

import 'package:aewallet/application/account/accounts_notifier.dart';
import 'package:aewallet/model/blockchain/recent_transaction.dart';
import 'package:aewallet/model/data/account_token.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand All @@ -21,3 +22,26 @@ Future<List<RecentTransaction>?> selectedAccountRecentTransactions(
)
?.recentTransactions;
}

@riverpod
List<AccountToken> selectedAccountNFTFiltered(
Ref ref,
) {
final selectedAccount = ref.watch(
accountsNotifierProvider.select(
(accounts) => accounts.valueOrNull?.selectedAccount,
),
);
if (selectedAccount == null) {
return <AccountToken>[];
}

return <AccountToken>[
...selectedAccount.accountNFT ?? [],
// A collection of NFT has the same address for all the sub NFT, we only want to display one NFT in that case
...(selectedAccount.accountNFTCollections?.where(
(e) => <String>{}.add(e.tokenInformation?.address ?? ''),
) ??
[]),
];
}
20 changes: 20 additions & 0 deletions lib/application/account/selected_account.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions lib/ui/views/main/bloc/providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class HomePage extends _$HomePage {
..watch(verifiedTokensProvider)
..watch(DexTokensProviders.tokensFromAccount)
..watch(farmLockFormFarmLockProvider)
// ..watch(
// aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO,
// )
// ..watch(aedappfm.CoinPriceProviders.coinPrices)
..watch(
aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO,
)
..watch(aedappfm.CoinPriceProviders.coinPrices)
..listen(
connectivityStatusProviders,
(previous, next) async {
Expand All @@ -60,17 +60,17 @@ class HomePage extends _$HomePage {
}

Future<void> startSubscriptions() async {
// await ref
// .read(
// aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.notifier,
// )
// .startSubscription();

// await ref
// .read(
// aedappfm.CoinPriceProviders.coinPrices.notifier,
// )
// .startTimer();
await ref
.read(
aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.notifier,
)
.startSubscription();

await ref
.read(
aedappfm.CoinPriceProviders.coinPrices.notifier,
)
.startTimer();
}

Future<void> stopSubscriptions() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/main/bloc/providers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/ui/views/main/components/menu_widget_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MenuWidgetWallet extends ConsumerWidget {
await (await ref
.read(accountsNotifierProvider.notifier)
.selectedAccountNotifier)
?.refreshRecentTransactions();
?.refreshAll();
},
)
.animate()
Expand Down
13 changes: 2 additions & 11 deletions lib/ui/views/nft/layouts/components/nft_list.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:aewallet/application/account/accounts_notifier.dart';
import 'package:aewallet/application/account/selected_account.dart';
import 'package:aewallet/ui/themes/styles.dart';
import 'package:aewallet/ui/views/nft/layouts/components/nft_list_detail.dart';
import 'package:aewallet/ui/widgets/components/dynamic_height_grid_view.dart';
import 'package:aewallet/util/account_formatters.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -24,15 +23,7 @@ class _NFTListState extends ConsumerState<NFTList>
Widget build(BuildContext context) {
super.build(context);

final accountSelected = ref.watch(
accountsNotifierProvider.select(
(accounts) => accounts.valueOrNull?.selectedAccount,
),
);

if (accountSelected == null) return const _EmptyNFTList();

final accountTokenList = accountSelected.getAccountNFTFiltered();
final accountTokenList = ref.watch(selectedAccountNFTFilteredProvider);
if (accountTokenList.isEmpty) {
return const _EmptyNFTList();
}
Expand Down
15 changes: 1 addition & 14 deletions lib/util/account_formatters.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/model/data/account_token.dart';

extension AccountFormatters on Account {
String get format {
Expand All @@ -10,24 +9,12 @@ extension AccountFormatters on Account {
var result = name;
if (name.startsWith('archethic-wallet-')) {
result = result.replaceFirst('archethic-wallet-', '');
}
if (name.startsWith('aeweb-')) {
} else if (name.startsWith('aeweb-')) {
result = result.replaceFirst('aeweb-', '');
}

return Uri.decodeFull(
result,
);
}

List<AccountToken> getAccountNFTFiltered() {
return <AccountToken>[
...accountNFT ?? [],
// A collection of NFT has the same address for all the sub NFT, we only want to display one NFT in that case
...(accountNFTCollections?.where(
(e) => <String>{}.add(e.tokenInformation?.address ?? ''),
) ??
[]),
];
}
}

0 comments on commit c000bca

Please sign in to comment.