Skip to content

Commit

Permalink
fix: change event payload + use callback syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 18, 2023
1 parent 31f019c commit aec7801
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/components/tx-flow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,25 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
if (!ok) return

// Reject if the flow is closed
txDispatch(TxEvent.USER_QUIT, undefined)
txDispatch(TxEvent.USER_QUIT, {})

handleModalClose()
}, [shouldWarn, handleModalClose])

const setTxFlow = useCallback(
(newTxFlow: TxModalContextType['txFlow'], onClose?: () => void, shouldWarn?: boolean) => {
// Reject if a flow is open and the user changes to a different one
if (txFlow && txFlow !== newTxFlow && newTxFlow?.type !== SuccessScreen) {
txDispatch(TxEvent.USER_QUIT, undefined)
}
setFlow((prevFlow) => {
// Reject if a flow is open and the user changes to a different one
if (prevFlow && prevFlow !== newTxFlow && newTxFlow?.type !== SuccessScreen) {
txDispatch(TxEvent.USER_QUIT, {})
}

setFlow(newTxFlow)
return newTxFlow
})
setOnClose(() => onClose ?? noop)
setShouldWarn(shouldWarn ?? true)
},
[txFlow],
[],
)

// Show the confirmation dialog if user navigates
Expand Down
4 changes: 0 additions & 4 deletions src/hooks/useTxPendingStatuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ const useTxPendingStatuses = (): void => {
useEffect(() => {
const unsubFns = Object.entries(pendingStatuses).map(([event, status]) =>
txSubscribe(event as TxEvent, (detail) => {
if (!detail) {
return
}

// All pending txns should have a txId
const txId = 'txId' in detail && detail.txId
if (!txId) return
Expand Down
2 changes: 1 addition & 1 deletion src/services/tx/txEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Id = { txId: string; groupKey?: string } | { txId?: string; groupKey: strin
type HumanDescription = { humanDescription?: string }

interface TxEvents {
[TxEvent.USER_QUIT]: undefined
[TxEvent.USER_QUIT]: {}
[TxEvent.SIGNED]: { txId?: string }
[TxEvent.SIGN_FAILED]: HumanDescription & { txId?: string; error: Error }
[TxEvent.PROPOSE_FAILED]: HumanDescription & { error: Error }
Expand Down

0 comments on commit aec7801

Please sign in to comment.