Skip to content

Commit

Permalink
fix(hooks-store): log simulation only on trade simulation (#5101)
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesfracari authored Nov 18, 2024
1 parent 5c3881f commit 84f5d5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ interface OrderHooksDetailsProps {
appData: string | AppDataInfo
children: (content: ReactElement) => ReactElement
margin?: string
isTradeConfirmation?: boolean
}

export function OrderHooksDetails({ appData, children, margin }: OrderHooksDetailsProps) {
export function OrderHooksDetails({ appData, children, margin, isTradeConfirmation }: OrderHooksDetailsProps) {
const [isOpen, setOpen] = useState(false)
const appDataDoc = useMemo(() => {
return typeof appData === 'string' ? decodeAppData(appData) : appData.doc
Expand All @@ -33,14 +34,14 @@ export function OrderHooksDetails({ appData, children, margin }: OrderHooksDetai
const { mutate, isValidating, data } = useTenderlyBundleSimulation()

useEffect(() => {
mutate()
}, []) // eslint-disable-line react-hooks/exhaustive-deps
if (isTradeConfirmation) mutate()
}, [isTradeConfirmation, mutate])

if (!appDataDoc) return null

const metadata = appDataDoc.metadata as latest.Metadata

const hasSomeFailedSimulation = Object.values(data || {}).some((hook) => !hook.status)
const hasSomeFailedSimulation = isTradeConfirmation && Object.values(data || {}).some((hook) => !hook.status)

const preHooksToDapp = matchHooksToDappsRegistry(metadata.hooks?.pre || [], preCustomHookDapps)
const postHooksToDapp = matchHooksToDappsRegistry(metadata.hooks?.post || [], postCustomHookDapps)
Expand Down Expand Up @@ -76,8 +77,8 @@ export function OrderHooksDetails({ appData, children, margin }: OrderHooksDetai
</styledEl.Summary>
{isOpen && (
<styledEl.Details>
<HooksInfo data={preHooksToDapp} hooks={hooks.preHooks} title="Pre Hooks" />
<HooksInfo data={postHooksToDapp} hooks={hooks.postHooks} title="Post Hooks" />
<HooksInfo data={preHooksToDapp} hooks={isTradeConfirmation ? hooks.preHooks : []} title="Pre Hooks" />
<HooksInfo data={postHooksToDapp} hooks={isTradeConfirmation ? hooks.postHooks : []} title="Post Hooks" />
</styledEl.Details>
)}
</styledEl.Wrapper>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export function TradeConfirmation(props: TradeConfirmationProps) {
}

const hookDetailsElement = (
<>{appData && <OrderHooksDetails appData={appData}>{(hookChildren) => hookChildren}</OrderHooksDetails>}</>
<>
{appData && (
<OrderHooksDetails appData={appData} isTradeConfirmation>
{(hookChildren) => hookChildren}
</OrderHooksDetails>
)}
</>
)

return (
Expand Down

0 comments on commit 84f5d5e

Please sign in to comment.