Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
258 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useClient } from 'wagmi'; | ||
import { QcContext } from '../masa-provider'; | ||
|
||
export const useMasaQueryClient = () => { | ||
const queryClient = useQueryClient({ context: QcContext }); | ||
const client = useClient(); | ||
|
||
console.log('wagmiclient', { client }); | ||
|
||
return queryClient; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ export const useMasaSDK = ( | |
verbose, | ||
}); | ||
}, [ | ||
address, | ||
signer, | ||
apiUrl, | ||
environmentName, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useAsync } from 'react-use'; | ||
import { useMasaClient } from '../masa-client/use-masa-client'; | ||
import { useNetwork } from '../wallet-client/network'; | ||
import type { useSession } from './use-session'; | ||
import type { useIdentity } from './use-identity'; | ||
|
||
export const useIdentityListen = ({ | ||
identity, | ||
getIdentity, | ||
sessionAddress, | ||
}: { | ||
identity?: ReturnType<typeof useIdentity>['identity']; | ||
getIdentity: ReturnType<typeof useIdentity>['getIdentity']; | ||
sessionAddress?: ReturnType<typeof useSession>['sessionAddress']; | ||
}) => { | ||
const { masaAddress, masaNetwork } = useMasaClient(); | ||
const { activeNetwork } = useNetwork(); | ||
// const { identity, getIdentity } = useIdentity(); | ||
|
||
useAsync(async () => { | ||
if ( | ||
masaAddress === sessionAddress && | ||
masaNetwork === activeNetwork && | ||
identity?.address !== masaAddress | ||
) | ||
// * NOTE: we need to make sure the states are in sync before loading the identity | ||
await getIdentity(); | ||
|
||
return undefined; | ||
}, [ | ||
getIdentity, | ||
masaAddress, | ||
activeNetwork, | ||
masaNetwork, | ||
sessionAddress, | ||
identity, | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/refactor/masa-feature/use-session.ts → src/refactor/masa/use-session.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { PaymentMethod } from '@masa-finance/masa-sdk'; | ||
import { useAsyncFn } from 'react-use'; | ||
import { useMasaClient } from '../masa-client/use-masa-client'; | ||
import { useMasaQueryClient } from '../masa-client/use-masa-query-client'; | ||
|
||
export const useSoulNamesPurchase = () => { | ||
const { sdk: masa } = useMasaClient(); | ||
const queryClient = useMasaQueryClient(); | ||
const [ | ||
{ loading: isPurchasingSoulName, value: hasPurchasedSoulName }, | ||
purchaseSoulName, | ||
] = useAsyncFn( | ||
async ( | ||
soulname: string, | ||
registrationPeriod: number, | ||
paymentMethod: PaymentMethod, | ||
style?: string | ||
) => { | ||
const result = await masa?.soulName.create( | ||
paymentMethod, | ||
soulname, | ||
registrationPeriod, | ||
undefined, | ||
style | ||
); | ||
await queryClient.invalidateQueries(['soulnames']); | ||
return !!result?.success; | ||
}, | ||
[masa, queryClient] | ||
); | ||
|
||
return { | ||
isPurchasingSoulName, | ||
hasPurchasedSoulName, | ||
purchaseSoulName, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useAsync } from 'react-use'; | ||
import { QcContext } from '../masa-provider'; | ||
import { useMasaClient } from '../masa-client/use-masa-client'; | ||
|
||
export const useSoulNames = () => { | ||
const { masaAddress, masaNetwork, sdk: masa } = useMasaClient(); | ||
const { | ||
data: soulnames, | ||
isFetching: isLoadingSoulnames, | ||
refetch: getSoulnames, | ||
} = useQuery({ | ||
enabled: !!masa && !!masaAddress && !!masaNetwork, | ||
context: QcContext, | ||
queryKey: ['soulnames', { masaAddress, masaNetwork, persist: false }], | ||
queryFn: async () => masa?.soulName.list(), | ||
}); | ||
|
||
useAsync(async () => getSoulnames(), [getSoulnames]); | ||
return { | ||
soulnames, | ||
isLoadingSoulnames, | ||
getSoulnames, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Masa } from '@masa-finance/masa-sdk'; | ||
import { constants } from 'ethers'; | ||
|
||
export const isIdentityContractAvailible = (masa?: Masa) => { | ||
if (!masa) return false; | ||
if ( | ||
masa?.contracts.instances.SoulboundIdentityContract.address === | ||
constants.AddressZero || | ||
!masa?.contracts.instances.SoulboundIdentityContract.hasAddress | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; |
Oops, something went wrong.