Skip to content

Commit

Permalink
block-sending-when-address-error
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-fan1991 committed Mar 8, 2024
1 parent 6427983 commit cd543f8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.slideFromRight
import io.horizontalsystems.bankwallet.entities.DataState
import io.horizontalsystems.bankwallet.modules.address.AddressInputModule
import io.horizontalsystems.bankwallet.modules.address.AddressParserModule
import io.horizontalsystems.bankwallet.modules.address.AddressParserViewModel
import io.horizontalsystems.bankwallet.modules.address.AddressViewModel
import io.horizontalsystems.bankwallet.modules.address.HSAddressInput
import io.horizontalsystems.bankwallet.modules.amount.AmountInputModeViewModel
import io.horizontalsystems.bankwallet.modules.amount.HSAmountInput
Expand All @@ -28,6 +31,7 @@ import io.horizontalsystems.bankwallet.modules.send.SendScreen
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
import io.horizontalsystems.bankwallet.ui.compose.components.FormsInput
import timber.log.Timber

@Composable
fun SendStellarScreen(
Expand All @@ -43,13 +47,39 @@ fun SendStellarScreen(
val availableBalance = uiState.availableBalance
val addressError = uiState.addressError
val amountCaution = uiState.amountCaution
val proceedEnabled = uiState.proceedEnabled
var proceedEnabled = uiState.proceedEnabled
val amountInputType = amountInputModeViewModel.inputType

val paymentAddressViewModel =
viewModel<AddressParserViewModel>(factory = AddressParserModule.Factory(wallet.token.blockchainType))
val amountUnique = paymentAddressViewModel.amountUnique

val addressViewModel = viewModel<AddressViewModel>(
factory = AddressInputModule.FactoryToken(wallet.token.tokenQuery, wallet.coin.code, null),
key = "address_view_model_${wallet.token.tokenQuery.id}"
)
when (addressViewModel.inputState) {
is DataState.Success -> {

}

is DataState.Error -> {
proceedEnabled = false
Timber.e("AddressViewModel error: ${addressViewModel.inputState}")

}

DataState.Loading -> {
proceedEnabled = false
}

null -> {
proceedEnabled = false
}
}



ComposeAppTheme {
val fullCoin = wallet.token.fullCoin
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -98,9 +128,10 @@ fun SendStellarScreen(
coinCode = wallet.coin.code,
error = addressError,
textPreprocessor = paymentAddressViewModel,
navController = navController
) {
viewModel.onEnterAddress(it)
navController = navController,

) {
viewModel.onAddressSport(it)
}

Spacer(modifier = Modifier.height(12.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.entities.Address
import io.horizontalsystems.bankwallet.entities.ViewState
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.bankwallet.modules.address.AddressValidationException
import io.horizontalsystems.bankwallet.modules.send.SendAmountAdvancedService
import io.horizontalsystems.bankwallet.modules.send.SendResult
import io.horizontalsystems.bankwallet.modules.send.tron.SendTronConfirmationData
Expand All @@ -27,7 +28,6 @@ import io.horizontalsystems.tronkit.transaction.Fee
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.stellar.sdk.Transaction
import timber.log.Timber
import java.math.BigDecimal
import java.net.UnknownHostException
Expand Down Expand Up @@ -109,7 +109,7 @@ class SendStellarViewModel(
amountService.setAmount(amount)
}

fun onEnterAddress(address: Address?) {
fun onAddressSport(address: Address?) {
viewModelScope.launch {
addressService.setAddress(address)
}
Expand Down Expand Up @@ -272,7 +272,13 @@ class SendStellarViewModel(
// logger.info("sending tx")

Timber.d("evmAmount: ${amountState.evmAmount!!}")
adapter.send(sendToken, amountState.evmAmount!!, addressState.address!!.hex, memo, addressState.isInactiveAddress)
adapter.send(
sendToken,
amountState.evmAmount!!,
addressState.address!!.hex,
memo,
addressState.isInactiveAddress
)

sendResult = SendResult.Sent
// logger.info("success")
Expand Down Expand Up @@ -311,8 +317,8 @@ class SendStellarViewModel(
availableBalance = amountState.availableBalance,
amountCaution = amountState.amountCaution,
addressError = addressState.addressError,
proceedEnabled = amountState.canBeSend && addressState.canBeSend && ! addressState.isInactiveAddress,
sendEnabled = cautions.isEmpty()&& ! addressState.isInactiveAddress ,
proceedEnabled = amountState.canBeSend && addressState.canBeSend,
sendEnabled = cautions.isEmpty(),
feeViewState = feeState.viewState,
cautions = cautions
)
Expand Down

0 comments on commit cd543f8

Please sign in to comment.