Skip to content

Commit 215ada9

Browse files
author
Tangem
committed
${LATEST_TAG}
1 parent 0a55ed4 commit 215ada9

4 files changed

Lines changed: 91 additions & 46 deletions

File tree

features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,48 +140,65 @@ internal class DefaultSendComponent @AssistedInject constructor(
140140
),
141141
)
142142

143-
private fun getAmountComponent(factoryContext: AppComponentContext, route: SendRoute) = SendAmountComponent(
144-
appComponentContext = factoryContext,
145-
params = SendAmountComponentParams.AmountParams(
146-
state = model.uiState.value.amountUM,
147-
currentRoute = currentRoute.filterIsInstance<SendRoute.Amount>(),
148-
isBalanceHidingFlow = model.isBalanceHiddenFlow,
149-
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
150-
userWallet = model.userWallet,
151-
appCurrency = model.appCurrency,
152-
cryptoCurrencyStatus = model.cryptoCurrencyStatus,
153-
callback = model,
154-
isEditMode = route.isEditMode,
155-
predefinedAmountValue = model.predefinedAmountValue,
156-
),
157-
)
143+
private fun getAmountComponent(factoryContext: AppComponentContext, route: SendRoute): ComposableContentComponent {
144+
val cryptoCurrencyStatus = model.cryptoCurrencyStatus
145+
return if (cryptoCurrencyStatus != null) {
146+
SendAmountComponent(
147+
appComponentContext = factoryContext,
148+
params = SendAmountComponentParams.AmountParams(
149+
state = model.uiState.value.amountUM,
150+
currentRoute = currentRoute.filterIsInstance<SendRoute.Amount>(),
151+
isBalanceHidingFlow = model.isBalanceHiddenFlow,
152+
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
153+
userWallet = model.userWallet,
154+
appCurrency = model.appCurrency,
155+
cryptoCurrencyStatus = cryptoCurrencyStatus,
156+
callback = model,
157+
isEditMode = route.isEditMode,
158+
predefinedAmountValue = model.predefinedAmountValue,
159+
),
160+
)
161+
} else {
162+
model.showAlertError()
163+
getStubComponent()
164+
}
165+
}
158166

