stack_wallet/lib/wallets/isar/providers/wallet_info_provider.dart

92 lines
2.7 KiB
Dart
Raw Normal View History

2023-11-01 19:00:36 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/providers/db/main_db_provider.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
import 'package:stackwallet/wallets/isar/providers/util/watcher.dart';
final _wiProvider = ChangeNotifierProvider.family<Watcher, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
final collection = ref.watch(mainDBProvider).isar.walletInfo;
final watcher = Watcher(
collection.where().walletIdEqualTo(walletId).findFirstSync()!,
collection: collection,
);
ref.onDispose(() => watcher.dispose());
return watcher;
},
);
final pWalletInfo = Provider.family<WalletInfo, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)).value as WalletInfo;
},
);
final pWalletCoin = Provider.family<Coin, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).coin));
},
);
final pWalletBalance = Provider.family<Balance, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).cachedBalance));
},
);
final pWalletBalanceSecondary = Provider.family<Balance, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
2023-11-16 23:32:47 +00:00
.select((value) => (value.value as WalletInfo).cachedBalanceSecondary));
},
);
final pWalletBalanceTertiary = Provider.family<Balance, String>(
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).cachedBalanceTertiary));
2023-11-01 19:00:36 +00:00
},
);
final pWalletChainHeight = Provider.family<int, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).cachedChainHeight));
},
);
final pWalletIsFavourite = Provider.family<bool, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).isFavourite));
},
);
final pWalletName = Provider.family<String, String>(
2023-11-01 19:00:36 +00:00
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).name));
},
);
final pWalletReceivingAddress = Provider.family<String, String>(
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).cachedReceivingAddress));
},
);
final pWalletTokenAddresses = Provider.family<List<String>, String>(
(ref, walletId) {
return ref.watch(_wiProvider(walletId)
.select((value) => (value.value as WalletInfo).tokenContractAddresses));
},
);