Skip to content
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

[MOB-1960] Update Referrals refresh logic #573

Merged
merged 6 commits into from
Oct 11, 2023

Conversation

d4r1091
Copy link
Member

@d4r1091 d4r1091 commented Oct 10, 2023

MOB-1960

Context

Due to a regression found on G Changes, we take the occasion to review the Referrals update logic.

Approach

  • Make use of HomepageViewModelProtocol's refreshData(:) to conform to other cells and delegate its ViewModel to refresh its own data. As the HomePageViewController sits within the BrowserViewController domain, viewWillAppear won't respond every time the HomePageViewController is shown. The BrowserViewController creates the object only once and then orchestrates the transitions between views accordingly.
  • Update of referrals.refresh specifying the force:true parameter within the updateInviteLink() function called in viewWillAppear

@d4r1091 d4r1091 requested a review from a team October 10, 2023 14:11
@d4r1091 d4r1091 changed the title MOB-1960 Update Referrals refresh logic [MOB-1960] Update Referrals refresh logic Oct 10, 2023
Copy link
Collaborator

@lucaschifino lucaschifino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice quick fix 🔨

Added some points that I do believe need to be addressed before merging, let me know if you want to sync on them.

Client/Ecosia/UI/MultiplyImpact/MultiplyImpact.swift Outdated Show resolved Hide resolved
@@ -508,7 +508,7 @@ final class MultiplyImpact: UIViewController, NotificationThemeable {
private func updateInviteLink() {
guard let inviteLink = inviteLink else {
copyLink?.text = "-"
referrals.refresh(createCode: true) {[weak self] error in
referrals.refresh(force: true, createCode: true) {[weak self] error in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, I see the only thing we do after the refresh is call self?.updateInviteLink() again so that copyLink?.text = inviteLink can be set. Since we are now refreshing the referrals and potentially get new claims, we should also refresh the counter when there is an update. I would even suggest properly subscribing to referrals since it is a Publisher and does already have a logic of sending whenever the count updates.

Also this might be a bit conflicting with the changes made on #568 since there a new component for the referral counter is used that would need to be updated 🤔 I guess it all depends on which is merged first to see how it is handled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'll be planning to move the refresh logic out of the updateInviteLink() we can also double-check whether this is still needed.

@d4r1091 d4r1091 requested a review from lucaschifino October 11, 2023 10:24
@d4r1091
Copy link
Member Author

d4r1091 commented Oct 11, 2023

Reviewed logic to extract the Referrals' refresh while keeping the higher level logic as similar as possible.

Copy link
Collaborator

@lucaschifino lucaschifino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice extraction of the refresh to viewWillAppear 👏

Added some comments that I believe are still valid, let me know what you think 🙂

private func refreshReferrals() {
referrals.refresh(force: true, createCode: true) { [weak self] error in
guard error == nil else {
self?.showObtainingCode(error!)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have showReferralError which might also be relevant in here.

Probably showReferralError and showObtainingCode can be merged now since the only difference is the retrying logic, which I guess can be the same 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation was only referring to the showObtainingCode(:) error.
We have only separated the updateInviteLinks() from the refresh which is called at the same entry point now (viewWillAppear()).
To minimize in-scope changes only, I'd like to leave this small refactor off these changes for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see with not changing it is that now with the new implementation we might reach an error on a different request and by showing this message from showObtainingCode(:) the retry attempt would be only calling self?.updateInviteLink() which does not actually retry

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to fetch the latest ios-core version so that the new increased cooldown takes effect, right? Or were you planning on doing it separately?

Copy link
Member Author

@d4r1091 d4r1091 Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or were you planning on doing it separately?

Planned to update only after receiving a ✅ on these requested changes logic wise

}
return
self?.updateInviteLink()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also believe you need to update the UI for the counter and not only the invite link after the refresh happens. If you update from main with the changes from #568, this should be only updating referralImpactRowView.info.

@d4r1091 d4r1091 force-pushed the MOB-1960_referrals_refresh_review branch from 878c9df to c1f8102 Compare October 11, 2023 15:10
@d4r1091 d4r1091 requested a review from lucaschifino October 11, 2023 15:12
lucaschifino
lucaschifino previously approved these changes Oct 11, 2023
Copy link
Collaborator

@lucaschifino lucaschifino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Copy link
Collaborator

@lucaschifino lucaschifino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢

@d4r1091 d4r1091 merged commit bbd08fe into main Oct 11, 2023
2 checks passed
@d4r1091 d4r1091 deleted the MOB-1960_referrals_refresh_review branch October 11, 2023 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants