Skip to content

Commit

Permalink
OCT-1762: UI does not show delegated state properly (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek authored Jul 15, 2024
2 parents ca0de93 + 7ad1de7 commit f09b7cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { useTranslation } from 'react-i18next';
import { useAccount } from 'wagmi';

import Identicon from 'components/ui/Identicon';
import Svg from 'components/ui/Svg';
import useSettingsStore from 'store/settings/store';
import { octant } from 'svg/logo';
import truncateEthAddress from 'utils/truncateEthAddress';

import styles from './SettingsUniquenessScoreAddresses.module.scss';
Expand Down Expand Up @@ -34,7 +36,8 @@ const SettingsUniquenessScoreAddresses: FC<SettingsUniquenessScoreAddressesProps
}));

const addresses =
isDelegationCompleted && delegationPrimaryAddress && delegationSecondaryAddress
(isDelegationCompleted && delegationPrimaryAddress && delegationSecondaryAddress) ||
(delegationPrimaryAddress && delegationSecondaryAddress === '0x???')
? [delegationPrimaryAddress, delegationSecondaryAddress]
: [accountAddress];

Expand Down Expand Up @@ -66,7 +69,11 @@ const SettingsUniquenessScoreAddresses: FC<SettingsUniquenessScoreAddressesProps
<div className={styles.avatarsGroup}>
{addresses.map(address => (
<div key={address} className={styles.addressAvatar}>
<Identicon className={styles.avatar} username={address} />
{address === '0x???' ? (
<Svg img={octant} size={1.4} />
) : (
<Identicon className={styles.avatar} username={address} />
)}
</div>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ const SettingsUniquenessScoreBox = (): ReactNode => {
} = useRefreshAntisybilStatus();

const { data: antisybilStatusScore, isSuccess: isSuccessAntisybilStatusScore } =
useAntisybilStatusScore(isDelegationCompleted ? delegationSecondaryAddress! : address!, {
enabled:
isSuccessRefreshAntisybilStatus ||
(refreshAntisybilStatusError as null | { message: string })?.message ===
'Address is already used for delegation',
});
useAntisybilStatusScore(
isDelegationCompleted && delegationSecondaryAddress !== '0x???'
? delegationSecondaryAddress!
: address!,
{
enabled:
isSuccessRefreshAntisybilStatus ||
(refreshAntisybilStatusError as null | { message: string })?.message ===
'Address is already used for delegation',
},
);

const checkDelegation = async () => {
if (!isUserTOSAccepted) {
Expand Down Expand Up @@ -139,6 +144,10 @@ const SettingsUniquenessScoreBox = (): ReactNode => {
if (isDelegationCompleted) {
setSecondaryAddressScore(antisybilStatusScore);
} else {
if (refreshAntisybilStatusError) {
setDelegationPrimaryAddress(address);
setDelegationSecondaryAddress('0x???');
}
setPrimaryAddressScore(
antisybilStatusScore < DELEGATION_MIN_SCORE && uqScore === 100n
? DELEGATION_MIN_SCORE
Expand All @@ -147,7 +156,7 @@ const SettingsUniquenessScoreBox = (): ReactNode => {
}
setIsFetchingScore(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSuccessAntisybilStatusScore, isFetchingUqScore]);
}, [isSuccessAntisybilStatusScore, isFetchingUqScore, refreshAntisybilStatusError]);

useEffect(() => {
if (
Expand Down Expand Up @@ -208,7 +217,12 @@ const SettingsUniquenessScoreBox = (): ReactNode => {
<div className={styles.buttonsWrapper}>
<Button
className={styles.button}
isDisabled={isDelegationCompleted || isFetchingScore || isFetchingUqScore}
isDisabled={
isDelegationCompleted ||
isFetchingScore ||
isFetchingUqScore ||
delegationSecondaryAddress === '0x???'
}
isHigh
onClick={() => setIisRecalculatingScoreModalOpen(true)}
variant="cta"
Expand All @@ -224,7 +238,8 @@ const SettingsUniquenessScoreBox = (): ReactNode => {
primaryAddressScore === undefined ||
primaryAddressScore >= 20 ||
isFetchingUqScore ||
uqScore === 100n
uqScore === 100n ||
delegationSecondaryAddress === '0x???'
}
isHigh
onClick={() => {
Expand Down

0 comments on commit f09b7cc

Please sign in to comment.