Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code #7410

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.viewModels
import androidx.navigation.NavController
import androidx.navigation.navGraphViewModels
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.BaseComposeFragment
Expand All @@ -21,7 +20,6 @@ import io.horizontalsystems.bankwallet.modules.address.AddressInputModule
import io.horizontalsystems.bankwallet.modules.address.AddressParserViewModel
import io.horizontalsystems.bankwallet.modules.address.AddressViewModel
import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmAddressService
import io.horizontalsystems.bankwallet.modules.send.evm.confirmation.EvmKitWrapperHoldingViewModel
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.TranslatableString
import io.horizontalsystems.bankwallet.ui.compose.components.AppBar
Expand All @@ -41,12 +39,6 @@ class SendNftFragment : BaseComposeFragment() {

when (factory?.evmNftRecord?.nftType) {
NftType.Eip721 -> {
val evmKitWrapperViewModel by navGraphViewModels<EvmKitWrapperHoldingViewModel>(
R.id.nftSendFragment
) { factory }
val initiateLazyViewModel =
evmKitWrapperViewModel //needed in SendEvmConfirmationFragment

val eip721ViewModel by viewModels<SendEip721ViewModel> { factory }
val addressViewModel by viewModels<AddressViewModel> {
AddressInputModule.FactoryNft(factory.nftUid.blockchainType)
Expand All @@ -62,12 +54,6 @@ class SendNftFragment : BaseComposeFragment() {
}

NftType.Eip1155 -> {
val evmKitWrapperViewModel by navGraphViewModels<EvmKitWrapperHoldingViewModel>(
R.id.nftSendFragment
) { factory }
val initiateLazyViewModel =
evmKitWrapperViewModel //needed in SendEvmConfirmationFragment

val eip1155ViewModel by viewModels<SendEip1155ViewModel> { factory }
val addressViewModel by viewModels<AddressViewModel> {
AddressInputModule.FactoryNft(factory.nftUid.blockchainType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.horizontalsystems.bankwallet.entities.nft.EvmNftRecord
import io.horizontalsystems.bankwallet.entities.nft.NftUid
import io.horizontalsystems.bankwallet.modules.address.AddressParserViewModel
import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmAddressService
import io.horizontalsystems.bankwallet.modules.send.evm.confirmation.EvmKitWrapperHoldingViewModel

object SendNftModule {

Expand Down Expand Up @@ -45,9 +44,6 @@ object SendNftModule {
nftMetadataManager
) as T
}
EvmKitWrapperHoldingViewModel::class.java -> {
EvmKitWrapperHoldingViewModel(evmKitWrapper) as T
}
AddressParserViewModel::class.java -> {
AddressParserViewModel(AddressUriParser(nftUid.blockchainType, null), null) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import io.horizontalsystems.bankwallet.modules.send.binance.SendBinanceViewModel
import io.horizontalsystems.bankwallet.modules.send.bitcoin.SendBitcoinModule
import io.horizontalsystems.bankwallet.modules.send.bitcoin.SendBitcoinNavHost
import io.horizontalsystems.bankwallet.modules.send.bitcoin.SendBitcoinViewModel
import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmModule
import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmScreen
import io.horizontalsystems.bankwallet.modules.send.evm.SendEvmViewModel
import io.horizontalsystems.bankwallet.modules.send.evm.confirmation.EvmKitWrapperHoldingViewModel
import io.horizontalsystems.bankwallet.modules.send.solana.SendSolanaModule
import io.horizontalsystems.bankwallet.modules.send.solana.SendSolanaScreen
import io.horizontalsystems.bankwallet.modules.send.solana.SendSolanaViewModel
Expand Down Expand Up @@ -129,20 +126,14 @@ class SendFragment : BaseFragment() {
BlockchainType.Gnosis,
BlockchainType.Fantom,
BlockchainType.ArbitrumOne -> {
val factory = SendEvmModule.Factory(wallet, predefinedAddress)
val evmKitWrapperViewModel by navGraphViewModels<EvmKitWrapperHoldingViewModel>(
R.id.sendXFragment
) { factory }
@Suppress("UNUSED_VARIABLE")
val initiateLazyViewModel = evmKitWrapperViewModel //needed in SendEvmConfirmationFragment
val sendEvmViewModel by navGraphViewModels<SendEvmViewModel>(R.id.sendXFragment) { factory }
setContent {
SendEvmScreen(
title,
findNavController(),
sendEvmViewModel,
amountInputModeViewModel,
prefilledData,
wallet,
predefinedAddress
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import io.horizontalsystems.bankwallet.core.isNative
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.amount.AmountValidator
import io.horizontalsystems.bankwallet.modules.amount.SendAmountService
import io.horizontalsystems.bankwallet.modules.send.evm.confirmation.EvmKitWrapperHoldingViewModel
import io.horizontalsystems.bankwallet.modules.xrate.XRateService
import io.horizontalsystems.ethereumkit.models.TransactionData
import kotlinx.parcelize.Parcelize
Expand Down Expand Up @@ -63,9 +62,6 @@ object SendEvmModule {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when (modelClass) {
EvmKitWrapperHoldingViewModel::class.java -> {
EvmKitWrapperHoldingViewModel(adapter.evmKitWrapper) as T
}
SendEvmViewModel::class.java -> {
val amountValidator = AmountValidator()
val coinMaxAllowedDecimals = wallet.token.decimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.slideFromRightForResult
import io.horizontalsystems.bankwallet.entities.Address
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.address.AddressParserModule
import io.horizontalsystems.bankwallet.modules.address.AddressParserViewModel
import io.horizontalsystems.bankwallet.modules.address.HSAddressInput
Expand All @@ -34,11 +35,12 @@ import io.horizontalsystems.core.helpers.HudHelper
fun SendEvmScreen(
title: String,
navController: NavController,
viewModel: SendEvmViewModel,
amountInputModeViewModel: AmountInputModeViewModel,
prefilledData: PrefilledData?,
wallet: Wallet,
predefinedAddress: String?,
) {
val wallet = viewModel.wallet
val viewModel = viewModel<SendEvmViewModel>(factory = SendEvmModule.Factory(wallet, predefinedAddress))
val uiState = viewModel.uiState

val availableBalance = uiState.availableBalance
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.AppLogger
import io.horizontalsystems.bankwallet.core.setNavigationResultX
import io.horizontalsystems.bankwallet.core.slideFromBottom
import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.modules.confirm.ConfirmTransactionScreen
import io.horizontalsystems.bankwallet.modules.send.evm.confirmation.SendEvmConfirmationFragment
import io.horizontalsystems.bankwallet.modules.sendevmtransaction.SendEvmTransactionView
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryDefault
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
Expand Down Expand Up @@ -72,22 +70,19 @@ fun WCSendEthRequestScreen(
buttonEnabled = false
HudHelper.showInProcessMessage(view, R.string.Send_Sending, SnackbarDuration.INDEFINITE)

val result = try {
try {
logger.info("click confirm button")
viewModel.confirm()
logger.info("success")

HudHelper.showSuccessMessage(view, R.string.Hud_Text_Done)
delay(1200)
SendEvmConfirmationFragment.Result(true)
} catch (t: Throwable) {
logger.warning("failed", t)
HudHelper.showErrorMessage(view, t.javaClass.simpleName)
SendEvmConfirmationFragment.Result(false)
}

buttonEnabled = true
navController.setNavigationResultX(result)
navController.popBackStack()
}
}
Expand Down
Loading