mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 02:24:30 +00:00
extra info when run in debug mode
This commit is contained in:
parent
0acc2f2a08
commit
e06023d0fc
2 changed files with 121 additions and 8 deletions
|
@ -16,13 +16,17 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
|
||||
import '../../../models/isar/models/blockchain_data/v2/transaction_v2.dart';
|
||||
import '../../../models/isar/models/isar_models.dart';
|
||||
import '../../../pages/add_wallet_views/add_token_view/edit_wallet_tokens_view.dart';
|
||||
import '../../../pages/token_view/my_tokens_view.dart';
|
||||
import '../../../pages/wallet_view/sub_widgets/transactions_list.dart';
|
||||
import '../../../pages/wallet_view/transaction_views/all_transactions_view.dart';
|
||||
import '../../../pages/wallet_view/transaction_views/tx_v2/all_transactions_v2_view.dart';
|
||||
import '../../../pages/wallet_view/transaction_views/tx_v2/transaction_v2_list.dart';
|
||||
import '../../../providers/db/main_db_provider.dart';
|
||||
import '../../../providers/global/active_wallet_provider.dart';
|
||||
import '../../../providers/global/auto_swb_service_provider.dart';
|
||||
import '../../../providers/providers.dart';
|
||||
|
@ -35,6 +39,7 @@ import '../../../utilities/assets.dart';
|
|||
import '../../../utilities/enums/backup_frequency_type.dart';
|
||||
import '../../../utilities/enums/sync_type_enum.dart';
|
||||
import '../../../utilities/text_styles.dart';
|
||||
import '../../../utilities/wallet_tools.dart';
|
||||
import '../../../wallets/isar/providers/wallet_info_provider.dart';
|
||||
import '../../../wallets/wallet/impl/banano_wallet.dart';
|
||||
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
|
@ -207,17 +212,70 @@ class _DesktopWalletViewState extends ConsumerState<DesktopWalletView> {
|
|||
),
|
||||
if (kDebugMode) const Spacer(),
|
||||
if (kDebugMode)
|
||||
Row(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Debug Height:",
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
"dbgHeight: ",
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
Text(
|
||||
ref
|
||||
.watch(pWalletChainHeight(widget.walletId))
|
||||
.toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
Text(
|
||||
ref.watch(pWalletChainHeight(widget.walletId)).toString(),
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
"dbgTxCount: ",
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
Text(
|
||||
wallet.isarTransactionVersion == 2
|
||||
? ref
|
||||
.watch(mainDBProvider)
|
||||
.isar
|
||||
.transactionV2s
|
||||
.where()
|
||||
.walletIdEqualTo(widget.walletId)
|
||||
.countSync()
|
||||
.toString()
|
||||
: ref
|
||||
.watch(mainDBProvider)
|
||||
.isar
|
||||
.transactions
|
||||
.where()
|
||||
.walletIdEqualTo(widget.walletId)
|
||||
.countSync()
|
||||
.toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (wallet.isarTransactionVersion == 2)
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
"dbgBal: ",
|
||||
),
|
||||
const SizedBox(
|
||||
width: 2,
|
||||
),
|
||||
Text(
|
||||
WalletDevTools.checkFiroTransactionTally(
|
||||
widget.walletId,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
|
|
55
lib/utilities/wallet_tools.dart
Normal file
55
lib/utilities/wallet_tools.dart
Normal file
|
@ -0,0 +1,55 @@
|
|||
import 'package:isar/isar.dart';
|
||||
|
||||
import '../db/isar/main_db.dart';
|
||||
import '../models/isar/models/blockchain_data/v2/transaction_v2.dart';
|
||||
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||
import 'amount/amount.dart';
|
||||
import 'amount/amount_formatter.dart';
|
||||
import 'amount/amount_unit.dart';
|
||||
|
||||
abstract class WalletDevTools {
|
||||
static String checkFiroTransactionTally(String walletId) {
|
||||
final amtFmt = AmountFormatter(
|
||||
unit: AmountUnit.normal,
|
||||
locale: "en_US",
|
||||
coin: Firo(CryptoCurrencyNetwork.main),
|
||||
maxDecimals: 8,
|
||||
);
|
||||
|
||||
final all = MainDB.instance.isar.transactionV2s
|
||||
.where()
|
||||
.walletIdEqualTo(walletId)
|
||||
.findAllSync();
|
||||
|
||||
final totalCount = all.length;
|
||||
|
||||
BigInt runningBalance = BigInt.zero;
|
||||
for (final tx in all) {
|
||||
final ownIns = tx.inputs
|
||||
.where((e) => e.walletOwns)
|
||||
.map((e) => e.value)
|
||||
.fold(BigInt.zero, (p, e) => p + e);
|
||||
runningBalance -= ownIns;
|
||||
|
||||
final ownOuts = tx.outputs
|
||||
.where((e) => e.walletOwns)
|
||||
.map((e) => e.value)
|
||||
.fold(BigInt.zero, (p, e) => p + e);
|
||||
runningBalance += ownOuts;
|
||||
}
|
||||
|
||||
final balanceAccordingToTxHistory = Amount(
|
||||
rawValue: runningBalance,
|
||||
fractionDigits: 8,
|
||||
);
|
||||
|
||||
print("======== $walletId =============");
|
||||
print("totalTxCount: $totalCount");
|
||||
print(
|
||||
"balanceAccordingToTxns: ${amtFmt.format(balanceAccordingToTxHistory)}",
|
||||
);
|
||||
print("==================================================");
|
||||
|
||||
return amtFmt.format(balanceAccordingToTxHistory);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue