mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-09 20:53:47 +01:00
Simplify fetching latest subaddress
This commit is contained in:
parent
5545d8c6d0
commit
995e0be835
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user