From 28d19bce1ff51452cfbb638bd6009e7e915179d4 Mon Sep 17 00:00:00 2001 From: Kevin Gorham Date: Thu, 26 Mar 2020 09:45:31 -0400 Subject: [PATCH] Fix: improve handling of memo length. --- .../cash/z/ecc/android/ui/send/SendViewModel.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/cash/z/ecc/android/ui/send/SendViewModel.kt b/app/src/main/java/cash/z/ecc/android/ui/send/SendViewModel.kt index 986a426..2433543 100644 --- a/app/src/main/java/cash/z/ecc/android/ui/send/SendViewModel.kt +++ b/app/src/main/java/cash/z/ecc/android/ui/send/SendViewModel.kt @@ -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 { 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) }