Skip to content

Commit

Permalink
sc-42
Browse files Browse the repository at this point in the history
  • Loading branch information
arvifox committed Jul 31, 2024
1 parent 88d86ad commit 451c682
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import jp.co.soramitsu.ui_core.component.button.BleachedButton
import jp.co.soramitsu.ui_core.component.button.properties.Order
import jp.co.soramitsu.ui_core.component.button.properties.Size
import jp.co.soramitsu.ui_core.component.card.ContentCard
import jp.co.soramitsu.ui_core.extensions.withOpacity
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.ui_core.theme.customColors
import jp.co.soramitsu.ui_core.theme.customTypography
Expand Down Expand Up @@ -186,24 +187,28 @@ internal fun AssetDetailsBalanceCard(
AmountCardIcon(
res = R.drawable.ic_new_arrow_up_24,
text = stringResource(id = R.string.common_send),
enabled = true,
onClick = onSendClick,
)
}
AmountCardIcon(
res = R.drawable.ic_new_arrow_down_24,
text = stringResource(id = R.string.common_receive),
enabled = true,
onClick = onReceiveClick,
)
AmountCardIcon(
res = R.drawable.ic_refresh_24,
text = stringResource(id = R.string.polkaswap_swap_title),
enabled = true,
onClick = onSwapClick,
)

