Skip to content

Commit

Permalink
add a mechanism to update rootview decoded config from welcom screen.…
Browse files Browse the repository at this point in the history
… update changelog
  • Loading branch information
tobitech committed Aug 8, 2024
1 parent 1c160ae commit f90f292
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## [Unreleased]

### Changed
* Remove `prodUrl` and `testURl` from Config model struct since the `prod_url` and `test_url` keys are no longer used in the `smile_config.json` file.

## 10.2.7

### Changed
Expand Down
5 changes: 4 additions & 1 deletion Example/SmileID/App/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ struct RootView: View {
.ignoresSafeArea()
.preferredColorScheme(.light)
} else {
WelcomeScreen(showSuccess: $showSuccess)
WelcomeScreen(
showSuccess: $showSuccess,
didUpdateConfig: { viewModel.updateConfig(config: $0) }
)
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions Example/SmileID/WelcomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct WelcomeScreen: View {
@State private var showQrCodeScanner = false
@State private var errorMessage: String?
@Binding var showSuccess: Bool
@State private var partnerId: String?
@State private var config: Config?
var didUpdateConfig: (Config) -> Void

var body: some View {
VStack(alignment: .leading) {
Expand Down Expand Up @@ -82,8 +83,8 @@ struct WelcomeScreen: View {
.sheet(isPresented: $showManualEntrySheet) {
let content = SmileConfigEntryView(errorMessage: errorMessage) { smileConfig in
let response = updateSmileConfig(smileConfig)
if let smilePartnerId = response {
partnerId = smilePartnerId
if let config = response {
self.config = config
showSuccess = true
showManualEntrySheet = false
} else {
Expand All @@ -107,8 +108,8 @@ struct WelcomeScreen: View {
if case let .success(result) = response {
let configJson = result.string
let response = updateSmileConfig(configJson)
if let smilePartnerId = response {
partnerId = smilePartnerId
if let config = response {
self.config = config
showSuccess = true
showQrCodeScanner = false
}
Expand All @@ -117,18 +118,19 @@ struct WelcomeScreen: View {
}
.overlay(
Group {
if showSuccess {
if let config, showSuccess {
Color.black.opacity(0.3)
.edgesIgnoringSafeArea(.all)
.overlay(
AlertView(
icon: Image(systemName: "checkmark.circle.fill"),
title: "Configuration Added",
description: "Welcome Partner \(partnerId ?? ""), you can "
description: "Welcome Partner \(config.partnerId), you can "
+ "now proceed to the home screen of the Sample App",
buttonTitle: "Continue",
onClick: {
showSuccess = false
didUpdateConfig(config)
}
)
.padding([.leading, .trailing], 20)
Expand All @@ -139,11 +141,11 @@ struct WelcomeScreen: View {
}
}

private func updateSmileConfig(_ configJson: String) -> String? {
private func updateSmileConfig(_ configJson: String) -> Config? {
do {
let config = try JSONDecoder().decode(Config.self, from: configJson.data(using: .utf8)!)
UserDefaults.standard.set(configJson, forKey: "smileConfig")
return config.partnerId
return config
} catch {
print("Error decoding new config: \(error)")
return nil
Expand Down

0 comments on commit f90f292

Please sign in to comment.