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

Scan URL with QR Scanner from Chats #8403

Closed
wants to merge 1 commit into from
Closed

Scan URL with QR Scanner from Chats #8403

wants to merge 1 commit into from

Conversation

krisc
Copy link

@krisc krisc commented Jun 11, 2019

This PR resolves this bounty #5776

Previously was this PR #7880, but issues with nix, it was easier for me to make a new PR.

@churik had some issues in the old PR, but I currently can't recreate them in this PR. Can someone else confirm that these issues are not present?
#7880 (comment)

She also mentioned that Ethereum addresses are also a valid link, and I am not sure what to do about that. I feel like they should indeed be valid. Let me know what I should do about that.

Also just a note, the changes I made to src/status_im/browser/core.cljs are relevant to #8327 that has not been resolved yet. I wasn't sure if I should have left it in or not, but I just left it in. Let me know if I should remove it.

@krisc krisc requested a review from a team as a code owner June 11, 2019 16:06
@auto-assign auto-assign bot removed the request for review from a team June 11, 2019 16:06
@status-github-bot
Copy link

Pull Request Checklist

  • Have you updated the documentation, if impacted (e.g. docs.status.im)?

@status-im-auto
Copy link
Member

status-im-auto commented Jun 11, 2019

Jenkins Builds

Click to see older builds (6)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 4e927d5 #1 2019-06-11 16:19:24 ~12 min ios 📦 ipa
✔️ 4e927d5 #1 2019-06-11 16:20:32 ~13 min macos 📦 dmg
✔️ 4e927d5 #1 2019-06-11 16:20:44 ~13 min linux 📦 App
✔️ 4e927d5 #1 2019-06-11 16:23:07 ~15 min windows 📦 exe
✔️ 4e927d5 #1 2019-06-11 16:23:31 ~16 min android 📦 apk
✔️ 4e927d5 #1 2019-06-11 16:23:34 ~16 min android-e2e 📦 apk
Commit #️⃣ Finished (UTC) Duration Platform Result
ea2b466 #2 2019-06-18 20:32:41 ~11 min ios 📄 log
ea2b466 #2 2019-06-18 20:38:38 ~17 min macos 📄 log
ea2b466 #2 2019-06-18 20:44:15 ~23 min android 📄 log
ea2b466 #2 2019-06-18 20:44:24 ~23 min linux 📄 log
ea2b466 #2 2019-06-18 20:46:50 ~25 min android-e2e 📄 log
ea2b466 #2 2019-06-18 20:52:21 ~31 min windows 📄 log
ea2b466 #3 2019-06-19 10:38:56 ~13 min ios 📄 log
✔️ 6083c23 #5 2019-06-19 16:28:32 ~12 min ios 📦 ipa
✔️ 6083c23 #4 2019-06-19 16:31:44 ~15 min linux 📦 App
✔️ 6083c23 #4 2019-06-19 16:32:19 ~16 min windows 📦 exe
✔️ 6083c23 #4 2019-06-19 16:32:35 ~16 min macos 📦 dmg
✔️ 6083c23 #4 2019-06-19 16:37:30 ~21 min android 📦 apk
✔️ 6083c23 #4 2019-06-19 16:37:43 ~22 min android-e2e 📦 apk

@@ -200,6 +200,12 @@
(universal-links/handle-url cofx link)
{:browser/show-browser-selection link}))

