Skip to content

Commit

Permalink
fix: don't reject when signing (#2666)
Browse files Browse the repository at this point in the history
* fix: don't reject when signing

* fix: comment
  • Loading branch information
iamacook authored Oct 20, 2023
1 parent 287c3b0 commit 56bf7d8
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/components/tx-flow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export const TxModalContext = createContext<TxModalContextType>({
setFullWidth: noop,
})

const shouldClose = () => confirm('Closing this window will discard your current progress.')

export const TxModalProvider = ({ children }: { children: ReactNode }): ReactElement => {
const [txFlow, setFlow] = useState<TxModalContextType['txFlow']>(undefined)
const [shouldWarn, setShouldWarn] = useState<boolean>(true)
const [shouldWarn, setShouldWarn] = useState<boolean>(false)
const [, setOnClose] = useState<Parameters<TxModalContextType['setTxFlow']>[1]>(noop)
const [fullWidth, setFullWidth] = useState<boolean>(false)
const pathname = usePathname()
Expand All @@ -42,29 +44,27 @@ export const TxModalProvider = ({ children }: { children: ReactNode }): ReactEle
return
}

const ok = confirm('Closing this window will discard your current progress.')
if (!ok) return
if (!shouldClose()) return

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

handleModalClose()
}, [shouldWarn, handleModalClose])

const setTxFlow = useCallback(
(newTxFlow: TxModalContextType['txFlow'], onClose?: () => void, shouldWarn?: boolean) => {
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, {})
}

return newTxFlow
})
(newTxFlow: TxModalContextType['txFlow'], onClose?: () => void, newShouldWarn?: boolean) => {
// If flow is open and user opens a different one, show confirmation dialog if required
if (txFlow && newTxFlow && newTxFlow?.type !== SuccessScreen && shouldWarn) {
if (!shouldClose()) return

txDispatch(TxEvent.USER_QUIT, {})
}

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

// Show the confirmation dialog if user navigates
Expand Down

0 comments on commit 56bf7d8

Please sign in to comment.