-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
beb01d7
to
373423d
Compare
92de8a5
to
019d8f8
Compare
eb0f0de
to
8302c84
Compare
@@ -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} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [isShowingSwitchAccount, setIsShowingSwitchAccount] = useState(false); | ||
return ( | ||
<> | ||
{isShowingSwitchAccount && ( |
There was a problem hiding this comment.
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'; | ||
|
There was a problem hiding this comment.
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
99fc49e
to
3ced27c
Compare
@@ -0,0 +1,62 @@ | |||
import { ReactNode, createContext, useContext, useEffect, useReducer } from 'react'; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; | ||
}; | ||
|
There was a problem hiding this comment.
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?
e258fbd
to
9a240c7
Compare
@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. |
if (pathname === RouteUrls.RpcSendTransfer) return undefined; | ||
return 'Send'; | ||
} | ||
|
There was a problem hiding this comment.
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
7bfd15e
to
872d978
Compare
872d978
to
7aead25
Compare
We spoke about this on the engineering sync and I will refactor further to not use context and push the That will mean more code but likely better performance and scalability |
This PR alters the code we use for generic page containers to address concerns in this discussion
Key concepts that are introduced are:
onboarding
,home
,page
,popup
Context
is used where more dynamic updates are needed e.g. page titlespage
's can update their own title and props on an opt in basis