Skip to content

Commit

Permalink
release 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Oct 28, 2024
1 parent 74df4e2 commit 96f79b8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Parcelable
import android.util.Log
import com.tonapps.blockchain.ton.extensions.cellFromBase64
import com.tonapps.extensions.optStringCompat
import com.tonapps.extensions.optStringCompatJS
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.json.JSONObject
Expand Down Expand Up @@ -35,13 +36,13 @@ data class RawMessageEntity(
constructor(json: JSONObject) : this(
json.getString("address"),
parseAmount(json.get("amount")),
json.optStringCompat("stateInit"),
json.optStringCompat("payload")
json.optStringCompatJS("stateInit"),
json.optStringCompatJS("payload")
) {
if (stateInitValue?.startsWith("{") == true) {
if (stateInitValue?.startsWith("{") == true) { // for dudes how try to send JS Buffer
throw IllegalArgumentException("Invalid data format. Base64 encoding required for data transfer, JavaScript objects not supported. Received: stateInit = $stateInitValue")
}
if (payloadValue?.startsWith("{") == true) {
if (payloadValue?.startsWith("{") == true) { // for dudes how try to send JS Buffer
throw IllegalArgumentException("Invalid data format. Base64 encoding required for data transfer, JavaScript objects not supported. Received: payload = $payloadValue")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.tonapps.blockchain.ton.TonNetwork
import com.tonapps.blockchain.ton.extensions.isValidTonAddress
import com.tonapps.blockchain.ton.extensions.toAccountId
import com.tonapps.extensions.currentTimeSeconds
import com.tonapps.extensions.optStringCompatJS
import kotlinx.datetime.Clock
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
Expand Down Expand Up @@ -34,8 +35,8 @@ data class SignRequestEntity(

constructor(json: JSONObject, appUri: Uri) : this(
appUri = appUri,
fromValue = json.optString("from"),
sourceValue = json.optString("source"),
fromValue = json.optStringCompatJS("from"),
sourceValue = json.optStringCompatJS("source"),
validUntil = parseValidUnit(json),
messages = parseMessages(json.getJSONArray("messages")),
network = parseNetwork(json.opt("network"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.tonapps.blockchain.ton.extensions.storeAddress
import com.tonapps.blockchain.ton.extensions.storeCoins
import com.tonapps.blockchain.ton.extensions.storeOpCode
import com.tonapps.ledger.ton.remainingRefs
import com.tonapps.tonkeeper.core.DevSettings
import com.tonapps.wallet.data.core.entity.RawMessageEntity
import org.ton.block.AddrStd
import org.ton.block.Coins
Expand Down Expand Up @@ -130,6 +131,14 @@ fun RawMessageEntity.getWalletTransfer(
payload
}

getStateInitRef()?.let {
DevSettings.tonConnectLog("parsedStateInit: $it")
}

if (!payload.isEmpty()) {
DevSettings.tonConnectLog("parsedPayload: $body")
}

val builder = WalletTransferBuilder()
builder.destination = address
builder.messageData = MessageData.Raw(body, newStateInit ?: getStateInitRef())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.tonapps.tonkeeper.manager.tonconnect.bridge
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.tonapps.base64.encodeBase64
import com.tonapps.extensions.bestMessage
import com.tonapps.extensions.optStringCompat
import com.tonapps.extensions.optStringCompatJS
import com.tonapps.security.CryptoBox
import com.tonapps.security.hex
import com.tonapps.tonkeeper.core.DevSettings
Expand Down Expand Up @@ -95,14 +95,14 @@ internal class Bridge(private val api: API) {
return api.tonconnectEvents(publicKeys, lastEventId, onFailure = { FirebaseCrashlytics.getInstance().recordException(it) })
.mapNotNull { event ->
DevSettings.tonConnectLog("Received event:\n$event")
val from = event.json.optStringCompat("from") ?: throw BridgeException(
val from = event.json.optStringCompatJS("from") ?: throw BridgeException(
message = "Event \"from\" is missing"
)
val connection = connections.find { it.clientId == from } ?: throw BridgeException(
message = "Connection not found"
)
val id = event.id?.toLongOrNull() ?: throw BridgeException(message = "Event \"id\" is missing")
val message = event.json.optStringCompat("message") ?: throw BridgeException(
val message = event.json.optStringCompatJS("message") ?: throw BridgeException(
connect = connection,
message = "Field \"message\" is required"
)
Expand All @@ -112,7 +112,7 @@ internal class Bridge(private val api: API) {
throw BridgeException(
connect = connection,
cause = e,
message = "Failed to decrypt event from \"message\" field"
message = "Failed to decrypt event from \"message\" field; Received: $message"
)
}
DevSettings.tonConnectLog("Decrypted message:\n$json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class SendContactsViewModel(
/*if (savedContacts.isNotEmpty()) {
uiItems.addAll(savedContacts)
uiItems.add(Item.Space)
}*/
}
if (latestContacts.isNotEmpty()) {
uiItems.addAll(latestContacts)
uiItems.add(Item.Space)
}
}*/

uiItems.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import org.json.JSONObject
fun JSONObject.optStringCompat(vararg keys: String): String? {
for (key in keys) {
val value = optString(key)
if (!value.isNullOrBlank() && value != "null") {
if (!value.isNullOrBlank()) {
return value
}
}
return null
}

fun JSONObject.optStringCompatJS(vararg keys: String): String? {
val value = optStringCompat(*keys)
if (value == "null" || value == "undefined") { // Oh man... JavaScript compatibility
return null
}
return value
}

fun JSONObject.getLongCompat(key: String): Long {
return when (val value = opt(key)) {
is Long -> value
Expand Down

0 comments on commit 96f79b8

Please sign in to comment.