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

Mattupham/fe 478 reduce fe bundle size #3290

Merged
merged 30 commits into from
Jun 4, 2024

Conversation

mattupham
Copy link
Contributor

@mattupham mattupham commented Jun 4, 2024

What is the purpose of the change:

  • run Knip - a tool that detects unused files and helps us optimize our app

Linear Task

Linear Task URL

Brief Changelog

  • remove unused files
  • change some default exports to named exports

Testing and Verifying

  • ensure app renders after every change (1 removal per commit)
  • run through QA - especially the Nomic bridge

Copy link

vercel bot commented Jun 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend 🛑 Canceled (Inspect) Jun 4, 2024 9:20pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-datadog ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2024 9:20pm
osmosis-frontend-dev ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2024 9:20pm
osmosis-frontend-edgenet ⬜️ Ignored (Inspect) Jun 4, 2024 9:20pm
osmosis-testnet ⬜️ Ignored (Inspect) Visit Preview Jun 4, 2024 9:20pm

@mattupham mattupham marked this pull request as draft June 4, 2024 16:29
Copy link
Contributor

coderabbitai bot commented Jun 4, 2024

Walkthrough

The changes primarily involve removing default exports and converting them to named exports across various components in the project. This includes components like Spinner, OsmoverseCard, and TokenDetails. Additionally, some context options and interface declarations were modified to be non-exported. These adjustments enhance code clarity and maintainability by promoting explicit import statements and reducing the reliance on default exports.

Changes

Files/Directories (Shortened) Change Summary
packages/trpc/src/api.ts Removed export from CreateContextOptions type declaration.
packages/web/components/cards/osmoverse-card.tsx Removed default export of OsmoverseCard.
packages/web/components/cards/validator-squad-card.tsx Changed OsmoverseCard import from default to named import.
packages/web/components/complex/add-conc-liquidity.tsx Changed Spinner import from default to named import.
packages/web/components/complex/all-pools-table.tsx Changed Spinner import from default to named import.
packages/web/components/drawers/token-select-drawer.tsx Changed Spinner import from default to named import.
packages/web/components/loaders/spinner.tsx Removed default export of Spinner.
packages/web/components/navbar-osmosis-update/... Changed Spinner import from default to named import.
packages/web/components/pool-detail/concentrated.tsx Changed Spinner import from default to named import.
packages/web/components/table/asset-balances.tsx Changed Spinner import from default to named import.
packages/web/components/table/asset-info.tsx Changed Spinner import from default to named import.
packages/web/components/token-details/token-details.tsx Exported TokenDetails as TokenDetailsWithObserver.
packages/web/components/twitter-section/twitter-section.tsx Exported TwitterSection as a named export.
packages/web/components/wallet-states/connecting-wallet-state.tsx Converted to named export.
packages/web/components/wallet-states/error-wallet-state.tsx Converted to named export.
packages/web/components/your-balance/your-balance.tsx Converted to named export and removed default export.
packages/web/integrations/nomic/transfer.tsx Converted NomicTransfer to named export.
packages/web/integrations/notifi/.../history-rows.tsx Changed Spinner import from default to named import.
packages/web/integrations/notifi/.../loading-card.tsx Changed Spinner import from default to named import.
packages/web/modals/bridge-transfer-v1.tsx Modified dynamic import of NomicTransfer to use named import.
packages/web/modals/create-pool.tsx Updated import statements to new location within project structure.
packages/web/modals/profile.tsx Changed Spinner import from default to named import.
packages/web/modals/wallet-select/cosmos-wallet-state.tsx Updated imports of ConnectingWalletState and ErrorWalletState to named imports.
packages/web/modals/wallet-select/evm-wallet-state.tsx Updated imports of ConnectingWalletState and ErrorWalletState to named imports.
packages/web/pages/assets/[denom].tsx Changed imports of Spinner, TokenDetails, TwitterSection, and YourBalance to named imports.
packages/web/pages/components.tsx Changed Spinner import from default to named import.
packages/web/pages/earn/index.tsx Removed commented-out code and adjusted element positioning.
packages/web/utils/react-context.ts Removed export from CreateContextOptions interface declaration.

Poem

In the code where changes bloom,
Components dance in newfound room.
Named imports now take the stage,
Simplifying our coding page.
No more defaults, clear and bright,
Our codebase shines in the morning light.
Cheers to progress, onward we go,
With each commit, our project grows! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (39)
packages/web/components/navbar-osmosis-update/navbar-osmosis-update.tsx (1)

Line range hint 105-108: Add a title attribute to the iframe for better accessibility and compliance with web standards.

- <iframe className="z-10 h-full w-full" src={iframeUrl + "%26hide-ui%3D1"}></iframe>
+ <iframe className="z-10 h-full w-full" src={iframeUrl + "%26hide-ui%3D1"} title="Osmosis Updates"></iframe>
packages/web/components/twitter-section/twitter-section.tsx (1)

