Skip to content

Commit a70f02a

Browse files
authored
Merge pull request #140 from MetaMask/send-transaction
chore: send transaction fixes
2 parents 1c18a92 + 88de708 commit a70f02a

File tree

9 files changed

+27
-26
lines changed

9 files changed

+27
-26
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ code to your project file:
7070
@AndroidEntryPoint
7171
class SomeModel(context: Context) {
7272

73-
val dappMetadata = DappMetadata("Droid Dapp", "https://droiddapp.com")
73+
val dappMetadata = DappMetadata("Droid Dapp", "https://www.droiddapp.io")
7474
val infuraAPIKey = "1234567890" // We use Infura API for read-only RPCs for a seamless user experience
7575

7676
// A) Using callbacks
@@ -255,10 +255,10 @@ The following example sends a transaction by calling
255255
// Create parameters
256256
val from = ethereum.selectedAddress
257257
val to = "0x0000000000000000000000000000000000000000"
258-
val amount = "0x01"
258+
val value = "0x8ac7230489e80000"
259259

260260
// Make a transaction request
261-
when (val result = ethereum.sendTransaction(from, to, amount)) {
261+
when (val result = ethereum.sendTransaction(from, to, value)) {
262262
is Result.Success.Item -> {
263263
Logger.log("Ethereum transaction result: ${result.value}")
264264
balance = result.value
@@ -302,7 +302,7 @@ We have provided a convenience method that enables you to connect and make any r
302302
val params: Map<String, Any> = mutableMapOf(
303303
"from" to "", // this will be populated with selected address once connected
304304
"to" to "0x0000000000000000000000000000000000000000",
305-
"amount" to "0x01"
305+
"value" to "0x8ac7230489e80000"
306306
)
307307

308308
val transactionRequest = EthereumRequest(

app/src/main/java/com/metamask/dapp/AppModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import io.metamask.androidsdk.*
1515
internal object AppModule {
1616
@Provides
1717
fun provideDappMetadata(): DappMetadata {
18-
return DappMetadata("Droiddapp", "https://droiddapp.io", iconUrl = "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png")
18+
return DappMetadata("Droiddapp", "https://www.droiddapp.io", iconUrl = "https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png")
1919
}
2020

2121
@Provides

app/src/main/java/com/metamask/dapp/EthereumViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ class EthereumViewModel @Inject constructor(
5050
}
5151
}
5252

53-
fun connectWithSendTransaction(amount: String,
53+
fun connectWithSendTransaction(value: String,
5454
from: String,
5555
to: String,
5656
onSuccess: (Any?) -> Unit,
5757
onError: (message: String) -> Unit) {
5858
val params: MutableMap<String, Any> = mutableMapOf(
5959
"from" to from,
6060
"to" to to,
61-
"amount" to amount
61+
"value" to value
6262
)
6363

6464
val transactionRequest = EthereumRequest(
@@ -231,7 +231,7 @@ class EthereumViewModel @Inject constructor(
231231
}
232232

233233
fun sendTransaction(
234-
amount: String,
234+
value: String,
235235
from: String,
236236
to: String,
237237
onSuccess: (String) -> Unit,
@@ -240,7 +240,7 @@ class EthereumViewModel @Inject constructor(
240240
val params: MutableMap<String, Any> = mutableMapOf(
241241
"from" to from,
242242
"to" to to,
243-
"amount" to amount
243+
"value" to value
244244
)
245245

246246
val transactionRequest = EthereumRequest(

app/src/main/java/com/metamask/dapp/SendTransactionScreen.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ fun SendTransactionScreen(
3434
navController: NavController,
3535
ethereumState: EthereumState,
3636
isConnectWith: Boolean = false,
37-
sendTransaction: suspend (amount: String, from: String, to: String) -> Result,
38-
connectWithSendTransaction: suspend (amount: String, from: String, to: String) -> Result
37+
sendTransaction: suspend (value: String, from: String, to: String) -> Result,
38+
connectWithSendTransaction: suspend (value: String, from: String, to: String) -> Result
3939
) {
40-
var amount by remember { mutableStateOf("0x01") }
40+
var value by remember { mutableStateOf("0x8ac7230489e80000") }
4141
var from by remember { mutableStateOf(ethereumState.selectedAddress) }
4242
var to by remember { mutableStateOf("0x0000000000000000000000000000000000000000") }
4343
var sendResult by remember { mutableStateOf("") }
@@ -67,7 +67,7 @@ fun SendTransactionScreen(
6767
.height(48.dp)
6868
) {
6969
Text(
70-
text = "Amount:",
70+
text = "Value:",
7171
fontSize = 14.sp,
7272
fontWeight = FontWeight.Bold,
7373
textAlign = TextAlign.Start,
@@ -87,10 +87,10 @@ fun SendTransactionScreen(
8787
}
8888
) {
8989
BasicTextField(
90-
value = amount,
90+
value = value,
9191
textStyle = TextStyle(color = if (isSystemInDarkTheme()) { Color.White} else { Color.Black}),
9292
onValueChange = {
93-
amount = it
93+
value = it
9494
},
9595
modifier = Modifier
9696
.padding(start = 8.dp, top = 16.dp, end = 8.dp, bottom = 0.dp)
@@ -184,7 +184,7 @@ fun SendTransactionScreen(
184184
if (isConnectWith) {
185185
DappButton(buttonText = stringResource(R.string.connect_with_send)) {
186186
coroutineScope.launch {
187-
when (val result = connectWithSendTransaction(amount, from, to)) {
187+
when (val result = connectWithSendTransaction(value, from, to)) {
188188
is Result.Success.Item -> {
189189
errorMessage = null
190190
sendResult = result.value
@@ -199,7 +199,7 @@ fun SendTransactionScreen(
199199
} else {
200200
DappButton(buttonText = stringResource(R.string.send)) {
201201
coroutineScope.launch {
202-
when (val result = sendTransaction(amount, from, to)) {
202+
when (val result = sendTransaction(value, from, to)) {
203203
is Result.Success.Item -> {
204204
errorMessage = null
205205
sendResult = result.value

metamask-android-sdk/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ android {
1515
targetSdk 33
1616

1717
ext.versionCode = 1
18-
ext.versionName = "0.6.1"
18+
ext.versionName = "0.6.2"
1919

2020
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
2121
consumerProguardFiles 'consumer-rules.pro'
@@ -68,7 +68,7 @@ dependencies {
6868

6969
ext {
7070
PUBLISH_GROUP_ID = 'io.metamask.androidsdk'
71-
PUBLISH_VERSION = '0.6.1'
71+
PUBLISH_VERSION = '0.6.2'
7272
PUBLISH_ARTIFACT_ID = 'metamask-android-sdk'
7373
}
7474

metamask-android-sdk/src/main/java/io/metamask/androidsdk/CommunicationClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class CommunicationClient(
330330
val errorCode = errorMap["code"] as? Double ?: -1
331331
val code = errorCode.toInt()
332332
val message = errorMap["message"] as? String ?: ErrorType.message(code)
333-
logger.error("CommunicationClient:: Got error $message")
333+
logger.error("CommunicationClient:: Got error $error")
334334
completeRequest(requestId, Result.Error(RequestError(code, message)))
335335
return true
336336
}
@@ -476,6 +476,7 @@ class CommunicationClient(
476476
val requestInfoJson = Gson().toJson(requestInfo)
477477

478478
logger.log("CommunicationClient:: Sending originator info: $requestInfoJson")
479+
logger.log("CommunicationClient:: SessionId $sessionId")
479480

480481
val payload = keyExchange.encrypt(requestInfoJson)
481482

metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ class Ethereum (
256256
ethereumRequest(method = EthereumMethod.ETH_SIGN_TYPED_DATA_V4, params = listOf(address, typedData), callback)
257257
}
258258

259-
fun sendTransaction(from: String, to: String, amount: String, callback: ((Result) -> Unit)?) {
259+
fun sendTransaction(from: String, to: String, value: String, callback: ((Result) -> Unit)?) {
260260
ethereumRequest(method = EthereumMethod.ETH_SEND_TRANSACTION, params = listOf(mutableMapOf(
261261
"from" to from,
262262
"to" to to,
263-
"amount" to amount
263+
"value" to value
264264
)), callback)
265265
}
266266

metamask-android-sdk/src/main/java/io/metamask/androidsdk/EthereumFlow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface EthereumFlowWrapper {
2929
suspend fun getBlockTransactionCountByHash(blockHash: String) : Result
3030
suspend fun getBlockTransactionCountByNumber(blockNumber: String) : Result
3131
suspend fun getTransactionCount(address: String, tagOrblockNumber: String) : Result
32-
suspend fun sendTransaction(from: String, to: String, amount: String) : Result
32+
suspend fun sendTransaction(from: String, to: String, value: String) : Result
3333

3434
suspend fun switchEthereumChain(targetChainId: String) : Result
3535
suspend fun addEthereumChain(chainId: String,
@@ -139,11 +139,11 @@ constructor(
139139
override suspend fun ethSignTypedDataV4(typedData: Any, address: String) : Result =
140140
ethereumRequest(method = EthereumMethod.ETH_SIGN_TYPED_DATA_V4, params = listOf(address, typedData))
141141

142-
override suspend fun sendTransaction(from: String, to: String, amount: String) : Result =
142+
override suspend fun sendTransaction(from: String, to: String, value: String) : Result =
143143
ethereumRequest(method = EthereumMethod.ETH_SEND_TRANSACTION, params = listOf(mapOf(
144144
"from" to from,
145145
"to" to to,
146-
"amount" to amount
146+
"value" to value
147147
)))
148148

149149
override suspend fun sendRawTransaction(signedTransaction: String) : Result =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.metamask.androidsdk
22

33
object SDKInfo {
4-
const val VERSION = "0.6.1"
4+
const val VERSION = "0.6.2"
55
const val PLATFORM = "android"
66
}

0 commit comments

Comments
 (0)