Fix: improve handling of memo length.

This commit is contained in:
Kevin Gorham 2020-03-26 09:45:31 -04:00
parent dcd1e63491
commit 28d19bce1f
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 10 additions and 5 deletions

View File

@ -51,7 +51,7 @@ class SendViewModel @Inject constructor() : ViewModel() {
var includeFromAddress: Boolean = false
set(value) {
require(!value || (value && !fromAddress.isNullOrEmpty())) {
"Error: from address was empty while attempting to include it in the memo. Verify" +
"Error: fromAddress was empty while attempting to include it in the memo. Verify" +
" that initFromAddress() has previously been called on this viewmodel."
}
field = value
@ -60,7 +60,7 @@ class SendViewModel @Inject constructor() : ViewModel() {
fun send(): Flow<PendingTransaction> {
funnel(SendSelected)
val memoToSend = if (includeFromAddress) "$memo\nsent from\n$fromAddress" else memo
val memoToSend = createMemoToSend()
val keys = initializer.deriveSpendingKeys(
lockBox.getBytes(WalletSetupViewModel.LockBoxKey.SEED)!!
)
@ -76,6 +76,8 @@ class SendViewModel @Inject constructor() : ViewModel() {
}
}
fun createMemoToSend() = if (includeFromAddress) "$memo\nsent from\n$fromAddress" else memo
private fun reportIssues(memoToSend: String) {
if (toAddress == fromAddress) feedback.report(Issue.SelfSend)
when {
@ -98,13 +100,16 @@ class SendViewModel @Inject constructor() : ViewModel() {
when {
synchronizer.validateAddress(toAddress).isNotValid -> {
emit("Please enter a valid address")
emit("Please enter a valid address.")
}
zatoshiAmount < 1 -> {
emit("Too little! Please enter at least 1 Zatoshi.")
emit("Please enter at least 1 Zatoshi.")
}
maxZatoshi != null && zatoshiAmount > maxZatoshi -> {
emit( "Too much! Please enter no more than ${maxZatoshi.convertZatoshiToZecString(8)}")
emit( "Please enter no more than ${maxZatoshi.convertZatoshiToZecString(8)} ZEC.")
}
createMemoToSend().length > ZcashSdk.MAX_MEMO_SIZE -> {
emit( "Memo must be less than ${ZcashSdk.MAX_MEMO_SIZE} in length.")
}
else -> emit(null)
}