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

Dapps Typed Data request improvements #21333

Merged
merged 9 commits into from
Oct 2, 2024
Merged

Conversation

clauxx
Copy link
Member

@clauxx clauxx commented Sep 26, 2024

fixes #21278

Summary

User story

Improved the UI of the wallet connect typed data request by flattening the data and displaying it to the user, as seen in the screenshot below.

image

Steps to test

status: ready

@status-im-auto
Copy link
Member

status-im-auto commented Sep 26, 2024

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ dac775d #2 2024-09-26 11:39:12 ~4 min tests 📄log
✔️ dac775d #2 2024-09-26 11:41:12 ~6 min android-e2e 🤖apk 📲
✔️ dac775d #2 2024-09-26 11:42:47 ~8 min android 🤖apk 📲
✔️ dac775d #2 2024-09-26 11:47:58 ~13 min ios 📱ipa 📲
✔️ ad19102 #4 2024-10-01 08:47:47 ~4 min tests 📄log
✔️ ad19102 #4 2024-10-01 08:49:33 ~6 min android-e2e 🤖apk 📲
✔️ ad19102 #4 2024-10-01 08:50:00 ~6 min android 🤖apk 📲
✔️ ad19102 #4 2024-10-01 08:52:23 ~8 min ios 📱ipa 📲

Copy link
Contributor

@mohsen-ghafouri mohsen-ghafouri left a comment

Choose a reason for hiding this comment

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

Nice work 🚀

