Fixes for tx key for monero wallet

M committed Jan 31, 2022 at 14:08 UTC 28cf8163ff98ad2b2116ef85cc4feb5d46159952
5 files changed +46 -25
cw_core/lib/transaction_info.dart
+2 -1
@@ -1,5 +1,4 @@
1 import 'package:cw_core/transaction_direction.dart';
2 -//import 'package:cake_wallet/utils/mobx.dart';
2 import 'package:cw_core/keyable.dart';
3
4 abstract class TransactionInfo extends Object with Keyable {
@@ -18,4 +17,6 @@ abstract class TransactionInfo extends Object with Keyable {
17
18 @override
19 dynamic get keyIndex => id;
20 +
21 + Map<String, dynamic> additionalInfo;
22 }
\ No newline at end of file
cw_monero/lib/monero_transaction_info.dart
+14 -2
@@ -23,7 +23,13 @@ class MoneroTransactionInfo extends TransactionInfo {
23 accountIndex = int.parse(map['accountIndex'] as String),
24 addressIndex = map['addressIndex'] as int,
25 key = getTxKey((map['hash'] ?? '') as String),
26 - fee = map['fee'] as int ?? 0;
26 + fee = map['fee'] as int ?? 0 {
27 + additionalInfo = {
28 + 'key': key,
29 + 'accountIndex': accountIndex,
30 + 'addressIndex': addressIndex
31 + };
32 + }
33
34 MoneroTransactionInfo.fromRow(TransactionInfoRow row)
35 : id = row.getHash(),
@@ -36,7 +42,13 @@ class MoneroTransactionInfo extends TransactionInfo {
42 accountIndex = row.subaddrAccount,
43 addressIndex = row.subaddrIndex,
44 key = getTxKey(row.getHash()),
39 - fee = row.fee;
45 + fee = row.fee {
46 + additionalInfo = {
47 + 'key': key,
48 + 'accountIndex': accountIndex,
49 + 'addressIndex': addressIndex
50 + };
51 + }
52
53 final String id;
54 final int height;
lib/monero/cw_monero.dart
+5
@@ -288,4 +288,9 @@ class CWMonero extends Monero {
288 WalletService createMoneroWalletService(Box<WalletInfo> walletInfoSource) {
289 return MoneroWalletService(walletInfoSource);
290 }
291 +
292 + String getTransactionAddress(Object wallet, int accountIndex, int addressIndex) {
293 + final moneroWallet = wallet as MoneroWallet;
294 + return moneroWallet.getTransactionAddress(accountIndex, addressIndex);
295 + }
296 }
lib/view_model/transaction_details_view_model.dart
+23 -22
@@ -13,6 +13,7 @@ import 'package:mobx/mobx.dart';
13 import 'package:cake_wallet/store/settings_store.dart';
14 import 'package:cake_wallet/generated/i18n.dart';
15 import 'package:url_launcher/url_launcher.dart';
16 +import 'package:cake_wallet/monero/monero.dart';
17
18 part 'transaction_details_view_model.g.dart';
19
@@ -31,6 +32,9 @@ abstract class TransactionDetailsViewModelBase with Store {
32
33 final dateFormat = DateFormatter.withCurrentLocal();
34 final tx = transactionInfo;
35 + final key = tx.additionalInfo['key'] as String;
36 + final accountIndex = tx.additionalInfo['accountIndex'] as int;
37 + final addressIndex = tx.additionalInfo['addressIndex'] as int;
38
39 if (wallet.type == WalletType.monero) {
40 final _items = [
@@ -46,30 +50,27 @@ abstract class TransactionDetailsViewModelBase with Store {
50 value: tx.amountFormatted()),
51 StandartListItem(
52 title: S.current.transaction_details_fee, value: tx.feeFormatted()),
53 + if (key?.isNotEmpty ?? false)
54 + StandartListItem(title: S.current.transaction_key, value: key)
55 ];
56
51 - //if (tx.key?.isNotEmpty ?? null) {
52 - // _items.add(
53 - // StandartListItem(title: S.current.transaction_key, value: tx.key));
54 - //}
55 -
56 - //if (tx.direction == TransactionDirection.incoming) {
57 - // try {
58 - // final accountIndex = tx.accountIndex;
59 - // final addressIndex = tx.addressIndex;
60 - //final address = moneroUtils.getTransactionAddress(wallet, accountIndex, addressIndex);
61 -
62 - //if (address?.isNotEmpty ?? false) {
63 - // isRecipientAddressShown = true;
64 - // _items.add(
65 - // StandartListItem(
66 - // title: S.current.transaction_details_recipient_address,
67 - // value: address));
68 - //}
69 - // } catch (e) {
70 - // print(e.toString());
71 - // }
72 - //}
57 + if (tx.direction == TransactionDirection.incoming &&
58 + accountIndex != null &&
59 + addressIndex != null) {
60 + try {
61 + final address = monero.getTransactionAddress(wallet, accountIndex, addressIndex);
62 +
63 + if (address?.isNotEmpty ?? false) {
64 + isRecipientAddressShown = true;
65 + _items.add(
66 + StandartListItem(
67 + title: S.current.transaction_details_recipient_address,
68 + value: address));
69 + }
70 + } catch (e) {
71 + print(e.toString());
72 + }
73 + }
74
75 items.addAll(_items);
76 }
tool/configure.dart
+2
@@ -204,6 +204,8 @@ abstract class Monero {
204
205 MoneroWalletDetails getMoneroWalletDetails(Object wallet);
206
207 + String getTransactionAddress(Object wallet, int accountIndex, int addressIndex);
208 +
209 int getHeigthByDate({DateTime date});
210 TransactionPriority getDefaultTransactionPriority();
211 TransactionPriority deserializeMoneroTransactionPriority({int raw});