Skip to content

Commit 931c843

Browse files
feat(demo): update demo app with new features (#133)
1 parent 7bfcaaf commit 931c843

File tree

77 files changed

+3426
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3426
-154
lines changed

AtalaPrismSDK/Pollux/Sources/Operation/Anoncreds/CreateAnoncredCredentialRequest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct CreateAnoncredCredentialRequest {
3939
let linkSecretObj = try LinkSecret.newFromValue(valueString: linkSecret)
4040
let offer = try CredentialOffer(jsonString: String(data: offerData, encoding: .utf8)!)
4141
let credDefId = offer.getCredDefId()
42-
42+
4343
let credentialDefinitionData = try await credentialDefinitionDownloader.downloadFromEndpoint(urlOrDID: credDefId)
4444
let credentialDefinitionJson = try credentialDefinitionData.toString()
4545
let credentialDefinition = try CredentialDefinition(jsonString: credentialDefinitionJson)
@@ -53,7 +53,7 @@ struct CreateAnoncredCredentialRequest {
5353
credentialOffer: offer
5454
)
5555

56-
guard
56+
guard
5757
let metadata = try requestData.metadata.getJson().data(using: .utf8)
5858
else {
5959
throw CommonError.invalidCoding(message: "Could not decode to data")

AtalaPrismSDK/PrismAgent/Sources/PrismAgent.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class PrismAgent {
111111
castor: castor,
112112
secretsStream: secretsStream
113113
).build()
114-
114+
115115
let seed = seedData.map { Seed(value: $0) } ?? apollo.createRandomSeed().seed
116116
self.init(
117117
apollo: apollo,
@@ -193,7 +193,7 @@ public class PrismAgent {
193193
state = .stoped
194194
logger.info(message: "Agent not running")
195195
}
196-
196+
197197
private func firstLinkSecretSetup() async throws {
198198
if try await pluto.getLinkSecret().first().await() == nil {
199199
let secret = try apollo.createNewLinkSecret()

Core/Sources/Helpers/Map+AsyncAwait.swift

+22
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,26 @@ public extension Sequence {
1010

1111
return values
1212
}
13+
14+
func asyncCompactMap<T>(
15+
_ transform: (Element) async throws -> T?
16+
) async rethrows -> [T] {
17+
var values = [T]()
18+
19+
for element in self {
20+
if let value = try await transform(element) {
21+
values.append(value)
22+
}
23+
}
24+
25+
return values
26+
}
27+
28+
func asyncForEach(
29+
_ process: (Element) async throws -> Void
30+
) async rethrows {
31+
for element in self {
32+
try await process(element)
33+
}
34+
}
1335
}

Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo.xcodeproj/project.pbxproj

+343-23
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import SwiftUI
2+
3+
struct ActivityView: UIViewControllerRepresentable {
4+
let activityItems: [Any]
5+
let applicationActivities: [UIActivity]?
6+
7+
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController {
8+
UIActivityViewController(activityItems: activityItems,
9+
applicationActivities: applicationActivities)
10+
}
11+
12+
func updateUIViewController(
13+
_ uiViewController: UIActivityViewController,
14+
context: UIViewControllerRepresentableContext<ActivityView>
15+
) {}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import SwiftUI
2+
3+
struct AtalaButton<Label: View>: View {
4+
enum Configuration {
5+
case primary
6+
case secondary
7+
}
8+
9+
let configuration: Configuration
10+
let loading: Bool
11+
let action: () -> Void
12+
@ViewBuilder var label: () -> Label
13+
14+
init(
15+
configuration: Configuration = .primary,
16+
loading: Bool = false,
17+
action: @escaping () -> Void,
18+
@ViewBuilder label: @escaping () -> Label
19+
) {
20+
self.configuration = configuration
21+
self.loading = loading
22+
self.action = action
23+
self.label = label
24+
}
25+
26+
@Environment(\.isEnabled) var isEnabled: Bool
27+
28+
var body: some View {
29+
let button = Button(action: action, label: {
30+
HStack(spacing: 6) {
31+
label()
32+
if loading {
33+
ProgressView()
34+
.progressViewStyle(
35+
CircularProgressViewStyle(
36+
tint: .white
37+
)
38+
)
39+
}
40+
}
41+
})
42+
if configuration == .primary {
43+
button
44+
.primeButtonConfiguration()
45+
.environment(\.isLoading, loading)
46+
} else {
47+
button
48+
.secondaryButtonConfiguration()
49+
.environment(\.isLoading, loading)
50+
}
51+
}
52+
}
53+
54+
struct AtalaButton_Previews: PreviewProvider {
55+
static var previews: some View {
56+
AtalaButton(loading: true, action: {}, label: {
57+
Text("Something")
58+
})
59+
.disabled(true)
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import SwiftUI
2+
3+
struct PrimeButtonNavidationLink<Destination: View>: View {
4+
let text: String
5+
let destination: Destination
6+
7+
var body: some View {
8+
NavigationLink(
9+
destination: destination,
10+
label: {
11+
Text(text)
12+
.bold()
13+
.frame(maxWidth: .infinity)
14+
.primeButtonModifier()
15+
}
16+
)
17+
}
18+
}
19+
20+
struct SecondaryButtonNavidationLink<Destination: View>: View {
21+
let text: String
22+
let destination: Destination
23+
24+
var body: some View {
25+
NavigationLink(
26+
destination: destination,
27+
label: {
28+
Text(text)
29+
.bold()
30+
.frame(maxWidth: .infinity)
31+
.secondaryButtonModifier()
32+
}
33+
)
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import SwiftUI
2+
3+
struct CheckButton: View {
4+
@Binding var isSelected: Bool
5+
6+
var body: some View {
7+
Button(action: {
8+
withAnimation {
9+
self.isSelected = !isSelected
10+
}
11+
}, label: {
12+
if isSelected {
13+
Image("ico_check_on")
14+
.resizable()
15+
} else {
16+
Image("ico_check_off")
17+
.resizable()
18+
}
19+
})
20+
.frame(width: 40, height: 40)
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SwiftUI
2+
3+
struct ClosableSheet<SheetContent: View>: View {
4+
@Environment(\.presentationMode) var presentationMode
5+
@ViewBuilder let content: () -> SheetContent
6+
7+
var body: some View {
8+
VStack(spacing: 16) {
9+
content()
10+
Button(action: {
11+
self.presentationMode.wrappedValue.dismiss()
12+
}, label: {
13+
Image("ico_close_red")
14+
})
15+
}
16+
}
17+
}
18+
19+
struct ClosableSheet_Previews: PreviewProvider {
20+
static var previews: some View {
21+
ClosableSheet(content: {
22+
Text("")
23+
})
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import SwiftUI
2+
3+
struct DeleteView<Content: View, Info: View>: View {
4+
private let deleteAction: () -> Void
5+
private let showInfoView: Bool
6+
private var loading: Bool
7+
8+
@ViewBuilder private var content: () -> Content
9+
@ViewBuilder private var info: () -> Info
10+
11+
@Environment(\.presentationMode) var presentationMode
12+
13+
init(
14+
showInfoView: Bool = true,
15+
loading: Bool = false,
16+
deleteAction: @escaping () -> Void,
17+
@ViewBuilder content: @escaping () -> Content,
18+
@ViewBuilder info: @escaping () -> Info
19+
) {
20+
self.deleteAction = deleteAction
21+
self.content = content
22+
self.info = info
23+
self.showInfoView = showInfoView
24+
self.loading = loading
25+
}
26+
27+
var body: some View {
28+
VStack(spacing: 15) {
29+
VStack(spacing: 9) {
30+
Image("icon_delete")
31+
VStack(spacing: 4) {
32+
Text("contacts_delete_confrimation_title".localize())
33+
.font(.body)
34+
.fontWeight(.heavy)
35+
.bold()
36+
.foregroundColor(Color(.red))
37+
Text("contacts_delete_confrimation_message".localize())
38+
.font(.body)
39+
.foregroundColor(.gray)
40+
}
41+
}
42+
Divider()
43+
content()
44+
Divider()
45+
if showInfoView {
46+
info()
47+
Divider()
48+
}
49+
HStack {
50+
Button(action: {
51+
self.presentationMode.wrappedValue.dismiss()
52+
}, label: {
53+
Text("cancel".localize())
54+
.frame(maxWidth: .infinity)
55+
.secondaryButtonModifier()
56+
})
57+
58+
AtalaButton(loading: self.loading) {
59+
self.deleteAction()
60+
} label: {
61+
Text("delete".localize())
62+
.frame(maxWidth: .infinity)
63+
}
64+
}
65+
}
66+
.padding(24)
67+
.background(Color.white)
68+
.clipShape(RoundedRectangle(cornerRadius: 10))
69+
.padding()
70+
}
71+
}
72+
73+
struct DeleteView_Previews: PreviewProvider {
74+
static var previews: some View {
75+
DeleteView(showInfoView: true) {} content: {
76+
HStack(spacing: 16) {
77+
Image("ico_placeholder_credential")
78+
.resizable()
79+
.frame(width: 40, height: 40)
80+
.clipShape(RoundedRectangle(cornerRadius: 10))
81+
Text("Atala KYC")
82+
.font(.title3)
83+
.fontWeight(.heavy)
84+
.bold()
85+
.foregroundColor(.black)
86+
Spacer()
87+
}
88+
} info: {
89+
VStack(alignment: .leading, spacing: 9) {
90+
Text("contacts_delete_description".localize())
91+
.font(.body)
92+
.foregroundColor(.gray)
93+
VStack(alignment: .leading, spacing: 6) {
94+
Text(". ID Credential")
95+
.bold()
96+
.font(.body)
97+
.foregroundColor(.black)
98+
Text(". University Credential")
99+
.bold()
100+
.font(.body)
101+
.foregroundColor(.black)
102+
}
103+
}
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)