Skip to content

Commit

Permalink
fix some transaction and query bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Jul 3, 2024
1 parent 9c845ec commit afc99c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/next/src/hooks/useApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export const useApi = () => {
const handleLoadApi = useCallback(async () => setApi(await activate(config)), [])

const handleQuery = useCallback(
async (query: any, setValue: (value: any) => void, setErrorForm?: (error: any) => void) => {
async (
query: () => any,
setValue: (value: any) => void,
setErrorForm?: (error: any) => void,
) => {
setErrorForm && setErrorForm('')
try {
if (!api) {
Expand All @@ -24,6 +28,8 @@ export const useApi = () => {
}

setValue(query)

return query
} catch (error) {
setErrorForm && setErrorForm((error as any).message)
}
Expand Down
6 changes: 4 additions & 2 deletions examples/next/src/hooks/useTx.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useApi } from '@/hooks/useApi'
import { useWallets } from '@/hooks/useWallet'
import type { SubmittableExtrinsic } from '@polkadot/api/types'
import type { ISubmittableResult } from '@polkadot/types/types'
import { useCallback, useState } from 'react'

export const useTx = () => {
Expand All @@ -8,7 +10,7 @@ export const useTx = () => {
const [txHash, setTxHash] = useState('')

const handleTx = useCallback(
async (tx: any, setErrorForm: any) => {
async (tx: SubmittableExtrinsic<'promise', ISubmittableResult>, setErrorForm: any) => {
try {
if (!selectedWallet) {
setErrorForm('Wallet not selected')
Expand All @@ -19,7 +21,7 @@ export const useTx = () => {
if (result.status.isInBlock) console.log('Successful tx')
else if (result.status.isFinalized) console.log('Finalized tx')
}),
(v) => setTxHash(v.hash.toString()),
() => setTxHash(tx.hash.toString()),
setErrorForm,
)
} catch (error) {
Expand Down

0 comments on commit afc99c8

Please sign in to comment.