@@ -4,6 +4,7 @@ import android.content.Context
4
4
import com.cosmos.base.v1beta1.CoinProto
5
5
import com.google.gson.Gson
6
6
import com.google.gson.JsonArray
7
+ import com.google.gson.JsonElement
7
8
import com.google.gson.JsonObject
8
9
import com.squareup.moshi.Json
9
10
import com.squareup.moshi.JsonClass
@@ -651,30 +652,43 @@ data class CosmosHistory(
651
652
} else if (msgType.contains(" MsgInstantiateContract" )) {
652
653
result = c.getString(R .string.tx_cosmwasm_instantiate)
653
654
} else if (msgType.contains(" MsgExecuteContract" )) {
654
- msgValue[" msg__@stringify" ].asString?.let { wasmMsg ->
655
- val wasmFunc = Gson ().fromJson(wasmMsg, JsonObject ::class .java)
656
- val recipient = try {
657
- wasmFunc.asJsonObject[" transfer" ].asJsonObject[" recipient" ].asString
658
- } catch (e: Exception ) {
659
- null
655
+ val msgStringify: JsonElement ? = msgValue.get(" msg__@stringify" )
656
+ when {
657
+ msgStringify == null -> {
658
+ result = c.getString(R .string.tx_cosmwasm_execontract)
660
659
}
661
- if (recipient != null ) {
662
- result = if (recipient.equals(address, true )) {
663
- c.getString(R .string.tx_cosmwasm_token_receive)
664
- } else {
665
- c.getString(R .string.tx_cosmwasm_token_send)
660
+
661
+ msgStringify.isJsonPrimitive && msgStringify.asJsonPrimitive.isString -> {
662
+ val wasmMsg = msgStringify.asString
663
+ val wasmFunc = Gson ().fromJson(wasmMsg, JsonObject ::class .java)
664
+ val recipient = try {
665
+ wasmFunc.asJsonObject[" transfer" ].asJsonObject[" recipient" ].asString
666
+ } catch (e: Exception ) {
667
+ null
666
668
}
669
+ if (recipient != null ) {
670
+ result = if (recipient.equals(address, true )) {
671
+ c.getString(R .string.tx_cosmwasm_token_receive)
672
+ } else {
673
+ c.getString(R .string.tx_cosmwasm_token_send)
674
+ }
667
675
668
- } else {
669
- val description = wasmFunc.entrySet().first().key ? : " "
670
- result = c.getString(R .string.tx_wasm) + " _" + description
671
- result = result.split(' _' ).joinToString(" " ) { des ->
672
- des.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
676
+ } else {
677
+ val description = if (wasmFunc.entrySet().isNotEmpty()) {
678
+ wasmFunc.entrySet().first().key
679
+ } else {
680
+ " "
681
+ }
682
+ result = c.getString(R .string.tx_wasm) + " _" + description
683
+ result = result.split(' _' ).joinToString(" " ) { des ->
684
+ des.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }
685
+ }
673
686
}
674
687
}
675
688
676
- } ? : run {
677
- result = c.getString(R .string.tx_cosmwasm_execontract)
689
+ else -> {
690
+ result = c.getString(R .string.tx_cosmwasm_execontract)
691
+ }
678
692
}
679
693
}
680
694
@@ -1051,22 +1065,36 @@ data class CosmosHistory(
1051
1065
val msgValue = firstMsg.asJsonObject[msgType.replace(" ." , " -" )]
1052
1066
1053
1067
if (msgType.contains(" cosmwasm." ) && msgType.contains(" MsgExecuteContract" )) {
1054
- msgValue.asJsonObject[" contract" ].asString?. let { contractAddress ->
1055
- val wasmMsg = msgValue.asJsonObject[" msg__@stringify " ].asString
1056
- val wasmFunc = Gson ().fromJson(wasmMsg, JsonObject :: class .java)
1057
- val amount = try {
1058
- wasmFunc.asJsonObject[ " transfer " ].asJsonObject[ " amount " ].asString
1059
- } catch (e : Exception ) {
1060
- null
1061
- }
1062
- if ( amount != null ) {
1063
- chain.cosmosFetcher?.tokens?.firstOrNull { it.contract == contractAddress }
1064
- ?. let { cw20 ->
1065
- return Pair (cw20, amount.toBigDecimal())
1068
+ if ( msgValue.asJsonObject[" contract" ] != null ) {
1069
+ val contractAddress = msgValue.asJsonObject[" contract " ].asString
1070
+ val msgStringify : JsonElement ? =
1071
+ msgValue.asJsonObject.get( " msg__@stringify " )
1072
+ when {
1073
+ msgStringify?.isJsonPrimitive == true && msgStringify.asJsonPrimitive?.isString == true -> {
1074
+ val wasmMsg = msgStringify.asString
1075
+ val wasmFunc = Gson ().fromJson(wasmMsg, JsonObject :: class .java)
1076
+ val amount = try {
1077
+ wasmFunc.asJsonObject[ " transfer " ].asJsonObject[ " amount " ].asString
1078
+ } catch (e : Exception ) {
1079
+ null
1066
1080
}
1067
- } else {
1068
- return null
1081
+ if (amount != null ) {
1082
+ chain.cosmosFetcher?.tokens?.firstOrNull { it.contract == contractAddress }
1083
+ ?.let { cw20 ->
1084
+ return Pair (cw20, amount.toBigDecimal())
1085
+ }
1086
+ } else {
1087
+ return null
1088
+ }
1089
+ }
1090
+
1091
+ else -> {
1092
+ null
1093
+ }
1069
1094
}
1095
+
1096
+ } else {
1097
+ null
1070
1098
}
1071
1099
1072
1100
} else if (msgType.contains(" ethermint.evm" ) && msgType.contains(" MsgEthereumTx" )) {
0 commit comments