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

feat: useDisplayUsdMode hook #859

Merged
merged 3 commits into from
Jun 5, 2024
Merged

feat: useDisplayUsdMode hook #859

merged 3 commits into from
Jun 5, 2024

Conversation

rin-st
Copy link
Member

@rin-st rin-st commented Jun 3, 2024

Description

Adds useDisplayUsdMode hook which helps to work with nativeCurrency/USD values.

Hook takes as parameter defaultUsdMode which sets an initial value, and returns { displayUsdMode, toggleDisplayUsdMode }. toggleDisplayUsdMode allows to change inner displayUsdMode, and displayUsdMode basically returns current USD mode.

defaultUsdMode and displayUsdMode variables are booleans. true means USD, false means Native Currency.

See discussion here

Note:

  • I didn't set default state to undefined since with it we need additional conditions like if (typeof nativeCurrencyPrice !== "undefined" && nativeCurrencyPrice > 0) etc.
  • I assigned default isFetching value for price to true, so it's clear that if !isFetching && price === 0 then fetch failed.

Additional Information

Copy link
Collaborator

@technophile-04 technophile-04 left a comment

Choose a reason for hiding this comment

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

Tysm @rin-st !! Tested it and works great !

Lol initally I was bit hesitant to have this hook in hooks/scaffold-eth since seem too specific to SE-2 internal use but then realised that we have hooks like useAnimateConfig etc too in their, not sure what the best place to keep this internal hooks but I think its fine for now !

@rin-st
Copy link
Member Author

rin-st commented Jun 5, 2024

Lol initally I was bit hesitant to have this hook in hooks/scaffold-eth since seem too specific to SE-2 internal use but then realised that we have hooks like useAnimateConfig etc too in their, not sure what the best place to keep this internal hooks but I think its fine for now !

I agree that the hooks folder is a little bit mess. Maybe in future create two folders like core (main hooks from docs) and internal/helpers/utils(all other hooks)?

@technophile-04
Copy link
Collaborator

Niceee tysm @rin-st !!


Maybe in future create two folders like core (main hooks from docs) and internal/helpers/utils(all other hooks)?

Yup makes sense !

@technophile-04 technophile-04 merged commit 18dd946 into main Jun 5, 2024
1 check passed
@technophile-04 technophile-04 deleted the update-balance branch June 5, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants