Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pages/reserve-overview.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export default function ReserveOverview() {

return (
<AssetCapsProviderSDK asset={reserve}>
<ReserveTopDetailsWrapper underlyingAsset={underlyingAsset} />
<ReserveTopDetailsWrapper
underlyingAsset={underlyingAsset}
onShowOracle={() => setMode('overview')}
/>

<ContentContainer>
<Box
Expand Down
1 change: 1 addition & 0 deletions public/icons/other/chainlink.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icons/other/safe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/ContentWithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ContentWithTooltipProps {
children: ReactNode;
// eslint-disable-next-line
tooltipContent: ReactElement<any, string | JSXElementConstructor<any>>;
placement?: 'right' | 'left' | 'bottom';
placement?: 'top' | 'right' | 'left' | 'bottom';
withoutHover?: boolean;
open?: boolean;
setOpen?: (value: boolean) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/locales/el/messages.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/en/messages.js

Large diffs are not rendered by default.

146 changes: 146 additions & 0 deletions src/locales/en/messages.po

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/es/messages.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/locales/fr/messages.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/modules/reserve-overview/Gho/GhoReserveConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ReserveWithId } from 'src/hooks/app-data-provider/useAppDataProvider';
import { ReserveBorrowCard } from '../ReserveBorrowCard';
import { ReserveCard } from '../ReserveCard';
import { ReserveCollectorInfo } from '../ReserveCollectorInfo';
import { ReserveOracleCard } from '../ReserveOracleCard';

// import { SavingsGho } from './SavingsGho';

Expand Down Expand Up @@ -51,6 +52,7 @@ export const GhoReserveConfiguration: React.FC<GhoReserveConfigurationProps> = (
</PanelRow> */}
<ReserveBorrowCard reserve={reserve} showStats showChart={false} showCollectorInfo={false} />
<ReserveCollectorInfo reserve={reserve} variant="card" />
<ReserveOracleCard reserve={reserve} />
</>
);
};
2 changes: 2 additions & 0 deletions src/modules/reserve-overview/ReserveConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReserveWithId } from 'src/hooks/app-data-provider/useAppDataProvider';

import { ReserveBorrowCard } from './ReserveBorrowCard';
import { ReserveInterestRateCard } from './ReserveInterestRateCard';
import { ReserveOracleCard } from './ReserveOracleCard';
import { ReserveSupplyCard } from './ReserveSupplyCard';

