Skip to content

Commit

Permalink
Fixes default campaign should always be expected for the menu item.
Browse files Browse the repository at this point in the history
  • Loading branch information
whattherestimefor committed Nov 6, 2024
1 parent 9ddda1b commit a7664de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Mastodon/Scene/Donation/DonationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import UIKit
class DonationViewController: UIHostingController<DonationView> {

init(
campaign: DonationCampaignViewModel?,
campaign: DonationCampaignViewModel,
completion: @escaping (URL?) -> Void
) {
super.init(
rootView: DonationView(
campaign ?? DefaultDonationViewModel(), completion: completion))
campaign, completion: completion))
self.navigationItem.leftBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: UIAction(handler: { _ in
completion(nil)
}))
Expand Down
4 changes: 2 additions & 2 deletions Mastodon/Scene/Donation/NewDonationNavigationFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class NewDonationNavigationFlow: NavigationFlow {

init(
flowPresenter: NavigationFlowPresenter,
campaign: DonationCampaignViewModel?, appContext: AppContext,
campaign: DonationCampaignViewModel, appContext: AppContext,
authContext: AuthContext, sceneCoordinator: SceneCoordinator
) {
self.campaign = campaign ?? DefaultDonationViewModel()
self.campaign = campaign
self.appContext = appContext
self.authContext = authContext
self.sceneCoordinator = sceneCoordinator
Expand Down
35 changes: 21 additions & 14 deletions Mastodon/Scene/Settings/SettingsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ class SettingsCoordinator: NSObject, Coordinator {
self.sceneCoordinator = sceneCoordinator

settingsViewController = SettingsViewController(accountName: accountName, domain: authContext.mastodonAuthenticationBox.domain)

super.init()

Task { [weak self] in
guard let s = self else { return }
let userAuthentication = s.authContext.mastodonAuthenticationBox.authentication
let seed = Mastodon.Entity.DonationCampaign.donationSeed(username: userAuthentication.username, domain: userAuthentication.domain)
do {
let campaign = try await s.appContext.apiService.getDonationCampaign(seed: seed, source: nil).value

await MainActor.run {
s.settingsViewController.donationCampaign = campaign

}
} catch {
// TODO: it would be nice to hide the Make Donation row if there was nothing to configure the donation screen with
}
}
}

func start() {
Expand Down Expand Up @@ -103,22 +121,11 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
navigationController.pushViewController(serverDetailsViewController, animated: true)

case .makeDonation:
Task { [weak self] in
guard let s = self else { return }
let campaign: Mastodon.Entity.DonationCampaign?
let userAuthentication = s.authContext.mastodonAuthenticationBox.authentication

let seed = Mastodon.Entity.DonationCampaign.donationSeed(username: userAuthentication.username, domain: userAuthentication.domain)

do {
campaign = try await s.appContext.apiService.getDonationCampaign(seed: seed, source: nil).value
} catch {
campaign = nil
}
Task {
await MainActor.run { [weak self] in
guard let s = self else { return }
guard let s = self, let donationCampaign = s.settingsViewController.donationCampaign else { return }

let donationFlow = NewDonationNavigationFlow(flowPresenter: viewController, campaign: campaign, appContext: s.appContext, authContext: s.authContext, sceneCoordinator: s.sceneCoordinator)
let donationFlow = NewDonationNavigationFlow(flowPresenter: viewController, campaign: donationCampaign, appContext: s.appContext, authContext: s.authContext, sceneCoordinator: s.sceneCoordinator)
s.navigationFlow = donationFlow
donationFlow.presentFlow { [weak self] in
self?.navigationFlow = nil
Expand Down

0 comments on commit a7664de

Please sign in to comment.