mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-05 02:09:22 +00:00
WIP hook up to ui
This commit is contained in:
parent
6be6caab72
commit
67bfc8bbce
2 changed files with 111 additions and 11 deletions
|
@ -9,17 +9,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.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 '../../../../models/isar/models/blockchain_data/v2/transaction_v2.dart';
|
||||||
|
import '../../../../models/isar/models/isar_models.dart';
|
||||||
import '../../../../pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart';
|
import '../../../../pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart';
|
||||||
import '../../../../pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/change_representative_view.dart';
|
import '../../../../pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/change_representative_view.dart';
|
||||||
import '../../../../pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/xpub_view.dart';
|
import '../../../../pages/settings_views/wallet_settings_view/wallet_settings_wallet_settings/xpub_view.dart';
|
||||||
|
import '../../../../providers/db/main_db_provider.dart';
|
||||||
|
import '../../../../providers/global/locale_provider.dart';
|
||||||
import '../../../../providers/global/wallets_provider.dart';
|
import '../../../../providers/global/wallets_provider.dart';
|
||||||
import '../../../../route_generator.dart';
|
import '../../../../route_generator.dart';
|
||||||
|
import '../../../../services/csv_exporter.dart';
|
||||||
import '../../../../themes/stack_colors.dart';
|
import '../../../../themes/stack_colors.dart';
|
||||||
import '../../../../utilities/assets.dart';
|
import '../../../../utilities/assets.dart';
|
||||||
import '../../../../utilities/constants.dart';
|
import '../../../../utilities/constants.dart';
|
||||||
|
@ -31,6 +38,7 @@ import '../../../../wallets/crypto_currency/intermediate/frost_currency.dart';
|
||||||
import '../../../../wallets/crypto_currency/intermediate/nano_currency.dart';
|
import '../../../../wallets/crypto_currency/intermediate/nano_currency.dart';
|
||||||
import '../../../../wallets/isar/providers/wallet_info_provider.dart';
|
import '../../../../wallets/isar/providers/wallet_info_provider.dart';
|
||||||
import '../../../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
|
import '../../../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
|
||||||
|
import '../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||||
import '../../../addresses/desktop_wallet_addresses_view.dart';
|
import '../../../addresses/desktop_wallet_addresses_view.dart';
|
||||||
import '../../../lelantus_coins/lelantus_coins_view.dart';
|
import '../../../lelantus_coins/lelantus_coins_view.dart';
|
||||||
import '../../../spark_coins/spark_coins_view.dart';
|
import '../../../spark_coins/spark_coins_view.dart';
|
||||||
|
@ -43,7 +51,8 @@ enum _WalletOptions {
|
||||||
showXpub,
|
showXpub,
|
||||||
lelantusCoins,
|
lelantusCoins,
|
||||||
sparkCoins,
|
sparkCoins,
|
||||||
frostOptions;
|
frostOptions,
|
||||||
|
exportTxsCsv;
|
||||||
|
|
||||||
String get prettyName {
|
String get prettyName {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
|
@ -61,10 +70,49 @@ enum _WalletOptions {
|
||||||
return "Spark Coins";
|
return "Spark Coins";
|
||||||
case _WalletOptions.frostOptions:
|
case _WalletOptions.frostOptions:
|
||||||
return "FROST settings";
|
return "FROST settings";
|
||||||
|
case _WalletOptions.exportTxsCsv:
|
||||||
|
return "Export to CSV";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _export(String walletId, WidgetRef ref) async {
|
||||||
|
final wallet = ref.read(pWallets).getWallet(walletId);
|
||||||
|
final mainDB = ref.read(mainDBProvider);
|
||||||
|
|
||||||
|
final transactions = await mainDB.isar.transactionV2s
|
||||||
|
.where()
|
||||||
|
.walletIdEqualTo(walletId)
|
||||||
|
.findAll();
|
||||||
|
final notes = await mainDB.isar.transactionNotes
|
||||||
|
.where()
|
||||||
|
.walletIdEqualTo(walletId)
|
||||||
|
.findAll();
|
||||||
|
final locale = ref.read(localeServiceChangeNotifierProvider).locale;
|
||||||
|
|
||||||
|
EthContract? ethContract;
|
||||||
|
String? sparkChangeAddress;
|
||||||
|
|
||||||
|
if (wallet is SparkInterface) {
|
||||||
|
sparkChangeAddress = wallet.sparkChangeAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
// final ethContract = ref
|
||||||
|
// .read(mainDBProvider)
|
||||||
|
// .getEthContractSync(_transaction.contractAddress!);
|
||||||
|
|
||||||
|
final csv = CsvExporter.transactionV2sToCsv(
|
||||||
|
transactions,
|
||||||
|
notes,
|
||||||
|
wallet.info.coin,
|
||||||
|
locale,
|
||||||
|
ethContract,
|
||||||
|
sparkChangeAddress,
|
||||||
|
);
|
||||||
|
|
||||||
|
log(csv);
|
||||||
|
}
|
||||||
|
|
||||||
class WalletOptionsButton extends ConsumerWidget {
|
class WalletOptionsButton extends ConsumerWidget {
|
||||||
const WalletOptionsButton({
|
const WalletOptionsButton({
|
||||||
super.key,
|
super.key,
|
||||||
|
@ -110,6 +158,9 @@ class WalletOptionsButton extends ConsumerWidget {
|
||||||
onFrostMSWalletOptionsPressed: () async {
|
onFrostMSWalletOptionsPressed: () async {
|
||||||
Navigator.of(context).pop(_WalletOptions.frostOptions);
|
Navigator.of(context).pop(_WalletOptions.frostOptions);
|
||||||
},
|
},
|
||||||
|
onExportTOCsvPressed: () async {
|
||||||
|
Navigator.of(context).pop(_WalletOptions.exportTxsCsv);
|
||||||
|
},
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -117,6 +168,10 @@ class WalletOptionsButton extends ConsumerWidget {
|
||||||
|
|
||||||
if (context.mounted && func != null) {
|
if (context.mounted && func != null) {
|
||||||
switch (func) {
|
switch (func) {
|
||||||
|
case _WalletOptions.exportTxsCsv:
|
||||||
|
_export(walletId, ref);
|
||||||
|
break;
|
||||||
|
|
||||||
case _WalletOptions.addressList:
|
case _WalletOptions.addressList:
|
||||||
unawaited(
|
unawaited(
|
||||||
Navigator.of(context).pushNamed(
|
Navigator.of(context).pushNamed(
|
||||||
|
@ -277,6 +332,7 @@ class WalletOptionsPopupMenu extends ConsumerWidget {
|
||||||
required this.onFiroShowLelantusCoins,
|
required this.onFiroShowLelantusCoins,
|
||||||
required this.onFiroShowSparkCoins,
|
required this.onFiroShowSparkCoins,
|
||||||
required this.onFrostMSWalletOptionsPressed,
|
required this.onFrostMSWalletOptionsPressed,
|
||||||
|
required this.onExportTOCsvPressed,
|
||||||
required this.walletId,
|
required this.walletId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -287,6 +343,7 @@ class WalletOptionsPopupMenu extends ConsumerWidget {
|
||||||
final VoidCallback onFiroShowLelantusCoins;
|
final VoidCallback onFiroShowLelantusCoins;
|
||||||
final VoidCallback onFiroShowSparkCoins;
|
final VoidCallback onFiroShowSparkCoins;
|
||||||
final VoidCallback onFrostMSWalletOptionsPressed;
|
final VoidCallback onFrostMSWalletOptionsPressed;
|
||||||
|
final VoidCallback onExportTOCsvPressed;
|
||||||
final String walletId;
|
final String walletId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -543,6 +600,41 @@ class WalletOptionsPopupMenu extends ConsumerWidget {
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
|
TransparentButton(
|
||||||
|
onPressed: onExportTOCsvPressed,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
Assets.svg.arrowUpRight,
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textFieldActiveSearchIconLeft,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 14),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
_WalletOptions.exportTxsCsv.prettyName,
|
||||||
|
style: STextStyles.desktopTextExtraExtraSmall(
|
||||||
|
context,
|
||||||
|
).copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textDark,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 8,
|
||||||
|
),
|
||||||
TransparentButton(
|
TransparentButton(
|
||||||
onPressed: onDeletePressed,
|
onPressed: onDeletePressed,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
|
|
@ -8,7 +8,7 @@ import '../utilities/amount/amount_unit.dart';
|
||||||
import '../wallets/crypto_currency/crypto_currency.dart';
|
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||||
|
|
||||||
abstract final class CsvExporter {
|
abstract final class CsvExporter {
|
||||||
String transactionV2sToCsv(
|
static String transactionV2sToCsv(
|
||||||
List<TransactionV2> transactions,
|
List<TransactionV2> transactions,
|
||||||
List<TransactionNote> notes,
|
List<TransactionNote> notes,
|
||||||
CryptoCurrency coin,
|
CryptoCurrency coin,
|
||||||
|
@ -19,14 +19,16 @@ abstract final class CsvExporter {
|
||||||
final List<List<dynamic>?> rows = [];
|
final List<List<dynamic>?> rows = [];
|
||||||
|
|
||||||
rows.add([
|
rows.add([
|
||||||
"timestamp",
|
"Timestamp",
|
||||||
"height",
|
"Height",
|
||||||
"txid",
|
"Txid",
|
||||||
"amount",
|
"Amount",
|
||||||
"fee",
|
"Fee",
|
||||||
"type",
|
"Type",
|
||||||
"sub type",
|
"Sub Type",
|
||||||
"note",
|
"Note",
|
||||||
|
"Input Addresses",
|
||||||
|
"Output Addresses",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (final _transaction in transactions) {
|
for (final _transaction in transactions) {
|
||||||
|
@ -80,6 +82,12 @@ abstract final class CsvExporter {
|
||||||
);
|
);
|
||||||
row.add(note.value);
|
row.add(note.value);
|
||||||
|
|
||||||
|
// in addresses
|
||||||
|
row.add(_transaction.inputs.map((e) => e.addresses.join(",")).join(","));
|
||||||
|
|
||||||
|
// out addresses
|
||||||
|
row.add(_transaction.outputs.map((e) => e.addresses.join(",")).join(","));
|
||||||
|
|
||||||
// finally add row
|
// finally add row
|
||||||
rows.add(row);
|
rows.add(row);
|
||||||
}
|
}
|
||||||
|
@ -90,7 +98,7 @@ abstract final class CsvExporter {
|
||||||
return csv;
|
return csv;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _parseAmountFromTxnV2(
|
static String _parseAmountFromTxnV2(
|
||||||
TransactionV2 txn,
|
TransactionV2 txn,
|
||||||
AmountFormatter amountFormatter,
|
AmountFormatter amountFormatter,
|
||||||
EthContract? ethContract,
|
EthContract? ethContract,
|
||||||
|
|
Loading…
Reference in a new issue