c4f8f4eab0
* MP-1757: implemented the WalletProvider and connect buttons * tidy: tidy up the search * MP-1691: moved modals outside of the DOM * MP-1691: changed CreditManager into AccountDetails * fix: fixed the naming * MP-1691: UX approvements * MP-1691: global confirm and delete modal added * fix: merged the credit-account and wallet branch * MP-1757: added the status store * fix: updated the store interaction * MP-1757: major cleanup of stores * tidy: format
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'react-toastify'
|
|
|
|
import { contractAddresses } from 'config/contracts'
|
|
import { useWalletStore } from 'stores'
|
|
import { queryKeys } from 'types/query-keys-factory'
|
|
import { hardcodedFee } from 'utils/contants'
|
|
|
|
const useDepositCreditAccount = (
|
|
accountId: string,
|
|
denom: string,
|
|
amount: number,
|
|
options?: {
|
|
onSuccess?: () => void
|
|
},
|
|
) => {
|
|
const signingClient = useWalletStore((s) => s.signingClient)
|
|
const address = useWalletStore((s) => s.address)
|
|
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation(
|
|
async () =>
|
|
await signingClient?.execute(
|
|
address ?? '',
|
|
contractAddresses.creditManager,
|
|
{
|
|
update_credit_account: {
|
|
account_id: accountId,
|
|
actions: [
|
|
{
|
|
deposit: {
|
|
denom,
|
|
amount: String(amount),
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
hardcodedFee,
|
|
undefined,
|
|
[
|
|
{
|
|
denom,
|
|
amount: String(amount),
|
|
},
|
|
],
|
|
),
|
|
{
|
|
onError: (err: Error) => {
|
|
toast.error(err.message)
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(queryKeys.allBalances(address ?? ''))
|
|
queryClient.invalidateQueries(queryKeys.tokenBalance(address ?? '', denom))
|
|
queryClient.invalidateQueries(queryKeys.creditAccountsPositions(accountId))
|
|
|
|
options?.onSuccess && options.onSuccess()
|
|
},
|
|
},
|
|
)
|
|
}
|
|
|
|
export default useDepositCreditAccount
|