Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MBD errors #4428

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
78 changes: 48 additions & 30 deletions src/components/modals/PassportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ const PassportModal: FC<PassportModalProps> = props => {
const { locale, formatMessage } = useIntl();
const { isAnimating, closeModal } = useModalAnimation(setShowModal);

const MBDEligibile =
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED &&
passportState !== EPassportState.LOADING_SCORE;

const QFEligibilityCurrentState =
qfEligibilityState === EQFElegibilityState.ELIGIBLE
? EQFElegibilityTagState.ELIGIBLE
Expand All @@ -93,16 +98,20 @@ const PassportModal: FC<PassportModalProps> = props => {
passportState !== EPassportState.CONNECTING &&
passportState !== EPassportState.NOT_CONNECTED &&
passportState !== EPassportState.INVALID &&
passportState !== EPassportState.ERROR &&
![
EQFElegibilityState.CHECK_ELIGIBILITY,
EQFElegibilityState.PROCESSING,
EQFElegibilityState.ERROR,
EQFElegibilityState.LOADING,
].includes(qfEligibilityState) &&
!(
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED
);
!MBDEligibile;

const gitcoinNotConnected =
passportState === EPassportState.NOT_CONNECTED ||
passportState === EPassportState.NOT_SIGNED ||
passportState === EPassportState.NOT_CREATED ||
passportState === EPassportState.CONNECTING;

const qfRoundEndDate = currentRound?.endDate
? new Date(currentRound.endDate)
Expand Down Expand Up @@ -136,7 +145,7 @@ const PassportModal: FC<PassportModalProps> = props => {

useEffect(() => {
if (
passportState === EPassportState.ERROR ||
qfEligibilityState === EQFElegibilityState.ERROR ||
qfEligibilityState === EQFElegibilityState.ELIGIBLE
) {
setTimeout(() => {
Expand Down Expand Up @@ -228,6 +237,14 @@ const PassportModal: FC<PassportModalProps> = props => {
/>
)}
<Hr />
{passportState === EPassportState.ERROR && (
<InlineToast
type={EToastType.Error}
message={formatMessage({
id: 'label.passport.error',
})}
/>
)}
<EligibilityCardBottom>
{passportState === EPassportState.INVALID ? (
<Button
Expand All @@ -240,31 +257,32 @@ const PassportModal: FC<PassportModalProps> = props => {
window.open(links.PASSPORT, '_blank')
}
/>
) : passportState === EPassportState.NOT_SIGNED ||
passportState === EPassportState.CONNECTING ? (
<Button
label={formatMessage({
id: 'profile.qf_donor_eligibility.label.connect_gitcoin_passport',
})}
size='small'
buttonType='primary'
onClick={handleSign}
loading={
passportState === EPassportState.CONNECTING
}
/>
) : (
<RefreshButton onClick={refreshScore}>
<FlexCenter gap='8px'>
<IconPassport16 />
<ButtonText color={brandColors.pinky[500]}>
{formatMessage({
id: 'label.refresh_score',
})}
</ButtonText>
</FlexCenter>
</RefreshButton>
)}
) : passportState !== EPassportState.ERROR ? (
gitcoinNotConnected ? (
<Button
label={formatMessage({
id: 'profile.qf_donor_eligibility.label.connect_gitcoin_passport',
})}
size='small'
buttonType='primary'
onClick={handleSign}
loading={
passportState === EPassportState.CONNECTING
}
/>
) : (
<RefreshButton onClick={refreshScore}>
<FlexCenter gap='8px'>
<IconPassport16 />
<ButtonText color={brandColors.pinky[500]}>
{formatMessage({
id: 'label.refresh_score',
})}
</ButtonText>
</FlexCenter>
</RefreshButton>
)
) : null}
</EligibilityCardBottom>
</StyledWrapper>
</Modal>
Expand Down
37 changes: 20 additions & 17 deletions src/components/views/qfEligibility/QFEligibility.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,33 @@ export const QFEligibilityView = () => {
? EQFElegibilityTagState.ELIGIBLE
: EQFElegibilityTagState.NOT_ELIGIBLE;

const MBDEligibile =
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED &&
passportState !== EPassportState.LOADING_SCORE;

const showPassportScoreSection =
passportState !== EPassportState.NOT_SIGNED &&
passportState !== EPassportState.NOT_CREATED &&
passportState !== EPassportState.CONNECTING &&
passportState !== EPassportState.NOT_CONNECTED &&
passportState !== EPassportState.INVALID &&
passportState !== EPassportState.ERROR &&
![
EQFElegibilityState.CHECK_ELIGIBILITY,
EQFElegibilityState.PROCESSING,
EQFElegibilityState.ERROR,
EQFElegibilityState.LOADING,
].includes(qfEligibilityState) &&
!(
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED
);
!MBDEligibile;

const showQFStateSection =
passportState === EPassportState.NOT_SIGNED ||
[
EQFElegibilityState.CHECK_ELIGIBILITY,
EQFElegibilityState.PROCESSING,
].includes(qfEligibilityState) ||
(qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED);
MBDEligibile;

const checkEligibilityDisabled = [
EQFElegibilityState.LOADING,
Expand All @@ -88,6 +90,12 @@ export const QFEligibilityView = () => {
EQFElegibilityState.MORE_INFO_NEEDED,
].includes(qfEligibilityState);

const gitcoinNotConnected =
passportState === EPassportState.NOT_CONNECTED ||
passportState === EPassportState.NOT_SIGNED ||
passportState === EPassportState.NOT_CREATED ||
passportState === EPassportState.CONNECTING;

const qfRoundEndDate = currentRound?.endDate
? new Date(currentRound.endDate)
.toLocaleString(locale || 'en-US', {
Expand Down Expand Up @@ -130,8 +138,7 @@ export const QFEligibilityView = () => {
</>
);
case EQFElegibilityState.ELIGIBLE:
return passportState !== EPassportState.SIGNED &&
passportState !== EPassportState.LOADING_SCORE ? (
return MBDEligibile ? (
<>
{formatMessage({ id: 'label.you_are_all_set' })}
<IconVerifiedBadge size={24} />
Expand All @@ -140,7 +147,7 @@ export const QFEligibilityView = () => {
formatMessage({ id: 'label.passport_connected' })
);
case EQFElegibilityState.MORE_INFO_NEEDED:
return passportState === EPassportState.NOT_SIGNED
return gitcoinNotConnected
? formatMessage({
id: 'label.we_need_a_bit_more_info',
})
Expand All @@ -158,8 +165,7 @@ export const QFEligibilityView = () => {
EQFElegibilityState.LOADING,
EQFElegibilityState.NOT_CONNECTED,
].includes(qfEligibilityState) ||
(qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED)
MBDEligibile
) {
return (
<EligibilityCardBottom $justify='center'>
Expand All @@ -180,9 +186,7 @@ export const QFEligibilityView = () => {
);
} else if (
qfEligibilityState === EQFElegibilityState.MORE_INFO_NEEDED &&
(passportState === EPassportState.NOT_SIGNED ||
passportState === EPassportState.NOT_CREATED ||
passportState === EPassportState.CONNECTING)
gitcoinNotConnected
) {
return (
<EligibilityCardBottom $justify='center'>
Expand Down Expand Up @@ -241,8 +245,7 @@ export const QFEligibilityView = () => {
{QFEligibilityData[QFEligibilityCurrentState].icon}
</QFEligibilityStatus>
</EligibilityTop>
{(qfEligibilityState !== EQFElegibilityState.ELIGIBLE ||
passportState === EPassportState.SIGNED) && (
{!MBDEligibile && (
<EligibilityCardDesc>
{eligibilityDesc()}
</EligibilityCardDesc>
Expand Down Expand Up @@ -279,7 +282,7 @@ export const QFEligibilityView = () => {
</ScoreCard>
</PassportSection>
)}
{qfEligibilityState === EQFElegibilityState.ERROR && (
{passportState === EPassportState.ERROR && (
<InlineToast
type={EToastType.Error}
message={formatMessage({
Expand Down
33 changes: 21 additions & 12 deletions src/components/views/userProfile/QFDonorEligibilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const QFDonorEligibilityCard = () => {
const { passportState, passportScore, qfEligibilityState, currentRound } =
info;

const MBDEligibile =
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED &&
passportState !== EPassportState.LOADING_SCORE;

const QFEligibilityCurrentState =
qfEligibilityState === EQFElegibilityState.ELIGIBLE
? EQFElegibilityTagState.ELIGIBLE
Expand All @@ -55,16 +60,14 @@ export const QFDonorEligibilityCard = () => {
passportState !== EPassportState.CONNECTING &&
passportState !== EPassportState.NOT_CONNECTED &&
passportState !== EPassportState.INVALID &&
passportState !== EPassportState.ERROR &&
![
EQFElegibilityState.CHECK_ELIGIBILITY,
EQFElegibilityState.PROCESSING,
EQFElegibilityState.ERROR,
EQFElegibilityState.LOADING,
].includes(qfEligibilityState) &&
!(
qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED
);
!MBDEligibile;

const checkEligibilityDisabled = [
EQFElegibilityState.LOADING,
Expand All @@ -73,6 +76,12 @@ export const QFDonorEligibilityCard = () => {
EQFElegibilityState.MORE_INFO_NEEDED,
].includes(qfEligibilityState);

const gitcoinNotConnected =
passportState === EPassportState.NOT_CONNECTED ||
passportState === EPassportState.NOT_SIGNED ||
passportState === EPassportState.NOT_CREATED ||
passportState === EPassportState.CONNECTING;

const renderQFEligibilityState = () => {
switch (qfEligibilityState) {
case EQFElegibilityState.CHECK_ELIGIBILITY:
Expand All @@ -85,8 +94,7 @@ export const QFDonorEligibilityCard = () => {
</>
);
case EQFElegibilityState.ELIGIBLE:
return passportState !== EPassportState.SIGNED &&
passportState !== EPassportState.LOADING_SCORE ? (
return MBDEligibile ? (
<>
{formatMessage({ id: 'label.you_are_all_set' })}
<IconVerifiedBadge size={24} />
Expand All @@ -95,7 +103,7 @@ export const QFDonorEligibilityCard = () => {
formatMessage({ id: 'label.passport_connected' })
);
case EQFElegibilityState.MORE_INFO_NEEDED:
return passportState === EPassportState.NOT_SIGNED
return gitcoinNotConnected
? formatMessage({
id: 'label.we_need_a_bit_more_info',
})
Expand Down Expand Up @@ -192,9 +200,7 @@ export const QFDonorEligibilityCard = () => {
{[
EQFElegibilityState.CHECK_ELIGIBILITY,
EQFElegibilityState.PROCESSING,
].includes(qfEligibilityState) ||
(qfEligibilityState === EQFElegibilityState.ELIGIBLE &&
passportState !== EPassportState.SIGNED) ? (
].includes(qfEligibilityState) || MBDEligibile ? (
<Button
label={formatMessage({
id: 'profile.qf_donor_eligibility.label.check_eligibility',
Expand All @@ -210,14 +216,17 @@ export const QFDonorEligibilityCard = () => {
/>
) : qfEligibilityState ===
EQFElegibilityState.MORE_INFO_NEEDED &&
passportState === EPassportState.NOT_SIGNED ? (
gitcoinNotConnected ? (
<Button
label={formatMessage({
id: 'profile.qf_donor_eligibility.label.connect_gitcoin_passport',
})}
size='small'
buttonType='primary'
onClick={handleSign}
loading={
passportState === EPassportState.CONNECTING
}
/>
) : (
<RefreshButton onClick={refreshScore}>
Expand All @@ -233,7 +242,7 @@ export const QFDonorEligibilityCard = () => {
)}
</EligibilityCardBottom>
)}
{qfEligibilityState === EQFElegibilityState.ERROR && (
{passportState === EPassportState.ERROR && (
<InlineToast
type={EToastType.Error}
message={formatMessage({
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePassport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const usePassport = () => {
passportState: EPassportState.CONNECTING,
passportScore: null,
activeQFMBDScore: null,
currentRound: null,
currentRound: info.currentRound,
});

const passports = getPassports();
Expand All @@ -284,7 +284,7 @@ export const usePassport = () => {
passportState: EPassportState.NOT_SIGNED,
passportScore: null,
activeQFMBDScore: null,
currentRound: null,
currentRound: info.currentRound,
});
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ export const usePassport = () => {
passportState: EPassportState.NOT_SIGNED,
passportScore: null,
activeQFMBDScore: null,
currentRound: null,
currentRound: info.currentRound,
});
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/services/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const fetchPassportScore = async (account: string) => {
variables: {
address: account?.toLowerCase(),
},
fetchPolicy: 'network-only',
});
return data;
} catch (error) {
Expand Down
Loading