Updated on 2026-08-14
This commit is contained in:
parent
53b02cfb10
commit
2be7445212
81 changed files with 4444 additions and 3434 deletions
|
|
@ -49,6 +49,18 @@ internal object SwapDomainModule {
|
|||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGetSwapPairUseCase(
|
||||
swapRepositoryV2: SwapRepositoryV2,
|
||||
swapErrorResolver: SwapErrorResolver,
|
||||
): GetSwapPairUseCase {
|
||||
return GetSwapPairUseCase(
|
||||
swapRepositoryV2 = swapRepositoryV2,
|
||||
swapErrorResolver = swapErrorResolver,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSelectInitialPairUseCase(
|
||||
|
|
|
|||
|
|
@ -85,11 +85,29 @@ internal class DefaultRampManager(
|
|||
cryptoCurrency: CryptoCurrency,
|
||||
): ScenarioUnavailabilityReason {
|
||||
val availabilityState = runSuspendCatching {
|
||||
getExchangeableState()
|
||||
getExchangeableState(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
)
|
||||
}.getOrNull() ?: ExpressAvailabilityState.Error
|
||||
return availabilityState.toReason(cryptoCurrency.name)
|
||||
}
|
||||
|
||||
override suspend fun availableForSwap(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencies: List<CryptoCurrency>,
|
||||
): Map<CryptoCurrency, ScenarioUnavailabilityReason> {
|
||||
val availabilityStates = runSuspendCatching {
|
||||
getExchangeableStates(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencies = cryptoCurrencies,
|
||||
)
|
||||
}.getOrNull() ?: cryptoCurrencies.associateWith { ExpressAvailabilityState.Error }
|
||||
return availabilityStates.mapValues { entry ->
|
||||
entry.value.toReason(entry.key.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSellInitializationStatus(): Flow<SellServiceInitializationStatus> {
|
||||
return sellService.initializationStatus
|
||||
}
|
||||
|
|
@ -141,9 +159,42 @@ internal class DefaultRampManager(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getExchangeableState(): ExpressAvailabilityState {
|
||||
// In task [REDACTED_TASK_KEY], removed all checks to make all tokens available
|
||||
return ExpressAvailabilityState.Available
|
||||
private suspend fun getExchangeableState(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): ExpressAvailabilityState {
|
||||
val asset = expressServiceFetcher.getInitializationStatus(userWalletId).firstOrNull()
|
||||
?: return ExpressAvailabilityState.Loading
|
||||
|
||||
return when (asset) {
|
||||
is Lce.Error -> ExpressAvailabilityState.Error
|
||||
is Lce.Loading -> ExpressAvailabilityState.Loading
|
||||
is Lce.Content -> {
|
||||
val foundAsset = asset.getOrNull()?.find { cryptoCurrency.findAssetPredicate(assetId = it.id) }
|
||||
foundAsset?.isExchangeAvailable?.toSwapAvailabilityState()
|
||||
?: ExpressAvailabilityState.AssetNotFound
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getExchangeableStates(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencies: List<CryptoCurrency>,
|
||||
): Map<CryptoCurrency, ExpressAvailabilityState> {
|
||||
val asset = expressServiceFetcher.getInitializationStatus(userWalletId).firstOrNull()
|
||||
?: return cryptoCurrencies.associateWith { ExpressAvailabilityState.Loading }
|
||||
|
||||
return when (asset) {
|
||||
is Lce.Error -> cryptoCurrencies.associateWith { ExpressAvailabilityState.Error }
|
||||
is Lce.Loading -> cryptoCurrencies.associateWith { ExpressAvailabilityState.Loading }
|
||||
is Lce.Content -> {
|
||||
val foundAsset = asset.getOrNull()
|
||||
cryptoCurrencies.associateWith { cryptoCurrency ->
|
||||
foundAsset?.find { cryptoCurrency.findAssetPredicate(assetId = it.id) }?.isExchangeAvailable
|
||||
?.toSwapAvailabilityState() ?: ExpressAvailabilityState.AssetNotFound
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getOnrampAvailableState(
|
||||
|
|
@ -177,6 +228,14 @@ internal class DefaultRampManager(
|
|||
}
|
||||
}
|
||||
|
||||
private fun Boolean.toSwapAvailabilityState(): ExpressAvailabilityState {
|
||||
return if (this) {
|
||||
ExpressAvailabilityState.Available
|
||||
} else {
|
||||
ExpressAvailabilityState.NotExchangeable
|
||||
}
|
||||
}
|
||||
|
||||
private fun Boolean.toOnrampAvailabilityState(): ExpressAvailabilityState {
|
||||
return if (this) {
|
||||
ExpressAvailabilityState.Available
|
||||
|
|
|
|||
|
|
@ -304,11 +304,14 @@ internal class ChildFactory @Inject constructor(
|
|||
createComponentChild(
|
||||
context = context,
|
||||
params = SwapComponent.Params(
|
||||
currencyFrom = route.currencyFrom,
|
||||
currencyTo = route.currencyTo,
|
||||
cryptoCurrency = route.cryptoCurrency,
|
||||
userWalletId = route.userWalletId,
|
||||
isInitialReverseOrder = route.isInitialReverseOrder,
|
||||
screenSource = route.screenSource,
|
||||
currencyPosition = when (route.currencyPosition) {
|
||||
AppRoute.Swap.CurrencyPosition.FROM -> SwapComponent.Params.CurrencyPosition.FROM
|
||||
AppRoute.Swap.CurrencyPosition.TO -> SwapComponent.Params.CurrencyPosition.TO
|
||||
AppRoute.Swap.CurrencyPosition.ANY -> SwapComponent.Params.CurrencyPosition.ANY
|
||||
},
|
||||
tangemPayInput = route.tangemPayInput?.let { tangemPayInput ->
|
||||
SwapComponent.Params.TangemPayInput(
|
||||
cryptoAmount = tangemPayInput.cryptoAmount,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue