diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt index 5cc43be56..97dc3d831 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/CashuRedeem.kt @@ -21,15 +21,29 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.content.ContextCompat.startActivity +import com.google.gson.JsonParser import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.theme.QuoteBorder import com.vitorpamplona.amethyst.ui.theme.subtleBorder +import java.util.Base64 @Composable fun CashuPreview(cashutoken: String, accountViewModel: AccountViewModel) { val context = LocalContext.current val lnaddress = accountViewModel.account.userProfile().info?.lud16 + val base64token = cashutoken.replace("cashuA", "") + val cashu = JsonParser.parseString(String(Base64.getDecoder().decode(base64token))) + + val token = cashu.asJsonObject.get("token").asJsonArray[0].asJsonObject + val proofs = token["proofs"].asJsonArray + val mint = token["mint"] + + var totalamount = 0 + for (proof in proofs) { + totalamount += proof.asJsonObject["amount"].asInt + } + Column( modifier = Modifier .fillMaxWidth() @@ -65,12 +79,28 @@ fun CashuPreview(cashutoken: String, accountViewModel: AccountViewModel) { Divider() + totalamount?.let { + Text( + text = "$it ${stringResource(id = R.string.sats)}", + fontSize = 25.sp, + fontWeight = FontWeight.W500, + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 10.dp) + ) + } + Button( modifier = Modifier .fillMaxWidth() .padding(vertical = 10.dp), onClick = { runCatching { + // Alternative directly from client: call POST https://{mint}/melt with body + // { + // "proofs: {proofs}, + // "pr": {create ln invoice with totalamount * 0.98, at least -2 sats} + // } val url = "https://redeem.cashu.me?token=$cashutoken&lightning=$lnaddress&autopay=true" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) startActivity(context, intent, null) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ab4042c45..f23762d2c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -457,7 +457,7 @@ Auth Payment Cashu ecash - Redeem Sats + Redeem LIVE OFFLINE