Skip to content

Commit

Permalink
Fix deposit/withdrawal status issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Oct 23, 2024
1 parent 918bd06 commit 85d8abc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.13.2'
abacusVersion = '1.13.8'
carteraVersion = '0.1.15'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ object DydxAlertsView : DydxComponent {
.background(color = ThemeColor.SemanticColor.layer_3.color, shape = shape)
.border(2.dp, ThemeColor.SemanticColor.layer_6.color, shape = shape)
.clip(shape)
.padding(16.dp)
.clickable {
item.tapAction?.invoke()
},
}
.padding(16.dp),
horizontalArrangement = Arrangement.spacedBy(ThemeShapes.HorizontalPadding),
verticalAlignment = Alignment.CenterVertically,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import exchange.dydx.trading.common.navigation.DydxRouter
import exchange.dydx.trading.feature.shared.R
import exchange.dydx.trading.feature.shared.views.ProgressStepView
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import java.util.Timer
import javax.inject.Inject
import kotlin.concurrent.fixedRateTimer
Expand Down Expand Up @@ -58,26 +58,30 @@ class DydxTransferStatusViewModel @Inject constructor(
}

val state: Flow<DydxTransferStatusView.ViewState?> =
abacusStateManager.state.transferStatuses
.map { statuses ->
when (transfer?.transferType) {
DydxTransferInstance.TransferType.DEPOSIT -> createDepositViewState(
transfer,
statuses,
)
combine(
abacusStateManager.state.transferStatuses,
abacusStateManager.state.transferTrackStatuses,
) { statuses, trackStatuses ->
when (transfer?.transferType) {
DydxTransferInstance.TransferType.DEPOSIT -> createDepositViewState(
transfer = transfer,
statuses = statuses,
trackStatuses = trackStatuses,
)

DydxTransferInstance.TransferType.WITHDRAWAL -> createWithdrawalViewState(
transfer,
statuses,
)
DydxTransferInstance.TransferType.WITHDRAWAL -> createWithdrawalViewState(
transfer = transfer,
statuses = statuses,
trackStatuses = trackStatuses,
)

DydxTransferInstance.TransferType.TRANSFER_OUT -> createTransferOutViewState(
transfer,
)
DydxTransferInstance.TransferType.TRANSFER_OUT -> createTransferOutViewState(
transfer,
)

else -> null
}
else -> null
}
}
.distinctUntilChanged()

override fun onCleared() {
Expand All @@ -101,9 +105,10 @@ class DydxTransferStatusViewModel @Inject constructor(
private fun createDepositViewState(
transfer: DydxTransferInstance?,
statuses: Map<String, TransferStatus>?,
trackStatuses: Map<String, Boolean>?,
): DydxTransferStatusView.ViewState {
val status = statuses?.get(transactionHash)
val routeStatus = routeStatus(statuses)
val routeStatus = routeStatus(statuses, trackStatuses)
if (routeStatus == RouteStatus.Completed && transfer != null) {
stopTrackingTransaction()
}
Expand Down Expand Up @@ -194,9 +199,10 @@ class DydxTransferStatusViewModel @Inject constructor(
private fun createWithdrawalViewState(
transfer: DydxTransferInstance?,
statuses: Map<String, TransferStatus>?,
trackStatuses: Map<String, Boolean>?,
): DydxTransferStatusView.ViewState? {
val status = statuses?.get(transactionHash)
val routeStatus = routeStatus(statuses)
val routeStatus = routeStatus(statuses, trackStatuses)
if (routeStatus == RouteStatus.Completed && transfer != null) {
stopTrackingTransaction()
}
Expand Down Expand Up @@ -360,7 +366,16 @@ class DydxTransferStatusViewModel @Inject constructor(

private fun routeStatus(
statuses: Map<String, TransferStatus>?,
trackStatus: Map<String, Boolean>?,
): RouteStatus {
if (transactionHash == null) return RouteStatus.NoHash

// Remove the "0x" prefix from the transaction hash
val hash = transactionHash.removeRange(0, 2)
if (trackStatus?.get(hash) == true) {
return RouteStatus.Completed
}

val status = statuses?.get(transactionHash) ?: return RouteStatus.NoHash

return if (status.squidTransactionStatus == "success") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class AbacusState(
}
}

val transferTrackStatuses: StateFlow<Map<String, Boolean>> by lazy {
perpetualState
.mapState(appScope) {
it?.trackStatuses?.toMap() ?: emptyMap()
}
}

/**
Account
**/
Expand Down

0 comments on commit 85d8abc

Please sign in to comment.