mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
fix for not showing id and pubkey
This commit is contained in:
@@ -8,32 +8,15 @@ import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.greenart7c3.nostrsigner.models.IntentData
|
||||
import com.greenart7c3.nostrsigner.ui.AccountScreen
|
||||
import com.greenart7c3.nostrsigner.ui.AccountStateViewModel
|
||||
import com.greenart7c3.nostrsigner.ui.theme.NostrSignerTheme
|
||||
import java.net.URLDecoder
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContent {
|
||||
var event: IntentData? = null
|
||||
if (intent.data != null) {
|
||||
var data = URLDecoder.decode(intent?.data?.toString()?.replace("+", "%2b") ?: "", "utf-8")
|
||||
val split = data.split(";")
|
||||
var name = ""
|
||||
if (split.isNotEmpty()) {
|
||||
if (split.last().lowercase().contains("name=")) {
|
||||
name = split.last().replace("name=", "")
|
||||
val newList = split.toList().dropLast(1)
|
||||
data = newList.joinToString("")
|
||||
}
|
||||
}
|
||||
event = IntentData(data, name)
|
||||
}
|
||||
|
||||
NostrSignerTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
@@ -42,7 +25,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val accountStateViewModel: AccountStateViewModel = viewModel {
|
||||
AccountStateViewModel()
|
||||
}
|
||||
AccountScreen(accountStateViewModel, event)
|
||||
AccountScreen(accountStateViewModel, intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.greenart7c3.nostrsigner.models
|
||||
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
|
||||
class IntentData(
|
||||
val data: String,
|
||||
val data: Event,
|
||||
val name: String
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.greenart7c3.nostrsigner.ui
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -7,11 +8,14 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import com.greenart7c3.nostrsigner.models.IntentData
|
||||
import com.greenart7c3.nostrsigner.models.toHexKey
|
||||
import com.greenart7c3.nostrsigner.service.model.Event
|
||||
import java.net.URLDecoder
|
||||
|
||||
@Composable
|
||||
fun AccountScreen(
|
||||
accountStateViewModel: AccountStateViewModel,
|
||||
event: IntentData?
|
||||
intent: Intent
|
||||
) {
|
||||
val accountState by accountStateViewModel.accountContent.collectAsState()
|
||||
|
||||
@@ -25,7 +29,26 @@ fun AccountScreen(
|
||||
LoginPage(accountStateViewModel)
|
||||
}
|
||||
is AccountState.LoggedIn -> {
|
||||
MainScreen(state.account, accountStateViewModel, event)
|
||||
var intentData: IntentData? = null
|
||||
if (intent.data != null) {
|
||||
var data = URLDecoder.decode(intent.data?.toString()?.replace("+", "%2b") ?: "", "utf-8").replace("nostrsigner:", "")
|
||||
val split = data.split(";")
|
||||
var name = ""
|
||||
if (split.isNotEmpty()) {
|
||||
if (split.last().lowercase().contains("name=")) {
|
||||
name = split.last().replace("name=", "")
|
||||
val newList = split.toList().dropLast(1)
|
||||
data = newList.joinToString("")
|
||||
}
|
||||
}
|
||||
var event = Event.fromJson(data)
|
||||
if (event.pubKey.isEmpty()) {
|
||||
event = Event.setPubKeyIfEmpty(event, state.account.keyPair.pubKey.toHexKey())
|
||||
}
|
||||
intentData = IntentData(event, name)
|
||||
}
|
||||
|
||||
MainScreen(state.account, accountStateViewModel, intentData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +68,6 @@ import org.json.JSONObject
|
||||
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
|
||||
@Composable
|
||||
fun MainScreen(account: Account, accountStateViewModel: AccountStateViewModel, json: IntentData?) {
|
||||
val event = remember {
|
||||
mutableStateOf<Event?>(null)
|
||||
}
|
||||
|
||||
val scaffoldState = rememberScaffoldState(rememberDrawerState(DrawerValue.Closed))
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
@@ -104,21 +100,14 @@ fun MainScreen(account: Account, accountStateViewModel: AccountStateViewModel, j
|
||||
}
|
||||
} else {
|
||||
json.let {
|
||||
val data = it.data.replace("nostrsigner:", "")
|
||||
event.value = Event.fromJson(data)
|
||||
val event = it.data
|
||||
|
||||
EventData(
|
||||
it.name,
|
||||
event.value!!,
|
||||
data,
|
||||
event,
|
||||
event.toJson(),
|
||||
{
|
||||
if (event.value == null) {
|
||||
return@EventData
|
||||
}
|
||||
|
||||
val localEvent = Event.setPubKeyIfEmpty(event.value!!, account.keyPair.pubKey.toHexKey())
|
||||
|
||||
if (localEvent.pubKey != account.keyPair.pubKey.toHexKey()) {
|
||||
if (event.pubKey != account.keyPair.pubKey.toHexKey()) {
|
||||
coroutineScope.launch {
|
||||
Toast.makeText(
|
||||
context,
|
||||
@@ -129,7 +118,7 @@ fun MainScreen(account: Account, accountStateViewModel: AccountStateViewModel, j
|
||||
return@EventData
|
||||
}
|
||||
|
||||
val id = localEvent.id.hexToByteArray()
|
||||
val id = event.id.hexToByteArray()
|
||||
val sig = CryptoUtils.sign(id, account.keyPair.privKey!!).toHexKey()
|
||||
|
||||
clipboardManager.setText(AnnotatedString(sig))
|
||||
|
||||
Reference in New Issue
Block a user