2022-09-29 19:21:31 +00:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
|
|
import { toast } from 'react-toastify'
|
|
|
|
|
|
|
|
import useWalletStore from 'stores/useWalletStore'
|
|
|
|
import { contractAddresses } from 'config/contracts'
|
|
|
|
import { hardcodedFee } from 'utils/contants'
|
|
|
|
import { queryKeys } from 'types/query-keys-factory'
|
|
|
|
|
|
|
|
const useCreateCreditAccount = (accountId: string) => {
|
2022-10-28 11:14:14 +00:00
|
|
|
const signingClient = useWalletStore((s) => s.signingClient)
|
2022-09-30 12:50:16 +00:00
|
|
|
const address = useWalletStore((s) => s.address)
|
2022-09-29 19:21:31 +00:00
|
|
|
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
|
|
|
|
return useMutation(
|
|
|
|
async () =>
|
|
|
|
await signingClient?.execute(
|
|
|
|
address,
|
|
|
|
contractAddresses.accountNft,
|
|
|
|
{
|
|
|
|
burn: {
|
|
|
|
token_id: accountId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
hardcodedFee
|
|
|
|
),
|
|
|
|
{
|
|
|
|
onSettled: () => {
|
|
|
|
queryClient.invalidateQueries(queryKeys.creditAccounts(address))
|
|
|
|
},
|
|
|
|
onError: (err: Error) => {
|
|
|
|
toast.error(err.message)
|
|
|
|
},
|
|
|
|
onSuccess: () => {
|
|
|
|
toast.success('Credit Account Deleted')
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default useCreateCreditAccount
|