-
Notifications
You must be signed in to change notification settings - Fork 984
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
base: develop
Are you sure you want to change the base?
Conversation
0d617ba
to
1cfe322
Compare
(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)) | ||
|
There was a problem hiding this comment.
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.
Jenkins BuildsClick to see older builds (7)
|
(defn- fetch-swap-proposal | ||
[{:keys [amount valid-input? clean-approval-transaction?]}] | ||
(debounce/clear-all) |
There was a problem hiding this comment.
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.
:last-request-uuid request-uuid | ||
:amount amount | ||
:amount-hex amount-in-hex | ||
:initial-response? true) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
...
@@ -37,6 +37,11 @@ | |||
:<- [:wallet/swap] | |||
:-> :error-response) | |||
|
|||
(rf/reg-sub |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover, will remove it
Thanks for the PR! |
75% of end-end tests have passed
Failed tests (2)Click to expandClass TestCommunityOneDeviceMerged:
Class TestCommunityMultipleDeviceMerged:
Passed tests (6)Click to expandClass TestCommunityOneDeviceMerged:
Class TestWalletOneDevice:
Class TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestWalletMultipleDevice:
|
1cfe322
to
cf72bcb
Compare
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. |
@pavloburykh reopened! |
cd710e3
to
03a8a66
Compare
Signed-off-by: Brian Sztamfater <[email protected]>
03a8a66
to
cd82580
Compare
75% of end-end tests have passed
Failed tests (1)Click to expandClass TestCommunityOneDeviceMerged:
Expected to fail tests (1)Click to expandClass TestCommunityMultipleDeviceMerged:
Passed tests (6)Click to expandClass TestOneToOneChatMultipleSharedDevicesNewUi:
Class TestCommunityOneDeviceMerged:
Class TestWalletOneDevice:
Class TestWalletMultipleDevice:
|
Thanks @briansztamfater PR is blocked by #21555 Will be unblocked |
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 callwallet_stopSuggestedRoutesAsyncCalculation
only if there's a request-uuid set, so we don't call if if it is not necessary.Testing notes
Platforms
Areas that maybe impacted
Functional
Steps to test
status: ready