From 7bbd530319b6dd43114695a89ba774b29b2a481e Mon Sep 17 00:00:00 2001
From: OleksandrSobol <dr.alexander.sobol@gmail.com>
Date: Mon, 10 May 2021 19:10:33 +0300
Subject: [PATCH 1/4] CAKE-297 | applied subaddress  for incoming transaction

---
 lib/di.dart                                   | 12 ++++++----
 lib/monero/monero_transaction_info.dart       |  5 +++-
 lib/monero/monero_wallet.dart                 |  5 ++++
 .../transaction_details_view_model.dart       | 24 +++++++++++++++++++
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/lib/di.dart b/lib/di.dart
index 66ac22231..5af42cda0 100644
--- a/lib/di.dart
+++ b/lib/di.dart
@@ -482,10 +482,14 @@ Future setup(
 
   getIt
       .registerFactoryParam<TransactionDetailsViewModel, TransactionInfo, void>(
-          (TransactionInfo transactionInfo, _) => TransactionDetailsViewModel(
-              transactionInfo: transactionInfo,
-              transactionDescriptionBox: _transactionDescriptionBox,
-              settingsStore: getIt.get<SettingsStore>()));
+          (TransactionInfo transactionInfo, _) {
+            final wallet = getIt.get<AppStore>().wallet;
+            return TransactionDetailsViewModel(
+                transactionInfo: transactionInfo,
+                transactionDescriptionBox: _transactionDescriptionBox,
+                wallet: wallet,
+                settingsStore: getIt.get<SettingsStore>());
+          });
 
   getIt.registerFactoryParam<TransactionDetailsPage, TransactionInfo, void>(
       (TransactionInfo transactionInfo, _) => TransactionDetailsPage(
diff --git a/lib/monero/monero_transaction_info.dart b/lib/monero/monero_transaction_info.dart
index 71bc5957a..e28835fee 100644
--- a/lib/monero/monero_transaction_info.dart
+++ b/lib/monero/monero_transaction_info.dart
@@ -8,7 +8,7 @@ import 'package:cw_monero/transaction_history.dart';
 
 class MoneroTransactionInfo extends TransactionInfo {
   MoneroTransactionInfo(this.id, this.height, this.direction, this.date,
-      this.isPending, this.amount, this.accountIndex, this.fee);
+      this.isPending, this.amount, this.accountIndex, this.addressIndex, this.fee);
 
   MoneroTransactionInfo.fromMap(Map map)
       : id = (map['hash'] ?? '') as String,
@@ -21,6 +21,7 @@ class MoneroTransactionInfo extends TransactionInfo {
         isPending = parseBoolFromString(map['isPending'] as String),
         amount = map['amount'] as int,
         accountIndex = int.parse(map['accountIndex'] as String),
+        addressIndex = map['addressIndex'] as List<int>,
         key = getTxKey((map['hash'] ?? '') as String),
         fee = map['fee'] as int ?? 0;
 
@@ -33,6 +34,7 @@ class MoneroTransactionInfo extends TransactionInfo {
         isPending = row.isPending != 0,
         amount = row.getAmount(),
         accountIndex = row.subaddrAccount,
+        addressIndex = row.getSubaddrIndex(),
         key = getTxKey(row.getHash()),
         fee = row.fee;
 
@@ -44,6 +46,7 @@ class MoneroTransactionInfo extends TransactionInfo {
   final bool isPending;
   final int amount;
   final int fee;
+  final List<int> addressIndex;
   String recipientAddress;
   String key;
 
diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart
index 0891100c8..0c1949037 100644
--- a/lib/monero/monero_wallet.dart
+++ b/lib/monero/monero_wallet.dart
@@ -262,6 +262,11 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
     await walletInfo.save();
   }
 
+  String getTransactionAddress(int accountIndex, int addressIndex) =>
+      monero_wallet.getAddress(
+          accountIndex: accountIndex,
+          addressIndex: addressIndex);
+
   void _setListeners() {
     _listener?.stop();
     _listener = monero_wallet.setListeners(_onNewBlock, _onNewTransaction);
diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart
index 67822e207..51afb355d 100644
--- a/lib/view_model/transaction_details_view_model.dart
+++ b/lib/view_model/transaction_details_view_model.dart
@@ -1,10 +1,13 @@
 import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
+import 'package:cake_wallet/core/wallet_base.dart';
 import 'package:cake_wallet/entities/transaction_info.dart';
 import 'package:cake_wallet/monero/monero_transaction_info.dart';
+import 'package:cake_wallet/monero/monero_wallet.dart';
 import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
 import 'package:cake_wallet/src/screens/transaction_details/textfield_list_item.dart';
 import 'package:cake_wallet/src/screens/transaction_details/transaction_details_list_item.dart';
 import 'package:cake_wallet/src/screens/transaction_details/blockexplorer_list_item.dart';
+import 'package:cake_wallet/entities/transaction_direction.dart';
 import 'package:cake_wallet/utils/date_formatter.dart';
 import 'package:cake_wallet/entities/transaction_description.dart';
 import 'package:hive/hive.dart';
@@ -22,6 +25,7 @@ abstract class TransactionDetailsViewModelBase with Store {
   TransactionDetailsViewModelBase(
       {this.transactionInfo,
       this.transactionDescriptionBox,
+      this.wallet,
       this.settingsStore})
       : items = [] {
     showRecipientAddress = settingsStore?.shouldSaveRecipientAddress ?? false;
@@ -56,6 +60,25 @@ abstract class TransactionDetailsViewModelBase with Store {
             StandartListItem(title: S.current.transaction_key, value: tx.key));
       }
 
+      if ((tx.direction == TransactionDirection.incoming)&&
+          (wallet is MoneroWallet)) {
+        try {
+          final accountIndex = tx.accountIndex;
+          final addressIndex = tx.addressIndex;
+          final _wallet = wallet as MoneroWallet;
+
+          for (var index in addressIndex) {
+            final address = _wallet.getTransactionAddress(accountIndex, index);
+            _items.add(
+                StandartListItem(
+                    title: S.current.transaction_details_recipient_address,
+                    value: address));
+          }
+        } catch (e) {
+          print(e.toString());
+        }
+      }
+
       items.addAll(_items);
     }
 
@@ -122,6 +145,7 @@ abstract class TransactionDetailsViewModelBase with Store {
   final TransactionInfo transactionInfo;
   final Box<TransactionDescription> transactionDescriptionBox;
   final SettingsStore settingsStore;
+  final WalletBase wallet;
 
   final List<TransactionDetailsListItem> items;
   bool showRecipientAddress;

From 8567f20809d73fd10204a9755c2ae3c2970df0dc Mon Sep 17 00:00:00 2001
From: OleksandrSobol <dr.alexander.sobol@gmail.com>
Date: Wed, 12 May 2021 19:34:36 +0300
Subject: [PATCH 2/4] CAKE-297 | fixed addressIndex

---
 lib/monero/monero_transaction_info.dart            | 6 +++---
 lib/view_model/transaction_details_view_model.dart | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/monero/monero_transaction_info.dart b/lib/monero/monero_transaction_info.dart
index e28835fee..70f14879d 100644
--- a/lib/monero/monero_transaction_info.dart
+++ b/lib/monero/monero_transaction_info.dart
@@ -21,7 +21,7 @@ class MoneroTransactionInfo extends TransactionInfo {
         isPending = parseBoolFromString(map['isPending'] as String),
         amount = map['amount'] as int,
         accountIndex = int.parse(map['accountIndex'] as String),
-        addressIndex = map['addressIndex'] as List<int>,
+        addressIndex = map['addressIndex'] as int,
         key = getTxKey((map['hash'] ?? '') as String),
         fee = map['fee'] as int ?? 0;
 
@@ -34,7 +34,7 @@ class MoneroTransactionInfo extends TransactionInfo {
         isPending = row.isPending != 0,
         amount = row.getAmount(),
         accountIndex = row.subaddrAccount,
-        addressIndex = row.getSubaddrIndex(),
+        addressIndex = row.subaddrIndex,
         key = getTxKey(row.getHash()),
         fee = row.fee;
 
@@ -46,7 +46,7 @@ class MoneroTransactionInfo extends TransactionInfo {
   final bool isPending;
   final int amount;
   final int fee;
-  final List<int> addressIndex;
+  final int addressIndex;
   String recipientAddress;
   String key;
 
diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart
index 51afb355d..2ec151a2c 100644
--- a/lib/view_model/transaction_details_view_model.dart
+++ b/lib/view_model/transaction_details_view_model.dart
@@ -66,9 +66,9 @@ abstract class TransactionDetailsViewModelBase with Store {
           final accountIndex = tx.accountIndex;
           final addressIndex = tx.addressIndex;
           final _wallet = wallet as MoneroWallet;
-
-          for (var index in addressIndex) {
-            final address = _wallet.getTransactionAddress(accountIndex, index);
+          final address =
+            _wallet.getTransactionAddress(accountIndex, addressIndex);
+          if (address?.isNotEmpty ?? false) {
             _items.add(
                 StandartListItem(
                     title: S.current.transaction_details_recipient_address,

From 9da3d837c3cab005c521d44d9cb67a5ef714dba5 Mon Sep 17 00:00:00 2001
From: OleksandrSobol <dr.alexander.sobol@gmail.com>
Date: Wed, 12 May 2021 19:38:16 +0300
Subject: [PATCH 3/4] CAKE-297 | fixed subaddrIndex in the monero_api.cpp and
 transaction_info_row.dart

---
 cw_monero/ios/Classes/monero_api.cpp            | 3 +++
 cw_monero/lib/structs/transaction_info_row.dart | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp
index d0313a194..e25810502 100644
--- a/cw_monero/ios/Classes/monero_api.cpp
+++ b/cw_monero/ios/Classes/monero_api.cpp
@@ -134,6 +134,7 @@ extern "C"
         uint32_t subaddrAccount;
         int8_t direction;
         int8_t isPending;
+        uint32_t subaddrIndex;
         
         char *hash;
         char *paymentId;
@@ -146,6 +147,8 @@ extern "C"
             fee = transaction->fee();
             blockHeight = transaction->blockHeight();
             subaddrAccount = transaction->subaddrAccount();
+            std::set<uint32_t>::iterator it = transaction->subaddrIndex().begin();
+            subaddrIndex = *it;
             confirmations = transaction->confirmations();
             datetime = static_cast<int64_t>(transaction->timestamp());            
             direction = transaction->direction();
diff --git a/cw_monero/lib/structs/transaction_info_row.dart b/cw_monero/lib/structs/transaction_info_row.dart
index 0a0613a42..37b0d02e8 100644
--- a/cw_monero/lib/structs/transaction_info_row.dart
+++ b/cw_monero/lib/structs/transaction_info_row.dart
@@ -23,6 +23,9 @@ class TransactionInfoRow extends Struct {
   @Int8()
   int isPending;
 
+  @Uint32()
+  int subaddrIndex;
+
   Pointer<Utf8> hash;
 
   Pointer<Utf8> paymentId;

From 9ad276622fff62b8a4947f1a28b566c5c416b83b Mon Sep 17 00:00:00 2001
From: OleksandrSobol <dr.alexander.sobol@gmail.com>
Date: Tue, 18 May 2021 19:37:43 +0300
Subject: [PATCH 4/4] CAKE-297 | merged main branch into current

---
 lib/view_model/transaction_details_view_model.dart | 1 -
 pubspec.lock                                       | 6 +++---
 pubspec.yaml                                       | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart
index 285a54607..49748f7f0 100644
--- a/lib/view_model/transaction_details_view_model.dart
+++ b/lib/view_model/transaction_details_view_model.dart
@@ -1,5 +1,4 @@
 import 'package:cake_wallet/bitcoin/electrum_transaction_info.dart';
-//import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
 import 'package:cake_wallet/core/wallet_base.dart';
 import 'package:cake_wallet/entities/transaction_info.dart';
 import 'package:cake_wallet/entities/wallet_type.dart';
diff --git a/pubspec.lock b/pubspec.lock
index 3ff596074..207f4b18a 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -70,7 +70,7 @@ packages:
       path: "."
       ref: cake
       resolved-ref: "02fef082f20af13de00b4e64efb93a2c1e5e1cf2"
-      url: "git@github.com:cake-tech/bech32.git"
+      url: "https://github.com/cake-tech/bech32.git"
     source: git
     version: "0.2.0"
   bip32:
@@ -92,8 +92,8 @@ packages:
     description:
       path: "."
       ref: cake
-      resolved-ref: b3ab2926c665f0e68b74a4a5f31059f7fcd817b7
-      url: "git@github.com:cake-tech/bitcoin_flutter.git"
+      resolved-ref: cbabfd87b6ce3cae6051a3e86ddb56e7a934e188
+      url: "https://github.com/cake-tech/bitcoin_flutter.git"
     source: git
     version: "2.0.2"
   boolean_selector:
diff --git a/pubspec.yaml b/pubspec.yaml
index 27fb93b0d..4d1b63ceb 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -67,7 +67,7 @@ dependencies:
   basic_utils: ^2.0.3
   bitcoin_flutter:
     git:
-      url: git@github.com:cake-tech/bitcoin_flutter.git
+      url: https://github.com/cake-tech/bitcoin_flutter.git
       ref: cake
   get_it: ^6.0.0
   connectivity: ^3.0.3