-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2426 from pyth-network/cprussin/ui-16-improve-pri…
…ce-feed-icons feat(insights): improve feed generic icons
- Loading branch information
Showing
10 changed files
with
124 additions
and
14 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
apps/insights/src/components/PriceFeedIcon/crypto-redemption-rate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
apps/insights/src/components/PriceFeedIcon/index.module.scss
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,45 @@ | ||
@use "@pythnetwork/component-library/theme"; | ||
|
||
.generic { | ||
border-radius: theme.border-radius("md"); | ||
|
||
&[data-asset-class="Commodities"] { | ||
background: theme.pallette-color("zinc", 400); | ||
fill: theme.pallette-color("zinc", 700); | ||
} | ||
|
||
&[data-asset-class="Crypto Index"] { | ||
background: theme.pallette-color("fuchsia", 300); | ||
fill: theme.pallette-color("fuchsia", 700); | ||
} | ||
|
||
&[data-asset-class="Crypto Redemption Rate"] { | ||
background: theme.pallette-color("pink", 300); | ||
fill: theme.pallette-color("pink", 700); | ||
} | ||
|
||
&[data-asset-class="Crypto"] { | ||
background: theme.pallette-color("violet", 300); | ||
fill: theme.pallette-color("violet", 700); | ||
} | ||
|
||
&[data-asset-class="Equity"] { | ||
background: theme.pallette-color("rose", 300); | ||
fill: theme.pallette-color("rose", 700); | ||
} | ||
|
||
&[data-asset-class="FX"] { | ||
background: theme.pallette-color("indigo", 300); | ||
fill: theme.pallette-color("indigo", 700); | ||
} | ||
|
||
&[data-asset-class="Metal"] { | ||
background: theme.pallette-color("orange", 300); | ||
fill: theme.pallette-color("orange", 700); | ||
} | ||
|
||
&[data-asset-class="Rates"] { | ||
background: theme.pallette-color("emerald", 300); | ||
fill: theme.pallette-color("stone", 700); | ||
} | ||
} |
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,30 +1,67 @@ | ||
import Generic from "cryptocurrency-icons/svg/color/generic.svg"; | ||
import type { ComponentProps } from "react"; | ||
import type { ComponentProps, ComponentType } from "react"; | ||
|
||
import Commodities from "./commodities.svg"; | ||
import CryptoIndex from "./crypto-index.svg"; | ||
import CryptoRedemptionRate from "./crypto-redemption-rate.svg"; | ||
import Crypto from "./crypto.svg"; | ||
import Equity from "./equity.svg"; | ||
import Fx from "./fx.svg"; | ||
import { icons } from "./icons"; | ||
import styles from "./index.module.scss"; | ||
import Metal from "./metal.svg"; | ||
import Rates from "./rates.svg"; | ||
|
||
type OwnProps = { | ||
assetClass: string; | ||
symbol: string; | ||
}; | ||
type Props = Omit< | ||
ComponentProps<typeof Generic>, | ||
keyof OwnProps | "width" | "height" | "viewBox" | ||
> & | ||
type Props = Omit<SVGProps, keyof OwnProps | "width" | "height" | "viewBox"> & | ||
OwnProps; | ||
|
||
export const PriceFeedIcon = ({ assetClass, symbol, ...props }: Props) => { | ||
const Icon = getIcon(assetClass, symbol); | ||
return <Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} />; | ||
}; | ||
|
||
const getIcon = (assetClass: string, symbol: string) => { | ||
if (assetClass === "Crypto") { | ||
const firstPart = symbol.split("/")[0]; | ||
return firstPart && firstPart in icons | ||
? icons[firstPart as keyof typeof icons] | ||
: Generic; | ||
const Icon = firstPart ? (icons as SVGRecord)[firstPart] : undefined; | ||
return Icon ? ( | ||
<Icon width="100%" height="100%" viewBox="0 0 32 32" {...props} /> | ||
) : ( | ||
<GenericIcon assetClass={assetClass} {...props} /> | ||
); | ||
} else { | ||
return Generic; | ||
return <GenericIcon assetClass={assetClass} {...props} />; | ||
} | ||
}; | ||
|
||
type GenericProps = ComponentProps<"svg"> & { assetClass: string }; | ||
|
||
const GenericIcon = ({ assetClass, ...props }: GenericProps) => { | ||
const Icon = ASSET_CLASS_TO_ICON[assetClass] ?? Generic; | ||
return ( | ||
<Icon | ||
width="100%" | ||
height="100%" | ||
className={styles.generic} | ||
data-asset-class={assetClass} | ||
{...(!(assetClass in ASSET_CLASS_TO_ICON) && { | ||
viewBox: "0 0 32 32", | ||
})} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
type SVGProps = ComponentProps<"svg">; | ||
type SVGComponent = ComponentType<SVGProps>; | ||
type SVGRecord = Record<string, SVGComponent>; | ||
|
||
const ASSET_CLASS_TO_ICON: Record<string, SVGComponent> = { | ||
Commodities, | ||
"Crypto Index": CryptoIndex, | ||
"Crypto Redemption Rate": CryptoRedemptionRate, | ||
Crypto, | ||
Equity, | ||
FX: Fx, | ||
Metal, | ||
Rates, | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.