Line range hint 32-32: Replace the array index with a unique identifier as a key to avoid potential issues with re-renders and state management in React components.

- <React.Fragment key={index}>
+ <React.Fragment key={tweet.id}>
packages/web/integrations/notifi/notifi-subscription-card/fetched-card/history-rows.tsx (5)

Line range hint 48-51: Add keyboard accessibility to clickable elements.

- <div className="my-auto h-[2rem] w-full cursor-pointer bg-osmoverse-700 py-1 text-center" onClick={loadMore}>
+ <div className="my-auto h-[2rem] w-full cursor-pointer bg-osmoverse-700 py-1 text-center" onClick={loadMore} onKeyPress={(e) => e.key === 'Enter' && loadMore()} tabIndex={0}>

Line range hint 119-126: Ensure keyboard accessibility for clickable elements.

- <div className="flex h-[1.5rem] max-w-[5.5625rem] cursor-pointer items-center text-wosmongton-200 transition-all duration-[0.2s] hover:scale-[105%] hover:text-osmoverse-200" onClick={() => { logEvent([EventName.Notifications.alertClicked]); handleClick(); }}>
+ <div className="flex h-[1.5rem] max-w-[5.5625rem] cursor-pointer items-center text-wosmongton-200 transition-all duration-[0.2s] hover:scale-[105%] hover:text-osmoverse-200" onClick={() => { logEvent([EventName.Notifications.alertClicked]); handleClick(); }} onKeyPress={(e) => e.key === 'Enter' && handleClick()} tabIndex={0}>

Line range hint 44-44: Avoid using array index as key in React lists.

- <AvatarIcon key={index} />
+ <AvatarIcon key={row.id} />  // Assuming each row has a unique 'id' field

Line range hint 91-91: Correctly specify all dependencies in the useCallback hook.

