/
use-identity-purchase.ts
50 lines (44 loc) · 1.19 KB
/
use-identity-purchase.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
48
49
50
import { useAsyncFn } from 'react-use';
import type { PaymentMethod } from '@masa-finance/masa-sdk';
import { useMasaClient } from '../masa-client/use-masa-client';
export const useIdentityPurchase = () => {
const { sdk: masa } = useMasaClient();
const [
{ loading: isPurchasingIdentity, value: hasPurchasedIdentity },
purchaseIdentity,
] = useAsyncFn(async () => {
const purchasedIdentity = await masa?.identity.create();
return purchasedIdentity?.success;
}, [masa]);
const [
{
value: hasPurchasedIdentityWithSoulName,
loading: isPurchasingIdentityWithSoulName,
},
purchaseIdentityWithSoulName,
] = useAsyncFn(
async (
paymentMethod: PaymentMethod,
soulname: string,
registrationPeriod: number,
style?: string
) => {
const result = await masa?.identity.createWithSoulName(
paymentMethod,
soulname,
registrationPeriod,
style
);
return !!result?.success;
},
[masa]
);
return {
purchaseIdentity,
isPurchasingIdentity,
hasPurchasedIdentity,
purchaseIdentityWithSoulName,
isPurchasingIdentityWithSoulName,
hasPurchasedIdentityWithSoulName,
};
};