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

SN-2813: ui lib version upgrade #183

Merged
merged 16 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ buildscript {
composeMaterial : '1.4.3',
composeCompiler : '1.4.6',
composeConstraintLayout: '1.1.0-alpha05',
uiCore : '0.1.2',
uiCore : '0.1.3',
soraCard : '0.1.40',
lazySodium : '5.0.2',
jna : '5.8.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ import java.math.BigDecimal
data class AssetAmountInputState(
val token: Token,
val balance: String,
val amount: BigDecimal,
val initialAmount: BigDecimal? = null,
val amount: BigDecimal? = null,
val amountFiat: String,
val enabled: Boolean,
val readOnly: Boolean = false,
val error: Boolean = false,
val errorHint: String = "",
val errorHint: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.domain.AssetAmountInputState
import jp.co.soramitsu.common.domain.OptionsProvider
import jp.co.soramitsu.common.presentation.compose.TokenIcon
import jp.co.soramitsu.common.util.ext.orZero
import jp.co.soramitsu.common.util.ext.testTagAsId
import jp.co.soramitsu.ui_core.component.button.properties.Size
import jp.co.soramitsu.ui_core.component.input.number.BasicNumberInput
import jp.co.soramitsu.ui_core.component.input.number.DefaultCursorPosition
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.ui_core.theme.borderRadius
import jp.co.soramitsu.ui_core.theme.customColors
Expand Down Expand Up @@ -157,7 +159,8 @@ fun AssetAmountInput(
textStyle = MaterialTheme.customTypography.displayS.copy(textAlign = TextAlign.End),
enabled = state?.let { it.enabled && !it.readOnly } ?: false,
precision = state?.token?.precision ?: OptionsProvider.defaultScale,
initial = state?.initialAmount,
defaultCursorPosition = DefaultCursorPosition.START,
initial = state?.amount,
onValueChanged = onAmountChange,
focusRequester = focusRequester,
textFieldColors = TextFieldDefaults.textFieldColors(
Expand Down Expand Up @@ -215,8 +218,7 @@ val previewAssetAmountInputState = AssetAmountInputState(
token = previewToken,
balance = "10.234 ($2.234.23)",
amountFiat = "$2.342.12",
amount = BigDecimal.ZERO,
initialAmount = null,
amount = null,
enabled = true,
error = false,
errorHint = "",
Expand All @@ -237,7 +239,6 @@ private fun PreviewAssetAmountInput() {
Button(onClick = {
state.value = state.value.copy(
amount = bb.value,
initialAmount = bb.value,
)
bb.value = bb.value.plus(BigDecimal.ONE)
}) {
Expand All @@ -255,7 +256,7 @@ private fun PreviewAssetAmountInput() {
onFocusChange = {},
)
Spacer(modifier = Modifier.size(10.dp))
Text(text = state.value.amount.toPlainString())
Text(text = state.value.amount.orZero().toPlainString())
AssetAmountInput(
modifier = Modifier,
state = previewAssetAmountInputState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ object PolkaswapFormulas {
amount: BigDecimal,
percentage: Double,
precision: Int,
): BigDecimal {
return if (percentage == 100.0) amount else amount.safeDivide(Big100, precision)
.multiply(percentage.toBigDecimal())
}
): BigDecimal = if (percentage == 100.0) amount else
amount.multiply(percentage.toBigDecimal())
.safeDivide(Big100, precision)

fun calculateOneAmountFromAnother(
amount: BigDecimal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ class QRCodeFlowViewModel @Inject constructor(
nf = numbersFormatter,
precision = DEFAULT_TOKEN_PRINT_PRECISION,
),
amount = BigDecimal.ZERO,
initialAmount = null,
amount = null,
amountFiat = "",
enabled = false,
enabled = true,
) else _requestTokenScreenState.value.assetAmountInputState!!.copy(
token = assetInUse.token,
balance = getAssetBalanceText(
Expand Down Expand Up @@ -381,7 +380,7 @@ class QRCodeFlowViewModel @Inject constructor(
_requestTokenScreenState.value.assetAmountInputState?.let { assetAmountInputState ->
_requestTokenScreenState.value = _requestTokenScreenState.value.copy(
assetAmountInputState = assetAmountInputState.copy(
initialAmount = assetAmountInputState.amount,
amount = assetAmountInputState.amount,
)
)
}
Expand Down Expand Up @@ -417,7 +416,7 @@ class QRCodeFlowViewModel @Inject constructor(
.untransformedUserAddress,
assetAmountInputState = _requestTokenScreenState.value
.assetAmountInputState?.copy(
initialAmount = _requestTokenScreenState.value
amount = _requestTokenScreenState.value
.assetAmountInputState?.amount,
enabled = false,
readOnly = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ class TransferAmountViewModel @AssistedInject constructor(
input = AssetAmountInputState(
token = asset.token,
balance = getAssetBalanceText(asset),
amount = initialSendAmount?.toBigDecimalOrNull() ?: BigDecimal.ZERO,
initialAmount = initialSendAmount?.toBigDecimalOrNull(),
amount = initialSendAmount?.toBigDecimalOrNull(),
amountFiat = "",
enabled = false,
error = false,
errorHint = "",
errorHint = ""
)
)
} else {
Expand All @@ -178,7 +177,7 @@ class TransferAmountViewModel @AssistedInject constructor(
amountFiat = asset.token.printFiat(
_sendState.value.input?.amount.orZero(),
numbersFormatter
),
)
)
)
}
Expand Down Expand Up @@ -230,7 +229,7 @@ class TransferAmountViewModel @AssistedInject constructor(
_sendState.value = _sendState.value.copy(
input = _sendState.value.input?.copy(
readOnly = false,
initialAmount = _sendState.value.input?.amount?.nullZero()
amount = _sendState.value.input?.amount?.nullZero()
),
)
}
Expand Down Expand Up @@ -393,7 +392,7 @@ class TransferAmountViewModel @AssistedInject constructor(
fun onReviewClick() {
_sendState.value = _sendState.value.copy(
input = _sendState.value.input?.copy(
initialAmount = _sendState.value.input?.amount.orZero()
amount = _sendState.value.input?.amount.orZero()
)
)
}
Expand Down Expand Up @@ -425,7 +424,6 @@ class TransferAmountViewModel @AssistedInject constructor(
_sendState.value = _sendState.value.copy(
input = _sendState.value.input?.copy(
amount = amount,
initialAmount = amount,
amountFiat = _sendState.value.input?.token?.printFiat(
amount,
numbersFormatter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class QrCodeFlowViewModelTest {

Assert.assertEquals(
viewModel.requestTokenScreenState.value.assetAmountInputState?.amount,
viewModel.requestTokenConfirmScreenState.value.assetAmountInputState?.initialAmount
viewModel.requestTokenConfirmScreenState.value.assetAmountInputState?.amount
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import javax.inject.Singleton
import jp.co.soramitsu.common.config.BuildConfigWrapper
import jp.co.soramitsu.common.domain.AppStateProvider
import jp.co.soramitsu.common.domain.fiatChange
import jp.co.soramitsu.common.logger.FirebaseWrapper
import jp.co.soramitsu.core_db.AppDatabase
import jp.co.soramitsu.core_db.model.FiatTokenPriceLocal
import jp.co.soramitsu.core_db.model.ReferralLocal
Expand Down Expand Up @@ -72,7 +73,7 @@ class BlockExplorerManager @Inject constructor(
assetsInfo = it
}

private suspend fun getAssetsInfoInternal(tokenIds: List<String>): List<Pair<String, BigInteger>> {
private suspend fun getAssetsInfoInternal(tokenIds: List<String>): List<Pair<String, BigInteger>> = runCatching {
val selected = soraConfigManager.getSelectedCurrency()
val tokens = db.assetDao().getFiatTokenPriceLocal(selected.code)
val yesterdayHour = yesterday()
Expand All @@ -87,7 +88,10 @@ class BlockExplorerManager @Inject constructor(
resultList.add(assetInfo.tokenId to BigInteger(assetInfo.liquidity))
}
db.assetDao().insertFiatPrice(fiats)
return resultList
resultList
}.getOrElse {
FirebaseWrapper.recordException(it)
emptyList()
}

suspend fun updatePoolsSbApy() {
Expand All @@ -113,6 +117,9 @@ class BlockExplorerManager @Inject constructor(
db.referralsDao().insertReferrals(it)
}
}
.onFailure {
FirebaseWrapper.recordException(it)
}
}

suspend fun getXorPerEurRatio(): Double? = runCatching {
Expand Down
Loading