-
Notifications
You must be signed in to change notification settings - Fork 3
feat: show oracle vendors #63
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e25097
feat: oracle icons + simple badge
antoncoding af2b0ca
feat: icons and feed routes
antoncoding 8114912
feat: better visual
antoncoding 8b1df59
feat: add oracle to position page as well
antoncoding dff3ee2
feat: review fixes
antoncoding eb0c34d
fix: more review feedbacks and styling
antoncoding 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,37 +1,59 @@ | ||
| import { Tooltip } from '@nextui-org/tooltip'; | ||
| import { ExternalLinkIcon } from '@radix-ui/react-icons'; | ||
| import Image from 'next/image'; | ||
| import Link from 'next/link'; | ||
| import { Address, zeroAddress } from 'viem'; | ||
| import { IoIosSwap } from 'react-icons/io'; | ||
| import { IoWarningOutline } from 'react-icons/io5'; | ||
| import { Address } from 'viem'; | ||
| import { getSlicedAddress } from '@/utils/address'; | ||
| import { getExplorerURL } from '@/utils/external'; | ||
| import { OracleVendors, OracleVendorIcons } from '@/utils/oracle'; | ||
| import { OracleFeed } from '@/utils/types'; | ||
|
|
||
| export function OracleFeedInfo({ | ||
| address, | ||
| title, | ||
| feed, | ||
| chainId, | ||
| }: { | ||
| address: string; | ||
| title: string | null; | ||
| feed: OracleFeed | null; | ||
| chainId: number; | ||
| }): JSX.Element { | ||
| const isLink = address !== zeroAddress; | ||
| }): JSX.Element | null { | ||
| if (!feed) return null; | ||
|
|
||
| const fromAsset = feed.pair?.[0] ?? 'Unknown'; | ||
| const toAsset = feed.pair?.[1] ?? 'Unknown'; | ||
|
|
||
| const vendorIcon = | ||
| OracleVendorIcons[feed.vendor as OracleVendors] ?? OracleVendorIcons[OracleVendors.Unknown]; | ||
|
|
||
| const content = ( | ||
| <div className="ml-2 flex w-full items-center justify-between pb-1"> | ||
| <div className="flex items-center space-x-2 text-xs"> | ||
| <span>{fromAsset}</span> | ||
| <IoIosSwap /> | ||
| <span>{toAsset}</span> | ||
| </div> | ||
| {vendorIcon ? ( | ||
| <Image src={vendorIcon} alt={feed.vendor ?? 'Unknown'} width={16} height={16} /> | ||
| ) : ( | ||
| <IoWarningOutline size={16} /> | ||
| )} | ||
| </div> | ||
| ); | ||
|
|
||
| if (isLink) | ||
| return ( | ||
| <Link | ||
| className="group flex items-center gap-1 text-right no-underline hover:underline" | ||
| href={getExplorerURL(address as Address, chainId)} | ||
| target="_blank" | ||
| <Tooltip | ||
| content={feed.description ?? getSlicedAddress(feed.address as Address)} | ||
| className="rounded-sm" | ||
| > | ||
| {title ? ( | ||
| <p className="text-right font-zen text-xs"> {title} </p> | ||
| ) : ( | ||
| <p className="text-right font-zen text-sm"> {getSlicedAddress(address as Address)} </p> | ||
| )} | ||
| <ExternalLinkIcon /> | ||
| </Link> | ||
| <Link | ||
| className="group flex w-full items-center gap-1 text-right no-underline hover:underline" | ||
| href={getExplorerURL(feed.address as Address, chainId)} | ||
| target="_blank" | ||
| > | ||
| {content} | ||
| <ExternalLinkIcon className="ml-1" /> | ||
| </Link> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <p className="text-right font-zen text-sm text-yellow-500 hover:no-underline"> Hardcoded 1 </p> | ||
| ); | ||
| } |
This file contains hidden or 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,70 @@ | ||
| import React from 'react'; | ||
| import { Tooltip } from '@nextui-org/tooltip'; | ||
| import Image from 'next/image'; | ||
| import { IoWarningOutline } from 'react-icons/io5'; | ||
| import { OracleVendorIcons, OracleVendors, parseOracleVendors } from '@/utils/oracle'; | ||
| import { MorphoChainlinkOracleData } from '@/utils/types'; | ||
|
|
||
| type OracleVendorBadgeProps = { | ||
| oracleData: MorphoChainlinkOracleData | null; | ||
| useTooltip?: boolean; | ||
| }; | ||
|
|
||
| const renderVendorIcon = (vendor: OracleVendors) => ( | ||
| OracleVendorIcons[vendor] | ||
| ? <Image src={OracleVendorIcons[vendor]} alt={vendor} width={16} height={16} /> | ||
| : <IoWarningOutline className="text-secondary" size={16} /> | ||
| ); | ||
|
|
||
| function OracleVendorBadge({ oracleData, useTooltip = true }: OracleVendorBadgeProps) { | ||
| const { vendors } = parseOracleVendors(oracleData); | ||
|
|
||
| const noFeeds = vendors.length === 0; | ||
|
|
||
| const content = ( | ||
| <div className={`flex items-center space-x-1 ${useTooltip ? '' : 'rounded bg-primary p-1'}`}> | ||
| {!useTooltip && ( | ||
| <span className="mr-1 text-xs font-medium"> | ||
| {noFeeds ? 'No Oracle' : vendors.join(', ')}: | ||
| </span> | ||
| )} | ||
| {noFeeds ? ( | ||
| <IoWarningOutline className="text-secondary" size={16} /> | ||
| ) : ( | ||
| vendors.map((vendor, index) => ( | ||
| <React.Fragment key={index}> | ||
| {renderVendorIcon(vendor)} | ||
| </React.Fragment> | ||
| )) | ||
| )} | ||
| </div> | ||
| ); | ||
|
|
||
| if (useTooltip) { | ||
| return ( | ||
| <Tooltip | ||
| content={ | ||
| <div className="m-2"> | ||
| <p className="py-2 text-sm font-medium"> | ||
| {noFeeds ? 'No Oracle Feed Used' : 'Oracle Vendors:'} | ||
| </p> | ||
| <ul> | ||
| {vendors.map((vendor, index) => ( | ||
| <li key={index} className="text-xs"> | ||
| {vendor} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| } | ||
| className="rounded-sm" | ||
| > | ||
| {content} | ||
| </Tooltip> | ||
| ); | ||
| } | ||
|
|
||
| return content; | ||
| }; | ||
|
|
||
| export default OracleVendorBadge; |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.