mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-06 11:28:22 +00:00
add show/hide details button to get pubkey and encrypt/decrypt
This commit is contained in:
@@ -155,6 +155,8 @@ context.contentResolver.query(
|
||||
|
||||
* You can send a callbackUrl so your user doesn't need to copy the event manually to your application
|
||||
|
||||
* For Encryption/Decryption you should also send the hex pubkey that will be used to encrypt/decrypt the data eg (S.pubKey=cb8b8d378690f9a4a4f412c4e295051c4b76c3db24dc3941860fd3980f07d21d)
|
||||
|
||||
```js
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
@@ -89,7 +89,8 @@ fun HomeScreen(
|
||||
},
|
||||
{
|
||||
context.getAppCompatActivity()?.finish()
|
||||
}
|
||||
},
|
||||
account
|
||||
)
|
||||
}
|
||||
|
||||
@@ -159,6 +160,19 @@ fun HomeScreen(
|
||||
},
|
||||
{
|
||||
context.getAppCompatActivity()?.finish()
|
||||
},
|
||||
{
|
||||
try {
|
||||
AmberUtils.encryptOrDecryptData(
|
||||
it.data,
|
||||
it.type,
|
||||
account,
|
||||
it.pubKey
|
||||
)
|
||||
?: "Could not decrypt the message"
|
||||
} catch (e: Exception) {
|
||||
"Could not decrypt the message"
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
@@ -25,8 +28,13 @@ fun EncryptDecryptData(
|
||||
appName: String,
|
||||
type: SignerType,
|
||||
onAccept: () -> Unit,
|
||||
onReject: () -> Unit
|
||||
onReject: () -> Unit,
|
||||
onCopy: () -> String
|
||||
) {
|
||||
var showMore by androidx.compose.runtime.remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
@@ -53,8 +61,17 @@ fun EncryptDecryptData(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
RawJsonButton(
|
||||
onCLick = {
|
||||
showMore = !showMore
|
||||
},
|
||||
if (!showMore) stringResource(R.string.show_details) else stringResource(R.string.hide_details)
|
||||
)
|
||||
if (showMore) {
|
||||
RawJson(onCopy(), Modifier.weight(1f), stringResource(R.string.encrypted_decrypted_data))
|
||||
} else {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
|
||||
RememberMyChoice(
|
||||
shouldRunOnAccept,
|
||||
|
||||
@@ -10,11 +10,16 @@ import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.greenart7c3.nostrsigner.R
|
||||
import com.greenart7c3.nostrsigner.models.Account
|
||||
import com.vitorpamplona.quartz.encoders.toNpub
|
||||
|
||||
@Composable
|
||||
fun LoginWithPubKey(
|
||||
@@ -23,8 +28,12 @@ fun LoginWithPubKey(
|
||||
packageName: String?,
|
||||
appName: String,
|
||||
onAccept: () -> Unit,
|
||||
onReject: () -> Unit
|
||||
onReject: () -> Unit,
|
||||
account: Account
|
||||
) {
|
||||
var showMore by androidx.compose.runtime.remember {
|
||||
mutableStateOf(false)
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
@@ -47,7 +56,18 @@ fun LoginWithPubKey(
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
RawJsonButton(
|
||||
onCLick = {
|
||||
showMore = !showMore
|
||||
},
|
||||
if (!showMore) stringResource(R.string.show_details) else stringResource(R.string.hide_details)
|
||||
)
|
||||
|
||||
if (showMore) {
|
||||
RawJson(account.keyPair.pubKey.toNpub(), Modifier.weight(1f), stringResource(R.string.my_public_key))
|
||||
} else {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
|
||||
RememberMyChoice(
|
||||
shouldRunOnAccept,
|
||||
|
||||
@@ -23,15 +23,22 @@ import org.json.JSONObject
|
||||
@Composable
|
||||
fun RawJson(
|
||||
rawJson: String,
|
||||
modifier: Modifier
|
||||
modifier: Modifier,
|
||||
label: String = stringResource(R.string.copy_raw_json)
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
val value = try {
|
||||
JSONObject(rawJson).toString(2)
|
||||
} catch (e: Exception) {
|
||||
rawJson
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
modifier = modifier,
|
||||
value = TextFieldValue(JSONObject(rawJson).toString(2)),
|
||||
modifier = modifier
|
||||
.fillMaxWidth(),
|
||||
value = TextFieldValue(value),
|
||||
onValueChange = { },
|
||||
readOnly = true
|
||||
)
|
||||
@@ -47,13 +54,13 @@ fun RawJson(
|
||||
coroutineScope.launch {
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.raw_json_copied_to_the_clipboard),
|
||||
context.getString(R.string.data_copied_to_the_clipboard),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.copy_raw_json))
|
||||
Text(stringResource(R.string.copy) + label)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<string name="scan_qr">Scan QR</string>
|
||||
<string name="signature_copied_to_the_clipboard">Signature copied to the clipboard</string>
|
||||
<string name="sign">Sign</string>
|
||||
<string name="raw_json_copied_to_the_clipboard">Raw json copied to the clipboard</string>
|
||||
<string name="raw_json_copied_to_the_clipboard"> copied to the clipboard</string>
|
||||
<string name="reset_permissions">Reset permissions</string>
|
||||
<string name="logout">Logout</string>
|
||||
<string name="logging_out_deletes_all_your_local_information_make_sure_to_have_your_private_keys_backed_up_to_avoid_losing_your_account_do_you_want_to_continue">Logging out deletes all your local information. Make sure to have your private keys backed up to avoid losing your account. Do you want to continue?</string>
|
||||
@@ -67,9 +67,14 @@
|
||||
<string name="content">"Content "</string>
|
||||
<string name="show_details">Show Details</string>
|
||||
<string name="hide_details">Hide Details</string>
|
||||
<string name="copy_raw_json">Copy raw json</string>
|
||||
<string name="copy_raw_json">Raw json</string>
|
||||
<string name="add_new_account">Add New Account</string>
|
||||
<string name="select_account">Select Account</string>
|
||||
<string name="active_account">Active Account</string>
|
||||
<string name="edit_name">Edit name</string>
|
||||
<string name="copy_to_clipboard">Copy to clipboard</string>
|
||||
<string name="copy">"Copy "</string>
|
||||
<string name="my_public_key">my public key</string>
|
||||
<string name="encrypted_decrypted_data">Encrypted/Decrypted data</string>
|
||||
<string name="data_copied_to_the_clipboard">Data copied to the clipboard</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user