diff --git a/apps/wallet-mobile/.storybook/storybook.requires.js b/apps/wallet-mobile/.storybook/storybook.requires.js index 25d1517202..6f266bf904 100644 --- a/apps/wallet-mobile/.storybook/storybook.requires.js +++ b/apps/wallet-mobile/.storybook/storybook.requires.js @@ -118,7 +118,6 @@ const getStories = () => { "./src/features/Discover/useCases/BrowseDapp/BrowserTabsBar.stories.tsx": require("../src/features/Discover/useCases/BrowseDapp/BrowserTabsBar.stories.tsx"), "./src/features/Discover/useCases/BrowseDapp/BrowserToolbar.stories.tsx": require("../src/features/Discover/useCases/BrowseDapp/BrowserToolbar.stories.tsx"), "./src/features/Discover/useCases/BrowseDapp/WebViewItem.stories.tsx": require("../src/features/Discover/useCases/BrowseDapp/WebViewItem.stories.tsx"), - "./src/features/Discover/useCases/ReviewTransaction/ReviewTransaction.stories.tsx": require("../src/features/Discover/useCases/ReviewTransaction/ReviewTransaction.stories.tsx"), "./src/features/Discover/useCases/SearchDappInBrowser/SearchDappInBrowserScreen.stories.tsx": require("../src/features/Discover/useCases/SearchDappInBrowser/SearchDappInBrowserScreen.stories.tsx"), "./src/features/Discover/useCases/SelectDappFromList/CountDAppsAvailable/CountDAppsAvailable.stories.tsx": require("../src/features/Discover/useCases/SelectDappFromList/CountDAppsAvailable/CountDAppsAvailable.stories.tsx"), "./src/features/Discover/useCases/SelectDappFromList/CountDAppsConnected/CountDAppsConnected.stories.tsx": require("../src/features/Discover/useCases/SelectDappFromList/CountDAppsConnected/CountDAppsConnected.stories.tsx"), diff --git a/apps/wallet-mobile/src/features/Discover/useCases/BrowseDapp/WebViewItem.tsx b/apps/wallet-mobile/src/features/Discover/useCases/BrowseDapp/WebViewItem.tsx index 7060a8acf9..70b3988401 100644 --- a/apps/wallet-mobile/src/features/Discover/useCases/BrowseDapp/WebViewItem.tsx +++ b/apps/wallet-mobile/src/features/Discover/useCases/BrowseDapp/WebViewItem.tsx @@ -125,6 +125,7 @@ export const WebViewItem = ({tab, index}: Props) => { injectedJavaScriptBeforeContentLoaded={initScript} onMessage={handleEvent} style={[styles.roundedInsideContainer]} + allowsFullscreenVideo={isTabActive} /> {tabsOpen && ( diff --git a/packages/dapp-connector/src/connector.js b/packages/dapp-connector/src/connector.js index 333dab0c8d..cd74bc19ac 100644 --- a/packages/dapp-connector/src/connector.js +++ b/packages/dapp-connector/src/connector.js @@ -79,6 +79,10 @@ const initWallet = ({iconUrl, apiVersion, walletName, supportedExtensions, sessi const callExternalMethod = (method, args = undefined, options = {}) => { const requestId = getRandomId() + if (apisWhichRequireWindowFocus.includes(method) && !isWindowVisible()) { + return new Promise(() => throwUserRejectedError()) + } + if (options?.doNotWaitForResponse) { postMessage({id: requestId, method, source: 'dapp-connector', params: {args, browserContext: getContext()}}) return Promise.resolve() @@ -103,6 +107,19 @@ const initWallet = ({iconUrl, apiVersion, walletName, supportedExtensions, sessi logMessage('Unhandled rejection:' + serializeError(event.reason)) }) + const isWindowVisible = () => { + return document.visibilityState === 'visible' + } + + const getUserRejectedError = () => { + return new CIP30Error('User Rejected', -3) + } + + const throwUserRejectedError = () => { + logMessage('User Rejected') + throw getUserRejectedError() + } + /** * @param {Error | Object} error * @returns {string} @@ -114,6 +131,8 @@ const initWallet = ({iconUrl, apiVersion, walletName, supportedExtensions, sessi return JSON.stringify(error) } + const apisWhichRequireWindowFocus = ['api.getCollateral', 'api.signTx', 'api.signData', 'api.cip95.signData'] + window.addEventListener('message', (event) => { if (!event.data || typeof event.data.id !== 'string') return logMessage('Received message ' + JSON.stringify(event.data)) @@ -134,8 +153,7 @@ const initWallet = ({iconUrl, apiVersion, walletName, supportedExtensions, sessi */ const createApi = async (cardanoEnableResponse) => { if (!cardanoEnableResponse) { - logMessage('User Rejected') - throw new CIP30Error('User Rejected', -3) + return throwUserRejectedError() } localStorage.setItem('yoroi-session-id', sessionId) @@ -212,16 +230,18 @@ const initWallet = ({iconUrl, apiVersion, walletName, supportedExtensions, sessi } /** - * @param {Error} error + * @param {Error | String} error * @returns {CIP30Error} */ const normalizeError = (error) => { - if (error.message.toLowerCase().includes('user rejected')) { + const message = typeof error === 'string' ? error : error.message + + if (message.toLowerCase().includes('user rejected')) { logMessage('User Rejected') - return new CIP30Error('User Rejected', -3) + return getUserRejectedError() } - logMessage('Error:' + error.message) - return new CIP30Error(error.message, -1) + logMessage('Error:' + message) + return new CIP30Error(message, -1) } const walletObj = Object.freeze({