-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1660 from planetary-social/onboarding-public-key
#1596: Public Key screen in onboarding
- Loading branch information
Showing
10 changed files
with
191 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// The state of a copy button. | ||
enum CopyButtonState { | ||
case copy | ||
case copied | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import SwiftUI | ||
|
||
/// A bordered view that shows a key and a button to copy it. When the user taps the copy button, | ||
/// its title changes to "Copied!". | ||
struct CopyKeyView: View { | ||
let buttonTitle: LocalizedStringKey | ||
|
||
@Binding var keyString: String | ||
@Binding var copyButtonState: CopyButtonState | ||
|
||
init(_ buttonTitle: LocalizedStringKey, keyString: Binding<String>, copyButtonState: Binding<CopyButtonState>) { | ||
self.buttonTitle = buttonTitle | ||
_keyString = keyString | ||
_copyButtonState = copyButtonState | ||
} | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 16) { | ||
Text(keyString) | ||
HStack { | ||
if copyButtonState == .copy { | ||
Image.copyIcon | ||
.frame(width: 20, height: 20) | ||
} else { | ||
Image(systemName: "checkmark") | ||
.frame(width: 20, height: 20) | ||
} | ||
Button { | ||
UIPasteboard.general.string = keyString | ||
copyButtonState = .copied | ||
Task { @MainActor in | ||
try await Task.sleep(for: .seconds(10)) | ||
copyButtonState = .copy | ||
} | ||
} label: { | ||
Text(copyButtonState == .copy ? buttonTitle : "copied") | ||
} | ||
Spacer() | ||
} | ||
.foregroundStyle(Color.actionTertiary) | ||
} | ||
.padding() | ||
.withStyledBorder() | ||
} | ||
} | ||
|
||
#Preview { | ||
@State var privateKey = KeyFixture.nsec | ||
@State var privateCopyButtonState = CopyButtonState.copy | ||
|
||
@State var publicKey = KeyFixture.npub | ||
@State var publicCopyButtonState = CopyButtonState.copied | ||
|
||
return VStack(spacing: 40) { | ||
CopyKeyView("copyPrivateKey", keyString: $privateKey, copyButtonState: $privateCopyButtonState) | ||
CopyKeyView("copyPublicKey", keyString: $publicKey, copyButtonState: $publicCopyButtonState) | ||
} | ||
} | ||
|
||
enum KeyType { | ||
case `public` | ||
case `private` | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Dependencies | ||
import SwiftUI | ||
|
||
/// The Public Key view in the onboarding. | ||
struct PublicKeyView: View { | ||
@Environment(OnboardingState.self) private var state | ||
@Environment(CurrentUser.self) var currentUser | ||
|
||
@State private var publicKeyString = "" | ||
@State private var copyButtonState: CopyButtonState = .copy | ||
|
||
var body: some View { | ||
ZStack { | ||
Color.appBg | ||
.ignoresSafeArea() | ||
ViewThatFits(in: .vertical) { | ||
publicKeyStack | ||
|
||
ScrollView { | ||
publicKeyStack | ||
} | ||
} | ||
.onAppear { | ||
publicKeyString = currentUser.keyPair?.npub ?? "" | ||
} | ||
} | ||
.navigationBarHidden(true) | ||
} | ||
|
||
var publicKeyStack: some View { | ||
VStack(alignment: .leading, spacing: 20) { | ||
LargeNumberView(2) | ||
HStack(alignment: .firstTextBaseline) { | ||
Text("publicKeyHeadline") | ||
.font(.clarityBold(.title)) | ||
.foregroundStyle(Color.primaryTxt) | ||
Text("publicKeyNpubParenthetical") | ||
.font(.clarityRegular(.title2)) | ||
.foregroundStyle(Color.secondaryTxt) | ||
} | ||
Text("publicKeyDescription") | ||
.font(.body) | ||
.foregroundStyle(Color.secondaryTxt) | ||
CopyKeyView("copyPublicKey", keyString: $publicKeyString, copyButtonState: $copyButtonState) | ||
Spacer() | ||
BigActionButton("next") { | ||
state.step = .buildYourNetwork | ||
} | ||
} | ||
.padding(40) | ||
.readabilityPadding() | ||
} | ||
} | ||
|
||
#Preview { | ||
PublicKeyView() | ||
.environment(OnboardingState()) | ||
.inject(previewData: PreviewData()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters