Skip to content

Commit

Permalink
fix(app): changed passportHasCacaoError from func to boolean value, f…
Browse files Browse the repository at this point in the history
…ixed error message setState loop (passportxyz#1144)

changed passportHasCacaoError from func to boolean value
fixed warning message render loop
  • Loading branch information
lucianHymer authored Apr 20, 2023
1 parent 33209e0 commit 1fff094
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/__test-fixtures__/contextTestHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const makeTestCeramicContext = (initialState?: Partial<CeramicContextStat
handleDeleteStamps: jest.fn(),
handleCheckRefreshPassport: () => Promise.resolve(true),
expiredProviders: [],
passportHasCacaoError: () => false,
passportHasCacaoError: false,
cancelCeramicConnection: jest.fn(),
...initialState,
};
Expand Down
6 changes: 3 additions & 3 deletions app/__tests__/components/RefreshModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("RefreshStampModal", () => {
mockUserContext,
{
...mockCeramicContext,
passportHasCacaoError: () => true,
passportHasCacaoError: true,
},
<RefreshStampModal isOpen={true} onClose={jest.fn()} />
);
Expand All @@ -50,7 +50,7 @@ describe("RefreshStampModal", () => {
mockUserContext,
{
...mockCeramicContext,
passportHasCacaoError: () => true,
passportHasCacaoError: true,
},
<RefreshStampModal isOpen={true} onClose={jest.fn()} />
);
Expand All @@ -64,7 +64,7 @@ describe("RefreshStampModal", () => {
mockUserContext,
{
...mockCeramicContext,
passportHasCacaoError: () => true,
passportHasCacaoError: true,
},
<RefreshStampModal isOpen={true} onClose={jest.fn()} />
);
Expand Down
4 changes: 2 additions & 2 deletions app/__tests__/pages/Dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ describe("when a user clicks on the Passport logo", () => {
mockUserContext,
{
...mockCeramicContext,
passportHasCacaoError: () => true,
passportHasCacaoError: true,
},
<Router>
<Dashboard />
Expand All @@ -293,7 +293,7 @@ describe("when a user clicks on the Passport logo", () => {
mockUserContext,
{
...mockCeramicContext,
passportHasCacaoError: () => true,
passportHasCacaoError: true,
},
<Router>
<Dashboard />
Expand Down
2 changes: 1 addition & 1 deletion app/components/PlatformCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const PlatformCard = ({
onClose: onCloseRemoveStampModal,
} = useDisclosure();

const disabled = passportHasCacaoError();
const disabled = passportHasCacaoError;

// hide platforms based on filter
const stampFilters = filter?.length && typeof filter === "string" ? getStampProviderFilters(filter) : false;
Expand Down
14 changes: 6 additions & 8 deletions app/context/ceramicContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { PlatformProps } from "../components/GenericPlatform";

// -- Trusted IAM servers DID
const IAM_ISSUER_DID = process.env.NEXT_PUBLIC_PASSPORT_IAM_ISSUER_DID || "";
const CACAO_ERROR_STATUSES: PassportLoadStatus[] = ["PassportCacaoError", "StampCacaoError"];

export interface CeramicContextState {
passport: Passport | undefined | false;
Expand All @@ -53,7 +54,7 @@ export interface CeramicContextState {
cancelCeramicConnection: () => void;
userDid: string | undefined;
expiredProviders: PROVIDER_ID[];
passportHasCacaoError: () => boolean;
passportHasCacaoError: boolean;
passportLoadResponse?: PassportLoadResponse;
}

Expand Down Expand Up @@ -460,7 +461,7 @@ const startingState: CeramicContextState = {
handleAddStamps: async () => {},
handleDeleteStamps: async () => {},
handleCheckRefreshPassport: async () => false,
passportHasCacaoError: () => false,
passportHasCacaoError: false,
cancelCeramicConnection: () => {},
userDid: undefined,
expiredProviders: [],
Expand All @@ -480,6 +481,7 @@ export const CeramicContextProvider = ({ children }: { children: any }) => {
const [userDid, setUserDid] = useState<string | undefined>();
const [expiredProviders, setExpiredProviders] = useState<PROVIDER_ID[]>([]);
const [passportLoadResponse, setPassportLoadResponse] = useState<PassportLoadResponse | undefined>();
const [passportHasCacaoError, setPassportHasCacaoError] = useState<boolean>(false);
const [viewerConnection] = useViewerConnection();
const [database, setDatabase] = useState<PassportDatabase | undefined>(undefined);

Expand Down Expand Up @@ -611,6 +613,8 @@ export const CeramicContextProvider = ({ children }: { children: any }) => {
}

setPassportLoadResponse({ passport, status, errorDetails });
setPassportHasCacaoError(CACAO_ERROR_STATUSES.includes(status));

return passportToReturn;
};

Expand Down Expand Up @@ -802,12 +806,6 @@ export const CeramicContextProvider = ({ children }: { children: any }) => {
setAllProviderState(startingAllProvidersState);
};

const passportHasCacaoError = (): boolean => {
const errorStatuses: PassportLoadStatus[] = ["PassportCacaoError", "StampCacaoError"];
if (passportLoadResponse) return errorStatuses.includes(passportLoadResponse.status);
else return false;
};

const stateMemo = useMemo(
() => ({
passport,
Expand Down
6 changes: 3 additions & 3 deletions app/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function Dashboard() {
}, [isLoadingPassport]);

useEffect(() => {
if (passportHasCacaoError()) {
if (passportHasCacaoError) {
setUserWarning({
name: "cacaoError",
content: (
Expand All @@ -102,7 +102,7 @@ export default function Dashboard() {
} else if (userWarning?.name === "cacaoError") {
setUserWarning();
}
});
}, [passportHasCacaoError]);

useEffect(() => {
if (expiredProviders.length > 0) {
Expand All @@ -123,7 +123,7 @@ export default function Dashboard() {
} else if (userWarning?.name === "expiredStamp") {
setUserWarning();
}
});
}, [expiredProviders]);

const retryModal = (
<Modal isOpen={retryModalIsOpen} onClose={onRetryModalClose}>
Expand Down

0 comments on commit 1fff094

Please sign in to comment.