11import { TypeRegistry } from "@polkadot/types" ;
2+ import { RegistryTypes } from "@polkadot/types/types" ;
23import { useQuery } from "@tanstack/react-query" ;
34import { useReadContract , useWatchContractEvent } from "wagmi" ;
45
@@ -7,11 +8,12 @@ import { catDogIdentifierAbi } from "./catDogIdentifierAbi";
78import { CAT_IDENTIFIER_CONTRACT_ADDRESS , GEAR_API_NODE } from "@/consts" ;
89import { CalcResult } from "../types" ;
910import { mirrorAbi } from "./mirrorAbi" ;
11+ import { retryWhileDataChanged } from "@/lib/utils" ;
1012
1113export const readRpcState = async ( mirrorId ?: HexString ) => {
1214 if ( ! mirrorId ) return ;
1315
14- const types : Record < string , any > = {
16+ const types : RegistryTypes = {
1517 FixedPoint : { num : "i128" , scale : "u32" } ,
1618 CalcResult : {
1719 probability : "FixedPoint" ,
@@ -57,7 +59,7 @@ export const readRpcState = async (mirrorId?: HexString) => {
5759 json . result . payload
5860 ) ;
5961
60- let data = result [ 2 ] . toJSON ( ) as unknown as CalcResult ;
62+ const data = result [ 2 ] . toJSON ( ) as unknown as CalcResult ;
6163
6264 return data ;
6365} ;
@@ -85,13 +87,9 @@ export const useReadRpcState = ({ isSubmiting, onSuccess }: Params) => {
8587 eventName : "StateChanged" ,
8688 address : mirrorId as HexString ,
8789 onLogs ( ) {
88- if ( isSubmiting ) {
89- console . log ( "success reply" ) ;
90- onSuccess ( ) ;
91- refetch ( ) ;
92- }
90+ retryWhileDataChanged ( { data, refetch } ) . then ( ( ) => onSuccess ( ) ) ;
9391 } ,
94- enabled : ! ! mirrorId ,
92+ enabled : ! ! mirrorId && isSubmiting ,
9593 } ) ;
9694
9795 return {
0 commit comments