-
Notifications
You must be signed in to change notification settings - Fork 194
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
fix(explorer): various fixes #3195
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f0fc0c
fix(explorer): default opts to empty object
holic 3c5e5e0
Create unlucky-icons-wonder.md
holic 61890f6
Update unlucky-icons-wonder.md
holic 6835f28
various fixes
holic 45b4d66
fix icon issue
holic 49d3d67
Update unlucky-icons-wonder.md
holic 4600a0e
cache bridges so we don't create a bunch
holic 2c91293
refactor
holic f985eb2
Create chilly-readers-heal.md
holic b4f5d61
Update unlucky-icons-wonder.md
holic 0779301
Create mean-radios-search.md
holic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
Refactored `observer` initialization to reuse bridge iframes with the same `url`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
Fixed favicon paths and fixed a few issues where we were incorrectly redirecting based on the chain name or ID. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@latticexyz/explorer": patch | ||
--- | ||
|
||
Fixed an issue where the `observer` Viem client decorator required an empty object arg when no options are used. | ||
|
||
```diff | ||
-client.extend(observer({})); | ||
+client.extend(observer()); | ||
``` |
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
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
File renamed without changes.
File renamed without changes
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
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
4 changes: 2 additions & 2 deletions
4
packages/explorer/src/app/page.tsx → ...ages/explorer/src/app/(explorer)/page.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { redirect } from "next/navigation"; | ||
import { supportedChainsById, validateChainId } from "../common"; | ||
import { chainIdToName, validateChainId } from "../../common"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export default function IndexPage() { | ||
const chainId = Number(process.env.CHAIN_ID); | ||
validateChainId(chainId); | ||
|
||
const chainName = supportedChainsById[chainId]; | ||
const chainName = chainIdToName[chainId] ?? "anvil"; | ||
return redirect(`/${chainName}/worlds`); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { anvil, garnet, redstone } from "viem/chains"; | ||
|
||
export const supportedChains = { anvil, garnet, redstone } as const; | ||
export const supportedChainsById = Object.fromEntries( | ||
Object.entries(supportedChains).map(([, chain]) => [chain.id, chain]), | ||
); | ||
export type supportedChains = typeof supportedChains; | ||
|
||
export type supportedChainName = keyof supportedChains; | ||
export type supportedChainId = supportedChains[supportedChainName]["id"]; | ||
|
||
export type SupportedChainIds = (typeof supportedChains)[keyof typeof supportedChains]["id"]; | ||
export type SupportedChainNames = keyof typeof supportedChains; | ||
export const chainIdToName = Object.fromEntries( | ||
Object.entries(supportedChains).map(([chainName, chain]) => [chain.id, chainName]), | ||
); | ||
|
||
export function validateChainId(chainId: number): asserts chainId is SupportedChainIds { | ||
if (!(chainId in supportedChainsById)) { | ||
throw new Error(`Invalid chain id. Supported chains are: ${Object.keys(supportedChainsById).join(", ")}.`); | ||
export function validateChainId(chainId: unknown): asserts chainId is supportedChainId { | ||
if (!(typeof chainId === "number" && chainId in chainIdToName)) { | ||
throw new Error(`Invalid chain ID. Supported chains are: ${Object.keys(chainIdToName).join(", ")}.`); | ||
} | ||
} | ||
|
||
export function validateChainName(name: string | string[] | undefined): asserts name is SupportedChainNames { | ||
if (Array.isArray(name) || typeof name !== "string" || !(name in supportedChains)) { | ||
throw new Error(`Invalid chain name. Supported chains are: ${Object.keys(supportedChainsById).join(", ")}.`); | ||
export function validateChainName(name: unknown): asserts name is supportedChainName { | ||
if (!(typeof name === "string" && name in supportedChains)) { | ||
throw new Error(`Invalid chain name. Supported chains are: ${Object.keys(supportedChains).join(", ")}.`); | ||
} | ||
} |
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
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
Oops, something went wrong.
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.
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.
Wonder if it should start uppercase given it's a type, and that's been the convention so far? Same for
supportedChainName
andsupportedChainId
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.
this is just a shortcut to avoid having to sprinkle
typeof
everywhere you're using it with aconst
when the name mirrors the type, you can use the same name/reference in both types and runtime (we borrowed this pattern from arktype and use it throughout config etc.)