Protects against crashes when the signer sends an unverifiable payload back to Amethyst
This commit is contained in:
@@ -45,6 +45,7 @@ import androidx.compose.ui.text.AnnotatedString
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.ui.components.toasts.ThrowableToastMsg
|
import com.vitorpamplona.amethyst.ui.components.toasts.ThrowableToastMsg
|
||||||
|
import com.vitorpamplona.amethyst.ui.components.toasts.ThrowableToastMsg2
|
||||||
import com.vitorpamplona.amethyst.ui.stringRes
|
import com.vitorpamplona.amethyst.ui.stringRes
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size16dp
|
import com.vitorpamplona.amethyst.ui.theme.Size16dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||||
@@ -72,6 +73,27 @@ fun InformationDialog(
|
|||||||
InformationDialog(title = stringRes(obj.titleResId), textContent = str, moreInfo = stack, buttonColors, onDismiss)
|
InformationDialog(title = stringRes(obj.titleResId), textContent = str, moreInfo = stack, buttonColors, onDismiss)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun InformationDialog(
|
||||||
|
obj: ThrowableToastMsg2,
|
||||||
|
buttonColors: ButtonColors = ButtonDefaults.buttonColors(),
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
val str = stringRes(obj.description)
|
||||||
|
|
||||||
|
val stack =
|
||||||
|
remember(obj) {
|
||||||
|
val writer = StringWriter()
|
||||||
|
writer.append("\n")
|
||||||
|
|
||||||
|
obj.throwable.printStackTrace(PrintWriter(writer))
|
||||||
|
|
||||||
|
writer.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
InformationDialog(title = stringRes(obj.titleResId), textContent = str, moreInfo = stack, buttonColors, onDismiss)
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun InformationDialog(
|
fun InformationDialog(
|
||||||
title: String,
|
title: String,
|
||||||
|
|||||||
+6
@@ -82,6 +82,12 @@ fun DisplayErrorMessages(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is ThrowableToastMsg2 -> {
|
||||||
|
InformationDialog(obj) {
|
||||||
|
toastManager.clearToasts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
is MultiErrorToastMsg -> {
|
is MultiErrorToastMsg -> {
|
||||||
MultiUserErrorMessageDialog(obj, accountViewModel, nav)
|
MultiUserErrorMessageDialog(obj, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -28,3 +28,10 @@ class ThrowableToastMsg(
|
|||||||
val msg: String? = null,
|
val msg: String? = null,
|
||||||
val throwable: Throwable,
|
val throwable: Throwable,
|
||||||
) : ToastMsg()
|
) : ToastMsg()
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ThrowableToastMsg2(
|
||||||
|
val titleResId: Int,
|
||||||
|
val description: Int,
|
||||||
|
val throwable: Throwable,
|
||||||
|
) : ToastMsg()
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ class ToastManager {
|
|||||||
toasts.tryEmit(ThrowableToastMsg(titleResId, message, throwable))
|
toasts.tryEmit(ThrowableToastMsg(titleResId, message, throwable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toast(
|
||||||
|
titleResId: Int,
|
||||||
|
description: Int,
|
||||||
|
throwable: Throwable,
|
||||||
|
) {
|
||||||
|
toasts.tryEmit(ThrowableToastMsg2(titleResId, description, throwable))
|
||||||
|
}
|
||||||
|
|
||||||
fun toast(
|
fun toast(
|
||||||
titleResId: Int,
|
titleResId: Int,
|
||||||
resourceId: Int,
|
resourceId: Int,
|
||||||
|
|||||||
+6
@@ -962,6 +962,12 @@ class AccountViewModel(
|
|||||||
Log.w("AccountViewModel", "AutomaticallyUnauthorizedException", e)
|
Log.w("AccountViewModel", "AutomaticallyUnauthorizedException", e)
|
||||||
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
|
} catch (e: SignerExceptions.RunningOnBackgroundWithoutAutomaticPermissionException) {
|
||||||
Log.w("AccountViewModel", "TimedOutRunningOnBackgroundWithoutAutomaticPermissionExceptionException", e)
|
Log.w("AccountViewModel", "TimedOutRunningOnBackgroundWithoutAutomaticPermissionExceptionException", e)
|
||||||
|
} catch (e: IllegalStateException) {
|
||||||
|
toastManager.toast(
|
||||||
|
R.string.signer_not_found_exception,
|
||||||
|
R.string.signer_illegal_state_exception_description,
|
||||||
|
e,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,8 @@
|
|||||||
|
|
||||||
<string name="signer_not_found_exception">Signer not found</string>
|
<string name="signer_not_found_exception">Signer not found</string>
|
||||||
<string name="signer_not_found_exception_description">Was the Signer app uninstalled? Check if the signer is installed and has this account. Log off and Log in again of the signer app has changed.</string>
|
<string name="signer_not_found_exception_description">Was the Signer app uninstalled? Check if the signer is installed and has this account. Log off and Log in again of the signer app has changed.</string>
|
||||||
|
<string name="signer_illegal_state_exception">Signer misbehaved</string>
|
||||||
|
<string name="signer_illegal_state_exception_description">External signer returned a payload that is strange for the request. There might be a bug on either Amethyst or the Signer.</string>
|
||||||
|
|
||||||
<string name="zaps">Zaps</string>
|
<string name="zaps">Zaps</string>
|
||||||
<string name="view_count">View count</string>
|
<string name="view_count">View count</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user