Skip to content

Commit

Permalink
Extract method WalletConnectTransaction::getGasPriceObj()
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed May 21, 2024
1 parent 2448a3b commit 60435e5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import io.horizontalsystems.bankwallet.modules.sendevmtransaction.ViewItem
import io.horizontalsystems.bankwallet.modules.walletconnect.WCDelegate
import io.horizontalsystems.bankwallet.modules.walletconnect.request.WCChainData
import io.horizontalsystems.core.toHexString
import io.horizontalsystems.ethereumkit.models.GasPrice
import io.horizontalsystems.ethereumkit.models.TransactionData
import io.horizontalsystems.marketkit.models.BlockchainType
import kotlinx.coroutines.Dispatchers
Expand All @@ -45,15 +44,11 @@ class WCSendEthereumTransactionRequestViewModel(
private var sendTransactionState: SendTransactionServiceState

init {
val gasPrice = if (transaction.maxFeePerGas != null && transaction.maxPriorityFeePerGas != null) {
GasPrice.Eip1559(transaction.maxFeePerGas, transaction.maxPriorityFeePerGas)
} else if (transaction.gasPrice != null) {
GasPrice.Legacy(transaction.gasPrice)
} else {
null
}

sendTransactionService = SendTransactionServiceEvm(blockchainType, gasPrice, transaction.nonce)
sendTransactionService = SendTransactionServiceEvm(
blockchainType = blockchainType,
initialGasPrice = transaction.getGasPriceObj(),
initialNonce = transaction.nonce
)
sendTransactionState = sendTransactionService.stateFlow.value

viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.horizontalsystems.bankwallet.modules.walletconnect.request.sendtransaction

import io.horizontalsystems.ethereumkit.models.Address
import io.horizontalsystems.ethereumkit.models.GasPrice
import java.math.BigInteger

data class WalletConnectTransaction(
Expand All @@ -13,4 +14,14 @@ data class WalletConnectTransaction(
val maxFeePerGas: Long?,
val value: BigInteger,
val data: ByteArray
)
) {
fun getGasPriceObj() = when {
maxFeePerGas != null && maxPriorityFeePerGas != null -> {
GasPrice.Eip1559(maxFeePerGas, maxPriorityFeePerGas)
}
this.gasPrice != null -> {
GasPrice.Legacy(this.gasPrice)
}
else -> null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import io.horizontalsystems.bankwallet.modules.sendevmtransaction.ViewItem
import io.horizontalsystems.bankwallet.modules.walletconnect.WCDelegate
import io.horizontalsystems.bankwallet.modules.walletconnect.WCSessionManager
import io.horizontalsystems.bankwallet.modules.walletconnect.request.sendtransaction.WalletConnectTransaction
import io.horizontalsystems.ethereumkit.models.GasPrice
import io.horizontalsystems.ethereumkit.models.TransactionData
import io.horizontalsystems.marketkit.models.BlockchainType
import kotlinx.coroutines.Dispatchers
Expand All @@ -48,13 +47,7 @@ class WCSignEthereumTransactionRequestViewModel(
private var fields: List<DataField>

init {
val gasPrice = if (transaction.maxFeePerGas != null && transaction.maxPriorityFeePerGas != null) {
GasPrice.Eip1559(transaction.maxFeePerGas, transaction.maxPriorityFeePerGas)
} else if (transaction.gasPrice != null) {
GasPrice.Legacy(transaction.gasPrice)
} else {
null
}
val gasPrice = transaction.getGasPriceObj()

feeAmountData = if (gasPrice != null && transaction.gasLimit != null) {
GasData(gasLimit = transaction.gasLimit, gasPrice = gasPrice).let {
Expand Down

0 comments on commit 60435e5

Please sign in to comment.