diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index a94cf067f5..e557e59247 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -132,7 +132,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac } override fun onDestroy() { - store.dispatch(NavigationAction.ActivityDestroyed) + store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this))) super.onDestroy() } diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt index 0579c7f651..e397d78d8a 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationAction.kt @@ -1,7 +1,7 @@ package com.tangem.tap.common.redux.navigation import android.net.Uri -import androidx.fragment.app.FragmentActivity +import androidx.appcompat.app.AppCompatActivity import org.rekotlin.Action import java.lang.ref.WeakReference @@ -9,7 +9,7 @@ sealed class NavigationAction : Action { data class NavigateTo( val screen: AppScreen, val fragmentShareTransition: FragmentShareTransition? = null, - val addToBackstack: Boolean = true + val addToBackstack: Boolean = true, ) : NavigationAction() data class PopBackTo(val screen: AppScreen? = null) : NavigationAction() @@ -20,6 +20,6 @@ sealed class NavigationAction : Action { data class Share(val data: String) : NavigationAction() - data class ActivityCreated(val activity: WeakReference) : NavigationAction() - object ActivityDestroyed : NavigationAction() + data class ActivityCreated(val activity: WeakReference) : NavigationAction() + data class ActivityDestroyed(val activity: WeakReference) : NavigationAction() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt index e742aa2e6b..7d63cb95ee 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt @@ -25,7 +25,14 @@ private fun internalReduce(action: Action, state: AppState): NavigationState { state.navigationState.copy(backStack = navState.backStack.subList(0, index)) } is NavigationAction.ActivityCreated -> navState.copy(activity = navigationAction.activity) - is NavigationAction.ActivityDestroyed -> navState.copy(activity = null) + is NavigationAction.ActivityDestroyed -> { + when { + // Destroy the activity if it invoked for the same activity. Prevents overwriting to null if there is a + // new scan from the background [REDACTED_TASK_KEY] + navState.activity?.get() == navigationAction.activity.get() -> navState.copy(activity = null) + else -> navState + } + } else -> navState } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt index 9c6468c049..224e12755b 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationState.kt @@ -1,12 +1,12 @@ package com.tangem.tap.common.redux.navigation -import androidx.fragment.app.FragmentActivity +import androidx.appcompat.app.AppCompatActivity import org.rekotlin.StateType import java.lang.ref.WeakReference data class NavigationState( val backStack: List = listOf(AppScreen.Home), - val activity: WeakReference? = null + val activity: WeakReference? = null, ) : StateType enum class AppScreen { diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt index 9965636a49..3238c3b372 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/FeeReducer.kt @@ -7,6 +7,7 @@ import com.tangem.tap.features.send.redux.SendScreenAction import com.tangem.tap.features.send.redux.states.FeeState import com.tangem.tap.features.send.redux.states.FeeType import com.tangem.tap.features.send.redux.states.SendState +import com.tangem.tap.features.wallet.redux.ProgressState /** [REDACTED_AUTHOR] @@ -36,7 +37,7 @@ class FeeReducer : SendInternalReducer { private fun handleAction(action: FeeAction, sendState: SendState, state: FeeState): SendState { val result = when (action) { is FeeAction.RequestFee -> { - state + state.copy(progressState = ProgressState.Loading) } is FeeAction.ChangeLayoutVisibility -> { fun getVisibility(current: Boolean, proposed: Boolean?): Boolean = proposed ?: current @@ -68,12 +69,15 @@ class FeeReducer : SendInternalReducer { currentFee = currentFee, feeIsApproximate = isFeeApproximate(sendState), ) - } + }.copy( + progressState = ProgressState.Done, + ) } FeeAction.FeeCalculation.ClearResult -> { state.copy( feeList = null, currentFee = null, + progressState = ProgressState.Done, ) } } diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt b/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt index d9b8798a1e..79b199a5e8 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/states/FeeState.kt @@ -1,6 +1,7 @@ package com.tangem.tap.features.send.redux.states import com.tangem.blockchain.common.Amount +import com.tangem.tap.features.wallet.redux.ProgressState import java.math.BigDecimal /** @@ -20,6 +21,7 @@ data class FeeState( val controlsLayoutIsVisible: Boolean = false, val feeChipGroupIsVisible: Boolean = true, val includeFeeSwitcherIsEnabled: Boolean = true, + val progressState: ProgressState = ProgressState.Done ) : SendScreenState { override val stateId: StateId = StateId.FEE diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt index fe3bee237d..4d6d80e6ce 100644 --- a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt +++ b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt @@ -11,6 +11,7 @@ import com.tangem.tap.common.extensions.beginDelayedTransition import com.tangem.tap.common.extensions.enableError import com.tangem.tap.common.extensions.getColor import com.tangem.tap.common.extensions.getString +import com.tangem.tap.common.extensions.hide import com.tangem.tap.common.extensions.show import com.tangem.tap.common.extensions.update import com.tangem.tap.common.redux.getMessageString @@ -35,6 +36,7 @@ import com.tangem.tap.features.send.ui.SendFragment import com.tangem.tap.features.send.ui.dialogs.RequestFeeErrorDialog import com.tangem.tap.features.send.ui.dialogs.SendTransactionFailsDialog import com.tangem.tap.features.send.ui.dialogs.TezosWarningDialog +import com.tangem.tap.features.wallet.redux.ProgressState import com.tangem.tap.features.wallet.redux.WalletState.Companion.ROUGH_SIGN import com.tangem.tap.features.wallet.redux.WalletState.Companion.UNKNOWN_AMOUNT_SIGN import com.tangem.tap.features.wallet.ui.adapters.WarningMessagesAdapter @@ -62,7 +64,7 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : StateId.TRANSACTION_EXTRAS -> handleTransactionExtrasState(fg, state.transactionExtrasState) StateId.AMOUNT -> handleAmountState(fg, state.amountState) StateId.FEE -> handleFeeState(fg, state.feeState) - StateId.RECEIPT -> handleReceiptState(fg, state.receiptState) + StateId.RECEIPT -> handleReceiptState(fg, state.receiptState, state.feeState.progressState) } } } @@ -263,7 +265,11 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : if (chipGroup.checkedChipId != chipId && chipId != View.NO_ID) chipGroup.check(chipId) } - private fun handleReceiptState(fg: SendFragment, state: ReceiptState) = with(fg.binding.clReceiptContainer) { + private fun handleReceiptState( + fg: SendFragment, + state: ReceiptState, + feeProgressState: ProgressState, + ) = with(fg.binding.clReceiptContainer) { val mainLayout = clReceiptContainer as ViewGroup val totalLayout = llTotalContainer.llTotal as ViewGroup val totalTokenLayout = llTotalContainer.flTotalTokenCrypto as ViewGroup @@ -274,11 +280,22 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : return if (value == UNKNOWN_AMOUNT_SIGN) value else "$ROUGH_SIGN $value" } + when (feeProgressState) { + ProgressState.Loading -> { + tvReceiptFeeValue.hide() + pbReceiptFee.show() + } + ProgressState.Done -> { + pbReceiptFee.hide() + tvReceiptFeeValue.show() + } + } + + when (state.visibleTypeOfReceipt) { ReceiptLayoutType.FIAT -> { val receipt = state.fiat ?: return - llTotalContainer.tvTotalValue totalLayout.show(true) totalTokenLayout.show(false) tvReceiptAmountValue.update("${receipt.amountFiat} ${receipt.symbols.fiat}") @@ -290,7 +307,6 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : receipt.willSentCrypto, receipt.symbols.crypto, ) llTotalContainer.tvWillBeSentValue.update(willSent) - } ReceiptLayoutType.CRYPTO -> { val receipt = state.crypto ?: return diff --git a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt index e8e5f7550d..6ccf1b9b58 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/redux/TokensMiddleware.kt @@ -10,7 +10,6 @@ import com.tangem.common.extensions.toMapKey import com.tangem.common.hdWallet.DerivationPath import com.tangem.common.services.Result import com.tangem.domain.DomainWrapped -import com.tangem.domain.common.KeyWalletPublicKey import com.tangem.domain.common.ScanResponse import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.domain.common.TapWorkarounds.isTestCard @@ -208,19 +207,17 @@ class TokensMiddleware { when (result) { is CompletionResult.Success -> { val newDerivedKeys = result.data.entries - val updatedDerivedKeys = - mutableMapOf() + val oldDerivedKeys = scanResponse.derivedKeys - newDerivedKeys.forEach { entry -> - val derivationData = derivationDataList.find { - it.mapKeyOfWalletPublicKey == entry.key - } ?: return@forEach - updatedDerivedKeys[entry.key] = - ExtendedPublicKeysMap(derivationData.alreadyDerivedKeys + entry.value) + val walletKeys = (newDerivedKeys.keys + oldDerivedKeys.keys).toSet() + + val updatedDerivedKeys = walletKeys.associateWith { walletKey -> + val oldDerivations = ExtendedPublicKeysMap(oldDerivedKeys[walletKey] ?: emptyMap()) + val newDerivations = newDerivedKeys[walletKey] ?: ExtendedPublicKeysMap(emptyMap()) + ExtendedPublicKeysMap(oldDerivations + newDerivations) } - val updatedScanResponse = scanResponse.copy( - derivedKeys = updatedDerivedKeys + derivedKeys = updatedDerivedKeys, ) store.dispatchOnMain(GlobalAction.SaveScanNoteResponse(updatedScanResponse)) delay(DELAY_SDK_DIALOG_CLOSE) diff --git a/app/src/main/res/layout/layout_send_receipt.xml b/app/src/main/res/layout/layout_send_receipt.xml index 7309706654..2cf18b1ed5 100644 --- a/app/src/main/res/layout/layout_send_receipt.xml +++ b/app/src/main/res/layout/layout_send_receipt.xml @@ -22,10 +22,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent" android:textAllCaps="true" android:textStyle="bold" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" tools:text="75.00 usd" /> + + +