Skip to content

Commit c108fe5

Browse files
committed
Merge pull-request #24
2 parents 7eea9fa + be8692f commit c108fe5

File tree

19 files changed

+2124
-272
lines changed

19 files changed

+2124
-272
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "8DB100392DD7E3D400885C8F"
19+
BuildableName = "swift-sdk-demo-wallet.app"
20+
BlueprintName = "swift-sdk-demo-wallet"
21+
ReferencedContainer = "container:swift-demo-wallet.xcodeproj">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "8DB100392DD7E3D400885C8F"
48+
BuildableName = "swift-sdk-demo-wallet.app"
49+
BlueprintName = "swift-sdk-demo-wallet"
50+
ReferencedContainer = "container:swift-demo-wallet.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "8DB100392DD7E3D400885C8F"
65+
BuildableName = "swift-sdk-demo-wallet.app"
66+
BlueprintName = "swift-sdk-demo-wallet"
67+
ReferencedContainer = "container:swift-demo-wallet.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Examples/swift-demo-wallet/swift-demo-wallet/AppView.swift

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,35 +52,48 @@ struct MainFlow: View {
5252

5353
struct AppView: View {
5454
@EnvironmentObject private var turnkey: TurnkeyContext
55-
@EnvironmentObject private var toast: ToastContext
56-
55+
@EnvironmentObject private var toast: ToastContext
56+
57+
@State private var hasLoaded = false
58+
5759
var body: some View {
5860
ZStack(alignment: .top) {
59-
if turnkey.client != nil {
60-
MainFlow()
61-
.transition(
62-
.asymmetric(
63-
insertion: .move(edge: .trailing),
64-
removal: .move(edge: .trailing)
65-
)
66-
)
67-
} else {
68-
AuthFlow()
69-
.transition(
70-
.asymmetric(
61+
Group {
62+
switch turnkey.authState {
63+
case .loading:
64+
ProgressView()
65+
.scaleEffect(1.5)
66+
.frame(maxWidth: .infinity, maxHeight: .infinity)
67+
.background(Color.red)
68+
.transition(.opacity)
69+
70+
case .unAuthenticated:
71+
AuthFlow()
72+
.transition(.asymmetric(
7173
insertion: .move(edge: .leading),
7274
removal: .move(edge: .leading)
73-
)
74-
)
75+
))
76+
.onAppear { hasLoaded = true }
77+
78+
case .authenticated:
79+
MainFlow()
80+
.transition(.asymmetric(
81+
insertion: .move(edge: .trailing),
82+
removal: .move(edge: .trailing)
83+
))
84+
.onAppear { hasLoaded = true }
85+
}
7586
}
76-
87+
7788
// add toast overlay
7889
if toast.isVisible {
7990
ToastView(message: toast.message, type: toast.type)
8091
.transition(.move(edge: .top).combined(with: .opacity))
8192
}
8293
}
83-
.animation(.easeInOut, value: turnkey.client == nil)
94+
// we only animate once we've left .loading at least once
95+
// this is to avoid showing a transition when going from loading
96+
// to another auth state
97+
.animation(hasLoaded ? .easeInOut : nil, value: turnkey.authState)
8498
}
8599
}
86-

Examples/swift-demo-wallet/swift-demo-wallet/Contexts/AuthContext.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ final class AuthContext: ObservableObject {
147147
}
148148

149149
let result = try JSONDecoder().decode(VerifyOtpResponse.self, from: data)
150-
try await turnkey.createSession(jwt: result.token)
150+
try await turnkey.createSession(jwt: result.token, refreshedSessionTTLSeconds: Constants.Turnkey.sessionDuration)
151151
}
152152

153153
func signUpWithPasskey(anchor: ASPresentationAnchor) async throws {
@@ -243,7 +243,7 @@ final class AuthContext: ObservableObject {
243243
}
244244

245245
let result = try JSONDecoder().decode(OAuthLoginResponse.self, from: data)
246-
try await turnkey.createSession(jwt: result.token)
246+
try await turnkey.createSession(jwt: result.token, refreshedSessionTTLSeconds: Constants.Turnkey.sessionDuration)
247247
}
248248

249249

@@ -290,10 +290,9 @@ final class AuthContext: ObservableObject {
290290
throw AuthError.serverError
291291
}
292292

293-
try await turnkey.createSession(jwt: jwt)
293+
try await turnkey.createSession(jwt: jwt, refreshedSessionTTLSeconds: Constants.Turnkey.sessionDuration)
294294

295295
} catch let error as TurnkeyRequestError {
296-
print("Turnkey \(error.statusCode ?? 0): \(error.fullMessage)")
297296
throw error
298297
}
299298
}

0 commit comments

Comments
 (0)