[#289] Crash while typing characters to Zec amount text field.
- Filed issue to SDK project. - Temporary workaround to prevent SDK from returning negative results and thus to avoid app crashing. - SuppressWarnings - ReturnCount - ZecString. - Added unit test for validation of implemented workaround.
This commit is contained in:
parent
f091da51ee
commit
e44e901676
|
@ -3,12 +3,17 @@ package cash.z.ecc.sdk.ext.ui.model
|
|||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.filters.SmallTest
|
||||
import cash.z.ecc.android.sdk.ext.Conversions
|
||||
import cash.z.ecc.sdk.model.Zatoshi
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.math.BigDecimal
|
||||
import java.util.Locale
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ZecStringTest {
|
||||
|
||||
|
@ -87,4 +92,18 @@ class ZecStringTest {
|
|||
assertNull(Zatoshi.fromZecString(context, "1,23,", EN_US_MONETARY_SEPARATORS))
|
||||
assertNull(Zatoshi.fromZecString(context, "1,234,", EN_US_MONETARY_SEPARATORS))
|
||||
}
|
||||
|
||||
// TODO [472]: https://github.com/zcash/zcash-android-wallet-sdk/issues/472
|
||||
@Test
|
||||
@SmallTest
|
||||
fun overflow_number_test() {
|
||||
assertNotNull(Zatoshi.fromZecString(context, "1", EN_US_MONETARY_SEPARATORS))
|
||||
assertNotNull(Zatoshi.fromZecString(context, "1,000", EN_US_MONETARY_SEPARATORS))
|
||||
assertNotNull(Zatoshi.fromZecString(context, "10,000,000,000", EN_US_MONETARY_SEPARATORS))
|
||||
assertNull(Zatoshi.fromZecString(context, "100,000,000,000", EN_US_MONETARY_SEPARATORS))
|
||||
|
||||
val overflowCausingNumber = 100000000000L
|
||||
assertTrue(BigDecimal(overflowCausingNumber).times(Conversions.ONE_ZEC_IN_ZATOSHI) > BigDecimal(Long.MAX_VALUE))
|
||||
assertNull(Zatoshi.fromZecString(context, overflowCausingNumber.toString(), EN_US_MONETARY_SEPARATORS))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cash.z.ecc.sdk.ext.ui.model
|
||||
|
||||
import android.content.Context
|
||||
import cash.z.ecc.android.sdk.ext.Conversions
|
||||
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString
|
||||
import cash.z.ecc.android.sdk.ext.convertZecToZatoshi
|
||||
import cash.z.ecc.sdk.ext.ui.ZecStringExt
|
||||
|
@ -67,6 +68,7 @@ fun Zatoshi.toZecString() = value.convertZatoshiToZecString(DECIMALS, DECIMALS)
|
|||
/**
|
||||
* @return [zecString] parsed into Zatoshi or null if parsing failed.
|
||||
*/
|
||||
@SuppressWarnings("ReturnCount")
|
||||
fun Zatoshi.Companion.fromZecString(
|
||||
context: Context,
|
||||
zecString: String,
|
||||
|
@ -97,5 +99,11 @@ fun Zatoshi.Companion.fromZecString(
|
|||
null
|
||||
}
|
||||
|
||||
// TODO [472]: https://github.com/zcash/zcash-android-wallet-sdk/issues/472
|
||||
// temporary workaround to prevent SDK to returns us negative result
|
||||
if (bigDecimal?.times(Conversions.ONE_ZEC_IN_ZATOSHI)?.compareTo(BigDecimal(Long.MAX_VALUE)) ?: 0 > 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return Zatoshi(bigDecimal.convertZecToZatoshi())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue