-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CORE-652] Add chain icon in SingleNetworkSelector + other chain icon…
… related fixes
- Loading branch information
Showing
19 changed files
with
170 additions
and
61 deletions.
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.