App icon indicating copy to clipboard operation
App copied to clipboard

clean up the deep link code

Open ntdiary opened this issue 1 year ago • 10 comments

Details

This is a followup PR for #16043. After we remove the redirection ui in the deep link component, We no longer need to update the appInstallationCheckStatus variable. We can also remove the call to Network.post(). We need to implement the transition process: oldDot --> newDot --> Desktop app

Fixed Issues

$ https://github.com/Expensify/App/issues/17391

Tests

Note: If we can't start OldDot locally, we can open the developer tools and add a breakpoint in the source panel to get the transition path, just like the image above.

  1. Open the local newDot and login with account A (tab 1).
  2. Open the local oldDot and login with the same account (tab 2).
  3. Open the local Desktop App and stay logged out.
  4. Click on the concierge button at bottom right on oldDot/inbox (tab 2).
  5. (Optional) Execute console.dir(t.replace('https://staging.new.expensify.com', '')) in console to get the /transition... path part, create a new tab and type localhost:8080 and append the transition path part and then open this url (tab 3).
  6. Tap on the 'Open Electron.app' button in the tab 3.
  7. Verify that account A is also logged in the desktop app.
  • [x] Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

  1. Open staging.new.expensify.com and login with account A (tab 1).
  2. Open staging.expensify.com and login with the same account (tab 2).
  3. Open the staging Desktop App and stay logged out.
  4. Click on the concierge button at bottom right on staging.expensify.com/inbox (tab 2).
  5. Tap on the 'Open New Expensify' button in the tab 3.
  6. Verify that account A is also logged in the desktop app.
  • [ ] Verify that no errors appear in the JS console

PR Author Checklist

  • [x] I linked the correct issue in the ### Fixed Issues section above
  • [x] I wrote clear testing steps that cover the changes made in this PR
    • [x] I added steps for local testing in the Tests section
    • [x] I added steps for the expected offline behavior in the Offline steps section
    • [x] I added steps for Staging and/or Production testing in the QA steps section
    • [x] I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • [x] I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • [x] I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • [x] I included screenshots or videos for tests on all platforms
  • [x] I ran the tests on all platforms & verified they passed on:
    • [x] Android / native
    • [x] Android / Chrome
    • [x] iOS / native
    • [x] iOS / Safari
    • [x] MacOS / Chrome / Safari
    • [x] MacOS / Desktop
  • [x] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • [x] I followed proper code patterns (see Reviewing the code)
    • [x] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • [x] I verified that comments were added to code that is not self explanatory
    • [x] I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • [x] I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • [x] If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • [x] I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • [x] I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • [x] I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • [x] I verified the JSDocs style guidelines (in STYLE.md) were followed
  • [x] If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • [x] I followed the guidelines as stated in the Review Guidelines
  • [x] I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • [x] I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • [x] I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • [x] I verified that if a function's arguments changed that all usages have also been updated correctly
  • [x] If a new component is created I verified that:
    • [x] A similar component doesn't exist in the codebase
    • [x] All props are defined accurately and each prop has a /** comment above it */
    • [x] The file is named correctly
    • [x] The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • [x] The only data being stored in the state is data necessary for rendering and nothing else
    • [x] For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • [x] Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • [x] All JSX used for rendering exists in the render method
    • [x] The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • [x] If any new file was added I verified that:
    • [x] The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • [x] If a new CSS style is added I verified that:
    • [x] A similar style doesn't already exist
    • [x] The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • [x] If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • [x] If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • [x] If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • [x] If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • [x] If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • [x] I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

https://user-images.githubusercontent.com/8579651/234503847-c4790472-ecaf-44ca-936b-9b3d93a3172a.mov

Mobile Web - Chrome N/A
Mobile Web - Safari N/A
Desktop N/A
iOS N/A
Android N/A

ntdiary avatar Apr 14 '23 08:04 ntdiary

@arosiclair Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

MelvinBot avatar Apr 14 '23 09:04 MelvinBot

Hi, I think the logic of deep link redirection is relatively clear now, could we merge this PR first? As for adding the BeginDeepLinkRedirect new command, we will do it in PR #17364?

If there are any other questions or anything I can do, please feel free to let me know.

cc @tgolen, @marcaaron

ntdiary avatar Apr 19 '23 09:04 ntdiary

Yeah, I'd like to get this merged. Can you please complete the PR description and checklist? It'd also be nice to have a C+ review/test this.

tgolen avatar Apr 19 '23 13:04 tgolen

@tgolen of course, please feel free to let me know if there are any mistakes. : )

ntdiary avatar Apr 19 '23 14:04 ntdiary

bump @arosiclair for review and checklist https://github.com/Expensify/App/pull/17452#issuecomment-1508218684

tgolen avatar Apr 20 '23 14:04 tgolen

@arosiclair sorry about the bump, I'm still confused on if we are wanting to merge this or not. I'm going to place a HOLD on it until we decide.

tgolen avatar Apr 20 '23 14:04 tgolen

What's the status of this PR? I'm thinking maybe we can create an issue for this to go over the general the plan then treat it like a normal "Bug" issue so that it doesn't fall off our radar? Does that sound OK to you @tgolen ?

marcaaron avatar Apr 25 '23 19:04 marcaaron

I thought the plan was to update this PR with all the necessary fixes. There was some discussion about it over here: https://github.com/Expensify/App/issues/17391#issuecomment-1520268938

