chore: refactor explorer links and menu, add explorer in menu #2836
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.
Summary
Address the issue we didn't have a explorer link in the header
Implementation notes for reviewers
TBH i thought this would be a 5min thing, and it turned out I had to implement a few features in order to make it work.
Let me drive you through the thinking process.
Our links are created by configuration of some const here
cowswap/src/modules/mainMenu/constants/mainMenu.tsx
Line 108 in b383642
The link to the explorer can't be added as a static type, because the URL changes for example between different networks
I decided to make a new type of Menu Item with an arbitrary component, this way we can make any dynamic logic. This new type is:
cowswap/src/modules/mainMenu/types.ts
Line 62 in 9f46264
cowswap/src/modules/mainMenu/types.ts
Line 10 in 9f46264
<ExplorerLink />
component, because it was assumed we always use it for links with anid
(a transaction, or address). In this case, i just want to send it to the home page of the explorercowswap/src/legacy/components/ExplorerLink/index.tsx
Line 56 in 9f46264
cowswap/src/legacy/components/ExplorerLink/index.tsx
Line 27 in 9f46264
Additionally, the link HTML was not good in this case, because i needed to have some image and custom markup for the link, so i gave
children
supportcowswap/src/legacy/components/ExplorerLink/index.tsx
Line 72 in 9f46264
with all this, implementing the link is just to:
cowswap/src/modules/mainMenu/constants/mainMenu.tsx
Line 110 in 9f46264
cowswap/src/modules/mainMenu/constants/mainMenu.tsx
Line 28 in 9f46264
Most of the changes will be to adapt the link parameters, because the
id
is now optional, it should be lastEDIT: adding default network
Before @elena-zh opens an issue, i noticed the link was not displayed if the network is unsupported
Now i created a parameter to the
ExplorerLink
component so it can have a default networkTo Test
1 .Check the link in the different networks