[#974] Post SbS adoption UI changes

* [#974] Post SbS adoption UI changes

Closes #974

* [#974] Add decimals to percentage
This commit is contained in:
Honza Rychnovský 2023-10-04 14:04:08 +02:00 committed by GitHub
parent 7527cda6d5
commit 8aaa5367d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 21 deletions

View File

@ -0,0 +1,59 @@
package cash.z.ecc.sdk.extension
import androidx.test.filters.SmallTest
import cash.z.ecc.android.sdk.model.MonetarySeparators
import cash.z.ecc.android.sdk.model.PercentDecimal
import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.test.assertEquals
class PercentDecimalExtTest {
@Test
@SmallTest
fun parse_non_zero_percent_decimal_test() = runTest {
val parsed = PercentDecimal(0.1234f).toPercentageWithDecimal()
assertEquals("12${MonetarySeparators.current().decimal}34", parsed)
}
@Test
@SmallTest
fun parse_zero_percent_decimal_test() = runTest {
val parsed = PercentDecimal(0.0000f).toPercentageWithDecimal()
assertEquals("0${MonetarySeparators.current().decimal}00", parsed)
}
@Test
@SmallTest
fun parse_max_percent_decimal_test() = runTest {
val parsed = PercentDecimal(1f).toPercentageWithDecimal()
assertEquals("100${MonetarySeparators.current().decimal}00", parsed)
}
@Test
@SmallTest
fun parse_min_percent_decimal_test() = runTest {
val parsed = PercentDecimal(0f).toPercentageWithDecimal()
assertEquals("0${MonetarySeparators.current().decimal}00", parsed)
}
@Test
@SmallTest
fun parse_round_down_percent_decimal_test() = runTest {
val parsed = PercentDecimal(0.11111f).toPercentageWithDecimal()
assertEquals("11${MonetarySeparators.current().decimal}11", parsed)
}
@Test
@SmallTest
fun parse_round_up_percent_decimal_test() = runTest {
val parsed = PercentDecimal(0.11119f).toPercentageWithDecimal()
assertEquals("11${MonetarySeparators.current().decimal}12", parsed)
}
}

View File

@ -5,7 +5,6 @@ import cash.z.ecc.android.sdk.model.WalletAddress
import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.sdk.fixture.Zip321UriBuildFixture
import cash.z.ecc.sdk.fixture.Zip321UriParseFixture
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Ignore
@ -32,7 +31,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun parse_uri_not_null() = runTest {
val parsed = ZecRequest.fromUri(Zip321UriParseFixture.URI)
@ -41,7 +39,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun parse_uri_valid_result() = runTest {
val parsed = ZecRequest.fromUri(Zip321UriParseFixture.URI)
@ -52,7 +49,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun parse_uri_correct_result() = runTest {
val parsed = ZecRequest.fromUri(Zip321UriParseFixture.URI)
val expected = ZecRequest(
@ -66,7 +62,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
// TODO [#397]: Waiting for an implementation of Uri parser in SDK project
@Ignore("Waiting for an implementation of Uri parser in SDK project")
fun parse_uri_incorrect_result() = runTest {
@ -84,7 +79,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun build_uri_not_null() = runTest {
val request = Zip321UriBuildFixture.REQUEST
val built = request.toUri()
@ -94,7 +88,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun build_uri_valid_result() = runTest {
val request = Zip321UriBuildFixture.REQUEST
val built = request.toUri()
@ -105,7 +98,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
fun built_uri_correct_result() = runTest {
val request = Zip321UriBuildFixture.REQUEST
val built = request.toUri()
@ -116,7 +108,6 @@ class ZecRequestTest {
@Test
@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
// TODO [#397]: Waiting for an implementation of Uri parser in SDK project
@Ignore("Waiting for an implementation of Uri parser in SDK project")
fun build_uri_incorrect_result() = runTest {

View File

@ -0,0 +1,20 @@
@file:Suppress("ktlint:filename")
package cash.z.ecc.sdk.extension
import cash.z.ecc.android.sdk.model.MonetarySeparators
import cash.z.ecc.android.sdk.model.PercentDecimal
import java.math.RoundingMode
import java.text.DecimalFormat
@Suppress("MagicNumber")
fun PercentDecimal.toPercentageWithDecimal(decimalFormat: DecimalFormat = preparePercentDecimalFormat()): String {
return decimalFormat.format(decimal * 100)
}
private fun preparePercentDecimalFormat(): DecimalFormat = DecimalFormat().apply {
val monetarySeparators = MonetarySeparators.current()
val localizedPattern = "##0${monetarySeparators.decimal}00"
applyLocalizedPattern(localizedPattern)
roundingMode = RoundingMode.HALF_UP
}

View File

@ -1,6 +1,6 @@
@file:Suppress("ktlint:filename")
package cash.z.ecc.sdk
package cash.z.ecc.sdk.extension
import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey

View File

@ -8,9 +8,9 @@ import cash.z.ecc.android.sdk.model.MonetarySeparators
import cash.z.ecc.android.sdk.model.PercentDecimal
import cash.z.ecc.android.sdk.model.toFiatCurrencyState
import cash.z.ecc.android.sdk.model.toZecString
import cash.z.ecc.sdk.extension.toPercentageWithDecimal
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.common.toKotlinLocale
import kotlin.math.roundToInt
data class WalletDisplayValues(
val progress: PercentDecimal,
@ -42,7 +42,6 @@ data class WalletDisplayValues(
when (walletSnapshot.status) {
Synchronizer.Status.SYNCING -> {
progress = walletSnapshot.progress
val progressPercent = (walletSnapshot.progress.decimal * 100).roundToInt()
// we add "so far" to the amount
if (fiatCurrencyAmountState != FiatCurrencyConversionRateState.Unavailable) {
fiatCurrencyAmountText = context.getString(
@ -50,7 +49,10 @@ data class WalletDisplayValues(
fiatCurrencyAmountText
)
}
statusText = context.getString(R.string.home_status_syncing_format, progressPercent)
statusText = context.getString(
R.string.home_status_syncing_format,
walletSnapshot.progress.toPercentageWithDecimal()
)
}
Synchronizer.Status.SYNCED -> {
statusText = if (updateAvailable) {

View File

@ -311,11 +311,6 @@ private fun HomeMainContent(
) {
Status(walletSnapshot, isUpdateAvailable, isFiatConversionEnabled, isCircularProgressBarEnabled)
if (walletSnapshot.status == Synchronizer.Status.SYNCING) {
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
Body(text = stringResource(id = R.string.home_information))
}
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
PrimaryButton(

View File

@ -16,7 +16,7 @@ import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.ZecSend
import cash.z.ecc.sdk.send
import cash.z.ecc.sdk.extension.send
import co.electriccoin.zcash.spackle.Twig
import co.electriccoin.zcash.ui.MainActivity
import co.electriccoin.zcash.ui.screen.home.model.spendableBalance

View File

@ -3,14 +3,14 @@
<string name="home_button_receive">Receive</string>
<string name="home_button_send">Send</string>
<string name="home_button_history">Transaction History</string>
<string name="home_information">You wont be able to transfer funds until your wallet is finished syncing. Please keep your device plugged in and the app open.</string>
<string name="home_menu_seed_phrase">My secret phrase</string>
<string name="home_menu_settings">Settings</string>
<string name="home_menu_about">About</string>
<string name="home_menu_support">Contact support</string>
<string name="home_status_syncing_format" formatted="true">Syncing - <xliff:g id="synced_percent" example="50">%1$d</xliff:g>%%</string> <!-- double %% for escaping -->
<string name="home_status_syncing_format" formatted="true">Syncing - <xliff:g id="synced_percent" example="50.25">
%1$s</xliff:g>%%</string> <!-- double %% for escaping -->
<string name="home_status_syncing_catchup">Syncing</string>
<string name="home_status_syncing_amount_suffix" formatted="true"><xliff:g id="amount_prefix" example="123$">%1$s</xliff:g> so far</string>
<string name="home_status_syncing_additional_information">We will show you funds as we discover them.</string>