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);
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()));

View File

@ -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<TransactionInfo> 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);
}