-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: listen for the transfer success event #1490
Changes from 2 commits
1a8bfaf
4e70f12
ddebbf6
1fea628
c047fda
904b65f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ import { ProposalStatus, ProposalTypeString } from "@namada/types"; | |
import { localnetConfigAtom } from "atoms/integrations/atoms"; | ||
import BigNumber from "bignumber.js"; | ||
import { getDefaultStore } from "jotai"; | ||
import { isEqual } from "lodash"; | ||
import namadaAssets from "namada-chain-registry/namada/assetlist.json"; | ||
import { useEffect } from "react"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
export const proposalStatusToString = (status: ProposalStatus): string => { | ||
const statusText: Record<ProposalStatus, string> = { | ||
|
@@ -38,32 +39,46 @@ export const proposalIdToString = (proposalId: bigint): string => | |
|
||
export const useTransactionEventListener = <T extends keyof WindowEventMap>( | ||
event: T, | ||
handler: (this: Window, ev: WindowEventMap[T]) => void, | ||
deps: React.DependencyList = [] | ||
handler: (event: WindowEventMap[T]) => void | ||
): void => { | ||
// `handlerRef` is useful to avoid recreating the listener every time | ||
const handlerRef = useRef(handler); | ||
handlerRef.current = handler; | ||
|
||
useEffect(() => { | ||
window.addEventListener(event, handler); | ||
const callback: typeof handler = (event) => handlerRef.current(event); | ||
window.addEventListener(event, callback); | ||
return () => { | ||
window.removeEventListener(event, handler); | ||
window.removeEventListener(event, callback); | ||
}; | ||
}, deps); | ||
}, [event]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I lost many hours debugging until realizing this dependencies was the issue 😢 Maybe we should enable the What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Daaaamn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we concatenate this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need the |
||
}; | ||
|
||
export const useTransactionEventListListener = <T extends keyof WindowEventMap>( | ||
events: T[], | ||
handler: (this: Window, ev: WindowEventMap[T]) => void, | ||
deps: React.DependencyList = [] | ||
handler: (event: WindowEventMap[T]) => void | ||
): void => { | ||
// `eventsRef` and `handlerRef` are useful to avoid recreating the listener every time | ||
const eventsRef = useRef(events); | ||
if (!isEqual(events, eventsRef.current)) { | ||
eventsRef.current = events; | ||
} | ||
const eventsValue = eventsRef.current; | ||
|
||
const handlerRef = useRef(handler); | ||
handlerRef.current = handler; | ||
|
||
useEffect(() => { | ||
events.forEach((event) => { | ||
window.addEventListener(event, handler); | ||
const callback: typeof handler = (event) => handlerRef.current(event); | ||
eventsValue.forEach((event) => { | ||
window.addEventListener(event, callback); | ||
}); | ||
return () => { | ||
events.forEach((event) => { | ||
window.removeEventListener(event, handler); | ||
eventsValue.forEach((event) => { | ||
window.removeEventListener(event, callback); | ||
}); | ||
}; | ||
}, deps); | ||
}, [eventsValue]); | ||
}; | ||
|
||
export const sumBigNumberArray = (numbers: BigNumber[]): BigNumber => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if what you want is not the tx[0].innerTxHashes[0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validated. The
tx[0].hash
is correct. We don't have theinnerTxHashes
on the event object, and we are creating the stored tx with thetxs[0].hash
from response, not thetxs[0].innerTxHashes[0]