Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/plugins/gui/providers/mtpelerinProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ export const mtpelerinProvider: FiatProviderFactory = {
injecteJs(run)
}

// This is the state of the user-journey through the quoting process
let userFlowStatus: 'preparing-quote' | 'submitted-quote' | 'navigating-back' = 'preparing-quote'

const onMessage: FiatPluginOpenWebViewParams['onMessage'] = (eventMessage: string, injectJs) => {
const message = asMessage(JSON.parse(eventMessage))
try {
Expand Down Expand Up @@ -655,6 +658,9 @@ export const mtpelerinProvider: FiatProviderFactory = {
}

sendResponse('onsenttransaction', tx.signedTx, injectJs)

// The user has signed and sent the transaction
userFlowStatus = 'submitted-quote'
}
send().catch((e: unknown) => {
if (!(e instanceof Error && e.message.includes(SendErrorBackPressed))) {
Expand Down Expand Up @@ -739,7 +745,23 @@ export const mtpelerinProvider: FiatProviderFactory = {
url,
injectedJs,
onMessage,
onClose: () => {}
onClose: () => {
// Hi-jack the back navigation
switch (userFlowStatus) {
case 'preparing-quote':
case 'navigating-back':
return true
case 'submitted-quote': {
// If the user has submitted a quote, then navigating back
// will skip all the way back to the plugin list scene.
showUi.exitScene()
showUi.exitScene()
userFlowStatus = 'navigating-back'
// Prevent default navigation
return false
}
}
}
})
},
closeQuote: async (): Promise<void> => {}
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/gui/scenes/FiatPluginWebView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useNavigation } from '@react-navigation/native'
import * as React from 'react'
import { WebView, WebViewNavigation } from 'react-native-webview'

Expand All @@ -8,7 +9,7 @@ import { BuyTabSceneProps } from '../../../types/routerTypes'
export interface FiatPluginOpenWebViewParams {
url: string
injectedJs?: string
onClose?: () => void
onClose?: (() => boolean) | (() => void)
onMessage?: (message: string, injectJs: (js: string) => void) => void
onUrlChange?: (url: string) => void
}
Expand All @@ -18,6 +19,7 @@ interface Props extends BuyTabSceneProps<'guiPluginWebView'> {}
export function FiatPluginWebViewComponent(props: Props): JSX.Element {
const { route } = props
const { injectedJs, onClose, onMessage, onUrlChange, url } = route.params
const navigation = useNavigation()

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

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

React.useEffect(() => () => {
// Cleanup code when scene unmounts
if (onClose != null) onClose()
})
React.useEffect(
() =>
navigation.addListener('beforeRemove', event => {
if (onClose != null) {
if (onClose() === false) event.preventDefault()
}
}),
[navigation, onClose]
)

return (
<SceneWrapper hasTabs avoidKeyboard>
Expand Down
Loading