Skip to content

Commit 4024785

Browse files
bfoss765claude
andcommitted
fix: ensure CTX API endpoints switch correctly between testnet and mainnet
- Removed cached kBaseURL constant that was preventing network switching - baseURL property now computes URL dynamically based on current network - This fixes the issue where switching from testnet to mainnet (or vice versa) required app restart - Updated CLAUDE.md with network switching documentation and best practices The issue occurred because the API endpoint was cached at initialization time. Now it correctly evaluates the network on each request, ensuring: - Testnet uses: http://staging.spend.ctx.com/ - Mainnet uses: https://spend.ctx.com/ Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2a69fce commit 4024785

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

CLAUDE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,27 @@ The project expects sibling directories:
385385
386386
## Special Considerations
387387
388+
### Network Switching (Testnet/Mainnet)
389+
**Important**: External API endpoints must switch dynamically when changing between testnet and mainnet without requiring app restart.
390+
391+
#### CTX API Configuration
392+
- **Mainnet**: `https://spend.ctx.com/`
393+
- **Testnet**: `http://staging.spend.ctx.com/`
394+
- The endpoint URL is computed dynamically in `CTXSpendEndpoint.baseURL` property
395+
- **Never cache the base URL** as a constant - it must be evaluated on each request to ensure the correct network endpoint is used
396+
397+
**Implementation Pattern**:
398+
```swift
399+
// ❌ WRONG - Caches URL at initialization
400+
private let kBaseURL = URL(string: CTXConstants.baseURI)!
401+
public var baseURL: URL { return kBaseURL }
402+
403+
// ✅ CORRECT - Computes URL dynamically
404+
public var baseURL: URL {
405+
return URL(string: CTXConstants.baseURI)!
406+
}
407+
```
408+
388409
### DashPay Features
389410
- Conditional compilation with `#if DASHPAY`
390411
- Username registration and management

DashWallet/Sources/Models/Explore Dash/Services/DashSpend/CTX/CTXSpendEndpoint.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import Foundation
1919
import Moya
2020

21-
private let kBaseURL = URL(string: CTXConstants.baseURI)!
22-
2321
// MARK: - CTXSpendAPIError
2422

2523
struct CTXSpendAPIError: Decodable {
@@ -64,7 +62,9 @@ extension CTXSpendEndpoint: TargetType, AccessTokenAuthorizable {
6462
}
6563

6664
public var baseURL: URL {
67-
return kBaseURL
65+
// Dynamically compute the base URL based on the current network
66+
// This ensures the correct endpoint is used even when switching between testnet/mainnet
67+
return URL(string: CTXConstants.baseURI)!
6868
}
6969

7070
public var path: String {

0 commit comments

Comments
 (0)