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

fix(swap): optimize endpoints calls #21549

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

briansztamfater
Copy link
Member

fixes #21412

Summary

This PR optimize the calls to endpoints on the swap flow. Basically we increase the debounce time when dispatching :wallet/start-get-swap-proposal so the endpoint is not called for every input change, and also call wallet_stopSuggestedRoutesAsyncCalculation only if there's a request-uuid set, so we don't call if if it is not necessary.

Testing notes

Platforms

  • Android
  • iOS

Areas that maybe impacted

Functional
  • wallet / transactions

Steps to test

  • Open Status
  • Login
  • Go to the swap flow
  • Enter some values and modify them
  • Verify we are calling the endpoints less times than before by checking the logs

status: ready

Comment on lines +42 to +48
(rf/dispatch [:wallet.swap/set-loading-swap-proposal])
(debounce/debounce-and-dispatch [:wallet/start-get-swap-proposal
{:amount-in amount
:clean-approval-transaction? clean-approval-transaction?}]
swap-proposal-debounce-time-ms))

Copy link
Member Author

@briansztamfater briansztamfater Nov 2, 2024

Choose a reason for hiding this comment

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

We immediately push the loading state so the user can see instant UI feedback, and debounce the endpoint call.

@status-im-auto
Copy link
Member

status-im-auto commented Nov 2, 2024

Jenkins Builds

Click to see older builds (7)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 1cfe322 #3 2024-11-02 19:54:42 ~4 min tests 📄log
✔️ 1cfe322 #3 2024-11-02 19:58:57 ~8 min ios 📱ipa 📲
✔️ 1cfe322 #3 2024-11-02 19:59:06 ~9 min android-e2e 🤖apk 📲
✔️ 1cfe322 #3 2024-11-02 19:59:29 ~9 min android 🤖apk 📲
✔️ cd710e3 #4 2024-11-05 13:39:14 ~5 min tests 📄log
✔️ cd710e3 #4 2024-11-05 13:40:38 ~6 min android-e2e 🤖apk 📲
✔️ cd710e3 #4 2024-11-05 13:43:00 ~8 min ios 📱ipa 📲
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 03a8a66 #5 2024-11-05 13:47:42 ~4 min tests 📄log
✔️ 03a8a66 #5 2024-11-05 13:51:17 ~8 min android-e2e 🤖apk 📲
✔️ 03a8a66 #5 2024-11-05 13:51:50 ~8 min android 🤖apk 📲
✔️ 03a8a66 #5 2024-11-05 13:52:03 ~8 min ios 📱ipa 📲
✔️ cd82580 #6 2024-11-10 23:40:19 ~4 min tests 📄log
✔️ cd82580 #6 2024-11-10 23:41:53 ~6 min android-e2e 🤖apk 📲
✔️ cd82580 #6 2024-11-10 23:44:05 ~8 min android 🤖apk 📲
✔️ cd82580 #6 2024-11-10 23:45:13 ~9 min ios 📱ipa 📲

(defn- fetch-swap-proposal
[{:keys [amount valid-input? clean-approval-transaction?]}]
(debounce/clear-all)
Copy link
Member Author

@briansztamfater briansztamfater Nov 2, 2024

Choose a reason for hiding this comment

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

We need to either fetch a new swap proposal with different values or clean the swap related values if the value is not valid (i.e. if value is zero or higher than the current account token balance), so we must clear the debounce queue first before the events in queue are actually dispatched with wrong values.

Comment on lines +159 to +162
:last-request-uuid request-uuid
:amount amount
:amount-hex amount-in-hex
:initial-response? true)
Copy link
Member Author

Choose a reason for hiding this comment

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

Just removing :loading-swap-proposal? true from the assoc, loading state is now set by a new event :wallet.swap/set-loading-swap-proposal.

