-
Notifications
You must be signed in to change notification settings - Fork 400
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
[CORE-652] Add chain icon in SingleNetworkSelector + other chain icon related fixes #5794
Merged
graphite-app
merged 1 commit into
main
from
12-18-_core-652_add_chain_icon_in_singlenetworkselector_other_chain_icon_related_fixes
Dec 19, 2024
Merged
Changes from all commits
Commits
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
55 changes: 55 additions & 0 deletions
55
apps/dashboard/src/@/components/blocks/MultiNetworkSelector.stories.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { useState } from "react"; | ||
import { BadgeContainer, mobileViewport } from "../../../stories/utils"; | ||
import { MultiNetworkSelector } from "./NetworkSelectors"; | ||
|
||
const meta = { | ||
title: "blocks/Cards/MultiNetworkSelector", | ||
component: Story, | ||
parameters: { | ||
nextjs: { | ||
appDirectory: true, | ||
}, | ||
}, | ||
} satisfies Meta<typeof Story>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Desktop: Story = { | ||
args: {}, | ||
}; | ||
|
||
export const Mobile: Story = { | ||
args: {}, | ||
parameters: { | ||
viewport: mobileViewport("iphone14"), | ||
}, | ||
}; | ||
|
||
function Story() { | ||
return ( | ||
<div className="container flex max-w-[1000px] flex-col gap-8 lg:p-10"> | ||
<Variant label="No Chains selected by default" selectedChainIds={[]} /> | ||
<Variant | ||
label="Polygon, Ethereum selected by default" | ||
selectedChainIds={[1, 137]} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
function Variant(props: { | ||
label: string; | ||
selectedChainIds: number[]; | ||
}) { | ||
const [chainIds, setChainIds] = useState<number[]>(props.selectedChainIds); | ||
return ( | ||
<BadgeContainer label={props.label}> | ||
<MultiNetworkSelector | ||
selectedChainIds={chainIds} | ||
onChange={setChainIds} | ||
/> | ||
</BadgeContainer> | ||
); | ||
} |
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
59 changes: 59 additions & 0 deletions
59
apps/dashboard/src/@/components/blocks/SingleNetworkSelector.stories.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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { useState } from "react"; | ||
import { BadgeContainer, mobileViewport } from "../../../stories/utils"; | ||
import { SingleNetworkSelector } from "./NetworkSelectors"; | ||
|
||
const meta = { | ||
title: "blocks/Cards/SingleNetworkSelector", | ||
component: Story, | ||
parameters: { | ||
nextjs: { | ||
appDirectory: true, | ||
}, | ||
}, | ||
} satisfies Meta<typeof Story>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Desktop: Story = { | ||
args: {}, | ||
}; | ||
|
||
export const Mobile: Story = { | ||
args: {}, | ||
parameters: { | ||
viewport: mobileViewport("iphone14"), | ||
}, | ||
}; | ||
|
||
function Story() { | ||
return ( | ||
<div className="container flex max-w-[1000px] flex-col gap-8 lg:p-10"> | ||
<Variant label="No Chain ID selected by default" chainId={undefined} /> | ||
<Variant label="Polygon selected by default" chainId={137} /> | ||
<Variant | ||
label="Show certain chains only" | ||
chainId={undefined} | ||
chainIds={[1, 137, 10]} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
function Variant(props: { | ||
label: string; | ||
chainId: number | undefined; | ||
chainIds?: number[]; | ||
}) { | ||
const [chainId, setChainId] = useState<number | undefined>(props.chainId); | ||
return ( | ||
<BadgeContainer label={props.label}> | ||
<SingleNetworkSelector | ||
chainId={chainId} | ||
onChange={setChainId} | ||
chainIds={props.chainIds} | ||
/> | ||
</BadgeContainer> | ||
); | ||
} |
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
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
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
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
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,49 +1,31 @@ | ||
"use client"; | ||
|
||
import { Img } from "@/components/blocks/Img"; | ||
/* eslint-disable @next/next/no-img-element */ | ||
import { replaceIpfsUrl } from "lib/sdk"; | ||
import { forwardRef } from "react"; | ||
|
||
const fallbackIcon = replaceIpfsUrl( | ||
"ipfs://QmU1r24UsmGg2w2RePz98zV5hR3CnjvakLZzB6yH4prPFh/globe.svg", | ||
); | ||
import { cn } from "../../@/lib/utils"; | ||
import { fallbackChainIcon } from "../../utils/chain-icons"; | ||
|
||
type ImageProps = React.ComponentProps<"img">; | ||
|
||
type ChainIconProps = ImageProps & { | ||
ipfsSrc?: string; | ||
size: ImageProps["width"]; | ||
}; | ||
|
||
export const ChainIcon = forwardRef<HTMLImageElement, ChainIconProps>( | ||
({ ipfsSrc, size, ...restProps }, ref) => { | ||
const src = ipfsSrc ? replaceIpfsUrl(ipfsSrc) : fallbackIcon; | ||
// treat size of number as "px" | ||
size = typeof size === "number" ? `${size}px` : size; | ||
export const ChainIcon = ({ ipfsSrc, ...restProps }: ChainIconProps) => { | ||
const src = ipfsSrc ? replaceIpfsUrl(ipfsSrc) : fallbackChainIcon; | ||
|
||
return ( | ||
<img | ||
{...restProps} | ||
ref={ref} | ||
// render different image element if src changes to avoid showing old image while loading new one | ||
key={src} | ||
src={src} | ||
width={size} | ||
height={size} | ||
style={{ | ||
objectFit: "contain", | ||
width: size, | ||
height: size, | ||
}} | ||
loading={restProps.loading || "lazy"} | ||
decoding="async" | ||
alt="" | ||
// fallbackSrc is not working | ||
onError={(event) => { | ||
event.currentTarget.srcset = `${fallbackIcon} 1x`; | ||
event.currentTarget.src = fallbackIcon; | ||
}} | ||
/> | ||
); | ||
}, | ||
); | ||
return ( | ||
<Img | ||
{...restProps} | ||
// render different image element if src changes to avoid showing old image while loading new one | ||
key={src} | ||
className={cn("object-contain", restProps.className)} | ||
src={src} | ||
loading={restProps.loading || "lazy"} | ||
alt="" | ||
fallback={<img src={fallbackChainIcon} alt="" />} | ||
skeleton={<div className="animate-pulse rounded-full bg-border" />} | ||
/> | ||
); | ||
}; |
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
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.
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.
btw this is one of the things we should switch to using the react sdk components for!