Skip to content

Commit 716bd99

Browse files
authored
Merge pull request #55 from lidofinance/feat/unsupport-banner
feat: add ChainBanner component to display error messages in layout
2 parents 2002e8f + dc3947b commit 716bd99

File tree

8 files changed

+71
-13
lines changed

8 files changed

+71
-13
lines changed

features/overview/components/capacity/capacity.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const Capacity = () => {
2626
{renderData.map((item) => {
2727
const isUtilizationRatio = item.key === 'utilizationRatio';
2828
const color = isUtilizationRatio
29-
? getUtilizationRatioColor(item.payload)
29+
? getUtilizationRatioColor(String(item.payload))
3030
: undefined;
3131

3232
return (

features/overview/components/health/heath.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { OverviewItem, OverviewSection } from 'features/overview/shared';
22
import { SectionPayload, useVaultOverview } from 'features/overview/contexts';
3-
import { getHealthFactorColor } from 'utils';
3+
import { formatPercent, getHealthFactorColor } from 'utils';
44

55
const sectionPayloadList: SectionPayload[] = [
66
{
7-
title: 'Health factor',
8-
key: 'healthFactor',
7+
title: 'Health factor number',
8+
key: 'healthFactorNumber',
99
},
1010
{
1111
title: 'Total value',
@@ -28,16 +28,19 @@ export const Health = () => {
2828
return (
2929
<OverviewSection title="Vault health" titleTooltip="Lorem Ipsum">
3030
{renderData.map((item) => {
31-
const isHealthy = item.key === 'healthFactor';
31+
const isHealthy = item.key === 'healthFactorNumber';
3232
const color = isHealthy
3333
? getHealthFactorColor(item.payload)
3434
: undefined;
35+
const value = isHealthy
36+
? formatPercent.format(Number(item.payload) / 100)
37+
: item.payload;
3538

3639
return (
3740
<OverviewItem
3841
key={item.title}
3942
title={item.title}
40-
content={item.payload}
43+
content={value}
4144
isLoading={item.isLoading}
4245
color={color}
4346
/>

features/overview/contexts/vault-overview.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface VaultOverviewContextType {
2424
utilizationRatio: string;
2525
rebalanceThreshold: string;
2626
healthFactor: string;
27+
healthFactorNumber: number;
2728
totalLocked: string;
2829
liabilityStETH: string;
2930
totalMintingCapacity: string;
@@ -37,7 +38,7 @@ export interface VaultOverviewContextType {
3738
isLoadingVault?: boolean;
3839
getVaultDataToRender: (
3940
payload: SectionPayload[],
40-
) => (SectionPayload & { payload: string | Address })[];
41+
) => (SectionPayload & { payload: string | Address | number })[];
4142
}
4243

4344
export type VaultOverviewContextKeys = keyof VaultOverviewContextType['values'];
@@ -98,6 +99,7 @@ export const VaultOverviewProvider: FC<PropsWithChildren> = ({ children }) => {
9899
forcedRebalanceThresholdBP / VAULT_TOTAL_BASIS_POINTS,
99100
);
100101
const healthFactor = formatPercent.format(healthScore / 100);
102+
const healthFactorNumber = healthScore;
101103
const utilizationRatio = formatPercent.format(
102104
overview.utilizationRatio / 100,
103105
);
@@ -120,6 +122,7 @@ export const VaultOverviewProvider: FC<PropsWithChildren> = ({ children }) => {
120122
utilizationRatio,
121123
rebalanceThreshold,
122124
healthFactor,
125+
healthFactorNumber,
123126
totalLocked,
124127
liabilityStETH,
125128
totalMintingCapacity,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useErrorMessage } from 'shared/wallet/fallback/useErrorMessage';
2+
3+
import { ErrorMessageWrapper, WarningIcon } from './styles';
4+
5+
export const ChainBanner = () => {
6+
const errorMessage = useErrorMessage();
7+
8+
if (!errorMessage) return null;
9+
10+
return (
11+
<ErrorMessageWrapper>
12+
<WarningIcon />
13+
{errorMessage}
14+
</ErrorMessageWrapper>
15+
);
16+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './chain-banner';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styled from 'styled-components';
2+
import WarningIconSrc from 'assets/icons/attention-triangle-ipfs.svg';
3+
4+
export const ErrorMessageWrapper = styled.div`
5+
display: flex;
6+
background-color: #fffae0;
7+
grid-area: error;
8+
padding: ${({ theme }) => theme.spaceMap.lg}px;
9+
border-radius: ${({ theme }) => theme.borderRadiusesMap.lg}px;
10+
color: #ec8600;
11+
`;
12+
13+
export const WarningIcon = styled.img.attrs({
14+
src: WarningIconSrc,
15+
alt: 'warning',
16+
})`
17+
display: block;
18+
width: 20px;
19+
height: 20px;
20+
margin-right: ${({ theme }) => theme.spaceMap.sm}px;
21+
`;

shared/components/layout/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { ReactNode, FC, PropsWithChildren } from 'react';
22
import { ContainerProps } from '@lidofinance/lido-ui';
33

44
import { config } from 'config';
5+
import { useErrorMessage } from 'shared/wallet/fallback/useErrorMessage';
56

67
import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box';
78
import { Header } from './header';
89
import { Main } from './main';
910
import { Navigation } from './navigation';
1011
import { Footer } from './footer';
12+
import { ChainBanner } from './chain-banner';
1113
import {
1214
LayoutTitleStyle,
1315
LayoutSubTitleStyle,
@@ -23,10 +25,12 @@ type LayoutProps = {
2325

2426
export const Layout: FC<PropsWithChildren<LayoutProps>> = (props) => {
2527
const { title, subtitle, containerSize, children } = props;
28+
const errorMessage = useErrorMessage();
2629

2730
return (
28-
<LayoutStyles>
31+
<LayoutStyles isError={!!errorMessage}>
2932
<Header />
33+
<ChainBanner />
3034
<Navigation />
3135
<Main size={containerSize}>
3236
{config.ipfsMode && (

shared/components/layout/styles.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ import { H1, Container } from '@lidofinance/lido-ui';
22
import styled from 'styled-components';
33
import { devicesHeaderMedia } from 'styles/global';
44

5-
export const LayoutStyles = styled(Container)`
5+
const templateAreas = {
6+
withError: `
7+
'header header header'
8+
'error error error'
9+
'nav content empty'
10+
'footer footer footer';`,
11+
default: `
12+
'header header header'
13+
'nav content empty'
14+
'footer footer footer';`,
15+
};
16+
17+
export const LayoutStyles = styled(Container)<{ isError: boolean }>`
618
position: relative;
719
display: grid;
820
grid-template-rows: min-content 1fr;
921
grid-template-columns: 166px 1fr 166px;
10-
grid-template-areas:
11-
'header header header'
12-
'nav content empty'
13-
'footer footer footer';
22+
grid-template-areas: ${({ isError }) =>
23+
templateAreas[isError ? 'withError' : 'default']};
1424
grid-column-gap: 0;
1525
grid-row-gap: 16px;
1626
min-height: 100vh;

0 commit comments

Comments
 (0)