I'm running substrate-contracts-node locally with --dev
(instant seals). I created a custom react hook to wrap events, but it never gets finalized. Am I doing something wrong, is there a caveat in using instant seals?
type Status = 'pending' | 'finalized' | 'none';
type Response = {
send: () => void;
events: EventRecord[];
status: Status;
};
export const useExecuteFunc = (): Response => {
const game = useGameContract();
const { activeAccount, activeSigner } = useInk();
const [pixels, setPixels] = useState<EventRecord[]>([]);
const [status, setStatus] = useState<Status>('none');
const send = useMemo(() => {
return async () => {
if (!activeAccount || !game || !activeSigner) return () => null;
const unsub = await game.tx
.executeTurns({
gasLimit: -1,
})
.signAndSend(activeAccount?.address, { signer: activeSigner.signer }, async (result) => {
console.log('result', result);
if (result.status.isInBlock) {
console.log('status is pending');
setStatus('pending');
} else if (result.status.isFinalized) {
console.log('status is finalized');
setStatus('finalized');
unsub();
}
});
};
}, [activeAccount, activeSigner, game]);
return {
send,
events: pixels,
status,
};
};
I then use this like this:
const executeGameFunc = useExecuteGameFunc()
// ...
<button onClick={() => executeGameFunc.send()}>Play Game</button>
polkadotjs explorer shows that the transaction was successful.