Skip to content

Commit

Permalink
fix(app): only set state once for expiredstamps
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz committed Jan 26, 2023
1 parent 1c05890 commit ea157c8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/__tests__/context/ceramicContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TestingComponent = () => {
return (
<div>
{expiredProviders.map((provider) => (
<div key={provider}>{provider}</div>
<p key={provider}>{provider}</p>
))}
</div>
);
Expand All @@ -42,7 +42,7 @@ jest.mock("@gitcoin/passport-database-client", () => {
return {
getPassport: jest.fn().mockReturnValue({
passport: {
stamps: [SUCCESFUL_POAP_RESULT, SUCCESFUL_ENS_RESULT],
stamps: [SUCCESFUL_ENS_RESULT],
},
status: "Success",
}),
Expand All @@ -62,7 +62,7 @@ describe("<CeramicContextProvider>", () => {
</UserContext.Provider>
);
await waitFor(() => {
expect(screen.getByText(SUCCESFUL_POAP_RESULT?.credential?.credentialSubject.provider || "")).toBeInTheDocument();
expect(screen.getAllByText(SUCCESFUL_POAP_RESULT?.credential?.credentialSubject.provider || "")).toHaveLength(1);
});
});
});
6 changes: 4 additions & 2 deletions app/context/ceramicContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,14 @@ export const CeramicContextProvider = ({ children }: { children: any }) => {
passport: Passport | undefined | false,
database: CeramicDatabase
): Passport | undefined | false => {
const tempExpiredProviders: PROVIDER_ID[] = [];
// clean stamp content if expired or from a different issuer
if (passport) {
passport.stamps = passport.stamps.filter((stamp: Stamp, i: number) => {
passport.stamps = passport.stamps.filter((stamp: Stamp) => {
if (stamp) {
const has_expired = new Date(stamp.credential.expirationDate) < new Date();
if (has_expired) {
setExpiredProviders([...expiredProviders, stamp.credential.credentialSubject.provider as PROVIDER_ID]);
tempExpiredProviders.push(stamp.credential.credentialSubject.provider as PROVIDER_ID);
}

const has_correct_issuer = stamp.credential.issuer === IAM_ISSUER_DID;
Expand All @@ -565,6 +566,7 @@ export const CeramicContextProvider = ({ children }: { children: any }) => {
return false;
}
});
setExpiredProviders(tempExpiredProviders);
}

return passport;
Expand Down

0 comments on commit ea157c8

Please sign in to comment.