-
Notifications
You must be signed in to change notification settings - Fork 136
Store creation using a webview #7602
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
Conversation
Generated by 🚫 dangerJS |
Codecov ReportBase: 42.98% // Head: 42.94% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## trunk #7602 +/- ##
============================================
- Coverage 42.98% 42.94% -0.04%
+ Complexity 3301 3299 -2
============================================
Files 607 607
Lines 34105 34141 +36
Branches 4421 4430 +9
============================================
+ Hits 14659 14663 +4
- Misses 18105 18137 +32
Partials 1341 1341
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
| navigateBackWithNotice(WEBVIEW_RESULT) | ||
| extractSiteUrl(url) | ||
|
|
||
| lifecycleScope.launchWhenResumed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary because the app kept crashing for me after a result was returned after site creation. Turns out the onLoadUrl() callback was still getting called even after that, which would the trigger the navigation again and crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have an unwanted side effect, let's say the user started loading the page that we want to detect to close the screen after, then they navigated to another app, the listener then will ignore the URL that's being loaded, and we'll end up showing a page that the user is not expected to navigate to.
We have the isAdded check below to avoid this crash, I think since the app crashed for you, then it's not enough (maybe because fragment transactions are async), so as an alternative, we can simply use a boolean to track whether the navigation was triggered by the listener, and then use it to ignore all subsequent calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! It's now fixed.
| var newSite: SiteModel? = null | ||
| while (newSite?.hasWooCommerce != true) { | ||
| newSite = urls.firstNotNullOfOrNull { url -> repository.getSiteBySiteUrl(url) } | ||
| if (newSite != null && newSite.hasWooCommerce) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a new site is first fetched, the Woo plugin is still not ready and the store can't be selected. So we need to wait for the hasWooCommerce to be true.
|
|
||
| private val webViewClient by lazy { WPComWebViewClient(this) } | ||
| private val navArgs: WPComWebViewFragmentArgs by navArgs() | ||
| private var siteUrls = ArrayList<String>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple address aliases associated with a new site. That's why a list of addresses is returned so that the site can be loaded and selected.
|
You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code: |
| const val WEBVIEW_STORE_CHECKOUT_STRING = "checkout/thank-you/" | ||
| const val WEBVIEW_STORE_URL_KEY = "store-url-key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before starting a full review for the PR @0nko, I wanted to raise the point below 🙂, if you feel like what I'm raising below doesn't make sense, or if the time doesn't allow it, please let me know, and I'll review the PR as is.
I feel like these constants and the logic below to extract the site URL don't belong in this class, this fragment was supposed to be a reusable screen for the authenticated WPCom logic, with the sole responsibility of loading a URL and then informing the parent screens when a specific URL was loaded as a termination of a specific flow, but with the current logic, it's responsible for more than this, and it has logic that's not reusable or part of other flows.
If the siteUrl extraction logic needed only the last URL of the flow, then I would've suggested to update the logic of the screen to return the last URL, and make the parsing of this URL a responsibility of the calling Fragment.
But given how it has to be done, I suggest we create a separate screen for this, I believe we can use the Composable component WCWebView, it supports WPCom authentication, and it's flexible enough, so that we can have the URL parsing and extraction easily separated. This will have some other advantages:
- Remove the responsibility of waiting from the site picker, it already handles too much, and by being implemented in the new screen, we can use a better ui/text for the loading if needed (something other than "verifying your site" which sounds weird for a site that we were responsible for creating 😅).
- Then in the site picker, the
onStoreCreatedcan be very simplified, basically the same implementation asonSiteAddressReceived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great suggestions, @hichamboushaba! I've been so focused on making the store creation flow load the new site automatically that I didn't stop and think about how to properly separate the new functionality from the existing components, thinking this is all just a temporary solution anyway...
As you suggested, we can use the WCWebView in its own Composable screen, with a ViewModel, which can then be used as a base for Iteration 2. I started working on it but I can already see it will be a bit more work.
Considering the circumstances, could we go ahead with the current PR (since it's already providing the desired functionality), and in the meantime, I'll refactor the code, as I mentioned above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good @0nko 🙂, thanks for this.
For the review, I added a comment about a potential issue that we want to fix before releasing this, and for the rest, I will review the code and functionality today or tomorrow morning.
hichamboushaba
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @0nko, I left one np comment, but it can be ignored for this PR.
| STORE_CREATION_FLOW -> PackageUtils.isDebugBuild() | ||
| STORE_CREATION_WEBVIEW_FLOW -> PackageUtils.isDebugBuild() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np, I think these two feature flags might be confusing, especially with how we are going to interact with them for the simplified login project.
I think we should updateSTORE_CREATION to be called ACCOUNT_CREATION, as this is what's really controls right now.
# Conflicts: # WooCommerce/src/main/res/values/strings.xml
This PR adds the store creation feature using a webview. Like on iOS, it's currently hidden behind a feature flag (debug build only).
Only a logged-in user use case is supported because we can't get the login credentials from a webview.
After a purchase is made, the store creation takes a long time and it's expected because a site must first be created, then the WooCommerce plugin is installed and then it takes a while to register as a new site for the user. A user's sites keep getting re-fetched until the new site is found.
store_creation_final.mp4
To test: (make sure you have free credits for testing)