Skip to content
Snippets Groups Projects
Commit 11ddd033 authored by vjrj's avatar vjrj
Browse files

Code refactor/rename

parent 23923fd1
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ import 'duniter_datapod_helper.dart'; ...@@ -9,7 +9,7 @@ import 'duniter_datapod_helper.dart';
import 'duniter_endpoint_helper.dart'; import 'duniter_endpoint_helper.dart';
import 'duniter_indexer_helper.dart'; import 'duniter_indexer_helper.dart';
import 'pay_result.dart'; import 'pay_result.dart';
import 'transaction_v1_parser.dart'; import 'transactions_v1_parser.dart';
import 'transactions_v2_parser.dart'; import 'transactions_v2_parser.dart';
abstract class DuniterService { abstract class DuniterService {
......
...@@ -10,7 +10,7 @@ import 'g1_helper.dart'; ...@@ -10,7 +10,7 @@ import 'g1_helper.dart';
final RegExp exp = RegExp(r'\((.*?)\)'); final RegExp exp = RegExp(r'\((.*?)\)');
Future<TransactionState> transactionParser( Future<TransactionState> transactionsParser(
String txData, List<Transaction> pendingTransactions) async { String txData, List<Transaction> pendingTransactions) async {
final Map<String, dynamic> parsedTxData = final Map<String, dynamic> parsedTxData =
json.decode(txData) as Map<String, dynamic>; json.decode(txData) as Map<String, dynamic>;
......
...@@ -692,7 +692,7 @@ Future<void> fetchTransactionsFromBackground([bool init = true]) async { ...@@ -692,7 +692,7 @@ Future<void> fetchTransactionsFromBackground([bool init = true]) async {
try { try {
if (init) { if (init) {
await hiveInit(); await hiveInit();
if (SharedPreferencesHelper().cards.isEmpty) { if (SharedPreferencesHelper().wallets.isEmpty) {
await SharedPreferencesHelper().init(); await SharedPreferencesHelper().init();
} }
try { try {
...@@ -713,9 +713,9 @@ Future<void> fetchTransactionsFromBackground([bool init = true]) async { ...@@ -713,9 +713,9 @@ Future<void> fetchTransactionsFromBackground([bool init = true]) async {
final GetIt getIt = GetIt.instance; final GetIt getIt = GetIt.instance;
final MultiWalletTransactionCubit transCubit = final MultiWalletTransactionCubit transCubit =
getIt.get<MultiWalletTransactionCubit>(); getIt.get<MultiWalletTransactionCubit>();
for (final Wallet card in SharedPreferencesHelper().cards) { for (final Wallet wallet in SharedPreferencesHelper().wallets) {
loggerDev('Fetching transactions for ${card.pubKey} in background'); loggerDev('Fetching transactions for ${wallet.pubKey} in background');
transCubit.fetchTransactions(pubKey: card.pubKey); transCubit.fetchTransactions(pubKey: wallet.pubKey);
} }
if (inDevelopment) { if (inDevelopment) {
NotificationController.notify( NotificationController.notify(
...@@ -817,7 +817,7 @@ Future<void> _clearCacheIfNeeded(Directory storageDir) async { ...@@ -817,7 +817,7 @@ Future<void> _clearCacheIfNeeded(Directory storageDir) async {
Future<void> fetchTransactions(BuildContext context) async { Future<void> fetchTransactions(BuildContext context) async {
final MultiWalletTransactionCubit transCubit = final MultiWalletTransactionCubit transCubit =
context.read<MultiWalletTransactionCubit>(); context.read<MultiWalletTransactionCubit>();
for (final Wallet card in SharedPreferencesHelper().cards) { for (final Wallet wallet in SharedPreferencesHelper().wallets) {
transCubit.fetchTransactions(pubKey: card.pubKey); transCubit.fetchTransactions(pubKey: wallet.pubKey);
} }
} }
...@@ -30,7 +30,7 @@ class SharedPreferencesHelper with ChangeNotifier { ...@@ -30,7 +30,7 @@ class SharedPreferencesHelper with ChangeNotifier {
late SharedPreferences _prefs; late SharedPreferences _prefs;
static final SharedPreferencesHelper _instance = static final SharedPreferencesHelper _instance =
SharedPreferencesHelper._internal(); SharedPreferencesHelper._internal();
// Legacy keys // Legacy keys
static const String _seedKey = 'seed'; static const String _seedKey = 'seed';
...@@ -117,7 +117,7 @@ class SharedPreferencesHelper with ChangeNotifier { ...@@ -117,7 +117,7 @@ class SharedPreferencesHelper with ChangeNotifier {
Future<void> saveWallets([bool notify = true]) async { Future<void> saveWallets([bool notify = true]) async {
final String json = final String json =
jsonEncode(wallets.map((Wallet e) => e.toJson()).toList()); jsonEncode(wallets.map((Wallet e) => e.toJson()).toList());
await _secureStorage.write(key: _accountsKey, value: json); await _secureStorage.write(key: _accountsKey, value: json);
if (notify) { if (notify) {
notifyListeners(); notifyListeners();
...@@ -133,7 +133,7 @@ class SharedPreferencesHelper with ChangeNotifier { ...@@ -133,7 +133,7 @@ class SharedPreferencesHelper with ChangeNotifier {
} else { } else {
// This should have the wallet loaded // This should have the wallet loaded
final CesiumWallet? volatileWallet = final CesiumWallet? volatileWallet =
cesiumVolatileCards[extractPublicKey(card.pubKey)]; cesiumVolatileCards[extractPublicKey(card.pubKey)];
if (volatileWallet != null) { if (volatileWallet != null) {
return volatileWallet; return volatileWallet;
} }
...@@ -180,11 +180,9 @@ class SharedPreferencesHelper with ChangeNotifier { ...@@ -180,11 +180,9 @@ class SharedPreferencesHelper with ChangeNotifier {
saveWallets(); saveWallets();
} }
List<Wallet> get cards => wallets;
int getCurrentWalletIndex() { int getCurrentWalletIndex() {
final String? indexStr = final String? indexStr =
_secureStorage.read(key: _currentAccountIndex) as String?; _secureStorage.read(key: _currentAccountIndex) as String?;
return indexStr != null ? int.parse(indexStr) : 0; return indexStr != null ? int.parse(indexStr) : 0;
} }
...@@ -194,9 +192,9 @@ class SharedPreferencesHelper with ChangeNotifier { ...@@ -194,9 +192,9 @@ class SharedPreferencesHelper with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> selectCurrentWallet(Wallet card) async { Future<void> selectCurrentWallet(Wallet wallet) async {
// TODO(vjrj): this should be a find with pubkey // TODO(vjrj): this should be a find with pubkey
final int index = cards.indexOf(card); final int index = wallets.indexOf(wallet);
if (index >= 0) { if (index >= 0) {
await _prefs.setInt(_legacyCurrentAccountIndex, index); await _prefs.setInt(_legacyCurrentAccountIndex, index);
notifyListeners(); notifyListeners();
......
...@@ -7,7 +7,7 @@ import '../../../data/models/node.dart'; ...@@ -7,7 +7,7 @@ import '../../../data/models/node.dart';
import '../../../data/models/transaction.dart'; import '../../../data/models/transaction.dart';
import '../../../data/models/transaction_state.dart'; import '../../../data/models/transaction_state.dart';
import '../../../g1/api.dart'; import '../../../g1/api.dart';
import '../../../g1/transaction_v1_parser.dart'; import '../../../g1/transactions_v1_parser.dart';
import '../../ui_helpers.dart'; import '../../ui_helpers.dart';
import '../connectivity_widget_wrapper_wrapper.dart'; import '../connectivity_widget_wrapper_wrapper.dart';
import '../fourth_screen/transaction_item.dart'; import '../fourth_screen/transaction_item.dart';
......
...@@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:ginkgo/data/models/transaction.dart'; import 'package:ginkgo/data/models/transaction.dart';
import 'package:ginkgo/data/models/transaction_state.dart'; import 'package:ginkgo/data/models/transaction_state.dart';
import 'package:ginkgo/data/models/transaction_type.dart'; import 'package:ginkgo/data/models/transaction_type.dart';
import 'package:ginkgo/g1/transaction_v1_parser.dart'; import 'package:ginkgo/g1/transactions_v1_parser.dart';
import 'package:ginkgo/ui/contacts_cache.dart'; import 'package:ginkgo/ui/contacts_cache.dart';
void main() { void main() {
...@@ -26,7 +26,7 @@ void main() { ...@@ -26,7 +26,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final String txData = await rootBundle.loadString('assets/tx.json'); final String txData = await rootBundle.loadString('assets/tx.json');
final TransactionState result = final TransactionState result =
await transactionParser(txData, <Transaction>[]); await transactionsParser(txData, <Transaction>[]);
expect(result.balance, equals(6700)); expect(result.balance, equals(6700));
final List<Transaction> txs = result.transactions; final List<Transaction> txs = result.transactions;
for (final Transaction tx in txs) { for (final Transaction tx in txs) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment