Skip to content

Commit 68dba90

Browse files
authored
Merge pull request #120 from lidofinance/develop
Merge into main from develop
2 parents 2e7a51e + 351a033 commit 68dba90

File tree

3 files changed

+49
-36
lines changed

3 files changed

+49
-36
lines changed

features/vesting/hooks.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,12 @@ export const useSnapshotDelegate = (escrow: string | undefined) => {
289289

290290
export const useSnapshotDelegateAddress = (escrow = AddressZero) => {
291291
const { contractRpc } = useSnapshotDelegationContract();
292-
const { chainId } = useWeb3();
293292

294293
return useSWR(`snapshot-delegate-${escrow}`, () =>
295-
chainId === CHAINS.Holesky
296-
? AddressZero
297-
: contractRpc.delegation(
298-
escrow,
299-
'0x0000000000000000000000000000000000000000000000000000000000000000',
300-
),
294+
contractRpc.delegation(
295+
escrow,
296+
'0x0000000000000000000000000000000000000000000000000000000000000000',
297+
),
301298
);
302299
};
303300

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { FC, memo } from 'react';
2+
import { AddressZero } from '@ethersproject/constants';
3+
4+
import { encodeAddress, useENS } from '../addressModal';
5+
import { useModal } from '../walletModal';
6+
import { InlineLoader } from '@lidofinance/lido-ui';
7+
import { Badge, BadgeContainer } from './vestingSlideStyles';
8+
9+
type Props = {
10+
delegateAddress: string | undefined;
11+
};
12+
13+
export const VestingDelegateBadge: FC<Props> = memo(({ delegateAddress }) => {
14+
const { data: ensName, isLoading } = useENS(delegateAddress);
15+
16+
const delegateNameToShow = ensName ?? delegateAddress;
17+
18+
const { openModal } = useModal(encodeAddress(delegateAddress, 'delegate'));
19+
20+
if (isLoading) {
21+
return <InlineLoader />;
22+
}
23+
24+
if (!delegateAddress || delegateAddress === AddressZero) {
25+
return <>Not delegated</>;
26+
}
27+
28+
return (
29+
<BadgeContainer>
30+
<Badge
31+
address={delegateNameToShow}
32+
title={delegateNameToShow}
33+
onClick={openModal}
34+
/>
35+
</BadgeContainer>
36+
);
37+
});
38+
39+
VestingDelegateBadge.displayName = 'VestingDelegateBadge';

features/vesting/vestingSummarySlide.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ import {
1919
BadgeContainer,
2020
Row,
2121
VestingSlide,
22-
EnsName,
2322
} from './vestingSlideStyles';
2423
import { BigNumber } from 'ethers';
25-
import { AddressZero } from '@ethersproject/constants';
2624
import { useModal } from '../walletModal';
2725
import { encodeAddress } from '../addressModal';
28-
import { useENS } from '../addressModal';
29-
import { InlineLoader } from '@lidofinance/lido-ui';
26+
import { VestingDelegateBadge } from './vestingDelegateBadge';
3027

3128
export type VestingSummarySlideProps = {
3229
title?: string;
@@ -47,12 +44,11 @@ export const VestingSummarySlide: FC<VestingSummarySlideProps> = memo(
4744
useAragonDelegateAddress(vesting?.escrow);
4845
const { data: snapshotDelegate, isLoading: snapshotDelegateIsLoading } =
4946
useSnapshotDelegateAddress(vesting?.escrow);
50-
const { data: ensName, isLoading: ensNameIsLoading } =
51-
useENS(aragonDelegate);
47+
48+
const delegateAddress =
49+
showDelegation === 'snapshot' ? snapshotDelegate : aragonDelegate;
50+
5251
const { data: token, isLoading: tokenIsLoading } = useVestingToken();
53-
const { openModal: openDelegateModal } = useModal(
54-
encodeAddress(aragonDelegate, 'delegate'),
55-
);
5652
const { openModal: openEscrowModal } = useModal(
5753
encodeAddress(vesting?.escrow, 'trp'),
5854
);
@@ -66,9 +62,6 @@ export const VestingSummarySlide: FC<VestingSummarySlideProps> = memo(
6662
return null;
6763
}
6864

69-
const delegate =
70-
showDelegation === 'snapshot' ? snapshotDelegate : aragonDelegate;
71-
7265
if (
7366
unclaimedIsLoading ||
7467
lockedIsLoading ||
@@ -128,23 +121,7 @@ export const VestingSummarySlide: FC<VestingSummarySlideProps> = memo(
128121
<DetailsHeader>Delegated to</DetailsHeader>
129122
</Column>
130123
<Column style={{ textAlign: 'right' }}>
131-
{delegate === AddressZero ? (
132-
'Not delegated'
133-
) : (
134-
<BadgeContainer>
135-
{ensNameIsLoading ? (
136-
<InlineLoader />
137-
) : !ensName ? (
138-
<Badge
139-
address={delegate}
140-
title={delegate}
141-
onClick={openDelegateModal}
142-
/>
143-
) : (
144-
<EnsName onClick={openDelegateModal}>{ensName}</EnsName>
145-
)}
146-
</BadgeContainer>
147-
)}
124+
<VestingDelegateBadge delegateAddress={delegateAddress} />
148125
</Column>
149126
</Row>
150127
)}

0 commit comments

Comments
 (0)