Skip to content

Commit

Permalink
Merge pull request #1 from OwlTing/feature--block-sending-when-addres…
Browse files Browse the repository at this point in the history
…s-error

Feature  block sending when address error
  • Loading branch information
jack-fan1991 committed Mar 18, 2024
2 parents d0a6b2a + cd543f8 commit 1d3a9b2
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 56 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-debug-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
workflow_dispatch:



jobs:
debug_build:
runs-on: [self-hosted, linux]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

/fastlane/service_credentials_file_dev.json
/fastlane/service_credentials_file_prod.json
/**/google-services.json
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import com.android.tools.profgen.ArtProfileKt
import com.android.tools.profgen.ArtProfileSerializer
import com.android.tools.profgen.DexFile


plugins {
// id 'com.android.application'
// id 'kotlin-android'
// id 'kotlin-parcelize'
// id 'kotlin-kapt'
id 'com.google.gms.google-services'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
Expand All @@ -16,6 +25,7 @@ if (propertiesFile.exists()) {
properties.load(new FileInputStream(propertiesFile))
}


android {

defaultConfig {
Expand Down Expand Up @@ -396,6 +406,9 @@ dependencies {

api 'com.jaredrummler:android-shell:1.0.0'
api 'com.offbynull.portmapper:portmapper:2.0.5'
// Firebase
implementation(platform("com.google.firebase:firebase-bom:32.7.3"))
implementation 'com.google.firebase:firebase-analytics-ktx:19.0.1'
}

configurations.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import io.horizontalsystems.bankwallet.owlwallet.data.source.DefaultOTRepository
import io.horizontalsystems.bankwallet.owlwallet.data.source.remote.OTWalletApiClient
import io.horizontalsystems.bankwallet.owlwallet.data.source.remote.OTWalletRemoteDataSource
import io.horizontalsystems.bankwallet.core.managers.StellarKitManager
import io.horizontalsystems.bankwallet.owlwallet.utils.FirebaseAnalyticHelper
import io.horizontalsystems.bankwallet.owlwallet.utils.PreferenceHelper
import io.horizontalsystems.bankwallet.owlwallet.utils.VersionChecker
import io.horizontalsystems.bankwallet.widgets.MarketWidgetManager
Expand Down Expand Up @@ -206,6 +207,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
lateinit var preferenceHelper: PreferenceHelper
lateinit var mainTabManager: MainTabManager
lateinit var versionChecker: VersionChecker
lateinit var firebaseAnalyticHelper: FirebaseAnalyticHelper

fun initOwlTingRepo() {
OTWalletApiClient.clear()
Expand Down Expand Up @@ -234,7 +236,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {

override fun onCreate() {
super.onCreate()

firebaseAnalyticHelper = FirebaseAnalyticHelper().apply { logLaunchEvent() }
if (!BuildConfig.DEBUG) {
//Disable logging for lower levels in Release build
Logger.getLogger("").level = Level.SEVERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class StellarAdapter(
stellarKit.refresh()
}

fun send(token: Token, amount: BigInteger, accountId: String, memo: String) {
fun send(token: Token, amount: BigInteger, accountId: String, memo: String,isInactiveAddress: Boolean) {

val asset = when (token.type) {
is TokenType.Alphanum4 -> Alphanum4(token.coin.code, (token.type as TokenType.Alphanum4).issuer)
else -> Native()
}

stellarKit.send(asset, amount, accountId, memo)
stellarKit.send(asset, amount, accountId, memo,isInactiveAddress)
}

private fun balanceInBigDecimal(balance: BigInteger?, decimal: Int): BigDecimal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ import io.horizontalsystems.bankwallet.modules.transactions.TransactionSource
import com.owlting.app.stellarkit.models.CreateAccountOperation
import com.owlting.app.stellarkit.models.Transaction
import io.horizontalsystems.marketkit.models.Token
import java.math.BigDecimal

class StellarCreateAccountTransactionRecord(
accountId: String,
transaction: Transaction,
val operation: CreateAccountOperation,
baseToken: Token,
val baseToken: Token,
source: TransactionSource,
val value: TransactionValue,
) : StellarTransactionRecord(accountId, transaction, baseToken, source) {

override val mainValue = value

fun copyWithCoinValue(value: BigDecimal): StellarCreateAccountTransactionRecord {
return StellarCreateAccountTransactionRecord(
accountId,
transaction,
operation,
baseToken,
source,
TransactionValue.CoinValue(baseToken, value)
)
}


}
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 @@ -5,6 +5,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owlting.app.stellarkit.exception.ErrorType
import com.owlting.app.stellarkit.exception.KitException
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.HSCaution
Expand All @@ -14,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 @@ -25,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 @@ -107,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 @@ -270,7 +272,13 @@ class SendStellarViewModel(
// logger.info("sending tx")

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

sendResult = SendResult.Sent
// logger.info("success")
Expand All @@ -283,9 +291,16 @@ class SendStellarViewModel(
private fun createCaution(error: Throwable) = when (error) {
is UnknownHostException -> HSCaution(TranslatableString.ResString(R.string.Hud_Text_NoInternet))
is LocalizedException -> HSCaution(TranslatableString.ResString(error.errorTextRes))
is KitException -> HSCaution(handleKitException(error))
else -> HSCaution(TranslatableString.PlainString(error.message ?: ""))
}

private fun handleKitException(e: KitException) = when (e.errorType){
ErrorType.Transactions_Failed -> TranslatableString.ResString(R.string.Transactions_Failed)
}



private fun handleUpdatedAmountState(amountState: SendAmountAdvancedService.State) {
this.amountState = amountState
emitState()
Expand All @@ -302,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
Loading

0 comments on commit 1d3a9b2

Please sign in to comment.