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

Fix missing Swap progress link #1210

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -2,7 +2,7 @@ package com.vultisig.wallet.ui.models

import androidx.lifecycle.ViewModel
import com.vultisig.wallet.ui.models.keysign.KeysignViewModel
import com.vultisig.wallet.ui.models.keysign.TransitionTypeUiModel
import com.vultisig.wallet.ui.models.keysign.TransactionTypeUiModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
Expand All @@ -15,7 +15,7 @@ internal class KeySignWrapperViewModel @AssistedInject constructor(
@Assisted val viewModel: KeysignViewModel,
) : ViewModel() {

val transactionUiModel = MutableStateFlow<TransitionTypeUiModel?>(null)
val transactionUiModel = MutableStateFlow<TransactionTypeUiModel?>(null)

@AssistedFactory
interface Factory {
Expand All @@ -27,7 +27,7 @@ internal class KeySignWrapperViewModel @AssistedInject constructor(
}

fun loadTransaction() {
viewModel.transitionTypeUiModel?.let { transactionUiType ->
viewModel.transactionTypeUiModel?.let { transactionUiType ->
transactionUiModel.update { transactionUiType }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ internal class JoinKeysignViewModel @Inject constructor(
private var _jobWaitingForKeysignStart: Job? = null
private var isNavigateToHome: Boolean = false

private var transitionTypeUiModel: TransitionTypeUiModel? = null
private var transactionTypeUiModel: TransactionTypeUiModel? = null

private val keysignPayload: KeysignPayload?
get() = _keysignPayload
Expand All @@ -196,7 +196,7 @@ internal class JoinKeysignViewModel @Inject constructor(
sessionApi = sessionApi,
suiApi = suiApi,
navigator = navigator,
transitionTypeUiModel = transitionTypeUiModel,
transactionTypeUiModel = transactionTypeUiModel,
encryption = encryption,
featureFlagApi = featureFlagApi,
)
Expand Down Expand Up @@ -308,7 +308,7 @@ internal class JoinKeysignViewModel @Inject constructor(
),
)

transitionTypeUiModel = TransitionTypeUiModel.Swap(swapTransaction)
transactionTypeUiModel = TransactionTypeUiModel.Swap(swapTransaction)

verifyUiModel.value = VerifyUiModel.Swap(
VerifySwapUiModel(
Expand Down Expand Up @@ -341,7 +341,7 @@ internal class JoinKeysignViewModel @Inject constructor(
convertTokenValueToFiat(dstToken, quote.fees, currency)
),
)
transitionTypeUiModel = TransitionTypeUiModel.Swap(swapTransactionUiModel)
transactionTypeUiModel = TransactionTypeUiModel.Swap(swapTransactionUiModel)
verifyUiModel.value = VerifyUiModel.Swap(
VerifySwapUiModel(
provider = R.string.swap_form_provider_thorchain.asUiText(),
Expand Down Expand Up @@ -374,7 +374,7 @@ internal class JoinKeysignViewModel @Inject constructor(
convertTokenValueToFiat(nativeToken, quote.fees, currency)
),
)
transitionTypeUiModel = TransitionTypeUiModel.Swap(swapTransactionUiModel)
transactionTypeUiModel = TransactionTypeUiModel.Swap(swapTransactionUiModel)
verifyUiModel.value = VerifyUiModel.Swap(
VerifySwapUiModel(
provider = R.string.swap_form_provider_mayachain.asUiText(),
Expand Down Expand Up @@ -417,7 +417,7 @@ internal class JoinKeysignViewModel @Inject constructor(
),
memo = payload.memo ?: "",
)
transitionTypeUiModel = TransitionTypeUiModel.Deposit(depositTransactionUiModel)
transactionTypeUiModel = TransactionTypeUiModel.Deposit(depositTransactionUiModel)
verifyUiModel.value = VerifyUiModel.Deposit(
VerifyDepositUiModel(
depositTransactionUiModel
Expand Down Expand Up @@ -469,7 +469,7 @@ internal class JoinKeysignViewModel @Inject constructor(
)

val transactionToUiModel = mapTransactionToUiModel(transaction)
transitionTypeUiModel = TransitionTypeUiModel.Send(transactionToUiModel)
transactionTypeUiModel = TransactionTypeUiModel.Send(transactionToUiModel)
verifyUiModel.value = VerifyUiModel.Send(
VerifyTransactionUiModel(
transaction = transactionToUiModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal class KeysignFlowViewModel @Inject constructor(
networkOption.value == NetworkPromptOption.INTERNET || isFastSign
}

private var transitionTypeUiModel: TransitionTypeUiModel? = null
private var transactionTypeUiModel: TransactionTypeUiModel? = null


val keysignViewModel: KeysignViewModel
Expand All @@ -186,7 +186,7 @@ internal class KeysignFlowViewModel @Inject constructor(
navigator = navigator,
encryption = encryption,
featureFlagApi = featureFlagApi,
transitionTypeUiModel = transitionTypeUiModel
transactionTypeUiModel = transactionTypeUiModel
)

init {
Expand Down Expand Up @@ -417,20 +417,20 @@ internal class KeysignFlowViewModel @Inject constructor(
else -> false
}
viewModelScope.launch {
transitionTypeUiModel = when {
isSwap -> TransitionTypeUiModel.Swap(
transactionTypeUiModel = when {
isSwap -> TransactionTypeUiModel.Swap(
mapSwapTransactionToUiModel(
swapTransactionRepository.getTransaction(transactionId)
)
)

isDeposit -> TransitionTypeUiModel.Deposit(
isDeposit -> TransactionTypeUiModel.Deposit(
mapDepositTransactionUiModel(
depositTransactionRepository.getTransaction(transactionId)
)
)

else -> TransitionTypeUiModel.Send(
else -> TransactionTypeUiModel.Send(
mapTransactionToUiModel(
transactionRepository.getTransaction(
transactionId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ internal sealed class KeysignState {
}


internal sealed interface TransitionTypeUiModel {
data class Send(val transactionUiModel: TransactionUiModel) : TransitionTypeUiModel
data class Swap(val swapTransactionUiModel: SwapTransactionUiModel) : TransitionTypeUiModel
data class Deposit(val depositTransactionUiModel: DepositTransactionUiModel) : TransitionTypeUiModel
internal sealed interface TransactionTypeUiModel {
data class Send(val transactionUiModel: TransactionUiModel) : TransactionTypeUiModel
data class Swap(val swapTransactionUiModel: SwapTransactionUiModel) : TransactionTypeUiModel
data class Deposit(val depositTransactionUiModel: DepositTransactionUiModel) : TransactionTypeUiModel
}

internal class KeysignViewModel(
Expand All @@ -95,13 +95,11 @@ internal class KeysignViewModel(
private val sessionApi: SessionApi,
private val encryption: Encryption,
private val featureFlagApi: FeatureFlagApi,
val transitionTypeUiModel: TransitionTypeUiModel?,
val transactionTypeUiModel: TransactionTypeUiModel?,
) : ViewModel() {
private var tssInstance: ServiceImpl? = null
private var tssMessenger: TssMessenger? = null
private val localStateAccessor: LocalStateAccessor = LocalStateAccessor(vault)
var isThorChainSwap =
keysignPayload.swapPayload is SwapPayload.ThorChain
val currentState: MutableStateFlow<KeysignState> =
MutableStateFlow(KeysignState.CreatingInstance)
private var _messagePuller: TssMessagePuller? = null
Expand All @@ -117,6 +115,12 @@ internal class KeysignViewModel(
private var featureFlag: FeatureFlagJson? = null
private var isNavigateToHome: Boolean = false

val swapProgressLink = txHash.map {
explorerLinkRepository.getSwapProgressLink(it, keysignPayload.swapPayload)
}.stateIn(
viewModelScope, SharingStarted.WhileSubscribed(), null
)

fun startKeysign() {
viewModelScope.launch {
withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.vultisig.wallet.ui.screens
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -12,7 +13,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
Expand All @@ -36,7 +36,7 @@ import com.vultisig.wallet.ui.components.library.form.FormCard
import com.vultisig.wallet.ui.components.library.form.FormDetails
import com.vultisig.wallet.ui.models.TransactionUiModel
import com.vultisig.wallet.ui.models.deposit.DepositTransactionUiModel
import com.vultisig.wallet.ui.models.keysign.TransitionTypeUiModel
import com.vultisig.wallet.ui.models.keysign.TransactionTypeUiModel
import com.vultisig.wallet.ui.models.swap.SwapTransactionUiModel
import com.vultisig.wallet.ui.screens.send.AddressField
import com.vultisig.wallet.ui.screens.send.OtherField
Expand All @@ -47,8 +47,8 @@ internal fun TransactionDoneScreen(
navController: NavController,
transactionHash: String,
transactionLink: String,
isThorChainSwap: Boolean,
transitionTypeUiModel: TransitionTypeUiModel,
progressLink:String?,
transactionTypeUiModel: TransactionTypeUiModel,
) {
UiBarContainer(
navController = navController,
Expand All @@ -58,8 +58,8 @@ internal fun TransactionDoneScreen(
transactionHash = transactionHash,
transactionLink = transactionLink,
onComplete = navController::popBackStack,
isThorChainSwap = isThorChainSwap,
transitionTypeUiModel = transitionTypeUiModel,
progressLink = progressLink,
transactionTypeUiModel = transactionTypeUiModel,
)
}
}
Expand All @@ -69,12 +69,11 @@ internal fun TransactionDoneView(
transactionHash: String,
transactionLink: String,
onComplete: () -> Unit,
isThorChainSwap: Boolean = false,
progressLink: String?,
onBack: () -> Unit = {},
transitionTypeUiModel: TransitionTypeUiModel?,
transactionTypeUiModel: TransactionTypeUiModel?,
) {
val uriHandler = LocalUriHandler.current
val context = LocalContext.current
BackHandler(onBack = onBack)
Column(
modifier = Modifier
Expand Down Expand Up @@ -125,39 +124,20 @@ internal fun TransactionDoneView(
color = Theme.colors.turquoise800,
style = Theme.menlo.subtitle3,
)
if (isThorChainSwap) {
Text(
modifier = Modifier
.align(Alignment.End)
.clickOnce {
uriHandler.openUri(
context.getString(
R.string.transaction_done_track_ninerealms,
transactionHash
)
)
},
text = stringResource(R.string.transaction_swap_tracking_link),
color = Theme.colors.turquoise800,
style = Theme.montserrat.body3.copy(
textDecoration = TextDecoration.Underline,
lineHeight = 22.sp
),

)
}
when (transactionTypeUiModel) {
is TransactionTypeUiModel.Deposit ->
DepositTransactionDetail(transactionTypeUiModel.depositTransactionUiModel)

when (transitionTypeUiModel) {
is TransitionTypeUiModel.Deposit ->
DepositTransactionDetail(transitionTypeUiModel.depositTransactionUiModel)
is TransactionTypeUiModel.Send ->
TransactionDetail(transaction = transactionTypeUiModel.transactionUiModel)

is TransitionTypeUiModel.Send ->
TransactionDetail(transaction = transitionTypeUiModel.transactionUiModel)

is TransitionTypeUiModel.Swap -> SwapTransactionDetail(
swapTransaction =
transitionTypeUiModel.swapTransactionUiModel
)
is TransactionTypeUiModel.Swap -> SwapTransactionDetail(
swapTransaction = transactionTypeUiModel.swapTransactionUiModel,
progressLink = progressLink,
) { progressLink ->
uriHandler.openUri(progressLink)
}
else -> Unit
}

Expand Down Expand Up @@ -209,7 +189,11 @@ private fun DepositTransactionDetail(depositTransaction: DepositTransactionUiMod
}

@Composable
private fun SwapTransactionDetail(swapTransaction: SwapTransactionUiModel?) {
private fun ColumnScope.SwapTransactionDetail(
swapTransaction: SwapTransactionUiModel?,
progressLink: String?,
onProgressLinkClick: (String) -> Unit,
) {
if (swapTransaction != null) {
AddressField(
title = stringResource(R.string.verify_transaction_from_title),
Expand All @@ -231,8 +215,24 @@ private fun SwapTransactionDetail(swapTransaction: SwapTransactionUiModel?) {
OtherField(
title = stringResource(R.string.verify_swap_screen_estimated_fees),
value = swapTransaction.estimatedFees,
divider = false,
)

if (progressLink != null) {
Text(
modifier = Modifier
.padding(top = 8.dp)
.align(Alignment.End)
.clickOnce(onClick = {
onProgressLinkClick(progressLink)
}),
text = stringResource(R.string.transaction_swap_tracking_link),
color = Theme.colors.turquoise800,
style = Theme.montserrat.body3.copy(
textDecoration = TextDecoration.Underline,
lineHeight = 22.sp
),
)
}
}
}

Expand Down Expand Up @@ -314,8 +314,8 @@ private fun TransactionDoneScreenPreview() {
navController = rememberNavController(),
transactionHash = "0x1234567890",
transactionLink = "",
isThorChainSwap = true,
transitionTypeUiModel = TransitionTypeUiModel.Send(
progressLink = "https://track.ninerealms.com/",
transactionTypeUiModel = TransactionTypeUiModel.Send(
TransactionUiModel(
srcAddress = "0x1234567890",
dstAddress = "0x1234567890",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ internal fun JoinKeysignView(
state = kState,
txHash = keysignViewModel.txHash.collectAsState().value,
transactionLink = keysignViewModel.txLink.collectAsState().value,
isThorChainSwap = keysignViewModel.isThorChainSwap,
progressLink = keysignViewModel.swapProgressLink.collectAsState().value,
onComplete = {
navController.navigate(Destination.Home().route)
},
onBack = keysignViewModel::navigateToHome,
transitionTypeUiModel = keysignViewModel.transitionTypeUiModel
transactionTypeUiModel = keysignViewModel.transactionTypeUiModel
)
}

Expand Down
Loading
Loading