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

chore: refactor containers #5619

Closed
wants to merge 1 commit into from
Closed

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented Jul 8, 2024

Try out Leather build 7aead25Extension build, Test report, Storybook, Chromatic

This PR alters the code we use for generic page containers to address concerns in this discussion

Key concepts that are introduced are:

  • the replacement of variant config with individual page layout wrappers
    • pages are grouped by type based on their layout - onboarding, home, page, popup
    • routes are then categorised accordingly and wrapped by their relevant layout
  • opt in Context is used where more dynamic updates are needed e.g. page titles
    • page's can update their own title and props on an opt in basis
    • this allows for specific use cases to be specified on a page rather than a global level

@pete-watters pete-watters self-assigned this Jul 8, 2024
Copy link

coderabbitai bot commented Jul 8, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

@pete-watters pete-watters force-pushed the chore/refactor-containers branch from beb01d7 to 373423d Compare July 8, 2024 07:16
@pete-watters pete-watters force-pushed the chore/refactor-containers branch 2 times, most recently from 92de8a5 to 019d8f8 Compare July 8, 2024 13:48
@pete-watters pete-watters changed the title Chore/refactor containers chore: refactor containers Jul 8, 2024
@pete-watters pete-watters force-pushed the chore/refactor-containers branch 4 times, most recently from eb0f0de to 8302c84 Compare July 9, 2024 14:12
@@ -25,7 +25,7 @@ export function Sip10TokenAssetList({
{tokens.map(token => (
<Sip10TokenAssetItem
balance={token.balance}
key={token.info.name}
key={token.info.name + token.info.contractId}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this as it was throwing a duplicate keys error for ALEX token

}

export function DialogHeader({ onClose, title }: DialogHeaderProps) {
export function DialogHeader({ onClose, title, variant = 'default' }: DialogHeaderProps) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to accept a variant as previously we were using another variant in Header - bigTitle. It's used in the Send flow.

Screenshot 2024-07-09 at 15 16 08

I'll move this component to the mono-repo to be located with Dialog

const [isShowingSwitchAccount, setIsShowingSwitchAccount] = useState(false);
return (
<>
{isShowingSwitchAccount && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isShowingSwitchAccount was located at the top container but when I was testing other re-rendering issues I noticed that when we open/close the dialog it was re-rendering the whole app.

I decided to localise instances of the SwitchAccountDialog to where they are called from. This means some duplicate code but helps to avoid re-rendering the app un-necessarily.

import { TotalBalance } from '../../total-balance';
import { ContainerLayout } from '../container.layout';
import { PopupHeader } from './popup-header';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left these localised switches here as we will be working on the popups in approval UX (popup.layout.tsx can become approval.layout). They toggle what is and isn't shown in the header.

I can refactor to setup a specific context for this if needed

@pete-watters pete-watters force-pushed the chore/refactor-containers branch 5 times, most recently from 99fc49e to 3ced27c Compare July 9, 2024 15:27
@@ -0,0 +1,62 @@
import { ReactNode, createContext, useContext, useEffect, useReducer } from 'react';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm placing this here for now as I'm not sure where it should be located

@@ -42,6 +41,9 @@ export function BtcSendForm() {
validationSchema,
} = useBtcSendForm();

// with this enabled PageLayout re-renders in a loop
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using useUpdatePageHeaderContext to update the title here causes a re-render loop in PageLayout . It seems to work well generally otherwise but is clearly not a good fit here

}
return context;
};

Copy link
Contributor Author

@pete-watters pete-watters Jul 9, 2024

Choose a reason for hiding this comment

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

I'm using a context to help dynamically update the page header as sometimes it needs to vary based on the page.

That is working well generally apart from on the Send flow when adding the title causes a re-render. I can try and fix that but I wonder if context is the best approach here.

See here

I tried using OutletContext and route state but hit a similar issue. I will keep working on it but maybe someone else has better ideas?

@pete-watters pete-watters force-pushed the chore/refactor-containers branch 2 times, most recently from e258fbd to 9a240c7 Compare July 9, 2024 16:18
@pete-watters
Copy link
Contributor Author

pete-watters commented Jul 9, 2024

@kyranjamie @fbwoolf @alter-eggo : Can you please help review the general approach I am taking here?

I worked on splitting up the container I had used to make it more composable. I have more refactoring to do to clean it up and optimise but I wanted to make sure the approach I am taking makes sense.

I'm using a context to help dynamically update the page header as sometimes it needs to vary based on the page. That is working well generally apart from on the Send flow when adding the title causes a re-render. I can try and fix that but I wonder if context is the best approach here see

Previously I was using this pathname based lookup to indicate the title to be shown. That's not great but I could re-introduce that but more localised to set titles for Send flows only. Then we could get the main benefits of this refactor but postpone this tricky part.

@pete-watters pete-watters linked an issue Jul 10, 2024 that may be closed by this pull request
if (pathname === RouteUrls.RpcSendTransfer) return undefined;
return 'Send';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously I was using this pathname based lookup to indicate the title to be shown

@pete-watters pete-watters force-pushed the chore/refactor-containers branch 2 times, most recently from 7bfd15e to 872d978 Compare July 10, 2024 15:00
@pete-watters pete-watters force-pushed the chore/refactor-containers branch from 872d978 to 7aead25 Compare July 11, 2024 05:56
@pete-watters
Copy link
Contributor Author

We spoke about this on the engineering sync and I will refactor further to not use context and push the Header further down the tree so components can opt in and load it on demand.

That will mean more code but likely better performance and scalability

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.

Refactor: Global app "back button" navigation
2 participants