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: Harden condition for loading spending limits #3981

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

usame-algan
Copy link
Member

@usame-algan usame-algan commented Jul 22, 2024

What it solves

Part of #2414

How this PR fixes it

  • getSpendingLimits was called twice because the condition only checked for the existence of tokenInfoFromBalances but the initial value is an empty array so it should check the length of the array instead

How to test it

  1. Open a Safe with a spending limit
  2. It should still be visible under settings and when trying to create a transaction

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

github-actions bot commented Jul 22, 2024

@usame-algan
Copy link
Member Author

I wonder what is the expected behaviour in case there are no tokens in a safe? Assuming tokenInfoFromBalances would always return an empty array we would not display the spending limits to the user anymore.

Copy link

github-actions bot commented Jul 22, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Jul 22, 2024

📦 Next.js Bundle Analysis for safe-wallet-web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1013.08 KB (🟡 +3 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Copy link
Collaborator

@compojoom compojoom left a comment

Choose a reason for hiding this comment

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

I think that this should get our RPC count significantly down as due to this we were doing the queries twice.

Copy link

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 79.06% 11673/14764
🔴 Branches 58.87% 2894/4916
🟡 Functions 66.09% 1867/2825
🟢 Lines 80.45% 10522/13079

Test suite run success

1442 tests passing in 199 suites.

Report generated by 🧪jest coverage report action from b93849e

@schmanu
Copy link
Member

schmanu commented Jul 23, 2024

Assuming tokenInfoFromBalances would always return an empty array we would not display the spending limits to the user anymore.

@usame-algan I think the tokenInfoFromBalances always contains an entry for the native token once fetched from the CGW - even if it is 0. I just setup Spending Limits on a Safe without any balances and they get displayed correctly in the settings.

@katspaugh
Copy link
Member

katspaugh commented Jul 23, 2024

@schmanu I think that's fine because the purpose of that check is to verify that the balances are fetched from CGW.
This could probably be more cleanly achieved via const { balances, loading } = useBalances().

Looks like this hook is also re-run each time balances are polled...

@francovenica
Copy link
Contributor

Spending limit looks fine

Creation, edition, removal.
With Native and ERC 20 token.
Use of the spending limt with the user
Use all the tokens allowed
Check the refresh of the allowance

LGTM

@usame-algan usame-algan merged commit 21731e2 into dev Jul 24, 2024
14 checks passed
@usame-algan usame-algan deleted the fix-spending-limit-requests branch July 24, 2024 07:41
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants