Import Wallet Screen added

Scaffold of the import wallet screen has been created and connected to the onboarding flow
This commit is contained in:
Lukas Korba 2022-03-01 09:12:50 +01:00
parent 3b2dd7c43a
commit f6548ee4ff
14 changed files with 408 additions and 20 deletions

View File

@ -82,6 +82,9 @@
66A0807B271993C500118B79 /* OnboardingProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */; };
66D50668271D9B6100E51F0D /* NavigationButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */; };
66DC733F271D88CC0053CBB6 /* StandardButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */; };
9E0FD7A027C910C000357DF0 /* ImportWalletStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0FD79F27C910C000357DF0 /* ImportWalletStore.swift */; };
9E0FD7A327C910D500357DF0 /* ImportWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0FD7A227C910D500357DF0 /* ImportWalletView.swift */; };
9E0FD7A527C9163900357DF0 /* ImportSeedEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0FD7A427C9163900357DF0 /* ImportSeedEditor.swift */; };
9E4DC6E027C409A100E657F4 /* NeumorphicDesignModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E4DC6DF27C409A100E657F4 /* NeumorphicDesignModifier.swift */; };
9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E4DC6E127C4C6B700E657F4 /* SecantButtonStyles.swift */; };
F9322DC0273B555C00C105B5 /* NavigationLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9322DBF273B555C00C105B5 /* NavigationLinks.swift */; };
@ -211,6 +214,9 @@
66A0807A271993C500118B79 /* OnboardingProgressIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingProgressIndicator.swift; sourceTree = "<group>"; };
66D50667271D9B6100E51F0D /* NavigationButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButtonStyle.swift; sourceTree = "<group>"; };
66DC733E271D88CC0053CBB6 /* StandardButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardButtonStyle.swift; sourceTree = "<group>"; };
9E0FD79F27C910C000357DF0 /* ImportWalletStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletStore.swift; sourceTree = "<group>"; };
9E0FD7A227C910D500357DF0 /* ImportWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletView.swift; sourceTree = "<group>"; };
9E0FD7A427C9163900357DF0 /* ImportSeedEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportSeedEditor.swift; sourceTree = "<group>"; };
9E4DC6DF27C409A100E657F4 /* NeumorphicDesignModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphicDesignModifier.swift; sourceTree = "<group>"; };
9E4DC6E127C4C6B700E657F4 /* SecantButtonStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecantButtonStyles.swift; sourceTree = "<group>"; };
F9322DBF273B555C00C105B5 /* NavigationLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationLinks.swift; sourceTree = "<group>"; };
@ -587,6 +593,7 @@
0D3D04052728B2D70032ABC1 /* BackupFlow */,
6654C73C2715A3FA00901167 /* Onboarding */,
F9971A6727680E1000A2DB75 /* WalletInfo */,
9E0FD79E27C910AE00357DF0 /* ImportWallet */,
);
path = Features;
sourceTree = "<group>";
@ -642,6 +649,24 @@
path = CircularFrame;
sourceTree = "<group>";
};
9E0FD79E27C910AE00357DF0 /* ImportWallet */ = {
isa = PBXGroup;
children = (
9E0FD79F27C910C000357DF0 /* ImportWalletStore.swift */,
9E0FD7A127C910C300357DF0 /* Views */,
);
path = ImportWallet;
sourceTree = "<group>";
};
9E0FD7A127C910C300357DF0 /* Views */ = {
isa = PBXGroup;
children = (
9E0FD7A227C910D500357DF0 /* ImportWalletView.swift */,
9E0FD7A427C9163900357DF0 /* ImportSeedEditor.swift */,
);
path = Views;
sourceTree = "<group>";
};
F93874EC273C4DE200F0E875 /* Home */ = {
isa = PBXGroup;
children = (
@ -999,6 +1024,7 @@
2EB660E02747EAB900A06A07 /* OnboardingScreen.swift in Sources */,
660558F8270C862F009D6954 /* XCAssets+Generated.swift in Sources */,
0D35CC46277A36E00074316A /* ScrollableWhenScaled.swift in Sources */,
9E0FD7A027C910C000357DF0 /* ImportWalletStore.swift in Sources */,
F96B41E9273B501F0021B49A /* TransactionHistoryView.swift in Sources */,
669FDAE9272C23B3007B9422 /* CircularFrame.swift in Sources */,
F96B41E8273B501F0021B49A /* TransactionDetailView.swift in Sources */,
@ -1010,6 +1036,7 @@
0DACFA7F27208CE00039EEA5 /* Clamped.swift in Sources */,
0DFE93E3272CA1AA000FCCA5 /* RecoveryPhraseValidation.swift in Sources */,
0D354A0B26D5A9D000315F45 /* MnemonicSeedPhraseHandling.swift in Sources */,
9E0FD7A527C9163900357DF0 /* ImportSeedEditor.swift in Sources */,
0D535FE2271F9476009A9E3E /* EnumeratedChip.swift in Sources */,
6654C73E2715A41300901167 /* OnboardingStore.swift in Sources */,
9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */,
@ -1062,6 +1089,7 @@
0D7DF08C271DCC0E00530046 /* ScreenBackground.swift in Sources */,
F9C165C22740403600592F76 /* CreateView.swift in Sources */,
F9C165B4274031F600592F76 /* Bindings.swift in Sources */,
9E0FD7A327C910D500357DF0 /* ImportWalletView.swift in Sources */,
F9971A6627680DFE00A2DB75 /* SettingsView.swift in Sources */,
F96B41EB273B50520021B49A /* Strings.swift in Sources */,
0D354A0A26D5A9D000315F45 /* KeyStoring.swift in Sources */,

View File

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xA0",
"green" : "0x81",
"red" : "0x6E"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xA0",
"green" : "0x81",
"red" : "0x6E"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -113,7 +113,9 @@ extension AppState {
static var placeholder: Self {
.init(
homeState: .placeholder,
onboardingState: .init(),
onboardingState: .init(
importWalletState: .placeholder
),
phraseValidationState: RecoveryPhraseValidationState.placeholder,
phraseDisplayState: RecoveryPhraseDisplayState(
phrase: .placeholder

View File

@ -20,12 +20,15 @@ struct AppView: View {
.navigationViewStyle(StackNavigationViewStyle())
case .onboarding:
OnboardingScreen(
store: store.scope(
state: \.onboardingState,
action: AppAction.onboarding
NavigationView {
OnboardingScreen(
store: store.scope(
state: \.onboardingState,
action: AppAction.onboarding
)
)
)
}
.navigationViewStyle(StackNavigationViewStyle())
case .startup:
ZStack(alignment: .topTrailing) {

View File

@ -0,0 +1,47 @@
//
// ImportWalletStore.swift
// secant-testnet
//
// Created by Lukáš Korba on 02/25/2022.
//
import ComposableArchitecture
typealias ImportWalletStore = Store<ImportWalletState, ImportWalletAction>
struct ImportWalletState: Equatable {
@BindableState var importedSeedPhrase: String = ""
}
enum ImportWalletAction: Equatable, BindableAction {
case importRecoveryPhrase
case importPrivateOrViewingKey
case binding(BindingAction<ImportWalletState>)
}
struct ImportWalletEnvironment { }
extension ImportWalletEnvironment {
static let demo = Self()
static let live = Self()
}
typealias ImportWalletReducer = Reducer<ImportWalletState, ImportWalletAction, ImportWalletEnvironment>
extension ImportWalletReducer {
static let `default` = ImportWalletReducer { _, action, _ in
switch action {
case .importRecoveryPhrase:
// TODO: once connected to SDK, use the state.importedSeedPhrase
return .none
case .importPrivateOrViewingKey:
return .none
case .binding:
return .none
}
}
.binding()
}

View File

@ -0,0 +1,68 @@
//
// ImportSeedEditor.swift
// secant-testnet
//
// Created by Lukáš Korba on 02/25/2022.
//
import SwiftUI
import ComposableArchitecture
struct ImportSeedEditor: View {
// @State var state: String = "moose moose moose chicken chicken moose moose moose moose moose chicken chicken moose moose moose moose moose chicken chicken moose moose"
var store: ImportWalletStore
/// Clearance of the black color for the TextEditor under the text (.dark colorScheme)
init(store: ImportWalletStore) {
self.store = store
UITextView.appearance().backgroundColor = .clear
}
var body: some View {
WithViewStore(store) { viewStore in
TextEditor(text: viewStore.binding(\.$importedSeedPhrase))
.importSeedEditorModifier()
.padding(28)
}
}
}
struct ImportSeedEditorModifier: ViewModifier {
func body(content: Content) -> some View {
content
.foregroundColor(Asset.Colors.Text.importSeedEditor.color)
.padding()
.background(Color.white)
.cornerRadius(4)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color.black, lineWidth: 2)
)
}
}
extension View {
func importSeedEditorModifier() -> some View {
modifier(ImportSeedEditorModifier())
}
}
struct ImportSeedInputField_Previews: PreviewProvider {
static let width: CGFloat = 400
static let height: CGFloat = 200
static var previews: some View {
Group {
ImportSeedEditor(store: .demo)
.frame(width: width, height: height)
.applyScreenBackground()
.preferredColorScheme(.light)
ImportSeedEditor(store: .demo)
.frame(width: width, height: height)
.applyScreenBackground()
.preferredColorScheme(.dark)
}
.previewLayout(.fixed(width: width + 50, height: height + 50))
}
}

View File

@ -0,0 +1,120 @@
//
// ImportWalletView.swift
// secant-testnet
//
// Created by Lukáš Korba on 02/25/2022.
//
import SwiftUI
import ComposableArchitecture
// jeste udelat scaledWhenBigFont
// fix button height
// zmena tlacitek na action pro dark
// navigaci, back nejak
// napojit na button v onboardingu
// texty do strings file
// back button at je jak ma byt
// action button ma spatnou barvu title v onboardingu
// progress bar se animuje skocenim dolu, protoze je animated
struct ImportWalletView: View {
@Environment(\.presentationMode) var presentationMode
var store: ImportWalletStore
var body: some View {
WithViewStore(store) { viewStore in
VStack {
VStack(alignment: .leading, spacing: 30) {
HStack {
Button("Back") { presentationMode.wrappedValue.dismiss() }
.navigationButtonStyle
.frame(width: 75, height: 40)
Text("Wallet Import")
.titleText()
}
Text("You can import your backed up wallet by entering your backup recovery phrase (aka seed phrase) now.")
.paragraphText()
.lineSpacing(4)
.opacity(0.53)
}
.padding(18)
ImportSeedEditor(store: store)
.frame(width: nil, height: 200, alignment: .center)
Button("Import Recovery Phrase") {
viewStore.send(.importRecoveryPhrase)
}
.activeButtonStyle
.importWalletButtonLayout()
Button("Import a private or viewing key") {
viewStore.send(.importPrivateOrViewingKey)
}
.secondaryButtonStyle
.importWalletButtonLayout()
Spacer()
}
.navigationBarHidden(true)
.applyScreenBackground()
.scrollableWhenScaledUp()
}
}
}
// swiftlint:disable:next private_over_fileprivate strict_fileprivate
fileprivate struct ImportWalletButtonLayout: ViewModifier {
func body(content: Content) -> some View {
content
.frame(
minWidth: 0,
maxWidth: .infinity,
minHeight: 60,
maxHeight: .infinity,
alignment: .center
)
.fixedSize(horizontal: false, vertical: true)
.padding(.horizontal, 28)
.transition(.opacity)
}
}
extension View {
func importWalletButtonLayout() -> some View {
modifier(ImportWalletButtonLayout())
}
}
extension ImportWalletStore {
static let demo = Store(
initialState: .placeholder,
reducer: .default,
environment: .demo
)
}
extension ImportWalletState {
static let placeholder = ImportWalletState(importedSeedPhrase: "")
static let live = ImportWalletState(importedSeedPhrase: "")
}
struct ImportWalletView_Previews: PreviewProvider {
static var previews: some View {
ImportWalletView(store: .demo)
.preferredColorScheme(.light)
ImportWalletView(store: .demo)
.preferredColorScheme(.dark)
ImportWalletView(store: .demo)
.previewDevice(PreviewDevice(rawValue: "iPhone SE (2nd generation)"))
.preferredColorScheme(.light)
.environment(\.sizeCategory, .accessibilityLarge)
}
}

View File

@ -9,7 +9,14 @@ import Foundation
import SwiftUI
import ComposableArchitecture
typealias OnboardingViewStore = ViewStore<OnboardingState, OnboardingAction>
struct OnboardingState: Equatable {
enum Route: Equatable, CaseIterable {
case createNewWallet
case importExistingWallet
}
struct Step: Equatable, Identifiable {
let id: UUID
let title: String
@ -21,7 +28,8 @@ struct OnboardingState: Equatable {
var steps: IdentifiedArrayOf<Step> = Self.onboardingSteps
var index = 0
var skippedAtindex: Int?
var route: Route?
var currentStep: Step { steps[index] }
var isFinalStep: Bool { steps.count == index + 1 }
var isInitialStep: Bool { index == 0 }
@ -32,20 +40,43 @@ struct OnboardingState: Equatable {
guard index != 0 else { return .zero }
return stepOffset * CGFloat(index)
}
/// Import Wallet
var importWalletState: ImportWalletState
}
extension OnboardingViewStore {
func bindingForRoute(_ route: OnboardingState.Route) -> Binding<Bool> {
self.binding(
get: { $0.route == route },
send: { isActive in
return .updateRoute(isActive ? route : nil)
}
)
}
}
enum OnboardingAction: Equatable {
case next
case back
case skip
case updateRoute(OnboardingState.Route?)
case createNewWallet
case importExistingWallet
case importWallet(ImportWalletAction)
}
typealias OnboardingReducer = Reducer<OnboardingState, OnboardingAction, Void>
extension OnboardingReducer {
static let `default` = Reducer<OnboardingState, OnboardingAction, Void> { state, action, _ in
static let `default` = OnboardingReducer.combine(
[
onboardingReducer,
importWalletReducer
]
)
private static let onboardingReducer = OnboardingReducer { state, action, _ in
switch action {
case .back:
guard state.index > 0 else { return .none }
@ -68,11 +99,26 @@ extension OnboardingReducer {
state.index = state.steps.count - 1
return .none
case .updateRoute(let route):
state.route = route
return .none
case .createNewWallet:
state.route = .createNewWallet
return .none
case .importExistingWallet:
state.route = .importExistingWallet
return .none
case .importWallet(let route):
return .none
}
}
private static let importWalletReducer: OnboardingReducer = ImportWalletReducer.default.pullback(
state: \OnboardingState.importWalletState,
action: /OnboardingAction.importWallet,
environment: { _ in ImportWalletEnvironment.live }
)
}

View File

@ -94,7 +94,9 @@ struct Onboarding_Previews: PreviewProvider {
Group {
OnboardingView(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: .default,
environment: ()
)

View File

@ -91,6 +91,7 @@ internal enum Asset {
internal static let body = ColorAsset(name: "Body")
internal static let button = ColorAsset(name: "Button")
internal static let heading = ColorAsset(name: "Heading")
internal static let importSeedEditor = ColorAsset(name: "ImportSeedEditor")
internal static let medium = ColorAsset(name: "Medium")
internal static let regular = ColorAsset(name: "Regular")
internal static let secondaryButtonText = ColorAsset(name: "SecondaryButtonText")

View File

@ -127,7 +127,10 @@ extension OnboardingContentView {
struct OnboardingContentView_Previews: PreviewProvider {
static var previews: some View {
let store = Store(
initialState: OnboardingState(index: 0),
initialState: OnboardingState(
index: 0,
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)

View File

@ -23,12 +23,12 @@ struct OnboardingFooterView: View {
viewStore.send(.createNewWallet)
}
}
.createButtonStyle
.activeButtonStyle
.onboardingFooterButtonLayout()
Button("Import an Existing Wallet") {
withAnimation(.easeInOut(duration: animationDuration)) {
viewStore.send(.createNewWallet)
viewStore.send(.importExistingWallet)
}
}
.secondaryButtonStyle
@ -52,6 +52,17 @@ struct OnboardingFooterView: View {
.padding(.vertical, 20)
}
}
.navigationLinkEmpty(
isActive: viewStore.bindingForRoute(.importExistingWallet),
destination: {
ImportWalletView(
store: store.scope(
state: \.importWalletState,
action: OnboardingAction.importWallet
)
)
}
)
}
}
}
@ -75,7 +86,10 @@ extension View {
struct OnboardingFooterView_Previews: PreviewProvider {
static var previews: some View {
let store = Store<OnboardingState, OnboardingAction>(
initialState: OnboardingState(index: 3),
initialState: OnboardingState(
index: 3,
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)

View File

@ -63,7 +63,10 @@ struct OnboardingHeaderView: View {
struct OnboardingHeaderView_Previews: PreviewProvider {
static var previews: some View {
let store = Store<OnboardingState, OnboardingAction>(
initialState: OnboardingState(index: 0),
initialState: OnboardingState(
index: 0,
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)

View File

@ -42,6 +42,7 @@ struct OnboardingScreen: View {
OnboardingFooterView(store: store)
}
}
.navigationBarHidden(true)
.applyScreenBackground()
}
}
@ -50,7 +51,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
static var previews: some View {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)
@ -60,7 +63,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)
@ -70,7 +75,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)
@ -80,7 +87,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)
@ -90,7 +99,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)
@ -100,7 +111,9 @@ struct OnboardingScreen_Previews: PreviewProvider {
OnboardingScreen(
store: Store(
initialState: OnboardingState(),
initialState: OnboardingState(
importWalletState: .placeholder
),
reducer: OnboardingReducer.default,
environment: ()
)