mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-10 05:03:44 +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);
|
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()));
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user