Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/db/isar/main_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ class MainDB {
return isar.transactions.getByTxidWalletId(txid, walletId);
}

Future<WalletTransaction?> getTradeTransaction(
String walletId,
String txid,
) async {
return await isar.transactionV2s.getByTxidWalletId(txid, walletId) ??
await getTransaction(walletId, txid);
}

Stream<Transaction?> watchTransaction({
required Id id,
bool fireImmediately = false,
Expand Down
21 changes: 12 additions & 9 deletions lib/models/isar/models/blockchain_data/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import 'output.dart';

part 'transaction.g.dart';

abstract interface class WalletTransaction {
String get txid;
}

@Collection()
class Transaction {
class Transaction implements WalletTransaction {
Transaction({
required this.walletId,
required this.txid,
Expand Down Expand Up @@ -94,6 +98,7 @@ class Transaction {
late final String walletId;

@Index(unique: true, composite: [CompositeIndex("walletId")])
@override
late final String txid;

@Index()
Expand Down Expand Up @@ -218,14 +223,12 @@ class Transaction {
slateId: json["slateId"] as String?,
otherData: json["otherData"] as String?,
nonce: json["nonce"] as int?,
inputs:
List<String>.from(
json["inputs"] as List,
).map((e) => Input.fromJsonString(e)).toList(),
outputs:
List<String>.from(
json["outputs"] as List,
).map((e) => Output.fromJsonString(e)).toList(),
inputs: List<String>.from(json["inputs"] as List)
.map((e) => Input.fromJsonString(e))
.toList(),
outputs: List<String>.from(json["outputs"] as List)
.map((e) => Output.fromJsonString(e))
.toList(),
numberOfMessages: json["numberOfMessages"] as int,
);
if (json["address"] == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import 'output_v2.dart';
part 'transaction_v2.g.dart';

@Collection()
class TransactionV2 {
class TransactionV2 implements WalletTransaction {
Id id = Isar.autoIncrement;

@Index()
final String walletId;

@Index(unique: true, composite: [CompositeIndex("walletId")])
@override
final String txid;

final String hash;
Expand Down
41 changes: 18 additions & 23 deletions lib/pages/exchange_view/exchange_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar_community/isar.dart';
import 'package:tuple/tuple.dart';

import '../../db/isar/main_db.dart';
import '../../models/isar/models/blockchain_data/transaction.dart';
import '../../providers/global/trades_service_provider.dart';
import '../../providers/providers.dart';
import '../../services/exchange/exchange_data_loading_service.dart';
Expand Down Expand Up @@ -94,9 +92,10 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
children: [
child,
Material(
color: Theme.of(
context,
).extension<StackColors>()!.overlay.withOpacity(0.6),
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.6),
child: const CustomLoadingOverlay(
message: "Updating exchange data",
subMessage: "This could take a few minutes",
Expand Down Expand Up @@ -151,10 +150,9 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
Text(
"Trades",
style: STextStyles.itemSubtitle(context).copyWith(
color:
Theme.of(
context,
).extension<StackColors>()!.textDark3,
color: Theme.of(context)
.extension<StackColors>()!
.textDark3,
),
),
const SizedBox(height: 12),
Expand All @@ -173,10 +171,9 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
onTap: () async {
final String tradeId = trades[index].tradeId;

final lookup =
ref
.read(tradeSentFromStackLookupProvider)
.all;
final lookup = ref
.read(tradeSentFromStackLookupProvider)
.all;

//todo: check if print needed
// debugPrint("ALL: $lookup");
Expand All @@ -198,12 +195,11 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
//todo: check if print needed
// debugPrint("name: ${manager.walletName}");

final tx =
await MainDB.instance
.getTransactions(walletIds.first)
.filter()
.txidEqualTo(txid)
.findFirst();
final tx = await MainDB.instance
.getTradeTransaction(
walletIds.first,
txid,
);

if (mounted) {
unawaited(
Expand Down Expand Up @@ -242,10 +238,9 @@ class _ExchangeViewState extends ConsumerState<ExchangeView> {
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Container(
decoration: BoxDecoration(
color:
Theme.of(
context,
).extension<StackColors>()!.popupBG,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
Expand Down
49 changes: 29 additions & 20 deletions lib/pages/exchange_view/trade_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../../app_config.dart';
import '../../models/exchange/change_now/cn_exchange_transaction_status.dart';
import '../../models/isar/models/blockchain_data/transaction.dart';
import '../../models/isar/models/blockchain_data/v2/transaction_v2.dart';
import '../../models/isar/stack_theme.dart';
import '../../notifications/show_flush_bar.dart';
import '../../providers/global/trades_service_provider.dart';
Expand All @@ -47,6 +48,7 @@ import '../../utilities/format.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
import '../../wallets/crypto_currency/crypto_currency.dart';
import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../widgets/background.dart';
import '../../widgets/conditional_parent.dart';
import '../../widgets/custom_buttons/app_bar_icon_button.dart';
Expand All @@ -59,6 +61,8 @@ import '../../widgets/rounded_white_container.dart';
import '../../widgets/stack_dialog.dart';
import '../wallet_view/transaction_views/edit_note_view.dart';
import '../wallet_view/transaction_views/transaction_details_view.dart' as tdv;
import '../wallet_view/transaction_views/tx_v2/transaction_v2_details_view.dart'
show TransactionV2DetailsView;
import 'edit_trade_note_view.dart';
import 'send_from_view.dart';

Expand All @@ -76,7 +80,7 @@ class TradeDetailsView extends ConsumerStatefulWidget {

final String tradeId;
final ClipboardInterface clipboard;
final Transaction? transactionIfSentFromStack;
final WalletTransaction? transactionIfSentFromStack;
final String? walletId;
final String? walletName;

Expand All @@ -87,7 +91,7 @@ class TradeDetailsView extends ConsumerStatefulWidget {
class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
late final String tradeId;
late final ClipboardInterface clipboard;
late final Transaction? transactionIfSentFromStack;
late final WalletTransaction? transactionIfSentFromStack;
late final String? walletId;

@override
Expand Down Expand Up @@ -551,16 +555,19 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
Text("Sent from", style: STextStyles.itemSubtitle(context)),
const SizedBox(height: 4),
SelectableText(
widget.walletName!,
widget.walletName ?? ref.watch(pWalletName(walletId!)),
style: STextStyles.itemSubtitle12(context),
),
const SizedBox(height: 10),
CustomTextButton(
text: "View transaction",
onTap: () {
final coin = AppConfig.getCryptoCurrencyForTicker(
trade.payInCurrency,
)!;
final tx = transactionIfSentFromStack!;
final id = walletId!;
final coin = ref.read(pWalletCoin(id));
final name = tx is TransactionV2
? TransactionV2DetailsView.routeName
: tdv.TransactionDetailsView.routeName;

if (isDesktop) {
Navigator.of(context).push(
Expand All @@ -569,25 +576,27 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
maxHeight:
MediaQuery.of(context).size.height - 64,
maxWidth: 580,
child: tdv.TransactionDetailsView(
coin: coin,
transaction: transactionIfSentFromStack!,
walletId: walletId!,
),
),
const RouteSettings(
name: tdv.TransactionDetailsView.routeName,
child: tx is TransactionV2
? TransactionV2DetailsView(
transaction: tx,
coin: coin,
walletId: id,
)
: tdv.TransactionDetailsView(
transaction: tx as Transaction,
coin: coin,
walletId: id,
),
),
RouteSettings(name: name),
),
);
} else {
Navigator.of(context).pushNamed(
tdv.TransactionDetailsView.routeName,
arguments: Tuple3(
transactionIfSentFromStack!,
coin,
walletId!,
),
name,
arguments: tx is TransactionV2
? (tx: tx, coin: coin, walletId: id)
: Tuple3(tx as Transaction, coin, id),
);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ class TxListItem extends ConsumerWidget {
Flexible(
child: TradeDetailsView(
tradeId: trade.tradeId,
// TODO: [prio:med]
// transactionIfSentFromStack: tx,
transactionIfSentFromStack: null,
transactionIfSentFromStack: _tx,
walletName: ref.watch(
pWalletName(_tx.walletId),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:isar_community/isar.dart';
import 'package:tuple/tuple.dart';

import '../../db/isar/main_db.dart';
import '../../models/exchange/change_now/cn_exchange_transaction_status.dart';
import '../../models/exchange/response_objects/trade.dart';
import '../../models/isar/models/isar_models.dart';
import '../../models/isar/stack_theme.dart';
import '../../pages/exchange_view/trade_details_view.dart';
import '../../providers/exchange/trade_sent_from_stack_lookup_provider.dart';
Expand Down Expand Up @@ -363,11 +361,8 @@ class _DesktopTradeRowCardState extends ConsumerState<DesktopTradeRowCard> {
// debugPrint("name: ${manager.walletName}");

await loadAndPresentDesktopTradeDetails(
load: () => MainDB.instance
.getTransactions(walletIds.first)
.filter()
.txidEqualTo(txid)
.findFirst(),
load: () =>
MainDB.instance.getTradeTransaction(walletIds.first, txid),
present: (tx) {
if (mounted) {
unawaited(
Expand Down
Loading
Loading