Skip to content

Commit

Permalink
feat: Android dd confirmation (#2010)
Browse files Browse the repository at this point in the history
* added dd confirmation dialog

* integrated auth confirmation dialog

* added message and handling for empty keys list
  • Loading branch information
Dmitry-Borodin authored Aug 18, 2023
1 parent c8bd784 commit 2e4ab4c
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.parity.signer.screens.scan.errors.TransactionErrorModel
import io.parity.signer.screens.scan.transaction.TransactionPreviewType
import io.parity.signer.screens.scan.transaction.TransactionsScreenFull
import io.parity.signer.screens.scan.transaction.dynamicderivations.AddDerivedKeysScreen
import io.parity.signer.screens.scan.transaction.dynamicderivations.AddDynamicDerivationScreenFull
import io.parity.signer.screens.scan.transaction.previewType
import io.parity.signer.ui.BottomSheetWrapperRoot
import io.parity.signer.uniffi.Action
Expand Down Expand Up @@ -105,9 +106,8 @@ fun ScanNavSubgraph(
},
)
} else if (dynamicDerivationsData != null) {
AddDerivedKeysScreen(
AddDynamicDerivationScreenFull(
model = dynamicDerivationsData,
modifier = Modifier.statusBarsPadding(),
onBack = scanViewModel::clearState,
onDone = {
scanViewModel.createDynamicDerivations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,19 @@ class ScanViewModel : ViewModel() {
}

is OperationResult.Ok -> {
clearState()
Toast.makeText(
context, context.getString(R.string.create_derivations_success),
Toast.LENGTH_SHORT
).show()
}
}
} else {
//list of derivations is empty
clearState()
Toast.makeText(
context, context.getString(R.string.create_derivations_empty),
Toast.LENGTH_SHORT
).show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.parity.signer.screens.scan.transaction.dynamicderivations

import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.parity.signer.R
import io.parity.signer.components.base.PrimaryButtonWide
import io.parity.signer.components.base.SecondaryButtonWide
import io.parity.signer.domain.Callback
import io.parity.signer.ui.theme.SignerNewTheme
import io.parity.signer.ui.theme.SignerTypeface
import io.parity.signer.ui.theme.textSecondary

@Composable
internal fun AddDDConfirmBottomSheet(
onConfirm: Callback,
onCancel: Callback,
) {
val sidePadding = 24.dp
Column(
modifier = Modifier
.fillMaxWidth()
.padding(start = sidePadding, end = sidePadding),
horizontalAlignment = Alignment.CenterHorizontally,
) {

Text(
text = stringResource(R.string.confirm_dynamic_derivation_header),
color = MaterialTheme.colors.primary,
style = SignerTypeface.TitleL,
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 24.dp)
)
Text(
modifier = Modifier.padding(top = 12.dp, bottom = 24.dp),
text = stringResource(R.string.confirm_dynamic_derivation_message),
color = MaterialTheme.colors.textSecondary,
style = SignerTypeface.BodyL,
textAlign = TextAlign.Center,
)

PrimaryButtonWide(
label = stringResource(R.string.confirm_dynamic_derivation_cta),
onClicked = onConfirm,
modifier = Modifier.padding(bottom = 8.dp)
)

SecondaryButtonWide(
label = stringResource(R.string.generic_cancel),
withBackground = true,
onClicked = onCancel,
modifier = Modifier.padding(bottom = 24.dp)
)
}
}


@Preview(
name = "light", group = "themes", uiMode = Configuration.UI_MODE_NIGHT_NO,
showBackground = true, backgroundColor = 0xFFFFFFFF,
)
@Preview(
name = "dark", group = "themes",
uiMode = Configuration.UI_MODE_NIGHT_YES,
showBackground = true, backgroundColor = 0xFF000000,
)
@Composable
private fun PreviewConfirmExportPrivateKeyMenu() {
SignerNewTheme {
AddDDConfirmBottomSheet({}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ import io.parity.signer.uniffi.QrData
import io.parity.signer.uniffi.SignerImage

@Composable
fun AddDerivedKeysScreen(
internal fun AddDerivedKeysScreen(
model: DdPreview,
modifier: Modifier = Modifier,
onBack: Callback,
onDone: Callback,
) {
BackHandler(onBack = onBack)

Column(
modifier = modifier.verticalScroll(rememberScrollState()),
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.parity.signer.screens.scan.transaction.dynamicderivations

import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import io.parity.signer.domain.Callback
import io.parity.signer.ui.BottomSheetWrapperRoot
import io.parity.signer.uniffi.DdPreview


@Composable
fun AddDynamicDerivationScreenFull(
model: DdPreview,
onBack: Callback,
onDone: Callback,
) {

val confirmState = remember { mutableStateOf(false) }

AddDerivedKeysScreen(
model = model,
modifier = Modifier.statusBarsPadding(),
onBack = onBack,
onDone = { confirmState.value = true },
)

if (confirmState.value) {
BottomSheetWrapperRoot(onClosedAction = { confirmState.value = false }) {
AddDDConfirmBottomSheet(
onConfirm = onDone,
onCancel = { confirmState.value = false },
)
}
}
}
4 changes: 4 additions & 0 deletions android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
<string name="import_derivations_failure_toast">Import Keys Has Failed</string>
<string name="import_derivations_failure_update_toast">Import Keys Has Failed. Update keys failed.</string>
<string name="create_derivations_success">Derived key successfully created.</string>
<string name="create_derivations_empty">All derived keys already added</string>
<string name="create_derivations_failure">Derivation key failure: %1$s</string>
<string name="unlock_screen_title">Please Unlock the App</string>
<string name="unlock_screen_description">The device has been locked because of failed authentication, please unlock the device to keep using the Polkadot Vault</string>
Expand Down Expand Up @@ -424,6 +425,9 @@
<string name="dymanic_derivation_error_some_network_missing">"Some keys can not be imported until their networks are added. Please add missing networks and their metadata. "</string>
<string name="dymanic_derivation_error_custom_message">Derived key %1$s could not be created: %2$s</string>
<string name="dymanic_derivation_error_custom_title">There was an issue importing keys.</string>
<string name="confirm_dynamic_derivation_header">Please confirm derived key import with authorisation</string>
<string name="confirm_dynamic_derivation_message">Please confirm that you scanned the QR code back into the app. Once confirmed, the imported key will be added to the key set.</string>
<string name="confirm_dynamic_derivation_cta">Confirm with authorisation</string>


</resources>
Expand Down

0 comments on commit 2e4ab4c

Please sign in to comment.