-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate rtk hooks with @graphql-codegen/cli
- Loading branch information
Showing
29 changed files
with
3,954 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"address":"0x2dE080e97B0caE9825375D31f5D0eD5751fDf16D"} | ||
{"address":"0xbCF26943C0197d2eE0E5D05c716Be60cc2761508"} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"counterAddress": "0x2dE080e97B0caE9825375D31f5D0eD5751fDf16D", | ||
"counterAddress": "0xbCF26943C0197d2eE0E5D05c716Be60cc2761508", | ||
"startBlock": 0, | ||
"network": "localhost" | ||
} |
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
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
"extends": [ | ||
"next/core-web-vitals", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/ban-ts-comment": "off" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"semi": false, | ||
"trailingComma": "es5", | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} |
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,84 @@ | ||
import { Exact, InputMaybe, Scalars } from 'kit' | ||
import { UseQuery } from '@reduxjs/toolkit/dist/query/react/buildHooks' | ||
import { QueryDefinition } from '@reduxjs/toolkit/query' | ||
import { useEffect, useState } from 'react' | ||
import { useContractWrite, useWaitForTransaction } from 'wagmi' | ||
import useChain from './useChain' | ||
import { PrepareWriteContractResult } from 'wagmi/dist/actions' | ||
|
||
const useIndexedTransaction = <SubgraphQuery>( | ||
config: PrepareWriteContractResult, | ||
useQuery: UseQuery< | ||
QueryDefinition< | ||
{ | ||
variables: Exact<{ | ||
where?: InputMaybe<{ | ||
transactionHash?: InputMaybe<Scalars['Bytes']['input']> | ||
}> | ||
}> | ||
chainId?: number | undefined | ||
}, | ||
any, | ||
never, | ||
SubgraphQuery, | ||
'subgraphAPI' | ||
> | ||
>, | ||
selectFromResult: (result: SubgraphQuery) => { | ||
indexed: boolean | ||
}, | ||
onSuccessfulIndexing?: () => void | ||
) => { | ||
const { chainId } = useChain() | ||
const [polling, setPolling] = useState(false) | ||
|
||
const { | ||
data, | ||
write, | ||
isLoading: confirmationPending, | ||
} = useContractWrite(config) | ||
|
||
const { isSuccess: transactionSucess, isLoading: transactionPending } = | ||
useWaitForTransaction({ | ||
hash: data?.hash, | ||
}) | ||
|
||
const { indexed } = useQuery( | ||
{ variables: { where: { transactionHash: data?.hash } }, chainId }, | ||
{ | ||
pollingInterval: polling ? 2000 : 0, | ||
skip: !polling || !Boolean(data?.hash), | ||
selectFromResult: (result) => { | ||
if (!result.data) { | ||
return { indexed: false } | ||
} | ||
const { indexed } = selectFromResult(result.data) | ||
return { | ||
indexed, | ||
} | ||
}, | ||
} | ||
) | ||
|
||
useEffect(() => { | ||
if (transactionSucess) { | ||
setPolling(true) | ||
} | ||
}, [transactionSucess]) | ||
|
||
useEffect(() => { | ||
if (indexed) { | ||
onSuccessfulIndexing?.() | ||
setPolling(false) | ||
} | ||
}, [indexed]) | ||
|
||
return { | ||
loading: confirmationPending || transactionPending || polling, | ||
execute: () => { | ||
write && write() | ||
}, | ||
} | ||
} | ||
|
||
export default useIndexedTransaction |
Oops, something went wrong.