diff --git a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/components/send/WcSendTransactionComponent.kt b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/components/send/WcSendTransactionComponent.kt index 62f838c9b7..5e78c040a8 100644 --- a/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/components/send/WcSendTransactionComponent.kt +++ b/features/walletconnect/impl/src/main/kotlin/com/tangem/features/walletconnect/transaction/components/send/WcSendTransactionComponent.kt @@ -19,27 +19,13 @@ internal class WcSendTransactionComponent( private val feeSelectorBlockComponentFactory: FeeSelectorBlockComponent.Factory, ) : AppComponentContext by appComponentContext, ComposableBottomSheetComponent { - private val feeSelectorBlockComponent by lazy { - val state = requireNotNull(model.uiState.value) { "in this step state should be not null" } - feeSelectorBlockComponentFactory.create( - context = appComponentContext, - params = FeeSelectorParams.FeeSelectorBlockParams( - state = state.feeSelectorUM, - onLoadFee = model::loadFee, - cryptoCurrencyStatus = model.cryptoCurrencyStatus, - feeCryptoCurrencyStatus = model.cryptoCurrencyStatus, - feeStateConfiguration = model.feeStateConfiguration, - feeDisplaySource = FeeSelectorParams.FeeDisplaySource.BottomSheet, - ), - onResult = model::updateFee, - ) - } + private var feeSelectorBlockComponent: FeeSelectorBlockComponent? = null init { lifecycle.doOnResume { val state = model.uiState.value if (state?.transaction?.feeState is WcTransactionFeeState.Success) { - feeSelectorBlockComponent.updateState(state.feeSelectorUM) + feeSelectorBlockComponent?.updateState(state.feeSelectorUM) } } } @@ -54,8 +40,12 @@ internal class WcSendTransactionComponent( val state = content?.transaction if (state != null) { - val feeSelectorBlock = - if (state.feeState !is WcTransactionFeeState.None) feeSelectorBlockComponent else null + val feeSelectorUM = content?.feeSelectorUM + val feeSelectorBlock = if (state.feeState !is WcTransactionFeeState.None && feeSelectorUM != null) { + getFeeSelectorBlockComponent(feeSelectorUM) + } else { + null + } WcSendTransactionModalBottomSheet( state = state, feeSelectorBlockComponent = feeSelectorBlock, @@ -67,4 +57,26 @@ internal class WcSendTransactionComponent( ) } } + + private fun getFeeSelectorBlockComponent(feeSelectorUM: FeeSelectorUM): FeeSelectorBlockComponent { + val local = feeSelectorBlockComponent + return if (local != null) { + local + } else { + val component = feeSelectorBlockComponentFactory.create( + context = appComponentContext, + params = FeeSelectorParams.FeeSelectorBlockParams( + state = feeSelectorUM, + onLoadFee = model::loadFee, + cryptoCurrencyStatus = model.cryptoCurrencyStatus, + feeCryptoCurrencyStatus = model.cryptoCurrencyStatus, + feeStateConfiguration = model.feeStateConfiguration, + feeDisplaySource = FeeSelectorParams.FeeDisplaySource.BottomSheet, + ), + onResult = model::updateFee, + ) + feeSelectorBlockComponent = component + component + } + } } \ No newline at end of file