if (buyCryptoAvailable && onBuyCryptoClick != null) {
AmountCardIcon(
res = R.drawable.ic_buy_crypto,
text = stringResource(id = R.string.common_buy),
enabled = false,
onClick = onBuyCryptoClick
)
}
Expand All @@ -216,6 +221,7 @@ internal fun AssetDetailsBalanceCard(
private fun AmountCardIcon(
@DrawableRes res: Int,
text: String,
enabled: Boolean,
onClick: () -> Unit,
) {
Column(
Expand All @@ -228,6 +234,7 @@ private fun AmountCardIcon(
shape = CircleShape,
size = Size.Large,
order = Order.TERTIARY,
enabled = enabled,
leftIcon = painterResource(res),
onClick = onClick,
)
Expand All @@ -238,7 +245,7 @@ private fun AmountCardIcon(
.padding(top = Dimens.x1),
text = text,
style = MaterialTheme.customTypography.textXSBold,
color = MaterialTheme.customColors.fgSecondary,
color = MaterialTheme.customColors.fgSecondary.withOpacity(opacity = if (enabled) 1.0f else 0.3f),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ internal fun ProfileItems(
icon = R.drawable.ic_buy_crypto,
onClick = onSoraCardClick,
)
CategoryItem(
modifier = Modifier
.testTagAsId("BuyXor")
.padding(top = Dimens.x2),
title = stringResource(id = R.string.buy_crypto_buy_xor_with_fiat_title),
subtitle = stringResource(id = R.string.buy_crypto_buy_xor_with_fiat_subtitle),
icon = R.drawable.ic_settings_buy_crypto,
onClick = onBuyCrypto,
)
// CategoryItem(
// modifier = Modifier
// .testTagAsId("BuyXor")
// .padding(top = Dimens.x2),
// title = stringResource(id = R.string.buy_crypto_buy_xor_with_fiat_title),
// subtitle = stringResource(id = R.string.buy_crypto_buy_xor_with_fiat_subtitle),
// icon = R.drawable.ic_settings_buy_crypto,
// onClick = onBuyCrypto,
// )
}
CategoryItem(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import jp.co.soramitsu.oauth.base.sdk.contract.IbanInfo
import jp.co.soramitsu.oauth.base.sdk.contract.SoraCardCommonVerification
import jp.co.soramitsu.sora.substrate.runtime.SubstrateOptionsProvider
import kotlin.math.min
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -58,6 +59,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

internal class SoraCardInteractorImpl @Inject constructor(
private val assetsInteractor: AssetsInteractor,
Expand Down Expand Up @@ -85,38 +87,42 @@ internal class SoraCardInteractorImpl @Inject constructor(

@Suppress("UNCHECKED_CAST")
override suspend fun initialize() {
combine(
flow { emit(soraCardClientProxy.init()) },
needInstallUpdate(),
fetchApplicationFee(),
_ibanFlow.asStateFlow(),
subscribeToSoraCardAvailabilityFlow(),
checkSoraCardPending(),
_phoneFlow.asStateFlow(),
) { flows ->
val init = flows[0] as Pair<Boolean, String>
val needUpdate = flows[1] as Boolean
val fee = flows[2] as String
val ibanInfo = flows[3] as IbanInfo?
val availability = flows[4] as SoraCardAvailabilityInfo
val verification = flows[5] as SoraCardCommonVerification
val phone = flows[6] as String
SoraCardBasicStatus(
initialized = init.first,
initError = init.second,
availabilityInfo = availability,
verification = verification,
needInstallUpdate = needUpdate,
applicationFee = fee,
ibanInfo = ibanInfo,
phone = phone,
)
}
.debounce(1000)
.collect {
_soraCardBasicStatus.value = it
coroutineScope {
launch {
resetInfo()
}
resetInfo()
combine(
flow { emit(soraCardClientProxy.init()) },
needInstallUpdate(),
fetchApplicationFee(),
_ibanFlow.asStateFlow(),
subscribeToSoraCardAvailabilityFlow(),
checkSoraCardPending(),
_phoneFlow.asStateFlow(),
) { flows ->
val init = flows[0] as Pair<Boolean, String>
val needUpdate = flows[1] as Boolean
val fee = flows[2] as String
val ibanInfo = flows[3] as IbanInfo?
val availability = flows[4] as SoraCardAvailabilityInfo
val verification = flows[5] as SoraCardCommonVerification
val phone = flows[6] as String
SoraCardBasicStatus(
initialized = init.first,
initError = init.second,
availabilityInfo = availability,
verification = verification,
needInstallUpdate = needUpdate,
applicationFee = fee,
ibanInfo = ibanInfo,
phone = phone,
)
}
.debounce(1000)
.collect {
_soraCardBasicStatus.value = it
}
}
}

override val basicStatus: StateFlow<SoraCardBasicStatus> = _soraCardBasicStatus.asStateFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ class SoraCardDetailsViewModel @Inject constructor(
ibanCache = basicStatus.ibanInfo
val phoneFormatted = basicStatus.phone?.let { "+$it" }
_soraCardDetailsScreenState.value = local.copy(
soraCardIBANCardState = basicStatus.ibanInfo?.let { iban ->
SoraCardIBANCardState(
iban.iban,
iban.ibanStatus == IbanStatus.CLOSED,
)
},
soraCardIBANCardState = SoraCardIBANCardState(
iban = basicStatus.ibanInfo?.iban.orEmpty(),
closed = basicStatus.ibanInfo?.ibanStatus == IbanStatus.CLOSED,
),
soraCardMainSoraContentCardState = local.soraCardMainSoraContentCardState.copy(
balance = basicStatus.ibanInfo?.balance,
phone = phoneFormatted,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fun SoraCardMainSoraContentCard(
.padding(horizontal = Dimens.x1)
.weight(1f),
size = Size.Large,
enabled = true,
enabled = false,
order = Order.PRIMARY,
onClick = onExchangeXor,
text = stringResource(id = jp.co.soramitsu.oauth.R.string.exchange_xor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class WalletRepositoryImpl @Inject constructor(
val card = CardsHubMapper.map(cardLocal)
when (card?.cardType) {
CardHubType.GET_SORA_CARD -> if (soraCard) card else null
CardHubType.BUY_XOR_TOKEN -> if (soraCard) card else null
// CardHubType.BUY_XOR_TOKEN -> if (soraCard) card else null
CardHubType.BUY_XOR_TOKEN -> null
else -> card
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ firebaseAppDistribution = "3.2.0"
tripletVersion = "3.8.4"
timber = "5.0.1"
ktor = "2.3.1"
soracard = "1.1.15"
soracard = "1.1.16"
xnetworkingLib = "1.0.7"
xsubstrate = "1.2.7"
uicore = "0.2.32"
Expand Down

0 comments on commit 451c682

Please sign in to comment.