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

WIP - refactoring containers and header #5223

Closed
wants to merge 8 commits into from

Conversation

pete-watters
Copy link
Contributor

@pete-watters pete-watters commented Apr 11, 2024

Try out Leather build b5d3bd7Extension build, Test report, Storybook, Chromatic

This is a POC of how we can refactor our code to make it easier to add headers to the approval flow.

In the screenshot below you can see a double header:

  • one in a ContainerLayout wrapper
  • one in the Approver component

Screenshot 2024-04-11 at 16 36 00

@pete-watters pete-watters requested a review from kyranjamie April 11, 2024 15:37
@pete-watters pete-watters force-pushed the chore/approver-header-refactor branch from 93b2af1 to f1f5a12 Compare April 11, 2024 15:39
@pete-watters pete-watters force-pushed the chore/approver-header-refactor branch from f1f5a12 to b5d3bd7 Compare April 11, 2024 15:39
>
{homePageModalRoutes}
</Route>
<Route>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kyranjamie I made a slight change here as a suggestion of an approach we could take. It would involve grouping the routes we use based on their use case which may be a good idea anyway but I'm not sure if it would lead to some duplication.

Before, all routes had the same route container. I've changed it to add another level so we have:

<Route> 
   <Route element={<Container />}>
     // everything in the main extension 
   </Route>
   // Other routes for popup windows e.g. Approver

<Route path="approver"   ...        />

I just did this as a quick POC but would need to review all the routes.

A lot of the complicated code came from the variants for different types of pages but @fbwoolf had a good suggestion to have different containers for each which I am doing here.

Copy link
Collaborator

@kyranjamie kyranjamie Apr 15, 2024

Choose a reason for hiding this comment

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

Interesting idea.

The problem currently is that we mix both functionality and container styles in the container.tsx component.

What if we want the behaviour of

  useOnWalletLock(() => closeWindow());
  useOnSignOut(() => closeWindow());

but not the styles.

I think this refactor should decouple the container styles & logic. If so, then the router based approach to wrapping is a good idea I think.


<Route
path={RouteUrls.ViewSecretKey}
path="approver"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is your Approver but outside of the generic <Container.

In this file I am wrapping it with ContainerLayout so the Header is wider to show how we could do this.

A good fit for this approach would be the OnBoarding pages.

For Approver I think we shouldn't wrap it but instead load the Header inside that component as I have done here

By grouping routes better I believe we can simplify our logic and remove all the pathname switches I added to get us away from storing headers in state.

</AccountGate>
<ContainerLayout
header={
<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.

This <Header component became overly complex when trying to be a do everything for everyone header.

In fact, once I had applied logic I reverse engineered from production and documented here it was decided that for most popups we would only show the logo anyway.

Steps I think we can take here are:

  • refactor and organise our routes
  • create simpler Containers and Headers

@pete-watters pete-watters marked this pull request as draft April 12, 2024 05:11
@pete-watters
Copy link
Contributor Author

This is just a POC. I'm thinking about how best to do this and also to include solving #5181

@@ -0,0 +1,59 @@

Copy link
Collaborator

Choose a reason for hiding this comment

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

to remove/add to gitignore

@@ -79,144 +85,175 @@ export const homePageModalRoutes = (
);

function useAppRoutes() {
// const navigate = useNavigate();
Copy link
Collaborator

Choose a reason for hiding this comment

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

to remove

src/app/common/has-children.ts Show resolved Hide resolved
>
{homePageModalRoutes}
</Route>
<Route>
Copy link
Collaborator

@kyranjamie kyranjamie Apr 15, 2024

Choose a reason for hiding this comment

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

Interesting idea.

The problem currently is that we mix both functionality and container styles in the container.tsx component.

What if we want the behaviour of

  useOnWalletLock(() => closeWindow());
  useOnSignOut(() => closeWindow());

but not the styles.

I think this refactor should decouple the container styles & logic. If so, then the router based approach to wrapping is a good idea I think.

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.

3 participants