Skip to content

Commit

Permalink
fix logout and update graphql query
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Aug 30, 2024
1 parent 496ce2c commit 1d5f88d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
18 changes: 4 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@rainbow-me/rainbowkit/styles.css';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import { Route, Routes, Navigate } from 'react-router-dom';
import { Route, Routes, Navigate, useNavigate } from 'react-router-dom';
import { WagmiProvider } from 'wagmi';
import {
AuthenticationStatus,
Expand Down Expand Up @@ -50,6 +50,7 @@ const config = getDefaultConfig({
});

const App: React.FC = () => {
const navigate = useNavigate();
const [authStatus, setAuthStatus] =
useState<AuthenticationStatus>('unauthenticated');

Expand Down Expand Up @@ -91,22 +92,11 @@ const App: React.FC = () => {
},
signOut: async () => {
localStorage.removeItem('OCI_TOKEN');
navigate('/auth/login');
setAuthStatus('unauthenticated');
},
});

useEffect(() => {
const checkStoredToken = () => {
const OCI_TOKEN = localStorage.getItem('OCI_TOKEN');
if (OCI_TOKEN) {
setAuthStatus('authenticated');
} else {
setAuthStatus('unauthenticated');
}
};

checkStoredToken();
}, []);

useEffect(() => {
console.log('authStatus', authStatus);
}, [authStatus]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/layouts/AppbarApp.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppBar, Box, Toolbar } from '@mui/material';
import AccountPopover from './AccountPopover';
import { ConnectButton } from '@rainbow-me/rainbowkit';

function AppbarApp() {
return (
Expand All @@ -24,7 +24,7 @@ function AppbarApp() {
justifyContent: 'flex-end',
}}
>
<AccountPopover />
<ConnectButton />
</Box>
</Toolbar>
</AppBar>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Identifiers/Identifiers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const IdentifierItem: React.FC<IdentifierItemProps> = ({

export function Identifiers() {
const { showSnackbar } = useSnackbarStore();
const { chainId } = useAccount();
const { chainId, address } = useAccount();
const navigate = useNavigate();

const signer = useSigner();
Expand All @@ -156,7 +156,7 @@ export function Identifiers() {
data: attestationsResponse,
refetch,
isLoading,
} = useGetAttestations();
} = useGetAttestations(address as `0x${string}`);

const { mutate: mutateRevokeIdentifier, data: revokeIdentifierResponse } =
useRevokeIdentifierMutation();
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Permissions/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useReadContracts,
useWriteContract,
useWaitForTransactionReceipt,
useAccount,
} from 'wagmi';
import { Address, Abi } from 'viem';
import {
Expand All @@ -30,6 +31,7 @@ import useSnackbarStore from '../../store/useSnackbarStore';

export function Permissions() {
const { showSnackbar } = useSnackbarStore();
const { address } = useAccount();
const navigate = useNavigate();
const {
data: transactionHash,
Expand All @@ -45,7 +47,7 @@ export function Permissions() {
data: attestationsResponse,
isLoading: isLoadingAttestations,
refetch: refetchAttestations,
} = useGetAttestations();
} = useGetAttestations(address as `0x${string}`);
const [applicationsArgs] = useState<[number, number]>([0, 10]);
const [attestations, setAttestations] = useState<
(IAttestation & { provider?: string; id?: string })[]
Expand Down
8 changes: 5 additions & 3 deletions src/services/eas/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { gql } from 'graphql-request';
import { Address } from 'viem';
import { ATTESTER_ADDRESS, graphQLClient } from '.';
import { EAS_SCHEMA_ID } from '../../utils/contracts/eas/constants';
import { IAttestation } from '../../libs/oci';
Expand All @@ -8,9 +9,9 @@ interface AttestationsResponse {
attestations: IAttestation[];
}

export const useGetAttestations = () => {
export const useGetAttestations = (recipient: Address) => {
return useQuery<IAttestation[]>({
queryKey: ['getAttestations'],
queryKey: ['getAttestations', recipient],
queryFn: async () => {
const query = gql`
query Attestations(
Expand Down Expand Up @@ -40,7 +41,7 @@ export const useGetAttestations = () => {

const variables = {
attester: ATTESTER_ADDRESS,
recipient: '0x026B727b60D336806B87d60e95B6d7FAd2443dD6',
recipient,
schemaId: EAS_SCHEMA_ID,
};

Expand All @@ -51,5 +52,6 @@ export const useGetAttestations = () => {

return attestedResults.attestations;
},
enabled: !!recipient,
});
};

0 comments on commit 1d5f88d

Please sign in to comment.