This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Dashboard frontend #5241
Merged
Dashboard frontend #5241
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cliffoo
force-pushed
the
dash-woah
branch
4 times, most recently
from
July 6, 2022 05:01
13c268a
to
da4f050
Compare
1 task
cliffoo
force-pushed
the
dash-woah
branch
2 times, most recently
from
July 13, 2022 07:51
17e1749
to
f35c516
Compare
This was referenced Jul 13, 2022
Closed
cliffoo
force-pushed
the
dash-woah
branch
4 times, most recently
from
July 15, 2022 18:27
48c43f4
to
3467c5e
Compare
cliffoo
force-pushed
the
dash-woah
branch
9 times, most recently
from
July 26, 2022 20:28
782a6f6
to
e0e58d1
Compare
Stop the cap Co-authored-by: g. nicholas d'andrea <[email protected]>
Bad nullish coalesce usage
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I revamped dashboard frontend.
Why?
This started when I looked into fleshing out features and adding them to dashboard (decoded tx, contract interaction, network + wallet management, and more), and I realized various problems with the existing react code, both the code itself and also more meta (file structure, maintainability) things. So I started from scratch, picked up a component library (mantine) I've been eyeing for a long time, and rebuilt the dashboard frontend.
Some problems and their solutions
Performance
Problem
There are examples of things that cause sub-optimal runtime (take a look at this,
ctrl + f
"requests" and see how many times it's looping.)Solution
I've made things as efficient as I could, bearing readability in mind. This specific example above (looping requests) is fixed with a hashmap so constant lookup time.
State management
Problem
State is everywhere right now, it seeps through components at different levels and it's hard to keep track / probably causing extra renders.
Solution
App state is managed better in general. There is a
<DashContext />
close to the root that the entire app relies on (to read and mutate state).UX
Problem
Right now:
Solution
Wagmi
Problem
Wagmi is used weird, it might be because wagmi has evolved and its usage has improved? Take a look at how wagmi is currently provided to the app. I think it's not very readable / might be doing the wrong thing.
Solution
New implementation is clean and easy to understand.
Code organization
This is a big one for me, but it's rather hard to articulate, since there is no right way to organize things in react. I guess an exercise you could do is start from the root (
src/App.tsx
), dig into how each component relate to each other until you've traversed through all of them; then do the same for this branch and see how they compare.Here's how I've organized things:
App.tsx
<- Only context providers and routing go here, no real app logiccontexts/
DashContext/
<- (Currently single) source for app's statecomponents/
common/
<- Reusable componentscomposed/
<- Distinct parts of the app, such as<Sidebar />
and<Txs />
, "composed" by nesting smaller components in larger ones, and reusing components fromcomponents/common
wrappers
<- Context providers by 3rd party libsassets/
<- Static things like fonts and imageshooks/
<- All custom hooksutils/
<- Convenience thingsCraco
Problem:
So it looked like craco was running out of community support, though someone seems to have picked it up recently.
I don't see a convincing argument for us to use it over CRA. Craco doesn't support CRA 5 yet, we don't need to override any webpack configs, and we're currently only using craco to get tailwind working (tailwind is no longer needed, as mantine uses emotion for styling).
Solution:
CRA.
Eslint & preflight checks
Problem:
Currently eslint and preflight checks are disabled during build and dev processes. This means important checks like
exhaustive-deps
are suppressed, which means components are likely not handling updates consistently.Solution:
Enable 'em. The build / start commands are now just
react-scripts build
andreact-scripts start
. Proper checks are in place and not generating warnings.Security
I'm probably being more cautious than necessary here, but since a big reason why you'd use dashboard in the first place is security (no need to hand off mnemonic, just let Metamask take care of it), as I mentioned here I want to minimize / elimiate all network requests that are not used for processing RPC requests.
This means no more requests to the following:
Other things
import
/export
type
wherever possible. This is good becausetype
imports are fully erased during runtime.Fun things
Why this is good
The biggest win for me is that this sets up a good foundation for future improvements. There is a clearer path forward on integrating new features, reasons in the lists above.
How to review
The best way is probably to ignore how dashboard frontend is now. I.e. When going through the changes, ignore all deletions (red) and look only at additions (green). There is almost no inherited code.
Problems I've introduced
Mantine + react dependency clash. See this.flushSync
warning on clipboard copy in modal. See this.Babel peer deps warning, but things work ok?Issues that are conveniently resolved
=>
This shouldn't happen, unless there's no browser wallet (like Metamask). (Aside: I'll probably add an ErrorBoundary in the future to catch errors like no wallet found.)=>
1337 resolves to "Dev Network" now.=>
No need to cache, chain names are now bundled.=>
Updated to latest.There may be more? I just searched
is:issue is:open dashboard
and filtered through the result.Future
This PR was originally more ambitious, but in favor of better git practices and PR reviewers' time, new features will ensue in the form of smaller, more digestible PRs after this one merges against develop.
Progress
Clear outdated(already made it to develop)caniuse-lite
warning<DashContext />