(-> typed-data
(select-keys [:domain :message])
flatten-data
(format-fields ": ")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the format from: wallets: 1: copied from other products or is this a standard we are creating ourselves for Status? I find hard to imagine users can figure out the indexes and the flattening going on, but maybe not, things are crazy in terms of usability when signing.

Do you know if there's any interest in improving the designs or if any concerns were raised?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we're doing small iterations on this. There is no standard around typed data, but there are definitely improvements to be made. Aside from the representation of arrays, which I agree that is not ideal, is the inclusion of custom types instead (or in addition) to key names, as it is now. The custom types should give more context around what the piece of data represents and the context it lives in. For now though, we decided move away from json but keep it simple at the same time.

@@ -0,0 +1,94 @@
(ns status-im.contexts.wallet.wallet-connect.utils.typed-data
Copy link
Contributor

Choose a reason for hiding this comment

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

@clauxx, is the Desktop app integrating now or will integrate with WC? Sorry if this is an obvious question, but my point is that I feel this logic doesn't belong in clients and should be in status-go. A lot of wallet-related code is living in the wrong place in my opinion. In the not so distant past, our high-level architectural goal was to build light clients and I think the goal still stands.

Well, this is just a thought for your PR, not a suggestion for change. It would be great if the Mobile Wallet team more heavily considered this factor because we are inflating too much the client with logic. It's great that you unit tested, but this is not always the case in mobile PRs. My belief and experience with status-go is that the slowdown in iterations would only come in the beginning as people learn how to solve with this backend-first mentality.

cc'ing @shivekkhurana @smohamedjavid just to bump this point a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's on the client for now, since this logic is directly related to the UI and how we show the typed data to the user. We are dealing with limited horizontal space on mobile, so we had to find solutions to remove nesting. On the desktop this might not be an issue, so the representation there might be different.

(defn display-data-view
[]
(let [typed-data? (->> (rf/sub [:wallet-connect/current-request-method])
(contains? typed-data-methods))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be a separate subscription. typed-data-methods is static, so the result for typed-data? will be nicely cached.

[{:keys [label value]}]
[quo/data-item
{:card? false
:container-style (merge style/data-item
Copy link
Contributor

Choose a reason for hiding this comment

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

merge is known to be quite slow, so if we can avoid it the better. Here you can use assoc, or better extract the container-style map into a var because it's a static map.

[["2"] 2]])))

(testing "correctly flattens a simple vec"
(is (= (sut/flatten-data ["zero" "one"])
Copy link
Contributor

Choose a reason for hiding this comment

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

The expected argument should be the first.

Example output from CIDER from another project:

(deftest some-test
  (is (= 1 0)))

@clauxx
Copy link
Member Author

clauxx commented Oct 1, 2024

@ilmotta the comments were addressed 👍

@status-im-auto
Copy link
Member

71% of end-end tests have passed

Total executed tests: 7
Failed tests: 2
Expected to fail tests: 0
Passed tests: 5
IDs of failed tests: 702745,727229 

Failed tests (2)

Click to expand
  • Rerun failed tests

  • Class TestWalletMultipleDevice:

    1. test_wallet_send_eth, id: 727229

    Device 2: Find `Text` by `xpath`: `//android.view.ViewGroup[@content-desc='container']/android.widget.TextView[@text='Ether']/../android.widget.TextView[3]`
    Device 2: `Text` is `0.07559 ETH`

    critical/test_wallet.py:159: in test_wallet_send_eth
        self.errors.verify_no_errors()
    base_test_case.py:192: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Sender balance is not updated on Etherscan, it is 0.4067 but expected to be 0.4068
    



    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745

    Device 2: Tap on found: Button
    Device 2: Attempt 0 is successful clicking close-activity-center

    Test setup failed: critical/chats/test_1_1_public_chats.py:40: in prepare_devices
        self.home_2.handle_contact_request(self.username_1)
    ../views/home_view.py:410: in handle_contact_request
        chat_element.accept_contact_request()
    ../views/home_view.py:162: in accept_contact_request
        self.handle_cr("accept-contact-request")
    ../views/home_view.py:159: in handle_cr
        ).wait_for_rendering_ended_and_click()
    ../views/base_element.py:163: in wait_for_rendering_ended_and_click
        self.wait_for_visibility_of_element(20)
    ../views/base_element.py:147: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 2: Button by xpath:`//*[contains(@text, 'sender')]/ancestor::*[@content-desc='activity']/*[@content-desc="accept-contact-request"]` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    Passed tests (5)

    Click to expand

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230

    Class TestCommunityOneDeviceMerged:

    1. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    2. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_message_edit, id: 702843
    Device sessions

    @mariia-skrypnyk
    Copy link

    mariia-skrypnyk commented Oct 1, 2024

    Hey @clauxx!

    I get an error during testing that blocks me.
    Can you please take a look?

    Screenshot 2024-10-01 at 15 11 43

    WC-PR-debug-logs.zip

    my steps:

    1. Login (Testnet but I also tried Mainnet too)
    2. Scan https://react-app.walletconnect.com/ QR code
    3. Generated a eth_signTypedData_v4 request

    Thanks

    @clauxx
    Copy link
    Member Author

    clauxx commented Oct 1, 2024

    Hey @clauxx!

    I get an error during testing that blocks me.
    Screenshot 2024-10-01 at 15 11 43

    my steps:

    1. Login (Testnet but I also tried Mainnet too)
    
    2. Scan https://react-app.walletconnect.com/ QR code
    
    3. Generated a eth_signTypedData_v4 request
    

    Thanks

    Hi! It will not work on testnet, since the data includes the wrong chainId (mainnet), and we check that for safety. It should work on Mainnet though. Did you make sure while connecting that both the dapp and the wallet are on mainnet? Should probably add this in the description.

    @status-im-auto
    Copy link
    Member

    0% of end-end tests have passed

    Total executed tests: 2
    Failed tests: 2
    Expected to fail tests: 0
    Passed tests: 0
    
    IDs of failed tests: 702745,727229 
    

    Failed tests (2)

    Click to expand
  • Rerun failed tests

  • Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745

    Device 2: Tap on found: Button
    Device 2: Attempt 0 is successful clicking close-activity-center

    Test setup failed: critical/chats/test_1_1_public_chats.py:40: in prepare_devices
        self.home_2.handle_contact_request(self.username_1)
    ../views/home_view.py:410: in handle_contact_request
        chat_element.accept_contact_request()
    ../views/home_view.py:162: in accept_contact_request
        self.handle_cr("accept-contact-request")
    ../views/home_view.py:159: in handle_cr
        ).wait_for_rendering_ended_and_click()
    ../views/base_element.py:163: in wait_for_rendering_ended_and_click
        self.wait_for_visibility_of_element(20)
    ../views/base_element.py:147: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 2: Button by xpath:`//*[contains(@text, 'sender')]/ancestor::*[@content-desc='activity']/*[@content-desc="accept-contact-request"]` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    Class TestWalletMultipleDevice:

    1. test_wallet_send_eth, id: 727229

    Device 2: Find Text by xpath: //android.view.ViewGroup[@content-desc='container']/android.widget.TextView[@text='Ether']/../android.widget.TextView[3]
    Device 2: Text is 0.07579 ETH

    critical/test_wallet.py:159: in test_wallet_send_eth
        self.errors.verify_no_errors()
    base_test_case.py:192: in verify_no_errors
        pytest.fail('\n '.join([self.errors.pop(0) for _ in range(len(self.errors))]))
     Sender balance is not updated on Etherscan, it is 0.4064 but expected to be 0.4065
    



    @mariia-skrypnyk
    Copy link

    mariia-skrypnyk commented Oct 1, 2024

    Thanks @clauxx .

    I've checked on Mainnet once again (probably didn't turn Testnet switcher on dApp) 🤔.

    Looks good on both platforms!

    Have a tiny question regarding Network element from design here:

    Screenshot 2024-10-01 at 18 57 48

    https://www.figma.com/design/mLyiYPXqu8KetdQONOlZpV/dApp-Interactions?node-id=1869-27020&node-type=shape_with_text&m=dev

    Is it planned to be added or I should report it?
    Thanks.

    PR can be merged.
    Failed e2e are not related.

    @clauxx
    Copy link
    Member Author

    clauxx commented Oct 2, 2024

    @mariia-skrypnyk I think it's not needed, as we're checking if the network of the session is the same as the one contained in the data (but it's not guaranteed it is), and if they're not the same we show a toast and reject the request.

    @clauxx clauxx merged commit 97aff27 into develop Oct 2, 2024
    6 checks passed
    @clauxx clauxx deleted the cl-21278-typed-data-improve branch October 2, 2024 10:50
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Archived in project
    Development

    Successfully merging this pull request may close these issues.

    I would like to understand the contents of typed data signing requests
    5 participants