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

Refactor PayPal Web Demo App into Single View #227

Merged
merged 17 commits into from
Dec 21, 2023

Conversation

jaxdesmarais
Copy link
Collaborator

@jaxdesmarais jaxdesmarais commented Dec 14, 2023

Reason for changes

Currently the PayPal Web feature exists across 3 total views with totally different result views. This simplifies the PayPal Web feature into a single view. It also gives us the ability to reset the PayPal flow for subsequent checkouts.

Summary of changes

  • Add LabelViewText to stack the text horizontally vs vertically to save space
  • Remove PayPalWebStatusView - now that we have a single success view we can remove this fine
  • Add segmented control for PayPalWebButtonsView - this saves space by not displaying all buttons at once
  • Add Reset button to PayPalWebCreateOrderView - this allows for resetting the flow and clearing out stored properties on the ViewModel
  • Add all views to PayPalWebPaymentsView
    • Conditionally hide/show views depending on where we are in the flow
  • Remove no longer needed OrderStatus
  • Replace PayPalWebStatusView with successView property on PayPalWebResultView
  • Simplify PayPalWebTransactionView now that we have 1 shared result view
  • Remove no longer needed createOrderResult and transactionResult - this can be shared across 1 updated order property as the order progresses

Visuals

Before After
Simulator Screen Recording - iPhone 15 - 2023-12-14 at 17 01 18 Simulator Screen Recording - iPhone 15 - 2023-12-14 at 17 02 43

Checklist

  • [ ] Added a changelog entry

Authors

@jaxdesmarais jaxdesmarais requested a review from a team as a code owner December 14, 2023 23:04

switch selectedFundingSource {
case .paypalCredit:
PayPalCreditButton.Representable(color: .black, size: .full) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the buttons are the same size now. We have a separate Payment Button demo that displays all of the options of size/color/etc.

.id("bottomView")
.onAppear {
withAnimation {
scrollView.scrollTo("bottomView")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Scrolling to the bottom of a view is most commonly used with table views or a view that has incrementing IDs to reference. In order to scroll to the bottom both when displaying this view as well as the bottom of the result after authorizing/capturing we need to duplicate this scrollTo logic. Bit odd but it seemed like the solution for this from what I found online. 🤷‍♂️

@@ -6,8 +6,7 @@ class PayPalWebViewModel: ObservableObject, PayPalWebCheckoutDelegate {

@Published var state: CurrentState = .idle
@Published var intent: Intent = .authorize
@Published var createOrderResult: Order?
@Published var transactionResult: Order?
@Published var order: Order?
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can get rid of the duplicate Order above now that we have a singular result view 🎉

Copy link
Collaborator

Choose a reason for hiding this comment

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

ux: on Android we do display multiple snapshots of the Order at different points in time. Not sure how it's designed on iOS, but adding some context about why these two values are separate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were mainly using this as a psudo state on iOS to display slightly different results. Since we have 1 result that is appended to as we get more data, we don't need 2 properties.

Copy link
Collaborator

@KunJeongPark KunJeongPark Jan 2, 2024

Choose a reason for hiding this comment

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

Hey @jaxdesmarais , it looks really smooth! I love the toggling of the buttons there in the UI. I am wondering about replacing result view from create with authorize/capture result view. I liked having history of the states, I think that's why we retained the different order snapshots in the first place, to compare the results to make sure that things match up. Another thing that is kind of unexpected for me is that the result view after order creation appears after the toggle for the funding source.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just getting back to these comments from being on PTO. 😄

I am wondering about replacing result view from create with authorize/capture result view. I liked having history of the states, I think that's why we retained the different order snapshots in the first place, to compare the results to make sure that things match up.

We can use breakpoints in these cases but should not busy up our demo app with different views containing the same data type. We could also add a quick print statement of the states if needed in each method that returns an order.

Another thing that is kind of unexpected for me is that the result view after order creation appears after the toggle for the funding source.

This made the most sense to keep the result view pinned in the same general place throughout the flow without it jumping around as we added subsequent views. Otherwise, we'd require unnecessary logic to move this view around throughout the flow. I had tested this initially and it was much cleaner to keep the result view relatively in 1 place.

Copy link
Collaborator

@KunJeongPark KunJeongPark Jan 8, 2024

Choose a reason for hiding this comment

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

Hey Jax welcome back! Yeah, I personally like comparing different states instead of new ones swapping out the other for comparison. Steven and I had talked about the one of primary uses for the demo app being able to surface issues or prove that a feature is working correctly. To me, being able to have different states is helpful. It definitely is cleaner the way you refactored it.

To me, being able to see history more clearly without print statements, things appearing chronologically is more important than cleaner code for demo app.

do {
let config = try await configManager.getCoreConfig()
let payPalClient = PayPalWebCheckoutClient(config: config)
return payPalClient
} catch {
updateState(.error(message: error.localizedDescription))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated this logic since we wouldn't display anything if we didn't get a config back, no we will return our error view in this case

@jaxdesmarais jaxdesmarais merged commit e86898f into main Dec 21, 2023
4 checks passed
@jaxdesmarais jaxdesmarais deleted the paypal-web-demo-single-view branch December 21, 2023 16:35
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.

4 participants