diff --git a/ui-lib/src/androidTest/java/cash/z/ecc/ui/screen/backup/view/BackupViewTest.kt b/ui-lib/src/androidTest/java/cash/z/ecc/ui/screen/backup/view/BackupViewTest.kt index e698b60c..8d48cf7d 100644 --- a/ui-lib/src/androidTest/java/cash/z/ecc/ui/screen/backup/view/BackupViewTest.kt +++ b/ui-lib/src/androidTest/java/cash/z/ecc/ui/screen/backup/view/BackupViewTest.kt @@ -34,6 +34,7 @@ class BackupViewTest { assertEquals(BackupStage.EducationOverview, testSetup.getStage()) assertEquals(0, testSetup.getOnCompleteCallbackCount()) + assertEquals(0, testSetup.getOnCopyToClipboardCount()) } @Test @@ -43,6 +44,19 @@ class BackupViewTest { assertEquals(BackupStage.Complete, testSetup.getStage()) assertEquals(0, testSetup.getOnCompleteCallbackCount()) + assertEquals(0, testSetup.getOnCopyToClipboardCount()) + } + + @Test + @MediumTest + fun copy_to_clipboard() { + val testSetup = newTestSetup(BackupStage.Seed) + + composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_copy)).also { + it.performClick() + } + + assertEquals(1, testSetup.getOnCopyToClipboardCount()) } @Test @@ -107,6 +121,7 @@ class BackupViewTest { val goToWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_finished)) goToWalletButton.performClick() + assertEquals(0, testSetup.getOnCopyToClipboardCount()) assertEquals(1, testSetup.getOnCompleteCallbackCount()) } @@ -118,6 +133,7 @@ class BackupViewTest { val newWalletButton = composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_5_button_back)) newWalletButton.performClick() + assertEquals(0, testSetup.getOnCopyToClipboardCount()) assertEquals(0, testSetup.getOnCompleteCallbackCount()) assertEquals(BackupStage.Seed, testSetup.getStage()) } @@ -139,6 +155,12 @@ class BackupViewTest { assertEquals(BackupStage.Seed, testSetup.getStage()) + composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_copy)).also { + it.performClick() + } + + assertEquals(1, testSetup.getOnCopyToClipboardCount()) + composeTestRule.onNodeWithText(getStringResource(R.string.new_wallet_3_button_finished)).also { it.performClick() } @@ -173,8 +195,15 @@ class BackupViewTest { private class TestSetup(private val composeTestRule: ComposeContentTestRule, initalStage: BackupStage) { private val state = BackupState(initalStage) + private var onCopyToClipboardCount = 0 + private var onCompleteCallbackCount = 0 + fun getOnCopyToClipboardCount(): Int { + composeTestRule.waitForIdle() + return onCopyToClipboardCount + } + fun getOnCompleteCallbackCount(): Int { composeTestRule.waitForIdle() return onCompleteCallbackCount @@ -192,6 +221,7 @@ class BackupViewTest { PersistableWalletFixture.new(), state, TestChoices(), + onCopyToClipboard = { onCopyToClipboardCount++ }, onComplete = { onCompleteCallbackCount++ } ) } diff --git a/ui-lib/src/main/java/cash/z/ecc/ui/MainActivity.kt b/ui-lib/src/main/java/cash/z/ecc/ui/MainActivity.kt index b6c50add..cf634e2e 100644 --- a/ui-lib/src/main/java/cash/z/ecc/ui/MainActivity.kt +++ b/ui-lib/src/main/java/cash/z/ecc/ui/MainActivity.kt @@ -1,5 +1,7 @@ package cash.z.ecc.ui +import android.content.ClipData +import android.content.ClipboardManager import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -41,9 +43,19 @@ class MainActivity : ComponentActivity() { @Composable private fun WrapBackup(persistableWallet: PersistableWallet) { - BackupWallet(persistableWallet, backupViewModel.backupState, backupViewModel.testChoices) { + BackupWallet( + persistableWallet, backupViewModel.backupState, backupViewModel.testChoices, + onCopyToClipboard = { + val clipboardManager = getSystemService(ClipboardManager::class.java) + val data = ClipData.newPlainText( + getString(R.string.new_wallet_clipboard_tag), + persistableWallet.seedPhrase.phrase + ) + clipboardManager.setPrimaryClip(data) + }, onComplete = { walletViewModel.persistBackupComplete() } + ) } @Composable diff --git a/ui-lib/src/main/java/cash/z/ecc/ui/screen/backup/view/BackupView.kt b/ui-lib/src/main/java/cash/z/ecc/ui/screen/backup/view/BackupView.kt index 4ef2f681..64ebe3bd 100644 --- a/ui-lib/src/main/java/cash/z/ecc/ui/screen/backup/view/BackupView.kt +++ b/ui-lib/src/main/java/cash/z/ecc/ui/screen/backup/view/BackupView.kt @@ -42,6 +42,7 @@ fun ComposablePreview() { PersistableWalletFixture.new(), BackupState(BackupStage.Test), TestChoices(), + onCopyToClipboard = {}, onComplete = {} ) } @@ -55,6 +56,7 @@ fun BackupWallet( wallet: PersistableWallet, backupState: BackupState, selectedTestChoices: TestChoices, + onCopyToClipboard: () -> Unit, onComplete: () -> Unit, ) { Surface { @@ -63,10 +65,9 @@ fun BackupWallet( BackupStage.EducationOverview -> EducationOverview(onNext = backupState::goNext) BackupStage.EducationRecoveryPhrase -> EducationRecoveryPhrase(onNext = backupState::goNext) BackupStage.Seed -> SeedPhrase( - wallet, onNext = backupState::goNext, - onCopyToClipboard = { - // TODO [#49] - } + wallet, + onNext = backupState::goNext, + onCopyToClipboard = onCopyToClipboard ) BackupStage.Test -> Test( wallet, diff --git a/ui-lib/src/main/res/ui/backup/values/strings.xml b/ui-lib/src/main/res/ui/backup/values/strings.xml index 24be7bb7..21501b98 100644 --- a/ui-lib/src/main/res/ui/backup/values/strings.xml +++ b/ui-lib/src/main/res/ui/backup/values/strings.xml @@ -1,4 +1,6 @@ + Zcash Seed Phrase + First things first It is important to understand that you are in charge here. Great, right? YOU get to be the bank! But it also means that YOU are the customer, and you need to be self-reliant.\n\nSo how do you recover funds that you‘ve hidden on a complete decentralized and private block-chain?