Skip to content

Commit c9ef80b

Browse files
authored
Merge pull request #39 from lidofinance/fix/overview-comps
feat: add loading state to overview components and create OverviewIte…
2 parents 7e15a29 + d8d51e8 commit c9ef80b

File tree

10 files changed

+68
-11
lines changed

10 files changed

+68
-11
lines changed

features/overview/components/balance/balance.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const Balance = () => {
4545
content={item.payload}
4646
actionText={item.actionText}
4747
actionLink={item.actionLink}
48+
isLoading={item.isLoading}
4849
/>
4950
))}
5051
</OverviewSection>

features/overview/components/capacity/capacity.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const Capacity = () => {
2727
key={item.title}
2828
title={item.title}
2929
content={item.payload}
30+
isLoading={item.isLoading}
3031
/>
3132
))}
3233
</OverviewSection>

features/overview/components/general/general.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const General = () => {
2727
key={item.title}
2828
title={item.title}
2929
content={item.payload}
30+
isLoading={item.isLoading}
3031
/>
3132
))}
3233
</OverviewSection>

features/overview/components/health/heath.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const Health = () => {
3131
key={item.title}
3232
title={item.title}
3333
content={item.payload}
34+
isLoading={item.isLoading}
3435
/>
3536
))}
3637
</OverviewSection>

features/overview/components/node-operator/node-operator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const NodeOperator = () => {
2727
content={item.payload}
2828
actionLink={item.actionLink}
2929
actionText={item.actionText}
30+
isLoading={item.isLoading}
3031
/>
3132
))}
3233
</OverviewSection>

features/overview/contexts/vault-overview.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface VaultOverviewContextType {
3535
collateral: string;
3636
pendingUnlockEth: string;
3737
};
38+
isLoadingVault?: boolean;
3839
getVaultDataToRender: (
3940
payload: SectionPayload[],
4041
) => (SectionPayload & { payload: string | Address })[];
@@ -46,6 +47,7 @@ export type SectionPayload = {
4647
key: VaultOverviewContextKeys;
4748
actionText?: string;
4849
actionLink?: string;
50+
isLoading?: boolean;
4951
};
5052

5153
const VaultOverviewContext = createContext<VaultOverviewContextType | null>(
@@ -56,7 +58,7 @@ const toEthValue = (value: bigint) => `${formatBalance(value).trimmed} ETH`;
5658
const toStethValue = (value: bigint) => `${formatBalance(value).trimmed} stETH`;
5759

5860
export const VaultOverviewProvider: FC<PropsWithChildren> = ({ children }) => {
59-
const { activeVault } = useVaultInfo();
61+
const { activeVault, isLoadingVault } = useVaultInfo();
6062

6163
const values: VaultOverviewContextType['values'] = useMemo(() => {
6264
if (activeVault) {
@@ -130,19 +132,24 @@ export const VaultOverviewProvider: FC<PropsWithChildren> = ({ children }) => {
130132
nodeOperatorFee,
131133
collateral,
132134
pendingUnlockEth,
135+
isLoadingVault,
133136
};
134137
}
135138

136139
return {} as VaultOverviewContextType['values'];
137-
}, [activeVault]);
140+
}, [activeVault, isLoadingVault]);
138141

139142
const getVaultDataToRender = useCallback(
140143
(sectionPayloadList: SectionPayload[]) => {
141144
return sectionPayloadList.map((item) => {
142-
return { ...item, payload: values[item.key] };
145+
return {
146+
...item,
147+
payload: values[item.key],
148+
isLoading: isLoadingVault,
149+
};
143150
});
144151
},
145-
[values],
152+
[values, isLoadingVault],
146153
);
147154

148155
return (

features/overview/contexts/vault-provider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export const VaultProvider: FC<PropsWithChildren> = ({ children }) => {
4343
() => ({
4444
vaultAddress: sanitizedVaultAddress,
4545
activeVault: query.data,
46-
isLoadingVault: query.isLoading,
46+
isLoadingVault: query.isPending,
4747
error: query.error,
4848
refetch: query.refetch,
4949
}),
5050
[
5151
sanitizedVaultAddress,
5252
query.data,
53-
query.isLoading,
53+
query.isPending,
5454
query.error,
5555
query.refetch,
5656
],
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { FC } from 'react';
2+
import { Text, InlineLoader } from '@lidofinance/lido-ui';
3+
4+
import { LoaderWrapper, ValueWrapper } from './styles';
5+
6+
export interface ItemValueProps {
7+
content: string | number | undefined;
8+
isLoading?: boolean;
9+
isSuccess?: boolean;
10+
}
11+
12+
export const OverviewItemValue: FC<ItemValueProps> = (props) => {
13+
const { content, isSuccess, isLoading } = props;
14+
const contentColor = isSuccess ? 'success' : 'default';
15+
16+
return (
17+
<>
18+
{isLoading ? (
19+
<LoaderWrapper>
20+
<InlineLoader />
21+
</LoaderWrapper>
22+
) : (
23+
<ValueWrapper>
24+
<Text size="lg" color={contentColor} strong>
25+
{content ?? '-'}
26+
</Text>
27+
</ValueWrapper>
28+
)}
29+
</>
30+
);
31+
};

features/overview/shared/overview-item/overview-item.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@ import { ItemWrapper, Title } from './styles';
55
import { useRouter } from 'next/router';
66
import { useVaultInfo } from 'features/overview/contexts';
77

8+
import { OverviewItemValue } from './overview-item-value';
9+
810
export interface ItemProps {
911
title: string;
1012
content: string | number | undefined;
1113
actionLink?: string;
1214
actionText?: string;
1315
isSuccess?: boolean;
16+
isLoading?: boolean;
1417
}
1518

1619
export const OverviewItem: FC<ItemProps> = (props) => {
1720
const router = useRouter();
1821
const { activeVault } = useVaultInfo();
19-
const { title, content, isSuccess, actionLink, actionText } = props;
20-
const contentColor = isSuccess ? 'success' : 'default';
22+
const { title, content, isSuccess, actionLink, actionText, isLoading } =
23+
props;
2124

2225
return (
2326
<ItemWrapper>
@@ -26,9 +29,11 @@ export const OverviewItem: FC<ItemProps> = (props) => {
2629
{title}
2730
</Text>
2831
</Title>
29-
<Text size="lg" color={contentColor} strong>
30-
{content ?? '-'}
31-
</Text>
32+
<OverviewItemValue
33+
content={content}
34+
isLoading={isLoading}
35+
isSuccess={isSuccess}
36+
/>
3237
{!!actionLink && !!actionText && (
3338
<Button
3439
size="xs"

features/overview/shared/overview-item/styles.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ export const Title = styled.div`
99
display: flex;
1010
align-items: center;
1111
`;
12+
13+
export const LoaderWrapper = styled.div`
14+
padding-top: ${({ theme }) => theme.spaceMap.sm}px;
15+
padding-bottom: 10px;
16+
`;
17+
18+
export const ValueWrapper = styled.div`
19+
padding-bottom: ${({ theme }) => theme.spaceMap.sm}px;
20+
`;

0 commit comments

Comments
 (0)