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';
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
final pWalletInfo = Provider.family<WalletInfo, String>(
|
2023-11-01 19:00:36 +00:00
|
|
|
(ref, walletId) {
|
|
|
|
return ref.watch(_wiProvider(walletId)).value as WalletInfo;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +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));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
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));
|
|
|
|
},
|
|
|
|
);
|
2023-11-03 19:46:55 +00:00
|
|
|
|
2023-11-08 19:57:38 +00:00
|
|
|
final pWalletReceivingAddress = Provider.family<String, String>(
|
2023-11-03 19:46:55 +00:00
|
|
|
(ref, walletId) {
|
|
|
|
return ref.watch(_wiProvider(walletId)
|
|
|
|
.select((value) => (value.value as WalletInfo).cachedReceivingAddress));
|
|
|
|
},
|
|
|
|
);
|
2024-01-10 18:21:28 +00:00
|
|
|
|
|
|
|
final pWalletTokenAddresses = Provider.family<List<String>, String>(
|
|
|
|
(ref, walletId) {
|
|
|
|
return ref.watch(_wiProvider(walletId)
|
|
|
|
.select((value) => (value.value as WalletInfo).tokenContractAddresses));
|
|
|
|
},
|
|
|
|
);
|