-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sample): update sample apps for 2.0
- Loading branch information
1 parent
5c94352
commit a88a9cc
Showing
31 changed files
with
1,711 additions
and
27 deletions.
There are no files selected for viewing
212 changes: 212 additions & 0 deletions
212
Sample/AtalaPrismWalletDemo/AtalaPrismWalletDemo.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
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
73 changes: 73 additions & 0 deletions
73
...WalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Connections/ConnectionsListView.swift
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,73 @@ | ||
import SwiftUI | ||
|
||
protocol ConnectionsListViewModel: ObservableObject { | ||
var connections: [ConnectionsViewState.Connection] { get } | ||
var error: FancyToast? { get set } | ||
|
||
func addConnection(invitation: String, alias: String) | ||
} | ||
|
||
struct ConnectionsListView<ViewModel: ConnectionsListViewModel>: View { | ||
@StateObject var viewModel: ViewModel | ||
@State var showAddConnection = false | ||
@State var aliasInput = "" | ||
@State var newConnectionInput = "" | ||
|
||
var body: some View { | ||
NavigationStack { | ||
VStack { | ||
if showAddConnection { | ||
VStack(spacing: 16) { | ||
TextField("Alias", text: $aliasInput) | ||
TextField("DID or OOB", text: $newConnectionInput) | ||
HStack(spacing: 8) { | ||
Button { | ||
viewModel.addConnection(invitation: newConnectionInput, alias: aliasInput) | ||
showAddConnection = false | ||
} label: { | ||
Text("Add") | ||
} | ||
Button { | ||
showAddConnection = false | ||
} label: { | ||
Text("Cancel") | ||
} | ||
} | ||
} | ||
} | ||
List { | ||
ForEach(viewModel.connections) { connection in | ||
VStack(spacing: 8) { | ||
if let alias = connection.alias { | ||
Text(alias) | ||
} | ||
HStack { | ||
Text("Host: ") | ||
Text(connection.hostDID) | ||
.lineLimit(1) | ||
.truncationMode(.middle) | ||
} | ||
|
||
HStack { | ||
Text("Recipient: ") | ||
Text(connection.recipientDID) | ||
.lineLimit(1) | ||
.truncationMode(.middle) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.padding() | ||
.toolbar(content: { | ||
ToolbarItem(placement: .navigationBarTrailing) { | ||
Button(action: { | ||
showAddConnection = true | ||
}, label: { | ||
Image(systemName: "plus") | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...tDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Connections/ConnectionsListViewModel.swift
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,78 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
import PrismAgent | ||
|
||
final class ConnectionsListViewModelImpl: ConnectionsListViewModel { | ||
@Published var connections = [ConnectionsViewState.Connection]() | ||
@Published var error: FancyToast? | ||
|
||
private let castor: Castor | ||
private let pluto: Pluto | ||
private let agent: PrismAgent | ||
|
||
init(castor: Castor, pluto: Pluto, agent: PrismAgent) { | ||
self.castor = castor | ||
self.pluto = pluto | ||
self.agent = agent | ||
|
||
bind() | ||
} | ||
|
||
func bind() { | ||
agent | ||
.getAllDIDPairs() | ||
.map { | ||
$0.map { | ||
ConnectionsViewState.Connection( | ||
hostDID: $0.holder.string, | ||
recipientDID: $0.other.string, | ||
alias: $0.name | ||
) | ||
} | ||
} | ||
.replaceError(with: []) | ||
.assign(to: &$connections) | ||
} | ||
|
||
func addConnection(invitation: String, alias: String) { | ||
let castor = self.castor | ||
let agent = self.agent | ||
Task { [weak self] in | ||
do { | ||
if let did = try? castor.parseDID(str: invitation) { | ||
let hostDID = try await agent.createNewPeerDID( | ||
alias: alias.isEmpty ? nil : alias, | ||
updateMediator: true | ||
) | ||
let connectionRequest = ConnectionRequest( | ||
from: hostDID, | ||
to: did, | ||
thid: nil, | ||
body: .init() | ||
) | ||
_ = try await agent.sendMessage(message: connectionRequest.makeMessage()) | ||
} else if let url = URL(string: invitation) { | ||
let inv = try agent.parseOOBInvitation(url: url) | ||
try await agent.acceptDIDCommInvitation(invitation: inv) | ||
} | ||
} catch let error as LocalizedError { | ||
await MainActor.run { [weak self] in | ||
self?.error = FancyToast( | ||
type: .error, | ||
title: error.localizedDescription, | ||
message: error.errorDescription ?? "" | ||
) | ||
} | ||
} catch { | ||
await MainActor.run { [weak self] in | ||
self?.error = FancyToast( | ||
type: .error, | ||
title: error.localizedDescription, | ||
message: "" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...alletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/Connections/ConnectionsViewState.swift
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,8 @@ | ||
struct ConnectionsViewState { | ||
struct Connection: Identifiable { | ||
var id: String { hostDID + recipientDID } | ||
let hostDID: String | ||
let recipientDID: String | ||
let alias: String? | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...rismWalletDemo/Modules/WalletDemo2/Credentials/CredentialsList/CredentialListRouter.swift
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,9 @@ | ||
import SwiftUI | ||
|
||
struct CredentialListRouterImpl: CredentialListRouter { | ||
let container: DIContainer | ||
|
||
func routeToCredentialDetail(id: String) -> some View { | ||
Text("") | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...aPrismWalletDemo/Modules/WalletDemo2/Credentials/CredentialsList/CredentialListView.swift
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,57 @@ | ||
import SwiftUI | ||
|
||
protocol CredentialListViewModel: ObservableObject { | ||
var credentials: [CredentialListViewState.Credential] { get } | ||
} | ||
|
||
protocol CredentialListRouter { | ||
associatedtype CredentialDetailV: View | ||
|
||
func routeToCredentialDetail(id: String) -> CredentialDetailV | ||
} | ||
|
||
struct CredentialListView< | ||
ViewModel: CredentialListViewModel, | ||
Router: CredentialListRouter | ||
>: View { | ||
@StateObject var viewModel: ViewModel | ||
let router: Router | ||
|
||
var body: some View { | ||
NavigationStack { | ||
List(viewModel.credentials, id: \.id) { credential in | ||
NavigationLink(value: credential) { | ||
VStack(alignment: .leading) { | ||
Text(credential.credentialType) | ||
.font(.headline) | ||
Text(credential.issuer) | ||
.lineLimit(1) | ||
.truncationMode(.middle) | ||
.font(.subheadline) | ||
.foregroundColor(.secondary) | ||
Text(credential.issuanceDate) | ||
.font(.subheadline) | ||
.foregroundColor(.secondary) | ||
if !credential.type.isEmpty { | ||
Spacer() | ||
HStack { | ||
ForEach(credential.type, id: \.self) { type in | ||
Text(type) | ||
.font(.caption) | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background(Color.blue.opacity(0.2)) | ||
.cornerRadius(4) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.navigationDestination(for: CredentialListViewState.Credential.self) { | ||
router.routeToCredentialDetail(id: $0.id) | ||
} | ||
.navigationTitle("My Credentials") | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...mWalletDemo/Modules/WalletDemo2/Credentials/CredentialsList/CredentialListViewModel.swift
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,44 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
final class CredentialListViewModelImpl: CredentialListViewModel { | ||
@Published var credentials = [CredentialListViewState.Credential]() | ||
|
||
private let pluto: Pluto | ||
|
||
init(pluto: Pluto) { | ||
self.pluto = pluto | ||
bind() | ||
} | ||
|
||
private func bind() { | ||
self.pluto | ||
.getAllCredentials() | ||
.map { | ||
$0.map { | ||
CredentialListViewState.Credential( | ||
credentialType: getTypeString(type: $0.credentialType), | ||
id: $0.id, | ||
issuer: $0.issuer.string, | ||
issuanceDate: $0.issuanceDate.formatted(), | ||
context: Array($0.context), | ||
type: Array($0.type) | ||
) | ||
} | ||
} | ||
.replaceError(with: []) | ||
.assign(to: &$credentials) | ||
} | ||
} | ||
|
||
private func getTypeString(type: CredentialType) -> String { | ||
switch type { | ||
case .jwt: | ||
return "jwt" | ||
case .w3c: | ||
return "w3c" | ||
default: | ||
return "unknown" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...mWalletDemo/Modules/WalletDemo2/Credentials/CredentialsList/CredentialListViewState.swift
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,10 @@ | ||
struct CredentialListViewState { | ||
struct Credential: Hashable { | ||
let credentialType: String | ||
let id: String | ||
let issuer: String | ||
let issuanceDate: String | ||
let context: [String] | ||
let type: [String] | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ismWalletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/DIDs/DIDDetail/DIDDetailView.swift
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,17 @@ | ||
import SwiftUI | ||
|
||
protocol DIDDetailViewModel: ObservableObject { | ||
var state: DIDDetailViewState { get } | ||
} | ||
|
||
struct DIDDetailView: View { | ||
var body: some View { | ||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) | ||
} | ||
} | ||
|
||
struct DIDDetailView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
DIDDetailView() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...lletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/DIDs/DIDDetail/DIDDetailViewModel.swift
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,29 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
import PrismAgent | ||
|
||
final class DIDDetailViewModelImpl: DIDDetailViewModel { | ||
@Published var state: DIDDetailViewState = .init( | ||
did: "", | ||
alias: nil, | ||
publicKeys: [], | ||
services: [:] | ||
) | ||
private let pluto: Pluto | ||
private let did: String | ||
|
||
init(did: String, pluto: Pluto) { | ||
self.did = did | ||
self.pluto = pluto | ||
} | ||
|
||
// func bind() { | ||
// let did = try! DID(string: did) | ||
// switch did.method { | ||
// case "prism": | ||
// pluto | ||
// .getPeerDIDInfo(did: <#T##DID#>) | ||
// } | ||
// } | ||
} |
6 changes: 6 additions & 0 deletions
6
...lletDemo/AtalaPrismWalletDemo/Modules/WalletDemo2/DIDs/DIDDetail/DIDDetailViewState.swift
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,6 @@ | ||
struct DIDDetailViewState { | ||
let did: String | ||
let alias: String? | ||
let publicKeys: [String] | ||
let services: [String: String] | ||
} |
Oops, something went wrong.