Add My addresses manager for all receive address types
This commit is contained in:
parent
ba44de3cfd
commit
7a2abc0115
1 changed files with 217 additions and 79 deletions
|
|
@ -1480,17 +1480,44 @@ class WalletActivity : FragmentActivity() {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addressLabel(index: Int): String {
|
private fun addressLabelKey(
|
||||||
|
addressType: ReceiveAddressType,
|
||||||
|
index: Int
|
||||||
|
): String {
|
||||||
|
return when (addressType) {
|
||||||
|
ReceiveAddressType.STANDARD ->
|
||||||
|
PREF_ADDRESS_LABEL_PREFIX + index
|
||||||
|
|
||||||
|
ReceiveAddressType.MLDSA ->
|
||||||
|
PREF_ADDRESS_LABEL_PREFIX + "MLDSA_" + index
|
||||||
|
|
||||||
|
ReceiveAddressType.SLHDSA ->
|
||||||
|
PREF_ADDRESS_LABEL_PREFIX + "SLHDSA_" + index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addressLabel(
|
||||||
|
addressType: ReceiveAddressType,
|
||||||
|
index: Int
|
||||||
|
): String {
|
||||||
return getSharedPreferences(PREFS, MODE_PRIVATE)
|
return getSharedPreferences(PREFS, MODE_PRIVATE)
|
||||||
.getString(
|
.getString(
|
||||||
PREF_ADDRESS_LABEL_PREFIX + index,
|
addressLabelKey(addressType, index),
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
?.trim()
|
?.trim()
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addressLabel(index: Int): String {
|
||||||
|
return addressLabel(
|
||||||
|
ReceiveAddressType.STANDARD,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setAddressLabel(
|
private fun setAddressLabel(
|
||||||
|
addressType: ReceiveAddressType,
|
||||||
index: Int,
|
index: Int,
|
||||||
label: String
|
label: String
|
||||||
) {
|
) {
|
||||||
|
|
@ -1498,15 +1525,19 @@ class WalletActivity : FragmentActivity() {
|
||||||
getSharedPreferences(PREFS, MODE_PRIVATE)
|
getSharedPreferences(PREFS, MODE_PRIVATE)
|
||||||
.edit()
|
.edit()
|
||||||
|
|
||||||
|
val key =
|
||||||
|
addressLabelKey(
|
||||||
|
addressType,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
val value = label.trim()
|
val value = label.trim()
|
||||||
|
|
||||||
if (value.isBlank()) {
|
if (value.isBlank()) {
|
||||||
editor.remove(
|
editor.remove(key)
|
||||||
PREF_ADDRESS_LABEL_PREFIX + index
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
editor.putString(
|
editor.putString(
|
||||||
PREF_ADDRESS_LABEL_PREFIX + index,
|
key,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1514,6 +1545,17 @@ class WalletActivity : FragmentActivity() {
|
||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setAddressLabel(
|
||||||
|
index: Int,
|
||||||
|
label: String
|
||||||
|
) {
|
||||||
|
setAddressLabel(
|
||||||
|
ReceiveAddressType.STANDARD,
|
||||||
|
index,
|
||||||
|
label
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun backgroundUtxoKey(
|
private fun backgroundUtxoKey(
|
||||||
addressType: BlockScanner.AddressType,
|
addressType: BlockScanner.AddressType,
|
||||||
addressIndex: Int
|
addressIndex: Int
|
||||||
|
|
@ -3757,30 +3799,36 @@ class WalletActivity : FragmentActivity() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val highestIndex = currentReceiveAddressIndex()
|
|
||||||
|
|
||||||
val content = baseLayout()
|
val content = baseLayout()
|
||||||
content.addView(space(10))
|
content.addView(space(10))
|
||||||
content.addView(centeredLogo(72))
|
content.addView(centeredLogo(72))
|
||||||
content.addView(space(14))
|
content.addView(space(14))
|
||||||
content.addView(title("Address Labels"))
|
content.addView(title("My addresses"))
|
||||||
content.addView(
|
content.addView(
|
||||||
subtitle(
|
subtitle(
|
||||||
"Name your receive addresses for easier identification"
|
"View, label and select your receive addresses"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
content.addView(space(20))
|
content.addView(space(20))
|
||||||
|
|
||||||
for (index in 0..highestIndex) {
|
fun addAddressCard(
|
||||||
val address = deriveAddress(words, index)
|
addressType: ReceiveAddressType,
|
||||||
val label = addressLabel(index)
|
index: Int,
|
||||||
|
address: String,
|
||||||
|
typeLabel: String
|
||||||
|
) {
|
||||||
|
val label =
|
||||||
|
addressLabel(
|
||||||
|
addressType,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
content.addView(
|
content.addView(
|
||||||
card {
|
card {
|
||||||
addView(
|
addView(
|
||||||
sectionTitle(
|
sectionTitle(
|
||||||
if (label.isBlank()) {
|
if (label.isBlank()) {
|
||||||
"Address ${index + 1}"
|
"$typeLabel address ${index + 1}"
|
||||||
} else {
|
} else {
|
||||||
label
|
label
|
||||||
}
|
}
|
||||||
|
|
@ -3791,7 +3839,7 @@ class WalletActivity : FragmentActivity() {
|
||||||
|
|
||||||
addView(
|
addView(
|
||||||
smallStatus(
|
smallStatus(
|
||||||
"Address ${index + 1}"
|
"$typeLabel • Address ${index + 1}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -3839,7 +3887,9 @@ class WalletActivity : FragmentActivity() {
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
val input =
|
val input =
|
||||||
EditText(this@WalletActivity).apply {
|
EditText(
|
||||||
|
this@WalletActivity
|
||||||
|
).apply {
|
||||||
hint =
|
hint =
|
||||||
"e.g. Mining, Pool payout, Personal"
|
"e.g. Mining, Pool payout, Personal"
|
||||||
setText(label)
|
setText(label)
|
||||||
|
|
@ -3850,7 +3900,7 @@ class WalletActivity : FragmentActivity() {
|
||||||
this@WalletActivity
|
this@WalletActivity
|
||||||
)
|
)
|
||||||
.setTitle(
|
.setTitle(
|
||||||
"Address ${index + 1} label"
|
"$typeLabel address ${index + 1} label"
|
||||||
)
|
)
|
||||||
.setView(input)
|
.setView(input)
|
||||||
.setNegativeButton(
|
.setNegativeButton(
|
||||||
|
|
@ -3860,13 +3910,18 @@ class WalletActivity : FragmentActivity() {
|
||||||
.setNeutralButton(
|
.setNeutralButton(
|
||||||
"Remove"
|
"Remove"
|
||||||
) { _, _ ->
|
) { _, _ ->
|
||||||
setAddressLabel(index, "")
|
setAddressLabel(
|
||||||
|
addressType,
|
||||||
|
index,
|
||||||
|
""
|
||||||
|
)
|
||||||
showAddressLabelManager()
|
showAddressLabelManager()
|
||||||
}
|
}
|
||||||
.setPositiveButton(
|
.setPositiveButton(
|
||||||
"Save"
|
"Save"
|
||||||
) { _, _ ->
|
) { _, _ ->
|
||||||
setAddressLabel(
|
setAddressLabel(
|
||||||
|
addressType,
|
||||||
index,
|
index,
|
||||||
input.text.toString()
|
input.text.toString()
|
||||||
)
|
)
|
||||||
|
|
@ -3875,12 +3930,135 @@ class WalletActivity : FragmentActivity() {
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
addView(space(10))
|
||||||
|
|
||||||
|
val isCurrent =
|
||||||
|
currentReceiveAddressType() == addressType &&
|
||||||
|
when (addressType) {
|
||||||
|
ReceiveAddressType.STANDARD ->
|
||||||
|
currentReceiveAddressIndex() == index
|
||||||
|
|
||||||
|
ReceiveAddressType.MLDSA,
|
||||||
|
ReceiveAddressType.SLHDSA ->
|
||||||
|
currentPqAddressIndex(
|
||||||
|
addressType
|
||||||
|
) == index
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCurrent) {
|
||||||
|
addView(
|
||||||
|
smallStatus(
|
||||||
|
"Current receive address"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
addView(
|
||||||
|
secondaryButton(
|
||||||
|
"Use this address"
|
||||||
|
) {
|
||||||
|
when (addressType) {
|
||||||
|
ReceiveAddressType.STANDARD ->
|
||||||
|
setCurrentReceiveAddressIndex(
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
|
ReceiveAddressType.MLDSA,
|
||||||
|
ReceiveAddressType.SLHDSA ->
|
||||||
|
setCurrentPqAddressIndex(
|
||||||
|
addressType,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
setCurrentReceiveAddressType(
|
||||||
|
addressType
|
||||||
|
)
|
||||||
|
|
||||||
|
showReceive()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
content.addView(space(14))
|
content.addView(space(14))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (
|
||||||
|
index in
|
||||||
|
0..currentReceiveAddressIndex()
|
||||||
|
) {
|
||||||
|
addAddressCard(
|
||||||
|
ReceiveAddressType.STANDARD,
|
||||||
|
index,
|
||||||
|
deriveAddress(words, index),
|
||||||
|
"Standard"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
pqAddressCreated(
|
||||||
|
ReceiveAddressType.MLDSA
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
for (
|
||||||
|
index in
|
||||||
|
0..currentPqAddressIndex(
|
||||||
|
ReceiveAddressType.MLDSA
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
val key =
|
||||||
|
derivePqKey(
|
||||||
|
words,
|
||||||
|
ReceiveAddressType.MLDSA,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
addAddressCard(
|
||||||
|
ReceiveAddressType.MLDSA,
|
||||||
|
index,
|
||||||
|
key.address,
|
||||||
|
"ML-DSA"
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
key.secretKey.fill(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
pqAddressCreated(
|
||||||
|
ReceiveAddressType.SLHDSA
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
for (
|
||||||
|
index in
|
||||||
|
0..currentPqAddressIndex(
|
||||||
|
ReceiveAddressType.SLHDSA
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
val key =
|
||||||
|
derivePqKey(
|
||||||
|
words,
|
||||||
|
ReceiveAddressType.SLHDSA,
|
||||||
|
index
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
addAddressCard(
|
||||||
|
ReceiveAddressType.SLHDSA,
|
||||||
|
index,
|
||||||
|
key.address,
|
||||||
|
"SPHINCS+"
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
key.secretKey.fill(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setContentView(
|
setContentView(
|
||||||
scroll(content) {
|
scroll(content) {
|
||||||
showReceive()
|
showReceive()
|
||||||
|
|
@ -3986,9 +4164,11 @@ class WalletActivity : FragmentActivity() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (receiveType == ReceiveAddressType.STANDARD) {
|
|
||||||
val currentLabel =
|
val currentLabel =
|
||||||
addressLabel(addressIndex)
|
addressLabel(
|
||||||
|
receiveType,
|
||||||
|
addressIndex
|
||||||
|
)
|
||||||
|
|
||||||
if (currentLabel.isNotBlank()) {
|
if (currentLabel.isNotBlank()) {
|
||||||
addView(space(8))
|
addView(space(8))
|
||||||
|
|
@ -3998,7 +4178,6 @@ class WalletActivity : FragmentActivity() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
addView(space(14))
|
addView(space(14))
|
||||||
|
|
||||||
|
|
@ -4066,57 +4245,6 @@ class WalletActivity : FragmentActivity() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (receiveType == ReceiveAddressType.STANDARD) {
|
|
||||||
addView(space(12))
|
|
||||||
addView(
|
|
||||||
secondaryButton("Edit address label") {
|
|
||||||
val input =
|
|
||||||
EditText(
|
|
||||||
this@WalletActivity
|
|
||||||
).apply {
|
|
||||||
hint =
|
|
||||||
"e.g. Mining, Pool payout, Personal"
|
|
||||||
setText(
|
|
||||||
addressLabel(
|
|
||||||
addressIndex
|
|
||||||
)
|
|
||||||
)
|
|
||||||
setSelection(text.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
AlertDialog.Builder(
|
|
||||||
this@WalletActivity
|
|
||||||
)
|
|
||||||
.setTitle(
|
|
||||||
"Address ${addressIndex + 1} label"
|
|
||||||
)
|
|
||||||
.setView(input)
|
|
||||||
.setNegativeButton(
|
|
||||||
"Cancel",
|
|
||||||
null
|
|
||||||
)
|
|
||||||
.setNeutralButton(
|
|
||||||
"Remove"
|
|
||||||
) { _, _ ->
|
|
||||||
setAddressLabel(
|
|
||||||
addressIndex,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
showReceive()
|
|
||||||
}
|
|
||||||
.setPositiveButton(
|
|
||||||
"Save"
|
|
||||||
) { _, _ ->
|
|
||||||
setAddressLabel(
|
|
||||||
addressIndex,
|
|
||||||
input.text.toString()
|
|
||||||
)
|
|
||||||
showReceive()
|
|
||||||
}
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -4210,6 +4338,16 @@ class WalletActivity : FragmentActivity() {
|
||||||
|
|
||||||
addView(space(10))
|
addView(space(10))
|
||||||
|
|
||||||
|
addView(
|
||||||
|
secondaryButton(
|
||||||
|
"My addresses"
|
||||||
|
) {
|
||||||
|
showAddressLabelManager()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
addView(space(10))
|
||||||
|
|
||||||
addView(
|
addView(
|
||||||
helpText(
|
helpText(
|
||||||
"All previously generated addresses remain " +
|
"All previously generated addresses remain " +
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue