From 995e0be8353d5e07aea7ee0981081a9782d27c35 Mon Sep 17 00:00:00 2001 From: pokkst Date: Thu, 6 Oct 2022 00:23:36 -0500 Subject: [PATCH] Simplify fetching latest subaddress --- .../dialog/ReceiveBottomSheetDialog.java | 2 +- .../mynero/wallet/service/AddressService.java | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java index 744593d..82801b1 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/ReceiveBottomSheetDialog.java @@ -46,7 +46,7 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment { TextView addressTextView = view.findViewById(R.id.address_textview); ImageButton copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton); - Subaddress addr = AddressService.getInstance().getLatestSubaddress(); + Subaddress addr = AddressService.getInstance().currentSubaddress(); addressTextView.setText(addr.getAddress()); addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256)); copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", addr.getAddress())); diff --git a/app/src/main/java/net/mynero/wallet/service/AddressService.java b/app/src/main/java/net/mynero/wallet/service/AddressService.java index f10efd0..ddcbb2d 100644 --- a/app/src/main/java/net/mynero/wallet/service/AddressService.java +++ b/app/src/main/java/net/mynero/wallet/service/AddressService.java @@ -5,8 +5,11 @@ import net.mynero.wallet.model.TransactionInfo; import net.mynero.wallet.model.Wallet; import net.mynero.wallet.model.WalletManager; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; +import java.util.Locale; public class AddressService extends ServiceBase { public static AddressService instance = null; @@ -22,19 +25,22 @@ public class AddressService extends ServiceBase { } public void refreshAddresses() { - List localTransactionList = new ArrayList<>(HistoryService.getInstance().getHistory()); - for (TransactionInfo info : localTransactionList) { - if (info.addressIndex >= latestAddressIndex) { - latestAddressIndex = info.addressIndex + 1; - } - } + latestAddressIndex = WalletManager.getInstance().getWallet().getNumSubaddresses(); } public String getPrimaryAddress() { return WalletManager.getInstance().getWallet().getAddress(); } - public Subaddress getLatestSubaddress() { + public Subaddress freshSubaddress() { + String timeStamp = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss", Locale.US).format(new Date()); + Wallet wallet = WalletManager.getInstance().getWallet(); + wallet.addSubaddress(wallet.getAccountIndex(), timeStamp); + refreshAddresses(); + return wallet.getSubaddressObject(latestAddressIndex); + } + + public Subaddress currentSubaddress() { Wallet wallet = WalletManager.getInstance().getWallet(); return wallet.getSubaddressObject(latestAddressIndex); }