Skip to content

Commit

Permalink
Add result listener for legacy fee params
Browse files Browse the repository at this point in the history
  • Loading branch information
elgatovital committed Aug 21, 2023
1 parent b91dd58 commit 1f03615
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ class TxReviewFragment : BaseViewBindingFragment<FragmentTxReviewBinding>() {
)
}

setFragmentResultListener(TxEditFeeLegacyFragment.REQUEST_EDIT_FEE) { requestKey, bundle ->
val nonce = bundle.getString(TxEditFeeLegacyFragment.RESULT_NONCE)!!
val gasLimit = bundle.getString(TxEditFeeLegacyFragment.RESULT_GAS_LIMIT)!!
val gasPrice = bundle.getString(TxEditFeeLegacyFragment.RESULT_GAS_PRICE)!!
viewModel.updateLegacyEstimationParams(
nonce = nonce.toBigInteger(),
gasLimit = gasLimit.toBigInteger(),
gasPrice = gasPrice.toBigDecimal().stripTrailingZeros()
)
}

if (!viewModel.isInitialized()) {
viewModel.setTxData(
txData = txDetails!!.txData!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ class TxReviewViewModel
// base fee amount
val baseFee = estimationParams.gasPrice
minNonce = estimationParams.nonce
// adjust nonce if it is lower than the minimum
// this can happen if other transactions have been sent from the same account
// while the user was on the tx review screen
if (nonce ?: BigInteger.ZERO < minNonce) {
nonce = minNonce
}
// If user has not edited the fee data, we set the fee values
// Otherwise, we keep the user's values
if (!userEditedFeeData) {
Expand Down Expand Up @@ -223,6 +229,22 @@ class TxReviewViewModel
}
}

fun updateLegacyEstimationParams(
nonce: BigInteger,
gasLimit: BigInteger,
gasPrice: BigDecimal
) {
this.userEditedFeeData = true
this.nonce = nonce
this.gasLimit = gasLimit
this.gasPrice = gasPrice
safeLaunch {
updateState {
TxReviewState(viewAction = UpdateFee(fee = totalFee()))
}
}
}

private fun updateEthTxWithEstimationData() {
when (ethTx) {
is Transaction.Eip1559 -> {
Expand All @@ -232,7 +254,6 @@ class TxReviewViewModel
ethTxEip1559.maxFeePerGas = Wei.fromGWei(maxFeePerGas!!).value
ethTx = ethTxEip1559.copy(nonce = nonce!!)
}

is Transaction.Legacy -> {
val ethTxLegacy = ethTx as Transaction.Legacy
ethTxLegacy.gas = gasLimit!!
Expand All @@ -252,7 +273,6 @@ class TxReviewViewModel
ethTxEip1559.hash()
}
}

is Transaction.Legacy -> {
val ethTxLegacy = ethTx as Transaction.Legacy
if (ownerType == Owner.Type.KEYSTONE) {
Expand All @@ -261,7 +281,6 @@ class TxReviewViewModel
ethTxLegacy.hash()
}
}

else -> throw IllegalStateException("Unknown transaction type")
}
}
Expand Down

0 comments on commit 1f03615

Please sign in to comment.