That's a good reminder that this can be taken off HOLD (but it still needs updated before it can be reviewed).

tgolen avatar Apr 25 '23 19:04 tgolen

Ah hmm, first time seeing that comment. If there's a plan let's put it here to get on the same page?

marcaaron avatar Apr 25 '23 19:04 marcaaron

The code has been updated to fix issue #17391. The solution is to show the popup after the web transition is end.

ntdiary avatar Apr 26 '23 12:04 ntdiary

@marcaaron, thank you very much for the questions and suggestions!

I think the reason why it still looks confused is that we need to call this.openRouteInDesktopApp method after fetching the shortLivedAuthToken from the server in the DeepLinkWrapper component, which requires the onyx hoc.

So if we can move openRouteInDesktopApp out of the component as a utility function, we will no longer depend on onyx hoc, and the logic will be clearer. I first put openRouteInDesktopApp in Browser/index.web.js, unsure if it is appropriate, maybe we can create a new file for it.

Does the latest version look better? cc @tgolen, @marcaaron

ntdiary avatar Apr 28 '23 04:04 ntdiary

Personally, I think for this case, if we can get the shortLivedAuthToken from the response through an API (now we use makeRequestWithSideEffects), and then choose whether to show the popup window based on this value, it would be fine. I'm just not too sure if this would violate our code pattern. 😅


https://github.com/Expensify/App/blob/b4ed202dc9ae50c7e28e874ff38594cdb6cda2b8/src/libs/API.js#L69-L72

I read through the comments again, it seems that makeRequestWithSideEffects can be used when redirecting a user depending on the response data. If we want to avoid makeRequestWithSideEffects, we do have to use Onyx like the previous version.

If we prefer to use Onyx (e.g. session.shortLivedAuthToken), I can revert the latest commit and improve based on the previous version.

ntdiary avatar Apr 28 '23 12:04 ntdiary

Hi, @tgolen, is there anything else we need to do? : )

ntdiary avatar May 05 '23 13:05 ntdiary

Sounds like this is ready for the review checklist?

arosiclair avatar May 05 '23 15:05 arosiclair

As discussed on slack, I can review this and checklist if requires C+ review

0xmiroslav avatar May 05 '23 15:05 0xmiroslav

Hi, @tgolen, I resolved the conflicts again, not exactly sure how to get this PR merged, do we need a C+ to review or anything else? 🥲

ntdiary avatar May 09 '23 09:05 ntdiary

I will be reviewing this today

0xmiroslav avatar May 09 '23 09:05 0xmiroslav

Yep, last thing here is to get the C+ review and checklist. Thanks for doing this one @0xmiroslav

tgolen avatar May 09 '23 13:05 tgolen

@ntdiary please fix conflict caused by prettier run

0xmiroslav avatar May 10 '23 07:05 0xmiroslav

@0xmiroslav , thank you for the reminder, conflicts have been resolved. : )

ntdiary avatar May 10 '23 08:05 ntdiary

Hi, @0xmiroslav is there anything else I can do for this PR? : )

ntdiary avatar May 11 '23 08:05 ntdiary

reviewing right now

0xmiroslav avatar May 11 '23 09:05 0xmiroslav

  1. Verify that account A is also logged in the desktop app.

@ntdiary this doesn't work for me. Loading fixed but not auto logged in. Just stay on login page. can you retest on latest codebase?

https://github.com/Expensify/App/assets/97473779/a2083fa8-571b-4db2-8ef2-9924e5cdef39

0xmiroslav avatar May 11 '23 10:05 0xmiroslav

https://github.com/Expensify/App/assets/8579651/1ddb56af-5ed9-4cd1-bd35-594a1b44469f

https://youtu.be/Pu2LQw-d-U0

@0xmiroslav, interesting, it works for me. Could you temporarily print the value of deeplink in the openRouteInDesktopApp function? We can first check if it contains the shortLivedAuthToken parameter, like this:

console.dir(expensifyDeeplinkUrl);

ntdiary avatar May 11 '23 12:05 ntdiary

https://github.com/Expensify/App/assets/97473779/ee4c8644-6d0c-4830-aa8b-379a51ae497c

I know the reason: Screenshot 2023-05-11 at 2 53 41 PM

0xmiroslav avatar May 11 '23 12:05 0xmiroslav

Wow, I haven't encountered this error before, not sure what the expected behavior is in this case. If jsonCode is not 200, do not show the popup window?

ntdiary avatar May 11 '23 13:05 ntdiary

Wow, I haven't encountered this error before, not sure what the expected behavior is in this case. If jsonCode is not 200, do not show the popup window?

It's constantly reproducible to me right now. I even tried after logout and fresh login

0xmiroslav avatar May 11 '23 13:05 0xmiroslav

It's constantly reproducible to me right now. I even tried after logout and fresh login

Eh, maybe we need help from the backend to check why this error occurred. One more thing, we have a tracking issue #17987 and may add a command like BeginDeepLinkRedirect in the new PR to replace OpenOldDotLink.

ntdiary avatar May 11 '23 13:05 ntdiary

@tgolen can you please check in backend when this error happens?

Screenshot 2023-05-11 at 2 53 41 PM

0xmiroslav avatar May 11 '23 14:05 0xmiroslav

I'm looking into that error on the server side. I see it happening for many people

tgolen avatar May 11 '23 16:05 tgolen