From c2a22ccc25e1ee725a015ca947ed019190ea1ee7 Mon Sep 17 00:00:00 2001 From: Mpendulo Ndlovu Date: Thu, 22 Aug 2024 10:31:27 +0200 Subject: [PATCH 1/4] chore: send transaction updates --- README.md | 2 +- app/src/main/java/com/metamask/dapp/AppModule.kt | 2 +- app/src/main/java/com/metamask/dapp/EthereumViewModel.kt | 8 ++++---- .../main/java/com/metamask/dapp/SendTransactionScreen.kt | 4 ++-- .../java/io/metamask/androidsdk/CommunicationClient.kt | 3 ++- .../src/main/java/io/metamask/androidsdk/Ethereum.kt | 4 ++-- .../src/main/java/io/metamask/androidsdk/EthereumFlow.kt | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f5a93943..51ff5298 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ code to your project file: @AndroidEntryPoint class SomeModel(context: Context) { - val dappMetadata = DappMetadata("Droid Dapp", "https://droiddapp.com") + val dappMetadata = DappMetadata("Droid Dapp", "") val infuraAPIKey = "1234567890" // We use Infura API for read-only RPCs for a seamless user experience // A) Using callbacks diff --git a/app/src/main/java/com/metamask/dapp/AppModule.kt b/app/src/main/java/com/metamask/dapp/AppModule.kt index 389eab07..14f310ab 100644 --- a/app/src/main/java/com/metamask/dapp/AppModule.kt +++ b/app/src/main/java/com/metamask/dapp/AppModule.kt @@ -15,7 +15,7 @@ import io.metamask.androidsdk.* internal object AppModule { @Provides fun provideDappMetadata(): DappMetadata { - return DappMetadata("Droiddapp", "https://droiddapp.io", iconUrl = "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png") + return DappMetadata("Droiddapp", "https://www.droiddapp.io", iconUrl = "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png") } @Provides diff --git a/app/src/main/java/com/metamask/dapp/EthereumViewModel.kt b/app/src/main/java/com/metamask/dapp/EthereumViewModel.kt index 40e38008..0edb346c 100644 --- a/app/src/main/java/com/metamask/dapp/EthereumViewModel.kt +++ b/app/src/main/java/com/metamask/dapp/EthereumViewModel.kt @@ -50,7 +50,7 @@ class EthereumViewModel @Inject constructor( } } - fun connectWithSendTransaction(amount: String, + fun connectWithSendTransaction(value: String, from: String, to: String, onSuccess: (Any?) -> Unit, @@ -58,7 +58,7 @@ class EthereumViewModel @Inject constructor( val params: MutableMap = mutableMapOf( "from" to from, "to" to to, - "amount" to amount + "value" to value ) val transactionRequest = EthereumRequest( @@ -231,7 +231,7 @@ class EthereumViewModel @Inject constructor( } fun sendTransaction( - amount: String, + value: String, from: String, to: String, onSuccess: (String) -> Unit, @@ -240,7 +240,7 @@ class EthereumViewModel @Inject constructor( val params: MutableMap = mutableMapOf( "from" to from, "to" to to, - "amount" to amount + "value" to value ) val transactionRequest = EthereumRequest( diff --git a/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt b/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt index 5e1fc69f..7b2107e4 100644 --- a/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt +++ b/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt @@ -34,8 +34,8 @@ fun SendTransactionScreen( navController: NavController, ethereumState: EthereumState, isConnectWith: Boolean = false, - sendTransaction: suspend (amount: String, from: String, to: String) -> Result, - connectWithSendTransaction: suspend (amount: String, from: String, to: String) -> Result + sendTransaction: suspend (value: String, from: String, to: String) -> Result, + connectWithSendTransaction: suspend (value: String, from: String, to: String) -> Result ) { var amount by remember { mutableStateOf("0x01") } var from by remember { mutableStateOf(ethereumState.selectedAddress) } diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/CommunicationClient.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/CommunicationClient.kt index d8380ac2..c2b13785 100644 --- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/CommunicationClient.kt +++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/CommunicationClient.kt @@ -330,7 +330,7 @@ class CommunicationClient( val errorCode = errorMap["code"] as? Double ?: -1 val code = errorCode.toInt() val message = errorMap["message"] as? String ?: ErrorType.message(code) - logger.error("CommunicationClient:: Got error $message") + logger.error("CommunicationClient:: Got error $error") completeRequest(requestId, Result.Error(RequestError(code, message))) return true } @@ -476,6 +476,7 @@ class CommunicationClient( val requestInfoJson = Gson().toJson(requestInfo) logger.log("CommunicationClient:: Sending originator info: $requestInfoJson") + logger.log("CommunicationClient:: SessionId $sessionId") val payload = keyExchange.encrypt(requestInfoJson) diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt index 0f6c626e..f60530e7 100644 --- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt +++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt @@ -259,11 +259,11 @@ class Ethereum ( ethereumRequest(method = EthereumMethod.ETH_SIGN_TYPED_DATA_V4, params = listOf(address, typedData), callback) } - fun sendTransaction(from: String, to: String, amount: String, callback: ((Result) -> Unit)?) { + fun sendTransaction(from: String, to: String, value: String, callback: ((Result) -> Unit)?) { ethereumRequest(method = EthereumMethod.ETH_SEND_TRANSACTION, params = listOf(mutableMapOf( "from" to from, "to" to to, - "amount" to amount + "value" to value )), callback) } diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt index 944b7409..009ddf04 100644 --- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt +++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt @@ -143,7 +143,7 @@ constructor( ethereumRequest(method = EthereumMethod.ETH_SEND_TRANSACTION, params = listOf(mapOf( "from" to from, "to" to to, - "amount" to amount + "value" to amount ))) override suspend fun sendRawTransaction(signedTransaction: String) : Result = From 08cda6b99dd957e14b4416e726fed5a16412c805 Mon Sep 17 00:00:00 2001 From: Mpendulo Ndlovu Date: Thu, 22 Aug 2024 10:41:51 +0200 Subject: [PATCH 2/4] use value instead of amount --- README.md | 6 +++--- .../java/com/metamask/dapp/SendTransactionScreen.kt | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 51ff5298..3941fbed 100644 --- a/README.md +++ b/README.md @@ -255,10 +255,10 @@ The following example sends a transaction by calling // Create parameters val from = ethereum.selectedAddress val to = "0x0000000000000000000000000000000000000000" -val amount = "0x01" +val value = "0x8ac7230489e80000" // Make a transaction request -when (val result = ethereum.sendTransaction(from, to, amount)) { +when (val result = ethereum.sendTransaction(from, to, value)) { is Result.Success.Item -> { Logger.log("Ethereum transaction result: ${result.value}") balance = result.value @@ -302,7 +302,7 @@ We have provided a convenience method that enables you to connect and make any r val params: Map = mutableMapOf( "from" to "", // this will be populated with selected address once connected "to" to "0x0000000000000000000000000000000000000000", - "amount" to "0x01" + "value" to "0x8ac7230489e80000" ) val transactionRequest = EthereumRequest( diff --git a/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt b/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt index 7b2107e4..d945df1c 100644 --- a/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt +++ b/app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt @@ -37,7 +37,7 @@ fun SendTransactionScreen( sendTransaction: suspend (value: String, from: String, to: String) -> Result, connectWithSendTransaction: suspend (value: String, from: String, to: String) -> Result ) { - var amount by remember { mutableStateOf("0x01") } + var value by remember { mutableStateOf("0x8ac7230489e80000") } var from by remember { mutableStateOf(ethereumState.selectedAddress) } var to by remember { mutableStateOf("0x0000000000000000000000000000000000000000") } var sendResult by remember { mutableStateOf("") } @@ -67,7 +67,7 @@ fun SendTransactionScreen( .height(48.dp) ) { Text( - text = "Amount:", + text = "Value:", fontSize = 14.sp, fontWeight = FontWeight.Bold, textAlign = TextAlign.Start, @@ -87,10 +87,10 @@ fun SendTransactionScreen( } ) { BasicTextField( - value = amount, + value = value, textStyle = TextStyle(color = if (isSystemInDarkTheme()) { Color.White} else { Color.Black}), onValueChange = { - amount = it + value = it }, modifier = Modifier .padding(start = 8.dp, top = 16.dp, end = 8.dp, bottom = 0.dp) @@ -184,7 +184,7 @@ fun SendTransactionScreen( if (isConnectWith) { DappButton(buttonText = stringResource(R.string.connect_with_send)) { coroutineScope.launch { - when (val result = connectWithSendTransaction(amount, from, to)) { + when (val result = connectWithSendTransaction(value, from, to)) { is Result.Success.Item -> { errorMessage = null sendResult = result.value @@ -199,7 +199,7 @@ fun SendTransactionScreen( } else { DappButton(buttonText = stringResource(R.string.send)) { coroutineScope.launch { - when (val result = sendTransaction(amount, from, to)) { + when (val result = sendTransaction(value, from, to)) { is Result.Success.Item -> { errorMessage = null sendResult = result.value From cf18e38e4cffc472cf9262f13b095513a9b638bb Mon Sep 17 00:00:00 2001 From: Mpendulo Ndlovu Date: Thu, 22 Aug 2024 10:54:43 +0200 Subject: [PATCH 3/4] Updates --- README.md | 2 +- .../src/main/java/io/metamask/androidsdk/EthereumFlow.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3941fbed..518d3a30 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ code to your project file: @AndroidEntryPoint class SomeModel(context: Context) { - val dappMetadata = DappMetadata("Droid Dapp", "") + val dappMetadata = DappMetadata("Droid Dapp", "https://www.droiddapp.io") val infuraAPIKey = "1234567890" // We use Infura API for read-only RPCs for a seamless user experience // A) Using callbacks diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt index 009ddf04..b97a943b 100644 --- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt +++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt @@ -29,7 +29,7 @@ interface EthereumFlowWrapper { suspend fun getBlockTransactionCountByHash(blockHash: String) : Result suspend fun getBlockTransactionCountByNumber(blockNumber: String) : Result suspend fun getTransactionCount(address: String, tagOrblockNumber: String) : Result - suspend fun sendTransaction(from: String, to: String, amount: String) : Result + suspend fun sendTransaction(from: String, to: String, value: String) : Result suspend fun switchEthereumChain(targetChainId: String) : Result suspend fun addEthereumChain(chainId: String, @@ -139,11 +139,11 @@ constructor( override suspend fun ethSignTypedDataV4(typedData: Any, address: String) : Result = ethereumRequest(method = EthereumMethod.ETH_SIGN_TYPED_DATA_V4, params = listOf(address, typedData)) - override suspend fun sendTransaction(from: String, to: String, amount: String) : Result = + override suspend fun sendTransaction(from: String, to: String, value: String) : Result = ethereumRequest(method = EthereumMethod.ETH_SEND_TRANSACTION, params = listOf(mapOf( "from" to from, "to" to to, - "value" to amount + "value" to value ))) override suspend fun sendRawTransaction(signedTransaction: String) : Result = From 88de70879789e0045ab080e145487f7cc8b91dd8 Mon Sep 17 00:00:00 2001 From: Mpendulo Ndlovu Date: Thu, 22 Aug 2024 11:10:56 +0200 Subject: [PATCH 4/4] bump build number --- metamask-android-sdk/build.gradle | 4 ++-- .../src/main/java/io/metamask/androidsdk/SDKInfo.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metamask-android-sdk/build.gradle b/metamask-android-sdk/build.gradle index 9da2f575..dfedb26e 100644 --- a/metamask-android-sdk/build.gradle +++ b/metamask-android-sdk/build.gradle @@ -15,7 +15,7 @@ android { targetSdk 33 ext.versionCode = 1 - ext.versionName = "0.6.1" + ext.versionName = "0.6.2" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' consumerProguardFiles 'consumer-rules.pro' @@ -68,7 +68,7 @@ dependencies { ext { PUBLISH_GROUP_ID = 'io.metamask.androidsdk' - PUBLISH_VERSION = '0.6.1' + PUBLISH_VERSION = '0.6.2' PUBLISH_ARTIFACT_ID = 'metamask-android-sdk' } diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt index 3946081a..98f2917b 100644 --- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt +++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt @@ -1,6 +1,6 @@ package io.metamask.androidsdk object SDKInfo { - const val VERSION = "0.6.1" + const val VERSION = "0.6.2" const val PLATFORM = "android" } \ No newline at end of file