Skip to content

Commit

Permalink
Extract init code to start methods
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed May 20, 2024
1 parent 19b9ea6 commit 6a2f2ae
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ interface IEvmFeeService {

abstract class IEvmGasPriceService : ServiceState<DataState<GasPriceInfo>>() {
abstract fun setRecommended()
abstract fun start()
}

abstract class FeeSettingsError : Throwable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EvmFeeService(
MutableSharedFlow(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
override val transactionStatusFlow = _transactionStatusFlow.asSharedFlow()

init {
fun start() {
coroutineScope.launch {
gasPriceService.stateFlow.collect {
gasPriceInfoState = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kotlin.math.min

class Eip1559GasPriceService(
private val gasProvider: Eip1559GasPriceProvider,
refreshSignalFlowable: Flowable<Long>,
private val refreshSignalFlowable: Flowable<Long>,
minGasPrice: GasPrice.Eip1559? = null,
initialGasPrice: GasPrice.Eip1559? = null
) : IEvmGasPriceService() {
Expand Down Expand Up @@ -63,7 +63,7 @@ class Eip1559GasPriceService(
initialGasPrice: GasPrice.Eip1559? = null
) : this(gasProvider, evmKit.lastBlockHeightFlowable, minGasPrice, initialGasPrice)

init {
override fun start() {
if (initialBaseFee != null && initialPriorityFee != null) {
setGasPrice(initialBaseFee, initialPriorityFee)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.math.BigDecimal
class LegacyGasPriceService(
private val gasPriceProvider: LegacyGasPriceProvider,
private val minRecommendedGasPrice: Long? = null,
initialGasPrice: Long? = null,
private val initialGasPrice: Long? = null,
) : IEvmGasPriceService() {
private val coroutineScope = CoroutineScope(Dispatchers.Default)
private var setGasPriceJob: Job? = null
Expand All @@ -30,7 +30,7 @@ class LegacyGasPriceService(

override fun createState() = state

init {
override fun start() {
if (initialGasPrice != null) {
setGasPrice(initialGasPrice)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class SendTransactionServiceEvm(blockchainType: BlockchainType) : ISendTransacti
}
private val nonceService by lazy { SendEvmNonceService(evmKitWrapper.evmKit) }
private val settingsService by lazy { SendEvmSettingsService(feeService, nonceService) }
// private val sendService by lazy {
// SendEvmTransactionService(
// sendEvmData,
// evmKitWrapper,
// settingsService,
// App.evmLabelManager
// )
// }

private val baseCoinService = coinServiceFactory.baseCoinService
private val cautionViewItemFactory by lazy { CautionViewItemFactory(baseCoinService) }
Expand All @@ -124,6 +116,9 @@ class SendTransactionServiceEvm(blockchainType: BlockchainType) : ISendTransacti
)

override fun start(coroutineScope: CoroutineScope) {
gasPriceService.start()
feeService.start()

coroutineScope.launch {
gasPriceService.stateFlow.collect { gasPriceState ->
_sendTransactionSettingsFlow.update {
Expand All @@ -134,6 +129,9 @@ class SendTransactionServiceEvm(blockchainType: BlockchainType) : ISendTransacti
coroutineScope.launch {
settingsService.start()
}
coroutineScope.launch {
nonceService.start()
}
coroutineScope.launch {
settingsService.stateFlow.collect { transactionState ->
handleTransactionState(transactionState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class SendEvmSettingsService(
sync()
}
}

nonceService.start()
}

fun clear() {
Expand Down

0 comments on commit 6a2f2ae

Please sign in to comment.