update remaining ui to handle new data models

This commit is contained in:
julian 2023-01-11 22:45:32 -06:00
parent f8c6a17fa7
commit 525d0fa7c4
13 changed files with 111 additions and 91 deletions

View file

@ -2,6 +2,8 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
import 'package:stackwallet/pages/exchange_view/exchange_form.dart'; import 'package:stackwallet/pages/exchange_view/exchange_form.dart';
import 'package:stackwallet/pages/exchange_view/trade_details_view.dart'; import 'package:stackwallet/pages/exchange_view/trade_details_view.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart'; import 'package:stackwallet/providers/global/trades_service_provider.dart';
@ -129,10 +131,10 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
//todo: check if print needed //todo: check if print needed
// debugPrint("name: ${manager.walletName}"); // debugPrint("name: ${manager.walletName}");
// TODO store tx data completely locally in isar so we don't lock up ui here when querying txData final tx = await manager.db.transactions
final txData = await manager.transactionData; .filter()
.txidEqualTo(txid)
final tx = txData.getAllTransactions()[txid]; .findFirst();
if (mounted) { if (mounted) {
unawaited(Navigator.of(context).pushNamed( unawaited(Navigator.of(context).pushNamed(

View file

@ -438,8 +438,10 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
style: STextStyles.itemSubtitle(context), style: STextStyles.itemSubtitle(context),
), ),
FutureBuilder( FutureBuilder(
future: (manager.wallet as FiroWallet) // TODO redo this widget now that its not actually a future
.availablePrivateBalance(), future: Future(() =>
(manager.wallet as FiroWallet)
.availablePrivateBalance()),
builder: (builderContext, builder: (builderContext,
AsyncSnapshot<Decimal> snapshot) { AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==
@ -524,8 +526,10 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
style: STextStyles.itemSubtitle(context), style: STextStyles.itemSubtitle(context),
), ),
FutureBuilder( FutureBuilder(
future: (manager.wallet as FiroWallet) // TODO redo this widget now that its not actually a future
.availablePublicBalance(), future: Future(() =>
(manager.wallet as FiroWallet)
.availablePublicBalance()),
builder: (builderContext, builder: (builderContext,
AsyncSnapshot<Decimal> snapshot) { AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==
@ -634,7 +638,8 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
), ),
if (!isFiro) if (!isFiro)
FutureBuilder( FutureBuilder(
future: manager.totalBalance, // TODO redo this widget now that its not actually a future
future: Future(() => manager.balance.getTotal()),
builder: builder:
(builderContext, AsyncSnapshot<Decimal> snapshot) { (builderContext, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==

View file

@ -485,22 +485,22 @@ class _SendViewState extends ConsumerState<SendView> {
coin == Coin.firoTestNet) coin == Coin.firoTestNet)
const Spacer(), const Spacer(),
FutureBuilder( FutureBuilder(
// TODO redo this widget now that its not actually a future
future: (coin != Coin.firo && future: (coin != Coin.firo &&
coin != Coin.firoTestNet) coin != Coin.firoTestNet)
? ref.watch(provider.select( ? Future(() => ref.watch(
(value) => value.availableBalance)) provider.select((value) =>
: ref value.balance.getSpendable())))
.watch( : ref.watch(publicPrivateBalanceStateProvider.state).state ==
publicPrivateBalanceStateProvider
.state)
.state ==
"Private" "Private"
? (ref.watch(provider).wallet ? Future(() => (ref
as FiroWallet) .watch(provider)
.availablePrivateBalance() .wallet as FiroWallet)
: (ref.watch(provider).wallet .availablePrivateBalance())
as FiroWallet) : Future(() => (ref
.availablePublicBalance(), .watch(provider)
.wallet as FiroWallet)
.availablePublicBalance()),
builder: builder:
(_, AsyncSnapshot<Decimal> snapshot) { (_, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==
@ -1085,9 +1085,10 @@ class _SendViewState extends ConsumerState<SendView> {
.decimalPlacesForCoin(coin)); .decimalPlacesForCoin(coin));
} }
} else { } else {
cryptoAmountController.text = (await ref cryptoAmountController.text = (ref
.read(provider) .read(provider)
.availableBalance) .balance
.getSpendable())
.toStringAsFixed( .toStringAsFixed(
Constants.decimalPlacesForCoin( Constants.decimalPlacesForCoin(
coin)); coin));
@ -1523,43 +1524,43 @@ class _SendViewState extends ConsumerState<SendView> {
.read(walletsChangeNotifierProvider) .read(walletsChangeNotifierProvider)
.getManager(walletId); .getManager(walletId);
// TODO: remove the need for this!! // // TODO: remove the need for this!!
final bool isOwnAddress = // final bool isOwnAddress =
await manager.isOwnAddress(_address!); // await manager.isOwnAddress(_address!);
if (isOwnAddress && coin != Coin.dogecoinTestNet) { // if (isOwnAddress && coin != Coin.dogecoinTestNet) {
await showDialog<dynamic>( // await showDialog<dynamic>(
context: context, // context: context,
useSafeArea: false, // useSafeArea: false,
barrierDismissible: true, // barrierDismissible: true,
builder: (context) { // builder: (context) {
return StackDialog( // return StackDialog(
title: "Transaction failed", // title: "Transaction failed",
message: // message:
"Sending to self is currently disabled", // "Sending to self is currently disabled",
rightButton: TextButton( // rightButton: TextButton(
style: Theme.of(context) // style: Theme.of(context)
.extension<StackColors>()! // .extension<StackColors>()!
.getSecondaryEnabledButtonColor( // .getSecondaryEnabledButtonColor(
context), // context),
child: Text( // child: Text(
"Ok", // "Ok",
style: STextStyles.button( // style: STextStyles.button(
context) // context)
.copyWith( // .copyWith(
color: Theme.of(context) // color: Theme.of(context)
.extension< // .extension<
StackColors>()! // StackColors>()!
.accentColorDark), // .accentColorDark),
), // ),
onPressed: () { // onPressed: () {
Navigator.of(context).pop(); // Navigator.of(context).pop();
}, // },
), // ),
); // );
}, // },
); // );
return; // return;
} // }
final amount = final amount =
Format.decimalAmountToSatoshis( Format.decimalAmountToSatoshis(
@ -1575,22 +1576,20 @@ class _SendViewState extends ConsumerState<SendView> {
"Private") { "Private") {
availableBalance = availableBalance =
Format.decimalAmountToSatoshis( Format.decimalAmountToSatoshis(
await (manager.wallet (manager.wallet as FiroWallet)
as FiroWallet)
.availablePrivateBalance(), .availablePrivateBalance(),
coin); coin);
} else { } else {
availableBalance = availableBalance =
Format.decimalAmountToSatoshis( Format.decimalAmountToSatoshis(
await (manager.wallet (manager.wallet as FiroWallet)
as FiroWallet)
.availablePublicBalance(), .availablePublicBalance(),
coin); coin);
} }
} else { } else {
availableBalance = availableBalance =
Format.decimalAmountToSatoshis( Format.decimalAmountToSatoshis(
await manager.availableBalance, manager.balance.getSpendable(),
coin); coin);
} }

View file

@ -154,7 +154,9 @@ class _FiroBalanceSelectionSheetState
width: 2, width: 2,
), ),
FutureBuilder( FutureBuilder(
future: firoWallet.availablePrivateBalance(), // TODO redo this widget now that its not actually a future
future: Future(
() => firoWallet.availablePrivateBalance()),
builder: builder:
(context, AsyncSnapshot<Decimal> snapshot) { (context, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==
@ -244,7 +246,9 @@ class _FiroBalanceSelectionSheetState
width: 2, width: 2,
), ),
FutureBuilder( FutureBuilder(
future: firoWallet.availablePublicBalance(), // TODO redo this widget now that its not actually a future
future: Future(
() => firoWallet.availablePublicBalance()),
builder: builder:
(context, AsyncSnapshot<Decimal> snapshot) { (context, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==

View file

@ -145,7 +145,8 @@ class WalletSyncingOptionsView extends ConsumerWidget {
height: 2, height: 2,
), ),
FutureBuilder( FutureBuilder(
future: manager.totalBalance, future: Future(
() => manager.balance.getTotal()),
builder: (builderContext, builder: (builderContext,
AsyncSnapshot<Decimal> snapshot) { AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == if (snapshot.connectionState ==

View file

@ -217,8 +217,8 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
), ),
), ),
FutureBuilder( FutureBuilder(
future: ref.watch( future: Future(() => ref.watch(managerProvider
managerProvider.select((value) => value.totalBalance)), .select((value) => value.balance.getTotal()))),
builder: (builderContext, AsyncSnapshot<Decimal> snapshot) { builder: (builderContext, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == ConnectionState.done && if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) { snapshot.hasData) {

View file

@ -1,8 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/contact.dart'; import 'package:stackwallet/models/contact.dart';
import 'package:stackwallet/models/paymint/transactions_model.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
import 'package:stackwallet/pages/address_book_views/subviews/add_new_contact_address_view.dart'; import 'package:stackwallet/pages/address_book_views/subviews/add_new_contact_address_view.dart';
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_address_card.dart'; import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_address_card.dart';
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_options_menu_popup.dart'; import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_options_menu_popup.dart';
@ -57,11 +58,12 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
List<Tuple2<String, Transaction>> result = []; List<Tuple2<String, Transaction>> result = [];
for (final manager in managers) { for (final manager in managers) {
final transactions = (await manager.transactionData) final transactions = await manager.db.transactions
.getAllTransactions() .filter()
.values .anyOf(contact.addresses.map((e) => e.address),
.toList() (q, String e) => q.addressEqualTo(e))
.where((e) => _contactHasAddress(e.address, contact)); .sortByTimestampDesc()
.findAll();
for (final tx in transactions) { for (final tx in transactions) {
result.add(Tuple2(manager.walletId, tx)); result.add(Tuple2(manager.walletId, tx));

View file

@ -4,12 +4,15 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart'; import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart'; import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/pages/exchange_view/trade_details_view.dart'; import 'package:stackwallet/pages/exchange_view/trade_details_view.dart';
import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart'; import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart'; import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -26,8 +29,6 @@ import 'package:stackwallet/widgets/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import '../../route_generator.dart';
class DesktopAllTradesView extends ConsumerStatefulWidget { class DesktopAllTradesView extends ConsumerStatefulWidget {
const DesktopAllTradesView({Key? key}) : super(key: key); const DesktopAllTradesView({Key? key}) : super(key: key);
@ -349,10 +350,11 @@ class _DesktopTradeRowCardState extends ConsumerState<DesktopTradeRowCard> {
//todo: check if print needed //todo: check if print needed
// debugPrint("name: ${manager.walletName}"); // debugPrint("name: ${manager.walletName}");
// TODO store tx data completely locally in isar so we don't lock up ui here when querying txData final tx = await manager.db.transactions
final txData = await manager.transactionData; .filter()
.txidEqualTo(txid)
.findFirst();
final tx = txData.getAllTransactions()[txid];
await showDialog<void>( await showDialog<void>(
context: context, context: context,
builder: (context) => DesktopDialog( builder: (context) => DesktopDialog(

View file

@ -305,8 +305,9 @@ class _BalanceDisplayState extends ConsumerState<BalanceDisplay> {
final locale = ref.watch( final locale = ref.watch(
localeServiceChangeNotifierProvider.select((value) => value.locale)); localeServiceChangeNotifierProvider.select((value) => value.locale));
// TODO redo this widget now that its not actually a future
return FutureBuilder( return FutureBuilder(
future: manager.availableBalance, future: Future(() => manager.balance.getSpendable()),
builder: (context, AsyncSnapshot<Decimal> snapshot) { builder: (context, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == ConnectionState.done && if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData && snapshot.hasData &&

View file

@ -2,6 +2,8 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
import 'package:stackwallet/pages/exchange_view/trade_details_view.dart'; import 'package:stackwallet/pages/exchange_view/trade_details_view.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_all_trades_view.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_all_trades_view.dart';
import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart'; import 'package:stackwallet/providers/exchange/trade_sent_from_stack_lookup_provider.dart';
@ -126,10 +128,10 @@ class _DesktopTradeHistoryState extends ConsumerState<DesktopTradeHistory> {
//todo: check if print needed //todo: check if print needed
// debugPrint("name: ${manager.walletName}"); // debugPrint("name: ${manager.walletName}");
// TODO store tx data completely locally in isar so we don't lock up ui here when querying txData final tx = await manager.db.transactions
final txData = await manager.transactionData; .filter()
.txidEqualTo(txid)
final tx = txData.getAllTransactions()[txid]; .findFirst();
if (mounted) { if (mounted) {
await showDialog<void>( await showDialog<void>(

View file

@ -5,7 +5,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/contact_address_entry.dart'; import 'package:stackwallet/models/contact_address_entry.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart'; import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart'; import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/paymint/transactions_model.dart';
import 'package:stackwallet/models/send_view_auto_fill_data.dart'; import 'package:stackwallet/models/send_view_auto_fill_data.dart';
import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart';
import 'package:stackwallet/pages/add_wallet_views/create_or_restore_wallet_view/create_or_restore_wallet_view.dart'; import 'package:stackwallet/pages/add_wallet_views/create_or_restore_wallet_view/create_or_restore_wallet_view.dart';
@ -122,6 +121,8 @@ import 'package:stackwallet/utilities/enums/add_wallet_type_enum.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'models/isar/models/blockchain_data/transaction.dart';
class RouteGenerator { class RouteGenerator {
static const bool useMaterialPageRoute = true; static const bool useMaterialPageRoute = true;

View file

@ -105,7 +105,7 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
Expanded( Expanded(
child: Text( child: Text(
"${Format.localizedStringAsFixed( "${Format.localizedStringAsFixed(
value: manager.cachedTotalBalance, value: manager.balance.getTotal(),
locale: ref.watch( locale: ref.watch(
localeServiceChangeNotifierProvider localeServiceChangeNotifierProvider
.select((value) => value.locale)), .select((value) => value.locale)),
@ -147,7 +147,7 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
), ),
Text( Text(
"${Format.localizedStringAsFixed( "${Format.localizedStringAsFixed(
value: manager.cachedTotalBalance, value: manager.balance.getTotal(),
locale: ref.watch(localeServiceChangeNotifierProvider locale: ref.watch(localeServiceChangeNotifierProvider
.select((value) => value.locale)), .select((value) => value.locale)),
decimalPlaces: 8, decimalPlaces: 8,

View file

@ -27,8 +27,9 @@ class WalletInfoRowBalanceFuture extends ConsumerWidget {
), ),
); );
// TODO redo this widget now that its not actually a future
return FutureBuilder( return FutureBuilder(
future: manager.totalBalance, future: Future(() => manager.balance.getTotal()),
builder: (builderContext, AsyncSnapshot<Decimal> snapshot) { builder: (builderContext, AsyncSnapshot<Decimal> snapshot) {
if (snapshot.connectionState == ConnectionState.done && if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) { snapshot.hasData) {