:error error}))}]}))
(fn [{:keys [db]}]
(let [last-request-uuid (get-in db [:wallet :ui :swap :last-request-uuid])]
(when last-request-uuid
Copy link
Member Author

@briansztamfater briansztamfater Nov 2, 2024

Choose a reason for hiding this comment

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

If last-request-uuid exists, it means there is a swap route request ongoing and we can call wallet_stopSuggestedRoutesAsyncCalculation to stop receiving signals. Otherwise, there's no need to call the endpoint.

Copy link
Contributor

@vkjr vkjr Nov 4, 2024

Choose a reason for hiding this comment

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

The comment you provided can be also reflected in code by renaming variable:

(let [route-request-ongoing? (some? (get-in db [:wallet :ui :swap :last-request-uuid]))]
     (when route-request-ongoing?
     ...

@shivekkhurana shivekkhurana added this to the 2.32.0 Beta milestone Nov 4, 2024
@@ -37,6 +37,11 @@
:<- [:wallet/swap]
:-> :error-response)

(rf/reg-sub
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this sub never used

Copy link
Member Author

Choose a reason for hiding this comment

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

Leftover, will remove it

@vkjr
Copy link
Contributor

vkjr commented Nov 4, 2024

Thanks for the PR!

@status-im-auto
Copy link
Member

75% of end-end tests have passed

Total executed tests: 8
Failed tests: 2
Expected to fail tests: 0
Passed tests: 6
IDs of failed tests: 703133,702843 

Failed tests (2)

Click to expand
  • Rerun failed tests

  • Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_switch, id: 703133

    # STEP: Check that removed user is not shown in the list anymore
    Device 1: Wait for element `Button` for max 30s and click when it is available

    critical/chats/test_public_chat_browsing.py:240: in test_restore_multiaccount_with_waku_backup_remove_switch
        self.sign_in.show_profiles_button.wait_and_click()
    ../views/base_element.py:100: in wait_and_click
        self.wait_for_visibility_of_element(sec)
    ../views/base_element.py:147: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 1: Button by accessibility id:`show-profiles` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_message_edit, id: 702843

    Device 2: Find Text by xpath: //android.view.ViewGroup[@content-desc='chat-item']//android.widget.TextView[contains(@text,'https://status.app/c/')]
    Device 2: Wait for element Button for max 120s and click when it is available

    Test setup failed: critical/chats/test_public_chat_browsing.py:350: in prepare_devices
        self.community_2.join_community()
    ../views/chat_view.py:420: in join_community
        self.join_button.wait_and_click(120)
    ../views/base_element.py:100: in wait_and_click
        self.wait_for_visibility_of_element(sec)
    ../views/base_element.py:147: in wait_for_visibility_of_element
        raise TimeoutException(
     Device 2: Button by accessibility id:`show-request-to-join-screen-button` is not found on the screen after wait_for_visibility_of_element
    



    Device sessions

    Passed tests (6)

    Click to expand

    Class TestCommunityOneDeviceMerged:

    1. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    2. test_wallet_balance_mainnet, id: 740490

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230
    2. test_wallet_send_eth, id: 727229

    @pavloburykh pavloburykh closed this Nov 5, 2024
    @pavloburykh pavloburykh force-pushed the fix/swap-optimize-endpoint-calls branch from 1cfe322 to cf72bcb Compare November 5, 2024 11:38
    @pavloburykh
    Copy link
    Contributor

    pavloburykh commented Nov 5, 2024

    Sorry @briansztamfater, I have accidentally closed this branch when trying to rebase it. I must have overwritten your commits. Could you please restore the branch? Sorry once again for that.

    @briansztamfater
    Copy link
    Member Author

    @pavloburykh reopened!

    Signed-off-by: Brian Sztamfater <[email protected]>
    @status-im-auto
    Copy link
    Member

    75% of end-end tests have passed

    Total executed tests: 8
    Failed tests: 1
    Expected to fail tests: 1
    Passed tests: 6
    
    IDs of failed tests: 703133 
    
    IDs of expected to fail tests: 702843 
    

    Failed tests (1)

    Click to expand
  • Rerun failed tests

  • Class TestCommunityOneDeviceMerged:

    1. test_restore_multiaccount_with_waku_backup_remove_profile_switch, id: 703133

    Device 1: Find `Button` by `accessibility id`: `show-profiles`
    Device 1: Tap on found: Button

    critical/chats/test_public_chat_browsing.py:247: in test_restore_multiaccount_with_waku_backup_remove_profile_switch
        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))]))
     zQ3...dWXh5 was not restored as a contact from waku backup!
    E    zQ3...Vacac was not restored as a contact from waku backup!
    E    admin_open was not restored from waku-backup!!
    E    member_open was not restored from waku-backup!!
    E    admin_closed was not restored from waku-backup!!
    E    member_closed was not restored from waku-backup!!
    



    Device sessions

    Expected to fail tests (1)

    Click to expand

    Class TestCommunityMultipleDeviceMerged:

    1. test_community_message_edit, id: 702843

    Test is not run, e2e blocker  
    

    [[reason: [NOTRUN] Skipped due to waku issue on staging fleet]]

    Passed tests (6)

    Click to expand

    Class TestOneToOneChatMultipleSharedDevicesNewUi:

    1. test_1_1_chat_non_latin_messages_stack_update_profile_photo, id: 702745
    Device sessions

    Class TestCommunityOneDeviceMerged:

    1. test_community_copy_and_paste_message_in_chat_input, id: 702742
    Device sessions

    Class TestWalletOneDevice:

    1. test_wallet_add_remove_regular_account, id: 727231
    2. test_wallet_balance_mainnet, id: 740490

    Class TestWalletMultipleDevice:

    1. test_wallet_send_asset_from_drawer, id: 727230
    2. test_wallet_send_eth, id: 727229

    @pavloburykh
    Copy link
    Contributor

    pavloburykh commented Nov 11, 2024

    @pavloburykh reopened!

    Thanks @briansztamfater PR is blocked by #21555 Will be unblocked
    once #21541 is tested and merged into develop.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    Status: E2E Tests
    Status: Done
    Development

    Successfully merging this pull request may close these issues.

    Optimize calls for wallet_stopSuggestedRoutesAsyncCalculation and wallet_getSuggestedRoutesAsync
    8 participants