/**
Expand Down Expand Up @@ -38,6 +39,7 @@ export const ReserveConfiguration: React.FC<ReserveConfigurationProps> = ({ rese
showCollectorInfo
/>
{showBorrowDetails && <ReserveInterestRateCard reserve={reserve} />}
<ReserveOracleCard reserve={reserve} />
</>
);
};
246 changes: 246 additions & 0 deletions src/modules/reserve-overview/ReserveOracleCard/OracleParts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
import { ReserveOracle, ReserveOracleFeed } from '@aave/graphql';
import { Plural, Trans } from '@lingui/macro';
import { Box, keyframes, Typography } from '@mui/material';
import { ReactNode, useEffect, useState } from 'react';
import { ContentWithTooltip } from 'src/components/ContentWithTooltip';
import { ArrowUpRightIcon } from 'src/components/icons/ArrowUpRightIcon';
import { flushPercentSx, FormattedNumber } from 'src/components/primitives/FormattedNumber';
import { Link } from 'src/components/primitives/Link';
import { TextWithTooltip } from 'src/components/TextWithTooltip';
import { ReserveWithId } from 'src/hooks/app-data-provider/useAppDataProvider';
import { useRootStore } from 'src/store/root';
import { GENERAL } from 'src/utils/events';
import { FigmaColorName, figVars } from 'src/utils/figmaColors';
import { motion } from 'src/utils/motion';

import {
formatHeartbeat,
getOracleAge,
getOracleFreshness,
OracleAge,
OracleFreshness,
} from './oracleUtils';

const MINUTE_MS = 60_000;

const PROVIDER_ICONS: Record<string, string> = {
Chainlink: '/icons/other/chainlink.svg',
};

const FRESHNESS_COLORS: Record<OracleFreshness, FigmaColorName> = {
fresh: 'data-green',
stale: 'yellow-1',
outdated: 'red-1',
};

const pulseRing = keyframes`
0% { transform: scale(1); opacity: 0.45; }
70%, 100% { transform: scale(3.2); opacity: 0; }
`;

const useNow = (intervalMs: number) => {
const [now, setNow] = useState(() => Date.now());
useEffect(() => {
const id = setInterval(() => setNow(Date.now()), intervalMs);
return () => clearInterval(id);
}, [intervalMs]);
return now;
};

const dottedUnderline = {
backgroundImage: `radial-gradient(circle, ${figVars['fg-4']} 0.6px, transparent 0.75px)`,
backgroundSize: '3px 1.5px',
backgroundRepeat: 'space no-repeat',
backgroundPosition: 'left bottom',
};

export const InfoLabel = ({ label, children }: { label: ReactNode; children: ReactNode }) => (
<TextWithTooltip iconSize={16} iconMargin={1} variant="base" textColor="fg-3" text={label}>
<>{children}</>
</TextWithTooltip>
);

export const OracleLink = ({
href,
linkName,
reserve,
children,
}: {
href: string;
linkName: string;
reserve: ReserveWithId;
children: ReactNode;
}) => {
const trackEvent = useRootStore((store) => store.trackEvent);
const { address, name } = reserve.underlyingToken;

return (
<Link
href={href}
variant="h5"
onClick={() =>
trackEvent(GENERAL.EXTERNAL_LINK, {
asset: address,
Link: linkName,
assetName: name,
oracle: reserve.usdOracleAddress,
})
}
sx={{
display: 'inline-flex',
alignItems: 'center',
gap: '0.25rem',
verticalAlign: 'top',
color: 'fg-1',
}}
>
<Box component="span" sx={dottedUnderline}>
{children}
</Box>
<ArrowUpRightIcon sx={{ fontSize: '1rem', color: 'fg-4' }} />
</Link>
);
};

export const LogoValue = ({ icon, children }: { icon?: string; children: ReactNode }) => (
// The 20px icon overflows the 18px text line instead of growing the row.
<Box
sx={{
display: 'inline-flex',
alignItems: 'center',
gap: '0.375rem',
height: '1.125rem',
verticalAlign: 'top',
}}
>
{icon && <img src={icon} alt="" width={20} height={20} />}
{children}
</Box>
);

export const ProviderValue = ({
provider,
reserve,
}: {
provider: NonNullable<ReserveOracle['provider']>;
reserve: ReserveWithId;
}) => (
<LogoValue icon={PROVIDER_ICONS[provider.name]}>
{provider.url ? (
<OracleLink href={provider.url} linkName="Oracle Provider" reserve={reserve}>
{provider.name}
</OracleLink>
) : (
provider.name
)}
</LogoValue>
);

const Age = ({ age }: { age: OracleAge }) => {
if (age.unit === 'minute' && age.count === 0) return <Trans>under a min</Trans>;
if (age.unit === 'minute') return <Plural value={age.count} one="# min" other="# mins" />;
if (age.unit === 'hour') return <Plural value={age.count} one="# hour" other="# hours" />;
return <Plural value={age.count} one="# day" other="# days" />;
};

// The pulse marks a live price; the global reduced-motion rule ends it after one beat.
const StatusDot = ({ color, pulse }: { color: FigmaColorName; pulse?: boolean }) => (
<Box
component="span"
sx={{
position: 'relative',
width: 8,
height: 8,
m: '4px',
borderRadius: '50%',
bgcolor: color,
boxShadow: `0 0 0 4px color-mix(in srgb, ${figVars[color]} 18%, transparent)`,
flexShrink: 0,
...(pulse && {
'&::after': {
content: '""',
position: 'absolute',
inset: 0,
borderRadius: 'inherit',
bgcolor: 'inherit',
opacity: 0,
pointerEvents: 'none',
animation: `${pulseRing} 2s ${motion.easing.standard} infinite`,
},
}),
}}
/>
);

export const FeedStatus = ({
feeds,
lastUpdatedAt,
}: {
feeds: ReserveOracleFeed[];
lastUpdatedAt: string;
}) => {
const now = useNow(MINUTE_MS);
const freshness = getOracleFreshness(feeds, now);
const age = <Age age={getOracleAge(lastUpdatedAt, now)} />;
const color = FRESHNESS_COLORS[freshness];

if (freshness === 'fresh') {
return (
<Box sx={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem' }}>
<StatusDot color={color} pulse />
<Typography variant="base" color="fg-3">
<Trans>Updated {age} ago</Trans>
</Typography>
</Box>
);
}

return (
<Box sx={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem' }}>
<StatusDot color={color} />
<ContentWithTooltip
withoutHover
placement="top"
tooltipContent={
freshness === 'stale' ? (
<Trans>
The oracle price hasn&apos;t been updated within its expected interval. The displayed
price may not reflect current market conditions.
</Trans>
) : (
<Trans>
The oracle price hasn&apos;t been updated for an extended period. The displayed price
may be outdated and should not be relied on as a representation of the current market
price.
</Trans>
)
}
>
<Typography variant="base" color={color} sx={dottedUnderline}>
<Trans>Last price {age} ago</Trans>
</Typography>
</ContentWithTooltip>
</Box>
);
};

export const FeedSettings = ({ feed }: { feed: ReserveOracleFeed }) => {
if (!feed.heartbeatSeconds && !feed.deviationThreshold) return <>-</>;
return (
<>
{feed.heartbeatSeconds ? formatHeartbeat(feed.heartbeatSeconds) : '-'}
{' / '}
{feed.deviationThreshold ? (
<FormattedNumber
value={feed.deviationThreshold.value}
percent
variant="h5"
visibleDecimals={2}
sx={flushPercentSx}
/>
) : (
'-'
)}
</>
);
};
Loading
Loading