Skip to content

Commit 09b7a8f

Browse files
authored
Merge pull request #5428 from EdgeApp/sam/broke-back-mt-pelerin
Fix back navigation for Mt Pelerin quotes
2 parents ff8f975 + bbfecdf commit 09b7a8f

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/plugins/gui/providers/mtpelerinProvider.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ export const mtpelerinProvider: FiatProviderFactory = {
507507
injecteJs(run)
508508
}
509509

510+
// This is the state of the user-journey through the quoting process
511+
let userFlowStatus: 'preparing-quote' | 'submitted-quote' | 'navigating-back' = 'preparing-quote'
512+
510513
const onMessage: FiatPluginOpenWebViewParams['onMessage'] = (eventMessage: string, injectJs) => {
511514
const message = asMessage(JSON.parse(eventMessage))
512515
try {
@@ -655,6 +658,9 @@ export const mtpelerinProvider: FiatProviderFactory = {
655658
}
656659

657660
sendResponse('onsenttransaction', tx.signedTx, injectJs)
661+
662+
// The user has signed and sent the transaction
663+
userFlowStatus = 'submitted-quote'
658664
}
659665
send().catch((e: unknown) => {
660666
if (!(e instanceof Error && e.message.includes(SendErrorBackPressed))) {
@@ -739,7 +745,23 @@ export const mtpelerinProvider: FiatProviderFactory = {
739745
url,
740746
injectedJs,
741747
onMessage,
742-
onClose: () => {}
748+
onClose: () => {
749+
// Hi-jack the back navigation
750+
switch (userFlowStatus) {
751+
case 'preparing-quote':
752+
case 'navigating-back':
753+
return true
754+
case 'submitted-quote': {
755+
// If the user has submitted a quote, then navigating back
756+
// will skip all the way back to the plugin list scene.
757+
showUi.exitScene()
758+
showUi.exitScene()
759+
userFlowStatus = 'navigating-back'
760+
// Prevent default navigation
761+
return false
762+
}
763+
}
764+
}
743765
})
744766
},
745767
closeQuote: async (): Promise<void> => {}

src/plugins/gui/scenes/FiatPluginWebView.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNavigation } from '@react-navigation/native'
12
import * as React from 'react'
23
import { WebView, WebViewNavigation } from 'react-native-webview'
34

@@ -8,7 +9,7 @@ import { BuyTabSceneProps } from '../../../types/routerTypes'
89
export interface FiatPluginOpenWebViewParams {
910
url: string
1011
injectedJs?: string
11-
onClose?: () => void
12+
onClose?: (() => boolean) | (() => void)
1213
onMessage?: (message: string, injectJs: (js: string) => void) => void
1314
onUrlChange?: (url: string) => void
1415
}
@@ -18,6 +19,7 @@ interface Props extends BuyTabSceneProps<'guiPluginWebView'> {}
1819
export function FiatPluginWebViewComponent(props: Props): JSX.Element {
1920
const { route } = props
2021
const { injectedJs, onClose, onMessage, onUrlChange, url } = route.params
22+
const navigation = useNavigation()
2123

2224
const webViewRef = React.useRef<WebView>(null)
2325

@@ -35,10 +37,15 @@ export function FiatPluginWebViewComponent(props: Props): JSX.Element {
3537
if (onMessage != null) onMessage(data, injectJs)
3638
})
3739

38-
React.useEffect(() => () => {
39-
// Cleanup code when scene unmounts
40-
if (onClose != null) onClose()
41-
})
40+
React.useEffect(
41+
() =>
42+
navigation.addListener('beforeRemove', event => {
43+
if (onClose != null) {
44+
if (onClose() === false) event.preventDefault()
45+
}
46+
}),
47+
[navigation, onClose]
48+
)
4249

4350
return (
4451
<SceneWrapper hasTabs avoidKeyboard>

0 commit comments

Comments
 (0)