Skip to content

Commit

Permalink
feat(demo): update demo app with new features (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-frade-iohk authored Apr 15, 2024
1 parent 7bfcaaf commit 931c843
Show file tree
Hide file tree
Showing 77 changed files with 3,426 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct CreateAnoncredCredentialRequest {
let linkSecretObj = try LinkSecret.newFromValue(valueString: linkSecret)
let offer = try CredentialOffer(jsonString: String(data: offerData, encoding: .utf8)!)
let credDefId = offer.getCredDefId()

let credentialDefinitionData = try await credentialDefinitionDownloader.downloadFromEndpoint(urlOrDID: credDefId)
let credentialDefinitionJson = try credentialDefinitionData.toString()
let credentialDefinition = try CredentialDefinition(jsonString: credentialDefinitionJson)
Expand All @@ -53,7 +53,7 @@ struct CreateAnoncredCredentialRequest {
credentialOffer: offer
)

guard
guard
let metadata = try requestData.metadata.getJson().data(using: .utf8)
else {
throw CommonError.invalidCoding(message: "Could not decode to data")
Expand Down
4 changes: 2 additions & 2 deletions AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class PrismAgent {
castor: castor,
secretsStream: secretsStream
).build()

let seed = seedData.map { Seed(value: $0) } ?? apollo.createRandomSeed().seed
self.init(
apollo: apollo,
Expand Down Expand Up @@ -193,7 +193,7 @@ public class PrismAgent {
state = .stoped
logger.info(message: "Agent not running")
}

private func firstLinkSecretSetup() async throws {
if try await pluto.getLinkSecret().first().await() == nil {
let secret = try apollo.createNewLinkSecret()
Expand Down
22 changes: 22 additions & 0 deletions Core/Sources/Helpers/Map+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,26 @@ public extension Sequence {

return values
}

func asyncCompactMap<T>(
_ transform: (Element) async throws -> T?
) async rethrows -> [T] {
var values = [T]()

for element in self {
if let value = try await transform(element) {
values.append(value)
}
}

return values
}

func asyncForEach(
_ process: (Element) async throws -> Void
) async rethrows {
for element in self {
try await process(element)
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import SwiftUI

struct ActivityView: UIViewControllerRepresentable {
let activityItems: [Any]
let applicationActivities: [UIActivity]?

func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController {
UIActivityViewController(activityItems: activityItems,
applicationActivities: applicationActivities)
}

func updateUIViewController(
_ uiViewController: UIActivityViewController,
context: UIViewControllerRepresentableContext<ActivityView>
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import SwiftUI

struct AtalaButton<Label: View>: View {
enum Configuration {
case primary
case secondary
}

let configuration: Configuration
let loading: Bool
let action: () -> Void
@ViewBuilder var label: () -> Label

init(
configuration: Configuration = .primary,
loading: Bool = false,
action: @escaping () -> Void,
@ViewBuilder label: @escaping () -> Label
) {
self.configuration = configuration
self.loading = loading
self.action = action
self.label = label
}

@Environment(\.isEnabled) var isEnabled: Bool

var body: some View {
let button = Button(action: action, label: {
HStack(spacing: 6) {
label()
if loading {
ProgressView()
.progressViewStyle(
CircularProgressViewStyle(
tint: .white
)
)
}
}
})
if configuration == .primary {
button
.primeButtonConfiguration()
.environment(\.isLoading, loading)
} else {
button
.secondaryButtonConfiguration()
.environment(\.isLoading, loading)
}
}
}

struct AtalaButton_Previews: PreviewProvider {
static var previews: some View {
AtalaButton(loading: true, action: {}, label: {
Text("Something")
})
.disabled(true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import SwiftUI

struct PrimeButtonNavidationLink<Destination: View>: View {
let text: String
let destination: Destination

var body: some View {
NavigationLink(
destination: destination,
label: {
Text(text)
.bold()
.frame(maxWidth: .infinity)
.primeButtonModifier()
}
)
}
}

struct SecondaryButtonNavidationLink<Destination: View>: View {
let text: String
let destination: Destination

var body: some View {
NavigationLink(
destination: destination,
label: {
Text(text)
.bold()
.frame(maxWidth: .infinity)
.secondaryButtonModifier()
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SwiftUI

struct CheckButton: View {
@Binding var isSelected: Bool

var body: some View {
Button(action: {
withAnimation {
self.isSelected = !isSelected
}
}, label: {
if isSelected {
Image("ico_check_on")
.resizable()
} else {
Image("ico_check_off")
.resizable()
}
})
.frame(width: 40, height: 40)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SwiftUI

struct ClosableSheet<SheetContent: View>: View {
@Environment(\.presentationMode) var presentationMode
@ViewBuilder let content: () -> SheetContent

var body: some View {
VStack(spacing: 16) {
content()
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Image("ico_close_red")
})
}
}
}

struct ClosableSheet_Previews: PreviewProvider {
static var previews: some View {
ClosableSheet(content: {
Text("")
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import SwiftUI

struct DeleteView<Content: View, Info: View>: View {
private let deleteAction: () -> Void
private let showInfoView: Bool
private var loading: Bool

@ViewBuilder private var content: () -> Content
@ViewBuilder private var info: () -> Info

@Environment(\.presentationMode) var presentationMode

init(
showInfoView: Bool = true,
loading: Bool = false,
deleteAction: @escaping () -> Void,
@ViewBuilder content: @escaping () -> Content,
@ViewBuilder info: @escaping () -> Info
) {
self.deleteAction = deleteAction
self.content = content
self.info = info
self.showInfoView = showInfoView
self.loading = loading
}

var body: some View {
VStack(spacing: 15) {
VStack(spacing: 9) {
Image("icon_delete")
VStack(spacing: 4) {
Text("contacts_delete_confrimation_title".localize())
.font(.body)
.fontWeight(.heavy)
.bold()
.foregroundColor(Color(.red))
Text("contacts_delete_confrimation_message".localize())
.font(.body)
.foregroundColor(.gray)
}
}
Divider()
content()
Divider()
if showInfoView {
info()
Divider()
}
HStack {
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("cancel".localize())
.frame(maxWidth: .infinity)
.secondaryButtonModifier()
})

AtalaButton(loading: self.loading) {
self.deleteAction()
} label: {
Text("delete".localize())
.frame(maxWidth: .infinity)
}
}
}
.padding(24)
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding()
}
}

struct DeleteView_Previews: PreviewProvider {
static var previews: some View {
DeleteView(showInfoView: true) {} content: {
HStack(spacing: 16) {
Image("ico_placeholder_credential")
.resizable()
.frame(width: 40, height: 40)
.clipShape(RoundedRectangle(cornerRadius: 10))
Text("Atala KYC")
.font(.title3)
.fontWeight(.heavy)
.bold()
.foregroundColor(.black)
Spacer()
}
} info: {
VStack(alignment: .leading, spacing: 9) {
Text("contacts_delete_description".localize())
.font(.body)
.foregroundColor(.gray)
VStack(alignment: .leading, spacing: 6) {
Text(". ID Credential")
.bold()
.font(.body)
.foregroundColor(.black)
Text(". University Credential")
.bold()
.font(.body)
.foregroundColor(.black)
}
}
}
}
}
Loading

0 comments on commit 931c843

Please sign in to comment.