Skip to content

Commit

Permalink
[#1434] Improve Shielding UX
Browse files Browse the repository at this point in the history
* [#1434] Improve Shielding UX

- Closes #1434
- Changelog update

* Trigger balances refresh after sending too
  • Loading branch information
HonzaR committed May 6, 2024
1 parent 6160554 commit 5c21a77
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ directly impact users rather than highlighting other key architectural updates.*
design

### Fixed
- Transparent funds shielding action has been improved to address the latest user feedback
- A few more minor UI improvements

## [1.0 (638)] - 2024-04-26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package co.electriccoin.zcash.ui.screen.balances

import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -113,6 +114,11 @@ internal fun WrapBalances(

val (isShowingErrorDialog, setShowErrorDialog) = rememberSaveable { mutableStateOf(false) }

fun showShieldingSuccess() {
setShieldState(ShieldState.Shielded)
Toast.makeText(context, context.getString(R.string.balances_shielding_successful), Toast.LENGTH_LONG).show()
}

suspend fun showShieldingError(errorMessage: String?) {
Twig.error { "Shielding proposal failed with: $errorMessage" }

Expand Down Expand Up @@ -167,16 +173,18 @@ internal fun WrapBalances(
spendingKey = spendingKey,
proposal = newProposal
)

// Triggering the transaction history and balances refresh to be notified immediately
// about the wallet's updated state
(synchronizer as SdkSynchronizer).run {
refreshTransactions()
refreshAllBalances()
}

when (result) {
SubmitResult.Success -> {
Twig.info { "Shielding transaction done successfully" }
setShieldState(ShieldState.Shielded)
// Triggering transaction history refresh to be notified about the newly created
// transaction asap
(synchronizer as SdkSynchronizer).refreshTransactions()

// We could consider notifying UI with a change to emphasize the shielding action
// was successful, or we could switch the selected tab to Account
showShieldingSuccess()
}
is SubmitResult.SimpleTrxFailure -> {
Twig.warn { "Shielding transaction failed" }
Expand Down Expand Up @@ -205,15 +213,9 @@ fun updateTransparentBalanceState(
walletSnapshot: WalletSnapshot?
): ShieldState {
return when {
(walletSnapshot == null) -> {
currentShieldState
}
(
walletSnapshot.transparentBalance >= Zatoshi(DEFAULT_SHIELDING_THRESHOLD) &&
currentShieldState.isEnabled()
) -> ShieldState.Available
else -> {
currentShieldState
}
(walletSnapshot == null) -> currentShieldState
(walletSnapshot.transparentBalance >= Zatoshi(DEFAULT_SHIELDING_THRESHOLD) && currentShieldState.isEnabled()) ->
ShieldState.Available
else -> currentShieldState
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal fun MainActivity.WrapSendConfirmation(

@VisibleForTesting
@Composable
@Suppress("LongParameterList", "LongMethod")
@Suppress("LongParameterList", "LongMethod", "CyclomaticComplexMethod")
internal fun WrapSendConfirmation(
activity: ComponentActivity,
arguments: SendConfirmationArguments,
Expand Down Expand Up @@ -182,12 +182,17 @@ internal fun WrapSendConfirmation(
spendingKey = spendingKey,
proposal = newZecSend.proposal!!
)

// Triggering the transaction history and balances refresh to be notified immediately
// about the wallet's updated state
(synchronizer as SdkSynchronizer).run {
refreshTransactions()
refreshAllBalances()
}

when (result) {
SubmitResult.Success -> {
setStage(SendConfirmationStage.Confirmation)
// Triggering transaction history refreshing to be notified about the newly created
// transaction asap
(synchronizer as SdkSynchronizer).refreshTransactions()
goHome()
}
is SubmitResult.SimpleTrxFailure -> {
Expand Down
2 changes: 2 additions & 0 deletions ui-lib/src/main/res/ui/balances/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<string name="balances_status_detailed_stopped">Synchronizer stopped</string>
<string name="balances_status_restoring_text">The restore process can take several hours on lower-powered devices, and even on powerful devices is likely to take more than an hour.</string>

<string name="balances_shielding_successful">Shielding has been successfully submitted</string>

<string name="balances_shielding_dialog_error_title">Failed to shield funds</string>
<string name="balances_shielding_dialog_error_text">Error: The attempt to shield the transparent funds failed. Try it again, please.</string>
<string name="balances_shielding_dialog_error_btn">OK</string>
Expand Down

0 comments on commit 5c21a77

Please sign in to comment.