(fx/defn browser-selection-cancel
Copy link
Member

Choose a reason for hiding this comment

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

you can use {:events [:browser.ui/browser-selection-cancel]} in that case you don't need to register handler in events ns

Copy link
Author

@krisc krisc Jun 12, 2019

Choose a reason for hiding this comment

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

I'd like to keep it the way it is, unless you think it's preferable otherwise

Copy link
Contributor

Choose a reason for hiding this comment

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

We are moving to this new method so yes it would be preferable

Copy link
Author

Choose a reason for hiding this comment

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

I don't completely follow, but is this what you mean? In list_selection.cljs the browse fn will be define as such:


(defn browse [link]
  (show {:title       (i18n/label :t/browsing-title)
         :options     [{:label  (i18n/label :t/browsing-open-in-status)
                        :action #(re-frame/dispatch [:browser.ui/open-url link])}
                       {:label  (i18n/label (platform-web-browser))
                        :action #(.openURL (react/linking) (http/normalize-url link))}]
         :cancel-text (i18n/label :t/browsing-cancel)
         :on-cancel   #(re-frame/dispatch {:events [:browser.ui/browser-selection-cancel]})}))

And this:

(handlers/register-handler-fx
 :browser.ui/browser-selection-cancel
 (fn [cofx [_ _]]
   (browser/browser-selection-cancel cofx)))

is no longer needed in the events ns?

@jeluard
Copy link
Contributor

jeluard commented Jun 12, 2019

She also mentioned that Ethereum addresses are also a valid link, and I am not sure what to do about that. I feel like they should indeed be valid. Let me know what I should do about that.

Probably the best option would be to have all QR scanners support all types of URL?

[status-im.constants :as constants]
[status-im.extensions.core :as extensions]))

(defn- valid-url? [url]
Copy link
Contributor

Choose a reason for hiding this comment

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

What kind of URL do we validate here?

Copy link
Author

Choose a reason for hiding this comment

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

it uses regx-url defined in status-im.constants

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably cleaner to have this logic in a dedicated namespace. Do we have a relevant one already?

Copy link
Author

Choose a reason for hiding this comment

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

let me know where this helper function should be placed and I will move it. Otherwise i could just have it's implementation within the cond statement itself and not define any helper function.

{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content (i18n/label :t/use-valid-qr-code {:data data})
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}})))
(if (valid-url? data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use some cond instead of the mix of or and if? That would require a predicate to detect universal links.

Copy link
Author

Choose a reason for hiding this comment

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

okay I will clean this up.

@hesterbruikman
Copy link
Contributor

Thanks @krisc! Gave it a test run with 3 cases:

General QR code scanning

  1. [+-button] > [Scan QR code] to scan
    a [x] tap Profile tab > [Share my Profile]
    b [x] tap Wallet tab > [Receive]

Scanning from wallet

  1. Wallet tab > [Send] > [Scan QR code] to scan
    a [x] tap Profile tab > [Share my Profile] Error is correct, but needs new copy
    b [x] tap Wallet tab > [Receive]

Scanning from chat

  1. [+-button] > [Start new chat] > [Scan icon] to scan
    a [x] tap Profile tab > [Share my Profile]
    b [x] tap Wallet tab > [Receive] Error is correct, but needs new copy

2a and 3b should indeed be invalid as @churik mentioned in point 4 (#7880 (comment)). Thanks for making sure we get this right. The reason they are different stems from the technicalities of keys used inside Status. At the moment your contact code and wallet address are basically the same thing. Therefore yes, you would expect it to be valid to scan either whether you want to chat or transact. However, this is not necessarily the case going forward. The key used for chat and the key used for wallet are theoretically different now and in the near future will actually be different.

Requested changes

For 2a, scanning a chat key from wallet, could you replace the copy in the error message with:

No wallet address
The QR code you scanned doesn’t seem to contain a wallet address. Please try another QR code or enter recipient address.
QR scanning in wallet

For 3b, scanning a wallet address when starting a new chat, could you replace the copy in the error message with:

No Chat key
The QR code you scanned doesn’t seem to contain a Chat key. Please try another QR code or enter the Chat key.

Also, could you try to have the camera close and the error show up on the New chat screen that holds the input field. This gives more context to the error message.
QR scanning in chat

@statustestbot
Copy link

98% of end-end tests have passed

Total executed tests: 49
Failed tests: 1
Passed tests: 48

Failed tests (1)

Click to expand
1. test_backup_recovery_phrase_warning_from_wallet

Device 1: Wait for PlusButton
Device 1: Wait for PlusButton

Donation was not received during 300 seconds!

Device sessions

Passed tests (48)

Click to expand
1. test_block_user_from_public_chat
Device sessions

2. test_filters_from_daap
Device sessions

3. test_copy_and_paste_messages
Device sessions

4. test_send_transaction_from_daap
Device sessions

5. test_request_and_receive_tokens_in_1_1_chat
Device sessions

6. test_deploy_contract_from_daap
Device sessions

7. test_open_transaction_on_etherscan
Device sessions

8. test_public_chat_messaging
Device sessions

9. test_long_press_to_delete_1_1_chat
Device sessions

10. test_password_in_logcat_sign_in
Device sessions

11. test_text_message_1_1_chat
Device sessions

12. test_add_to_contacts
Device sessions

13. test_sign_typed_message (TestRail link is not found)
Device sessions

14. test_unread_messages_counter_1_1_chat
Device sessions

15. test_logcat_send_transaction_from_daap
Device sessions

16. test_send_message_in_group_chat
Device sessions

17. test_logcat_send_transaction_from_wallet
Device sessions

18. test_send_token_with_7_decimals
Device sessions

19. test_modify_transaction_fee_values
Device sessions

20. test_send_eth_from_wallet_to_address
Device sessions

21. test_manage_assets
Device sessions

22. test_logcat_send_transaction_in_1_1_chat
Device sessions

23. test_request_and_receive_eth_in_1_1_chat
Device sessions

24. test_long_press_to_delete_public_chat
Device sessions

25. test_send_emoji
Device sessions

26. test_search_chat_on_home
Device sessions

27. test_logcat_recovering_account
Device sessions

28. test_messaging_in_different_networks
Device sessions

29. test_send_tokens_in_1_1_chat
Device sessions

30. test_network_mismatch_for_send_request_commands
Device sessions

31. test_logcat_sign_message_from_daap
Device sessions

32. test_switch_users_and_add_new_account
Device sessions

33. test_send_stt_from_wallet
Device sessions

34. test_send_eth_in_1_1_chat
Device sessions

35. test_login_with_new_account
Device sessions

36. test_send_eth_from_wallet_to_contact
Device sessions

37. test_add_contact_from_public_chat
Device sessions

38. test_send_two_transactions_one_after_another_in_dapp
Device sessions

39. test_password_in_logcat_creating_account
Device sessions

40. test_backup_recovery_phrase
Device sessions

41. test_offline_status
Device sessions

42. test_open_google_com_via_open_dapp
Device sessions

43. test_unread_messages_counter_public_chat
Device sessions

44. test_sign_message_from_daap
Device sessions

45. test_user_can_remove_profile_picture
Device sessions

46. test_share_contact_code_and_wallet_address
Device sessions

47. test_request_eth_in_wallet
Device sessions

48. test_refresh_button_browsing_app_webview
Device sessions

@krisc
Copy link
Author

krisc commented Jun 12, 2019

She also mentioned that Ethereum addresses are also a valid link, and I am not sure what to do about that. I feel like they should indeed be valid. Let me know what I should do about that.

Probably the best option would be to have all QR scanners support all types of URL?

I agree with Scan QR code from Chat's tab, but not from Add new contact (should just be chat profiles)

@krisc
Copy link
Author

krisc commented Jun 12, 2019

@hesterbruikman , thanks for the feedback! I'll get to work on these requested changes.

@krisc
Copy link
Author

krisc commented Jun 13, 2019

@hesterbruikman I'm beginning your request for changes for 2a and 3b, but I'm wondering if these changes should even be part of this PR as they don't really address the original issue #5776 although they have to do with the QR Scanner. I'm just wondering if your requests should be their own issue with possibly their own bounty. I don't want to clutter this PR with a bunch of commits that will end up being squashed and undocumented.

I'll work on these requests for changes either way :) I'm just not sure how we want to keep this organized from a project management perspective

@hesterbruikman
Copy link
Contributor

@krisc I see what you mean. I'll set up seperate bounty in the coming days. There's also some related QR behavior I want to look into. I'll keep you posted once I set up new issue(s)!

@krisc
Copy link
Author

krisc commented Jun 13, 2019

@krisc I see what you mean. I'll set up seperate bounty in the coming days. There's also some related QR behavior I want to look into. I'll keep you posted once I set up new issue(s)!

Cool. I seem to be deep into the QR scanner issues lol

@krisc
Copy link
Author

krisc commented Jun 13, 2019

@jeluard I tried cleaning it up like this:

(fx/defn process-qr-code
  [cofx data]
  (if (spec/valid? :global/public-key data)
    (universal-links/handle-view-profile cofx data)
    (cond (universal-links/universal-link? data) (universal-links/handle-url cofx data)
          (valid-url? data) (browser/handle-message-link cofx data)
          :else {:utils/show-popup {:title   (i18n/label :t/unable-to-read-this-code)
                              :content (i18n/label :t/use-valid-qr-code {:data data})
                              :on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}})))

But the behavior was different, eg., wallet address was interpreted as a URL to open in the browser for some reason.

If it's okay, I think I'd prefer to delay cleaning up this area of the code until after @hesterbruikman creates new QR-related issues as was discussed here as I'll probably make more changes to this section the code.

I believe the code works as expected right now. But I would like to know why it says Mobile e2e tests — Failure - e2e tests are failed. This seems to happen everytime I make a PR.

@jeluard
Copy link
Contributor

jeluard commented Jun 17, 2019

@krisc I'd rather clean it up now, delayed cleanup rarely happen. Seems trivial to have a single cond?

@churik
Copy link
Member

churik commented Jun 17, 2019

@krisc e2e failure is not related to your PR, this is an infrastructure issue.

@krisc
Copy link
Author

krisc commented Jun 17, 2019

@krisc I'd rather clean it up now, delayed cleanup rarely happen. Seems trivial to have a single cond?

fair enough. I'll try get to this when I get a chance today or tomorrow.

@krisc
Copy link
Author

krisc commented Jun 18, 2019

@jeluard EDIT: I now have this:

(fx/defn process-qr-code
  [cofx data]
  (cond (spec/valid? :global/public-key data)  (universal-links/handle-view-profile cofx data)
        (universal-links/universal-link? data) (universal-links/handle-url cofx data)
        (universal-links/deep-link? data)      (universal-links/handle-url cofx data)
        (valid-url? data)                      (browser/handle-message-link cofx data)
        :else   {:utils/show-popup {:title   (i18n/label :t/unable-to-read-this-code)
                                    :content (i18n/label :t/use-valid-qr-code {:data data})
                                    :on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}}))

I added a check for deep-links to account for ethereum wallet addresses. With that said, I'm not sure how to manually test for universal-links. Other than that, this works as expected. I still have to change the method of handling events and to move the valid-url? function somewhere. Let me know what to do about that.

@jeluard
Copy link
Contributor

jeluard commented Jun 19, 2019 via email

@churik
Copy link
Member

churik commented Jun 19, 2019

@krisc please, rebase it to current develop.
Thanks!

@churik
Copy link
Member

churik commented Jun 20, 2019

@krisc thank you for the contribution!

1) After opening URL in native browser can't scan valid URL

Steps:

  • tap on +
  • scan QR code that contains link
  • tap on open on IOS (or Android)
  • go back to Status
  • try to scan same QR with link
    Expected result: can scan QR
    Actual result: QR is not recognizable again

2) White screen after scanning ethereum address

Example of QR:
photo_2019-04-16 12 14 49
When scanning this QR, the application ends up with the white screen.
2019-06-20 16 15 55
Platforms: IOS, Android
Logs:
Status-debug-logs.zip
Basically, I don't think it is a good idea to leave the camera opened after scanning valid QR - in other places (i.e. after scanning valid key or address in wallet) - camera is closed after scanning. I guess that is because they used the same view (i.e. chats -> after scanning chats) but anyway will be more consistent to close it.

@krisc
Copy link
Author

krisc commented Jun 20, 2019

@churik thanks for the feedback. Issue 2 acts as expected for me, ie., Goes to Send Transaction screen. Not sure why you're getting an error. As for issue 1, should it return to the home screen when changing back to the Status app?

@churik
Copy link
Member

churik commented Jun 28, 2019

Sorry @krisc for the late feedback.
It's OK if it returns to the home screen when changing back to the Status app.

@flexsurfer
Copy link
Member

hey @krisc any updates? thanks

@krisc
Copy link
Author

krisc commented Jul 17, 2019

Been busy with hackathons, and another one is starting next week too. But I'll try to see if I can possibly take a look again this week. But if anyone else wants to help me with this, I'll help them get onboard with the issue.

@oskarth
Copy link
Contributor

oskarth commented Aug 5, 2019

@krisc any chance you can take a look at this? Otherwise I'd suggest we close this PR

@krisc
Copy link
Author

krisc commented Aug 6, 2019

@krisc any chance you can take a look at this? Otherwise I'd suggest we close this PR

Sorry. Didn't have a chance before the Grow Ethereum hackathon. Seems like it's hackathon season lol. I won't be able to work on Status issues until September.

@oskarth
Copy link
Contributor

oskarth commented Aug 6, 2019

@krisc No worries, completely understandable! Let's close this PR for now and we can re-open it in the future if things change. Hope that's OK for you.

Keep hacking!

@oskarth oskarth closed this Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants