mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00:00
More forgiving Wallet Connect interface (nsec or hexes are accepted, relay url is trimmed and cleaned up, if relay doesn't have a wss://, adds one)
This commit is contained in:
parent
5038588d70
commit
0abac47ff2
@ -1,10 +1,11 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.note
|
package com.vitorpamplona.amethyst.ui.note
|
||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import com.vitorpamplona.amethyst.model.HexKey
|
||||||
import com.vitorpamplona.amethyst.model.decodePublicKey
|
import com.vitorpamplona.amethyst.model.decodePublicKey
|
||||||
import com.vitorpamplona.amethyst.model.toHexKey
|
import com.vitorpamplona.amethyst.model.toHexKey
|
||||||
|
|
||||||
data class Nip47URI(val pubKeyHex: String, val relayUri: String?, val secret: String?)
|
data class Nip47URI(val pubKeyHex: HexKey, val relayUri: String?, val secret: HexKey?)
|
||||||
|
|
||||||
// Rename to the corect nip number when ready.
|
// Rename to the corect nip number when ready.
|
||||||
object Nip47 {
|
object Nip47 {
|
||||||
|
@ -114,23 +114,41 @@ class UpdateZapAmountViewModel : ViewModel() {
|
|||||||
account?.changeZapAmounts(amountSet)
|
account?.changeZapAmounts(amountSet)
|
||||||
|
|
||||||
if (walletConnectRelay.text.isNotBlank() && walletConnectPubkey.text.isNotBlank()) {
|
if (walletConnectRelay.text.isNotBlank() && walletConnectPubkey.text.isNotBlank()) {
|
||||||
|
val pubkeyHex = try {
|
||||||
|
decodePublicKey(walletConnectPubkey.text.trim()).toHexKey()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
val relayUrl = walletConnectRelay.text.ifBlank { null }?.let {
|
||||||
|
var addedWSS =
|
||||||
|
if (!it.startsWith("wss://") && !it.startsWith("ws://")) "wss://$it" else it
|
||||||
|
if (addedWSS.endsWith("/")) addedWSS = addedWSS.dropLast(1)
|
||||||
|
|
||||||
|
addedWSS
|
||||||
|
}
|
||||||
|
|
||||||
val unverifiedPrivKey = walletConnectSecret.text.ifBlank { null }
|
val unverifiedPrivKey = walletConnectSecret.text.ifBlank { null }
|
||||||
val privKey = try {
|
val privKeyHex = try {
|
||||||
unverifiedPrivKey?.let { decodePublicKey(it).toHexKey() }
|
unverifiedPrivKey?.let { decodePublicKey(it).toHexKey() }
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pubkeyHex != null) {
|
||||||
account?.changeZapPaymentRequest(
|
account?.changeZapPaymentRequest(
|
||||||
Nip47URI(
|
Nip47URI(
|
||||||
walletConnectPubkey.text,
|
pubkeyHex,
|
||||||
walletConnectRelay.text.ifBlank { null },
|
relayUrl,
|
||||||
privKey
|
privKeyHex
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
account?.changeZapPaymentRequest(null)
|
account?.changeZapPaymentRequest(null)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
account?.changeZapPaymentRequest(null)
|
||||||
|
}
|
||||||
|
|
||||||
nextAmount = TextFieldValue("")
|
nextAmount = TextFieldValue("")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user