Skip to content

Commit

Permalink
[Connect] Add ability to specify arbitrary demo accounts in example a…
Browse files Browse the repository at this point in the history
…pp (#4048)

## Summary

Adds the ability specify arbitrary demo / test accounts in the Connect
example app.

Primary use case is so we can test with different accounts internally
during bug-bashing, but also useful for testing onboarding since we need
to create new accounts with empty data to test it properly.

## Motivation

https://jira.corp.stripe.com/browse/MXMOBILE-2793

## Testing

https://github.com/user-attachments/assets/6ad28c68-dd1b-4025-90d2-798cf2d31ec4
  • Loading branch information
mludowise-stripe authored Sep 25, 2024
1 parent ffdd561 commit 00c3032
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,32 @@ struct AppSettingsView: View {
URL(string: serverURLString)?.isValid == true
}

var isUsingCustomMerchant: Bool {
guard let selectedMerchant,
let appInfo else {
return true
}
return !appInfo.availableMerchants.contains(selectedMerchant)
}

var isMerchantIdValid: Bool {
if !isUsingCustomMerchant {
return true
} else if let selectedMerchant {
return selectedMerchant.id.starts(with: "acct_")
&& selectedMerchant.id.count > 5
} else {
return false
}
}

func isMerchantIdValid(_ id: String) -> Bool {
id.starts(with: "acct_") && id.count > 5
}

var saveEnabled: Bool {
isCustomEndpointValid &&
isMerchantIdValid &&
(AppSettings.shared.selectedMerchant(appInfo: appInfo)?.id != selectedMerchant?.id ||
AppSettings.shared.selectedServerBaseURL != serverURLString)
}
Expand All @@ -46,6 +70,27 @@ struct AppSettingsView: View {
selectedMerchant = merchant
})
}
HStack {
TextInput(label: "Other",
placeholder: "acct_xxxx",
text: .init(
get: {
guard let selectedMerchant,
isUsingCustomMerchant else {
return ""
}
return selectedMerchant.id
},
set: {
selectedMerchant = .init(displayName: nil, merchantId: $0)
}
),
isValid: isMerchantIdValid)
Spacer()
Image(systemName: "checkmark")
.foregroundColor(.accentColor)
.opacity(isUsingCustomMerchant ? 1.0 : 0.0)
}
} header: {
Text("Select a demo account")
}
Expand All @@ -67,13 +112,16 @@ struct AppSettingsView: View {
} label: {
Text("Reset to default")
.disabled(AppSettings.Constants.defaultServerBaseURL == serverURLString)
.keyboardType(.URL)
}
} header: {
Text("API Server Settings")
}
}
.listStyle(.insetGrouped)
.animation(.easeOut(duration: 0.2), value: selectedMerchant)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.navigationTitle("Configure server")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@ class AppSettings {
}

func selectedMerchant(appInfo: AppInfo?) -> MerchantInfo? {
let merchantId = defaults.string(forKey: Constants.selectedMerchantKey)
return appInfo?.availableMerchants.first(where: {
// Default to the first available merchant if this is the first time opening the app
guard let merchantId = defaults.string(forKey: Constants.selectedMerchantKey) else {
return appInfo?.availableMerchants.first
}

// If the merchant is in the list of available merchants, then use its display name
let displayName = appInfo?.availableMerchants.first(where: {
$0.merchantId == merchantId
}) ?? appInfo?.availableMerchants.first
})?.displayName

return .init(displayName: displayName, merchantId: merchantId)
}

func setSelectedMerchant(merchant: MerchantInfo?) {
Expand Down

0 comments on commit 00c3032

Please sign in to comment.