167+
@Suppress("ComplexCondition")
159168
private fun getFeeComponent(factoryContext: AppComponentContext): ComposableContentComponent {
160169
val state = model.uiState.value
161170
val sendAmount = (state.amountUM as? AmountState.Data)?.amountTextField?.cryptoAmount?.value
162171
val destinationAddress = (state.destinationUM as? DestinationUM.Content)?.addressTextField?.value
163-
return if (sendAmount != null && destinationAddress != null) {
172+
val cryptoCurrencyStatus = model.cryptoCurrencyStatus
173+
val feeCryptoCurrencyStatus = model.feeCryptoCurrencyStatus
174+
175+
return if (sendAmount != null && destinationAddress != null &&
176+
feeCryptoCurrencyStatus != null && cryptoCurrencyStatus != null
177+
) {
164178
SendFeeComponent(
165179
appComponentContext = factoryContext,
166180
params = SendFeeComponentParams.FeeParams(
167181
state = model.uiState.value.feeUM,
168182
currentRoute = currentRoute.filterIsInstance<SendRoute.Fee>(),
169183
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
170184
userWallet = model.userWallet,
171-
cryptoCurrencyStatus = model.cryptoCurrencyStatus,
172-
feeCryptoCurrencyStatus = model.feeCryptoCurrencyStatus,
185+
cryptoCurrencyStatus = cryptoCurrencyStatus,
186+
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
173187
appCurrency = model.appCurrency,
174188
sendAmount = sendAmount,
175189
destinationAddress = destinationAddress,
176190
callback = model,
177191
),
178192
)
179193
} else {
194+
model.showAlertError()
180195
getStubComponent()
181196
}
182197
}
183198

184-
private fun getConfirmComponent(factoryContext: AppComponentContext): SendConfirmComponent {
199+
private fun getConfirmComponent(factoryContext: AppComponentContext): ComposableContentComponent {
200+
val cryptoCurrencyStatus = model.cryptoCurrencyStatus
201+
val feeCryptoCurrencyStatus = model.feeCryptoCurrencyStatus
185202
val predefinedAmount = params.amount
186203
val predefinedTxId = params.transactionId
187204
val predefinedAddress = params.destinationAddress
@@ -196,31 +213,44 @@ internal class DefaultSendComponent @AssistedInject constructor(
196213
} else {
197214
SendConfirmComponent.Params.PredefinedValues.Empty
198215
}
199-
return SendConfirmComponent(
200-
appComponentContext = factoryContext,
201-
params = SendConfirmComponent.Params(
202-
state = model.uiState.value,
203-
userWallet = model.userWallet,
204-
currentRoute = currentRoute,
205-
isBalanceHidingFlow = model.isBalanceHiddenFlow,
206-
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
207-
cryptoCurrencyStatus = model.cryptoCurrencyStatus,
208-
feeCryptoCurrencyStatus = model.feeCryptoCurrencyStatus,
209-
appCurrency = model.appCurrency,
210-
callback = model,
211-
predefinedValues = predefinedValues,
212-
),
213-
)
216+
return if (cryptoCurrencyStatus != null && feeCryptoCurrencyStatus != null) {
217+
SendConfirmComponent(
218+
appComponentContext = factoryContext,
219+
params = SendConfirmComponent.Params(
220+
state = model.uiState.value,
221+
userWallet = model.userWallet,
222+
currentRoute = currentRoute,
223+
isBalanceHidingFlow = model.isBalanceHiddenFlow,
224+
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
225+
cryptoCurrencyStatus = cryptoCurrencyStatus,
226+
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
227+
appCurrency = model.appCurrency,
228+
callback = model,
229+
predefinedValues = predefinedValues,
230+
),
231+
)
232+
} else {
233+
model.showAlertError()
234+
getStubComponent()
235+
}
214236
}
215237

216-
private fun getStubComponent() = ComposableContentComponent { }
238+
private fun getStubComponent() = StubComponent()
239+
240+
class StubComponent : ComposableContentComponent {
241+
@Composable
242+
override fun Content(modifier: Modifier) {
243+
}
244+
}
217245

218246
private fun onChildBack() {
219247
val isEmptyRoute = childStack.value.active.configuration == SendRoute.Empty
220248
val isEmptyStack = childStack.value.backStack.isEmpty()
221249
val isSuccess = model.uiState.value.confirmUM is ConfirmUM.Success
250+
val isStubComponent = childStack.value.active.instance is StubComponent
222251

223-
if (isEmptyRoute || isEmptyStack || isSuccess) {
252+
val isPopSend = isEmptyRoute || isEmptyStack || isSuccess || isStubComponent
253+
if (isPopSend) {
224254
router.pop()
225255
} else {
226256
stackNavigation.pop()

features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmAlertFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ internal class SendConfirmAlertFactory @Inject constructor(
1616
private val messageSender: UiMessageSender,
1717
) {
1818

19-
fun getGenericErrorState(onFailedTxEmailClick: () -> Unit) {
19+
fun getGenericErrorState(onFailedTxEmailClick: () -> Unit, popBack: () -> Unit = {}) {
2020
messageSender.send(
2121
DialogMessage(
2222
title = resourceReference(id = R.string.send_alert_transaction_failed_title),
2323
message = resourceReference(id = R.string.common_unknown_error),
24+
onDismissRequest = popBack,
2425
firstAction = EventMessageAction(
2526
title = resourceReference(R.string.common_support),
2627
onClick = onFailedTxEmailClick,

features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,11 @@ internal class SendConfirmModel @Inject constructor(
337337
ifLeft = { error ->
338338
Timber.e(error)
339339
_uiState.update(SendConfirmSendingStateTransformer(isSending = false))
340-
alertFactory.getGenericErrorState {
341-
onFailedTxEmailClick(error.localizedMessage.orEmpty())
342-
}
340+
alertFactory.getGenericErrorState(
341+
onFailedTxEmailClick = {
342+
onFailedTxEmailClick(error.localizedMessage.orEmpty())
343+
},
344+
)
343345
},
344346
ifRight = { txData ->
345347
sendTransaction(txData)

features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import com.tangem.utils.coroutines.JobHolder
4747
import com.tangem.utils.coroutines.saveIn
4848
import kotlinx.coroutines.flow.*
4949
import kotlinx.coroutines.launch
50+
import timber.log.Timber
5051
import javax.inject.Inject
5152
import kotlin.properties.Delegates
5253

@@ -89,8 +90,8 @@ internal class SendModel @Inject constructor(
8990
val isBalanceHiddenFlow = _isBalanceHiddenFlow.asStateFlow()
9091

9192
var userWallet: UserWallet by Delegates.notNull()
92-
var cryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull()
93-
var feeCryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull()
93+
var cryptoCurrencyStatus: CryptoCurrencyStatus? = null
94+
var feeCryptoCurrencyStatus: CryptoCurrencyStatus? = null
9495
var appCurrency: AppCurrency = AppCurrency.Default
9596
var predefinedAmountValue: String? = null
9697

@@ -125,6 +126,13 @@ internal class SendModel @Inject constructor(
125126
_uiState.update { sendUM }
126127
}
127128

129+
fun showAlertError() {
130+
sendConfirmAlertFactory.getGenericErrorState(
131+
onFailedTxEmailClick = ::onFailedTxEmailClick,
132+
popBack = router::pop,
133+
)
134+
}
135+
128136
private fun initAppCurrency() {
129137
modelScope.launch {
130138
appCurrency = getSelectedAppCurrencyUseCase.invokeSync().getOrElse { AppCurrency.Default }
@@ -145,7 +153,8 @@ internal class SendModel @Inject constructor(
145153
)
146154
},
147155
ifLeft = {
148-
sendConfirmAlertFactory.getGenericErrorState(::onFailedTxEmailClick)
156+
Timber.w(it.toString())
157+
showAlertError()
149158
return@launch
150159
},
151160
)
@@ -176,9 +185,12 @@ internal class SendModel @Inject constructor(
176185
)
177186
},
178187
ifLeft = {
179-
sendConfirmAlertFactory.getGenericErrorState {
180-
onFailedTxEmailClick(it.toString())
181-
}
188+
sendConfirmAlertFactory.getGenericErrorState(
189+
onFailedTxEmailClick = {
190+
onFailedTxEmailClick(it.toString())
191+
},
192+
popBack = router::pop,
193+
)
182194
},
183195
)
184196
}.launchIn(modelScope)

0 commit comments

Comments
 (0)