- const handleClick = useCallback(() => {
+ const handleClick = useCallback((closeCard, row, setSelectedHistoryEntry, setIsOverLayEnabled, router) => {

Line range hint 146-146: Avoid using dangerouslySetInnerHTML due to potential XSS vulnerabilities.

- <div dangerouslySetInnerHTML={{ __html: message }} />
+ <div>{message}</div>  // Ensure 'message' is sanitized elsewhere if it contains HTML
packages/web/components/cards/validator-squad-card.tsx (1)

Line range hint 47-47: Avoid using array index as key in React lists.

- <AvatarIcon key={index} />
+ <AvatarIcon key={validator.operator_address} />  // Assuming each validator has a unique 'operator_address'
packages/web/components/token-details/token-details.tsx (1)

Line range hint 241-246: Specify the button type to avoid unintended form submissions.

- <button onClick={toggleExpand}>
+ <button type="button" onClick={toggleExpand}>
packages/web/modals/wallet-select/cosmos-wallet-state.tsx (1)

Line range hint 144-144: Remove redundant Boolean call for clarity and performance.

- Boolean(downloadInfo)
+ downloadInfo
packages/web/components/drawers/token-select-drawer.tsx (4)

Line range hint 235-238: Add keyboard accessibility for clickable elements.

To ensure accessibility for keyboard-only users, consider adding keyboard event handlers (onKeyDown, onKeyPress, or onKeyUp) that mimic the onClick behavior for these elements.

+ onKeyUp={(e) => e.key === 'Enter' && onClickAsset(coinDenom)}

Line range hint 254-257: Ensure keyboard accessibility for interactive elements.

Similar to the previous comment, it's important to provide keyboard event handlers for all clickable elements to support accessibility.

+ onKeyUp={(e) => e.key === 'Enter' && onClickAsset(coinDenom)}

Line range hint 273-273: Add keyboard event handlers for accessibility.

This clickable element also requires keyboard event handlers to ensure it is accessible to users who rely on keyboard navigation.

+ onKeyUp={(e) => e.key === 'Enter' && onClickAsset(coinDenom)}

Line range hint 300-311: Specify button type to prevent unintended form submissions.

The button elements should explicitly specify their type to avoid unexpected behaviors when used inside forms. The default type for buttons in HTML is "submit", which can cause forms to submit unintentionally.

+ type="button"
packages/web/components/table/asset-balances.tsx (3)

Line range hint 363-367: Add keyboard accessibility for button interactions.

<button
  className="h-11 w-11 rounded-full bg-osmoverse-825 p-1 transition-[color] duration-150 ease-out hover:bg-osmoverse-800 hover:text-white-full"
+ onKeyUp={(e) => { if (e.key === 'Enter') onExternalTransferUrl(externalTransfer.depositUrl); }}
  onClick={(e) => {
    e.preventDefault();
    if (externalTransfer && externalTransfer.depositUrl) {
      onExternalTransferUrl(externalTransfer.depositUrl);
    } else {
      onDeposit(coinMinimalDenom);
    }
  }}
>

Line range hint 511-523: Specify button type to prevent unintended form submissions.

- <Button
+ <Button type="button"

Also applies to: 530-542


Line range hint 516-516: Use optional chaining for safer code.

- const address = account?.address ?? "";
+ const address = account?.address ?? undefined;

Also applies to: 535-535

packages/web/components/your-balance/your-balance.tsx (3)

Line range hint 257-257: Remove unnecessary Boolean calls to simplify the code.

- const shrinkTitle = !Boolean(data?.currentPrice);
+ const shrinkTitle = !(data?.currentPrice);

Also applies to: 307-307


Line range hint 108-108: Optimize the use of spread syntax in .reduce to improve performance.

- return dustFilteredPools.reduce((total, nextPool) => {
-   const userPool = nextPool.poolDetail.userPoolAssets.find(
-     ({ asset }) => asset.currency.coinDenom === denom
-   );
-   if (userPool) {
-     return userPool.asset.add(total);
-   }
-   return total;
- }, new CoinPretty(currency, 0));
+ let total = new CoinPretty(currency, 0);
+ for (const nextPool of dustFilteredPools) {
+   const userPool = nextPool.poolDetail.userPoolAssets.find(
+     ({ asset }) => asset.currency.coinDenom === denom
+   );
+   if (userPool) {
+     total = userPool.asset.add(total);
+   }
+ }
+ return total;

Line range hint 464-471: Ensure button elements have an explicit type to avoid unexpected form submissions.

- <button
+ <button type="button"
packages/web/components/table/asset-info.tsx (2)

Line range hint 138-138: Remove redundant Boolean call for cleaner and more efficient code.

- const showUnverifiedAssets = Boolean(showUnverifiedAssetsSetting?.state.showUnverifiedAssets);
+ const showUnverifiedAssets = showUnverifiedAssetsSetting?.state.showUnverifiedAssets;

Line range hint 546-556: Add keyboard accessibility for the activation button.

<Button
  variant="ghost"
  className="flex gap-2 text-wosmongton-200 hover:text-rust-200"
  onClick={(e) => {
    e.preventDefault();
    confirmUnverifiedAsset({ coinDenom, coinImageUrl });
  }}
+ onKeyUp={(e) => {
+   if (e.key === 'Enter') {
+     e.preventDefault();
+     confirmUnverifiedAsset({ coinDenom, coinImageUrl });
+   }
+ }}
>
  {t("assets.table.activate")}
</Button>
packages/web/components/complex/all-pools-table.tsx (4)

Line range hint 114-114: Remove redundant Boolean call for cleaner and more efficient code.

- const sortKey = useMemo(() => (Boolean(filters.searchQuery) ? undefined : sortParams.allPoolsSort), [filters.searchQuery, sortParams.allPoolsSort]);
+ const sortKey = useMemo(() => (filters.searchQuery ? undefined : sortParams.allPoolsSort), [filters.searchQuery, sortParams.allPoolsSort]);

Line range hint 198-206: Consider using for...of instead of forEach for better performance.

- poolsData.forEach((pool) => {
+ for (const pool of poolsData) {
    if (pool.volume24hUsd) {
      volumePresenceCount++;
    }
    if (pool.feesSpent7dUsd) {
      feesPresenceCount++;
    }
- });
+ }

Line range hint 430-434: Add keyboard accessibility for the pool quick action cell.

<PoolQuickActionCell
  poolId={row.original.id}
  cellGroupEventEmitter={cellGroupEventEmitter}
  onAddLiquidity={() => quickAddLiquidity(row.original.id)}
+ onKeyUp={(e) => {
+   if (e.key === 'Enter') {
+     quickAddLiquidity(row.original.id);
+   }
+ }}
/>

Line range hint 652-652: Use strict equality checks to avoid potential bugs due to type coercion.

- if (type != "cosmwasm-astroport-pcl" && type != "cosmwasm-whitewhale") {
+ if (type !== "cosmwasm-astroport-pcl" && type !== "cosmwasm-whitewhale") {

Also applies to: 653-653

packages/web/integrations/nomic/transfer.tsx (3)

Line range hint 319-321: Specify explicit types instead of using any.

Using any type can lead to potential bugs and maintenance issues as it bypasses TypeScript's static type checking. Consider specifying more precise types for better code safety and clarity.


Line range hint 455-455: Add keyboard accessibility for clickable elements.

- <img onClick={...} />
+ <img onClick={...} onKeyUp={...} onKeyDown={...} />

Ensure that all clickable elements are accessible via keyboard by adding onKeyUp, onKeyDown, or onKeyPress events.


Line range hint 368-368: Specify the type attribute for button elements.

- <button onClick={...}>
+ <button type="button" onClick={...}>

To prevent unexpected form submissions, explicitly set the type attribute of button elements to button unless they are intended to submit forms.

Also applies to: 439-439

packages/web/modals/profile.tsx (5)

Line range hint 216-216: Remove redundant Boolean call.

- Boolean(props.icnsName)
+ props.icnsName

The Boolean call is unnecessary here as the value will be coerced to a boolean implicitly.


Line range hint 447-447: Remove the redundant catch clause.

- } catch (e) {
-   throw e;
- }

The catch clause that only rethrows the error is redundant and can be removed for cleaner code.


Line range hint 498-553: Specify explicit types instead of using any.

Using any type can lead to potential bugs and maintenance issues as it bypasses TypeScript's static type checking. Consider specifying more precise types for better code safety and clarity.

Also applies to: 577-577


Line range hint 111-111: Include all necessary dependencies in the useEffect hook.

- }, []);
+ }, [props.onRequestClose, router.events.off, router.events.on]);

Ensure that all dependencies used within the useEffect hook are correctly listed in the dependency array to avoid stale closures and bugs.


Line range hint 259-259: Specify the type attribute for button elements.

- <button onClick={...}>
+ <button type="button" onClick={...}>

To prevent unexpected form submissions, explicitly set the type attribute of button elements to button unless they are intended to submit forms.

Also applies to: 343-343, 413-413, 465-465

packages/web/pages/components.tsx (1)

Line range hint 1114-1114: Consider using a literal key instead of a string literal for better performance and readability.

- "X"
+ X
packages/web/components/complex/add-conc-liquidity.tsx (4)

Line range hint 279-288: Add keyboard accessibility for clickable elements.

Actions triggered by mouse events should also be accessible via keyboard events to support accessibility standards. Consider adding onKeyUp, onKeyDown, or onKeyPress events.

+ onKeyUp={yourKeyUpHandler}

Line range hint 380-383: Specify button type to prevent unintended form submissions.

The button element should explicitly declare its type to avoid unexpected behavior in forms. The default type is 'submit', which may cause form submission.

- <button
+ <button type="button"

Line range hint 631-634: Specify button type to prevent unintended form submissions.

Similar to the previous comment, ensure that this button element explicitly declares its type to avoid unexpected behavior in forms.

- <button
+ <button type="button"

Line range hint 926-936: Add keyboard accessibility for clickable elements.

Ensure that actions triggered by mouse events are also accessible via keyboard events to support accessibility standards. Consider adding onKeyUp, onKeyDown, or onKeyPress events.

+ onKeyUp={yourKeyUpHandler}

@mattupham mattupham requested a review from a team June 4, 2024 16:37
@mattupham mattupham marked this pull request as ready for review June 4, 2024 16:37
@MaxMillington
Copy link
Collaborator

@mattupham looks like we failed some localization tests

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (5)
packages/web/components/token-details/token-details.tsx (2)

Line range hint 124-124: Optimize the use of spread syntax in .reduce.

- const currencies = ChainList.map((info) => info.keplrChain.currencies).reduce((a, b) => [...a, ...b]);
+ const currencies = ChainList.flatMap((info) => info.keplrChain.currencies);

Line range hint 241-246: Add explicit type attribute to button to prevent unintended form submissions.

- <button className={`${!isExpanded && "bottom-0"} absolute z-10 flex items-center gap-1 self-stretch`} onClick={toggleExpand}>
+ <button type="button" className={`${!isExpanded && "bottom-0"} absolute z-10 flex items-center gap-1 self-stretch`} onClick={toggleExpand}>
packages/web/modals/wallet-select/cosmos-wallet-state.tsx (1)

Line range hint 144-144: Remove redundant Boolean call for cleaner code.

- Boolean(downloadInfo)
+ downloadInfo
packages/web/pages/assets/[denom].tsx (2)

Line range hint 179-179: Optimize the use of spread syntax in .reduce.

- const currencies = ChainList.map((info) => info.keplrChain.currencies).reduce((a, b) => [...a, ...b]);
+ const currencies = ChainList.flatMap((info) => info.keplrChain.currencies);

Also applies to: 312-312


Line range hint 598-598: Use literal keys directly for cleaner and more efficient code.

- const userId = tokenDetails.twitterURL.split("/").pop();
+ const userId = tokenDetails.twitterURL.split("/").pop()!;

@vercel vercel bot temporarily deployed to prod_swap_test June 4, 2024 21:20 Inactive
@mattupham mattupham merged commit 4c05418 into stage Jun 4, 2024
28 checks passed
@mattupham mattupham deleted the mattupham/fe-478-reduce-fe-bundle-size branch June 4, 2024 21:33
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.

5 participants