Skip to content

Commit

Permalink
fix(app): fetch passport after ceramic database initialized
Browse files Browse the repository at this point in the history
fixes a bug where brand new users have trouble creating a passport for the first time due to React
state not updating as expected. the app is often unable to actually create the passport unless React
timing works out just right...

[passportxyz#216]
  • Loading branch information
shavinac committed Jun 14, 2022
1 parent 0964cb5 commit 75c8ec6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface UserContextState {
walletLabel: string | undefined;
userDid: string | undefined;
}

const startingState: UserContextState = {
loggedIn: false,
passport: {
Expand Down Expand Up @@ -187,7 +188,6 @@ export const UserContextProvider = ({ children }: { children: any }) => {
);
setCeramicDatabase(ceramicDatabaseInstance);
setUserDid(ceramicDatabaseInstance.did);
fetchPassport(ceramicDatabaseInstance);
break;
}
case "failed": {
Expand All @@ -204,6 +204,12 @@ export const UserContextProvider = ({ children }: { children: any }) => {
}
}, [viewerConnection.status]);

useEffect(() => {
if (ceramicDatabase) {
fetchPassport(ceramicDatabase);
}
}, [ceramicDatabase]);

// Toggle connect/disconnect
// clear context passport on disconnect
const handleConnection = (): void => {
Expand Down

0 comments on commit 75c8ec6

Please sign in to comment.