From 0459f7a611b8e66e362daaa9f02b3d22738a0850 Mon Sep 17 00:00:00 2001 From: mateumiralles Date: Thu, 13 Feb 2025 17:46:50 +0100 Subject: [PATCH] fix: force events scan after new NO created --- assets/icons/star.svg | 3 ++ .../context/use-submit-keys-submit.ts | 32 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 assets/icons/star.svg diff --git a/assets/icons/star.svg b/assets/icons/star.svg new file mode 100644 index 00000000..3956505f --- /dev/null +++ b/assets/icons/star.svg @@ -0,0 +1,3 @@ + + + diff --git a/features/create-node-operator/submit-keys-form/context/use-submit-keys-submit.ts b/features/create-node-operator/submit-keys-form/context/use-submit-keys-submit.ts index 0a171f81..2fcc9779 100644 --- a/features/create-node-operator/submit-keys-form/context/use-submit-keys-submit.ts +++ b/features/create-node-operator/submit-keys-form/context/use-submit-keys-submit.ts @@ -22,10 +22,11 @@ import { getAddedNodeOperator, runWithTransactionLogger, } from 'utils'; -import { Address } from 'wagmi'; +import { Address, useAccount } from 'wagmi'; import { useConfirmCustomAddressesModal } from '../hooks/use-confirm-modal'; import { useTxModalStagesSubmitKeys } from '../hooks/use-tx-modal-stages-submit-keys'; import { SubmitKeysFormInputType, SubmitKeysFormNetworkData } from './types'; +import useDappnodeUrls from 'dappnode/hooks/use-dappnode-urls'; type SubmitKeysOptions = { onConfirm?: () => Promise | void; @@ -128,6 +129,26 @@ export const useSubmitKeysSubmit = ({ const confirmCustomAddresses = useConfirmCustomAddressesModal(); const { ask } = useAskHowDidYouLearnCsm(); + // DAPPNODE + const { backendUrl } = useDappnodeUrls(); + const { address } = useAccount(); + /** + * `scanEvents` is required to trigger a re-scan of events on the backend after a new node operator is added. + * By default, the backend does not re-scan events if the address is already indexed and the block difference + * since last scann is less than 320 blocks. + */ + const scanEvents = useCallback(async () => { + const url = `${backendUrl}/api/v0/events_indexer/address_events?address=${address}&force=${true}`; + const options = { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }; + await fetch(url, options); + }, [backendUrl, address]); + // DAPPNODE + return useCallback( async ( { @@ -198,6 +219,14 @@ export const useSubmitKeysSubmit = ({ waitTx, ); + // DAPPNODE + await scanEvents().catch((e) => { + console.error( + `Failed to trigger forced events re-scan after creating new NO: ${e}`, + ); + }); + // DAPPNODE + const nodeOperator = getAddedNodeOperator(receipt); txModalStages.success( @@ -240,6 +269,7 @@ export const useSubmitKeysSubmit = ({ isUserOrZero, onRetry, ask, + scanEvents, // DAPPNODE ], ); };