/
identity.ts
47 lines (43 loc) · 1.1 KB
/
identity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useCallback } from 'react';
import { useQuery } from 'react-query';
import { queryClient } from '../../masa-query-client';
import { Masa } from '@masa-finance/masa-sdk';
import { BigNumber } from 'ethers';
export const useIdentity = (
masa: Masa | null,
walletAddress: string | undefined
): {
identity:
| {
identityId?: BigNumber | undefined;
address?: string | undefined;
}
| undefined;
handlePurchaseIdentity: () => void;
status: string;
isLoading: boolean;
error: unknown;
} => {
const {
data: identity,
status,
isLoading,
error,
} = useQuery(
`identity-${walletAddress}`,
() => masa?.identity.load(walletAddress),
{
enabled: !!masa && !!walletAddress,
}
);
console.log('IDENTITY', {
identity,
error,
ENABLED: !!masa && !!walletAddress,
});
const handlePurchaseIdentity = useCallback(async () => {
await masa?.identity.create();
await queryClient.invalidateQueries(`identity-${walletAddress}`);
}, [masa, walletAddress]);
return { identity, handlePurchaseIdentity, status, isLoading, error };
};