-
Notifications
You must be signed in to change notification settings - Fork 54
test(swift-sdk): add testnet identity-discovery UI test #3560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3.1-dev
Are you sure you want to change the base?
Changes from 7 commits
03af8e2
b3c85a2
7c0ae94
c08f9fa
52312a2
e8eb123
4e4cf1a
296d966
3823ee4
33b6f3c
a228c04
983f89c
4801f03
0e38b24
92cddcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,27 @@ class AppState: ObservableObject { | |
| @Published var showError = false | ||
| @Published var errorMessage = "" | ||
|
|
||
| /// `true` from the moment a network change is requested until the | ||
| /// new SDK is bound. Spans the full async cycle (didSet → Task → | ||
| /// `switchNetwork` → `sdk = newSDK`), so consumers can wait on it | ||
| /// as a real readiness signal. UI bindings should treat | ||
| /// `appState.sdk != nil && !isSwitchingNetwork` as "connected on | ||
| /// the current network" — `appState.sdk != nil` alone is true even | ||
| /// while `switchNetwork` is still tearing down the previous SDK. | ||
| @Published var isSwitchingNetwork: Bool = false | ||
|
|
||
| /// Monotonic request id for in-flight switches. If two switches | ||
| /// overlap (user taps mainnet → testnet before the first lands), the | ||
| /// earlier task's completion would otherwise clear `isSwitchingNetwork` | ||
| /// while the later switch is still running. Each new request bumps | ||
| /// this counter and the spawned task only clears the flag when its | ||
| /// captured id still matches. | ||
| private var networkSwitchRequestID: UInt64 = 0 | ||
|
|
||
| @Published var currentNetwork: AppNetwork { | ||
| didSet { | ||
| UserDefaults.standard.set(currentNetwork.rawValue, forKey: "currentNetwork") | ||
| Task { | ||
| await switchNetwork(to: currentNetwork) | ||
| } | ||
| beginNetworkSwitch() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -27,7 +42,23 @@ class AppState: ObservableObject { | |
| UserDefaults.standard.set(useDockerSetup, forKey: "useLocalhostPlatform") | ||
| UserDefaults.standard.set(useDockerSetup, forKey: "useLocalhostCore") | ||
| UserDefaults.standard.set(useDockerSetup, forKey: "useLocalhost") | ||
| Task { await switchNetwork(to: currentNetwork) } | ||
| beginNetworkSwitch() | ||
| } | ||
| } | ||
|
|
||
| /// Bumps `networkSwitchRequestID`, raises `isSwitchingNetwork`, and | ||
| /// spawns the SDK-rebuild task. Only the task that owns the latest | ||
| /// request id may lower `isSwitchingNetwork` again — overlapping | ||
| /// switches' earlier tasks no-op on completion. | ||
| private func beginNetworkSwitch() { | ||
| networkSwitchRequestID &+= 1 | ||
| let requestID = networkSwitchRequestID | ||
| isSwitchingNetwork = true | ||
| Task { | ||
| await switchNetwork(to: currentNetwork) | ||
| if requestID == networkSwitchRequestID { | ||
| isSwitchingNetwork = false | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+53
to
63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard the SDK rebuild itself, not just The request ID only prevents an old task from clearing the spinner early. A stale 🔧 Suggested shape of the fix Task {
- await switchNetwork(to: currentNetwork)
+ await switchNetwork(to: currentNetwork, requestID: requestID)
if requestID == networkSwitchRequestID {
isSwitchingNetwork = false
}
}
- func switchNetwork(to network: Network) async {
+ func switchNetwork(to network: Network, requestID: UInt64) async {
guard let modelContext = modelContext else { return }
+ guard requestID == networkSwitchRequestID else { return }
dataManager?.currentNetwork = network
do {
isLoading = true
let newSDK = try SDK(network: network)
+ guard requestID == networkSwitchRequestID else { return }
sdk = newSDK
await loadKnownContractsIntoSDK(sdk: newSDK, modelContext: modelContext)
+ guard requestID == networkSwitchRequestID else { return }
isLoading = false
} catch {
+ guard requestID == networkSwitchRequestID else { return }
sdk = nil
...
}
}🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,12 @@ struct IdentityDetailView: View { | |
| Text(identity.formattedBalance) | ||
| .foregroundColor(.blue) | ||
| .fontWeight(.medium) | ||
| .accessibilityIdentifier("identityDetail.balanceLabel") | ||
| // Display string is "%.8f DASH" — rounding hides | ||
| // sub-1000-credit deltas. Expose the raw credit | ||
| // count via accessibilityValue for tests that | ||
| // need exact numbers. | ||
| .accessibilityValue("\(UInt64(bitPattern: identity.balance))") | ||
|
Comment on lines
139
to
+147
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion:
source: ['claude', 'codex'] 🤖 Fix this with AI agents
Comment on lines
+142
to
+147
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion:
source: ['claude', 'codex'] 🤖 Fix this with AI agents |
||
| } | ||
|
|
||
| // Top-up entry point. Hidden for purely-local rows | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.