Skip to content

Commit

Permalink
Hide the upgrade button it no upgradeURL present
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jun 10, 2024
1 parent 743c0ba commit acb42db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 6 additions & 4 deletions WordPress/Classes/ViewRelated/Voice/VoiceToContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ private struct VoiceToContentWelcomeView: View {
VStack(spacing: 4) {
Text(Strings.notEnoughRequests)
.multilineTextAlignment(.center)
Button(action: viewModel.buttonUpgradeTapped) {
HStack {
Text(Strings.upgrade)
Image("icon-post-actionbar-view")
if let upgradeURL = viewModel.upgradeURL {
Button(action: { viewModel.buttonUpgradeTapped(withUpgradeURL: upgradeURL) }) {
HStack {
Text(Strings.upgrade)
Image("icon-post-actionbar-view")
}
}
}
}.frame(maxWidth: 320)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ final class VoiceToContentViewModel: NSObject, ObservableObject, AVAudioRecorder
return isEligible
}

var upgradeURL: URL? {
featureInfo?.upgradeURL.flatMap(URL.init)
}
private var featureInfo: JetpackAssistantFeatureDetails?
private var audioSession: AVAudioSession?
private var audioRecorder: AVAudioRecorder?
Expand Down Expand Up @@ -112,15 +115,8 @@ final class VoiceToContentViewModel: NSObject, ObservableObject, AVAudioRecorder
}
}

func buttonUpgradeTapped() {
func buttonUpgradeTapped(withUpgradeURL upgradeURL: URL) {
WPAnalytics.track(.voiceToContentButtonUpgradeTapped)

guard let featureInfo else {
return wpAssertionFailure("feature info missing")
}
guard let upgradeURL = featureInfo.upgradeURL.flatMap(URL.init) else {
return wpAssertionFailure("invalid or missing upgrade URL")
}
UIApplication.shared.open(upgradeURL)
}

Expand Down

0 comments on commit acb42db

Please sign in to comment.