Simplify fetching latest subaddress

This commit is contained in:
pokkst 2022-10-06 00:23:36 -05:00
parent 5545d8c6d0
commit 995e0be835
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
2 changed files with 14 additions and 8 deletions

View File

@ -46,7 +46,7 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment {
TextView addressTextView = view.findViewById(R.id.address_textview); TextView addressTextView = view.findViewById(R.id.address_textview);
ImageButton copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton); ImageButton copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton);
Subaddress addr = AddressService.getInstance().getLatestSubaddress(); Subaddress addr = AddressService.getInstance().currentSubaddress();
addressTextView.setText(addr.getAddress()); addressTextView.setText(addr.getAddress());
addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256)); addressImageView.setImageBitmap(generate(addr.getAddress(), 256, 256));
copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", addr.getAddress())); copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", addr.getAddress()));

View File

@ -5,8 +5,11 @@ import net.mynero.wallet.model.TransactionInfo;
import net.mynero.wallet.model.Wallet; import net.mynero.wallet.model.Wallet;
import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.model.WalletManager;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
public class AddressService extends ServiceBase { public class AddressService extends ServiceBase {
public static AddressService instance = null; public static AddressService instance = null;
@ -22,19 +25,22 @@ public class AddressService extends ServiceBase {
} }
public void refreshAddresses() { public void refreshAddresses() {
List<TransactionInfo> localTransactionList = new ArrayList<>(HistoryService.getInstance().getHistory()); latestAddressIndex = WalletManager.getInstance().getWallet().getNumSubaddresses();
for (TransactionInfo info : localTransactionList) {
if (info.addressIndex >= latestAddressIndex) {
latestAddressIndex = info.addressIndex + 1;
}
}
} }
public String getPrimaryAddress() { public String getPrimaryAddress() {
return WalletManager.getInstance().getWallet().getAddress(); 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(); Wallet wallet = WalletManager.getInstance().getWallet();
return wallet.getSubaddressObject(latestAddressIndex); return wallet.getSubaddressObject(latestAddressIndex);
} }