diff --git a/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx b/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx index ac042798f..743181006 100644 --- a/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx +++ b/packages/keepkey-desktop-app/src/pages/Browser/Browser.tsx @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ +import React, { useCallback, useEffect, useState } from 'react' import { ArrowForwardIcon, ArrowLeftIcon, @@ -14,7 +14,6 @@ import { DrawerOverlay, HStack, IconButton, - IconButton, Input, Stack, useDisclosure, @@ -23,14 +22,12 @@ import * as Comlink from 'comlink' import { Main } from 'components/Layout/Main' import { getConfig } from 'config' import { ipcListeners } from 'electron-shim' -// import { WalletActions } from 'context/WalletProvider/actions' import { useWallet } from 'hooks/useWallet/useWallet' -import React, { useCallback, useEffect, useState } from 'react' import { FaBug } from 'react-icons/fa' const getWebview = () => document.getElementById('webview') as Electron.WebviewTag | null const getWebviewWc = () => - document.getElementById('second-webview-top') as Electron.WebviewTag | null + document.getElementById('second-webview-top') as Electron.WebviewTag | null const goBack = () => { const webview = getWebview() @@ -85,35 +82,35 @@ const checkIfSSDApp = (currentUrl: string) => { if (currentUrl === 'about:blank') return const url = new URL(currentUrl) if ( - url.origin === getConfig().REACT_APP_SHAPESHIFT_DAPP_URL || - url.origin === 'http://localhost:3000' + url.origin === getConfig().REACT_APP_SHAPESHIFT_DAPP_URL || + url.origin === 'http://localhost:3000' ) { const webview = getWebview() if (!webview) return webview - .executeJavaScript('localStorage.getItem("localWalletType");', true) - .then((savedWalletType: any) => { - if (!savedWalletType || savedWalletType === 'keepkey') { - const localWalletDeviceId = localStorage.getItem('localWalletDeviceId') - webview - .executeJavaScript('localStorage.getItem("localWalletDeviceId");', true) - .then((savedWalletId: any) => { - if (!savedWalletId || savedWalletId !== localWalletDeviceId) { - const kkDesktopApiKey = localStorage.getItem('@app/serviceKey') - if (!kkDesktopApiKey || !localWalletDeviceId) return - - ipcListeners.getSSAutoLogin(localWalletDeviceId, kkDesktopApiKey).then( - injection => { - console.log('INJECTION', injection) - webview.executeJavaScript(injection) - }, - // .then(() => webview.reload()) - ) - } - }) - } - }) - .catch(console.error) + .executeJavaScript('localStorage.getItem("localWalletType");', true) + .then((savedWalletType: any) => { + if (!savedWalletType || savedWalletType === 'keepkey') { + const localWalletDeviceId = localStorage.getItem('localWalletDeviceId') + webview + .executeJavaScript('localStorage.getItem("localWalletDeviceId");', true) + .then((savedWalletId: any) => { + if (!savedWalletId || savedWalletId !== localWalletDeviceId) { + const kkDesktopApiKey = localStorage.getItem('@app/serviceKey') + if (!kkDesktopApiKey || !localWalletDeviceId) return + + ipcListeners.getSSAutoLogin(localWalletDeviceId, kkDesktopApiKey).then( + injection => { + console.log('INJECTION', injection) + webview.executeJavaScript(injection) + }, + // .then(() => webview.reload()) + ) + } + }) + } + }) + .catch(console.error) } } catch (error) { console.error(error) @@ -254,8 +251,6 @@ export const Browser = () => { const webview = getWebviewWc()! const currentUrl = webview.getURL() setUrlWc(currentUrl) - // setCanGoBack(webview.canGoBack()) - // setCanGoForward(webview.canGoForward()) setLoadingWc(false) } webview.addEventListener('did-stop-loading', listener) @@ -284,20 +279,20 @@ export const Browser = () => { }, [webviewReady, url, forceLoad]) const formatAndSaveUrl = useCallback( - (e?: React.SyntheticEvent) => { - e?.preventDefault() - const newUrl = formatUrl(inputUrl) ?? url - setInputUrl(newUrl) - setUrl(newUrl) - setForceLoad(true) - }, - [inputUrl, url], + (e?: React.SyntheticEvent) => { + e?.preventDefault() + const newUrl = formatUrl(inputUrl) ?? url + setInputUrl(newUrl) + setUrl(newUrl) + setForceLoad(true) + }, + [inputUrl, url], ) useEffect(() => { if (webviewWcReady && walletConnectUri) { const newUrl = `https://wallet-connect-dapp-ochre.vercel.app/wc?uri=${encodeURIComponent( - walletConnectUri, + walletConnectUri, )}` const webviewWc = getWebviewWc() webviewWc?.loadURL(newUrl) @@ -310,11 +305,12 @@ export const Browser = () => { const newUrl = formatUrl(browserUrl) if (newUrl) { - console.log('browserUrl', browserUrl) + console.log('browserUrl:', browserUrl) + console.log('Formatted newUrl:', newUrl) setInputUrl(newUrl) setUrl(newUrl) } else { - console.error('invalid browserUrl', browserUrl) + console.error('invalid browserUrl:', browserUrl) } }, [browserUrl, webviewReady]) @@ -326,21 +322,19 @@ export const Browser = () => { if (!isOpen) { onOpen() } - console.log('walletConnectUri', walletConnectUri) - //src='https://wallet-connect-dapp-ochre.vercel.app/' + console.log('walletConnectUri:', walletConnectUri) if (walletConnectUri) { setUrlWc('https://wallet-connect-dapp-ochre.vercel.app/wc?=' + walletConnectUri) } else { setUrlWc('https://wallet-connect-dapp-ochre.vercel.app') } } else { - console.error('invalid browserUrl', browserUrl) + console.error('invalid browserUrl:', browserUrl) } }, [walletConnectUri, webviewWcReady]) - //walletConnectOpen useEffect(() => { - console.log('walletConnectOpen: ', walletConnectOpen) + console.log('walletConnectOpen:', walletConnectOpen) if (walletConnectOpen) { onOpen() } else { @@ -348,15 +342,6 @@ export const Browser = () => { } }, [walletConnectOpen]) - // Add a button to manually toggle the drawer for debugging - // const toggleSecondWebview = () => { - // if (isOpen) { - // onClose(); - // } else { - // onOpen(); - // } - // }; - useEffect(() => { if (!webviewReady) return @@ -364,8 +349,8 @@ export const Browser = () => { const contentsId = webview.getWebContentsId() const loadURL = webview.loadURL.bind(webview) ipcListeners - .webviewAttachOpenHandler(contentsId, Comlink.proxy(loadURL)) - .catch((e: any) => console.error('webviewAttachOpenHandler error:', e)) + .webviewAttachOpenHandler(contentsId, Comlink.proxy(loadURL)) + .catch((e: any) => console.error('webviewAttachOpenHandler error:', e)) }, [webviewReady]) useEffect(() => { @@ -375,71 +360,71 @@ export const Browser = () => { const contentsId = webviewWc.getWebContentsId() const loadURL = webviewWc.loadURL.bind(webviewWc) ipcListeners - .webviewAttachOpenHandler(contentsId, Comlink.proxy(loadURL)) - .catch((e: any) => console.error('webviewAttachOpenHandler error:', e)) + .webviewAttachOpenHandler(contentsId, Comlink.proxy(loadURL)) + .catch((e: any) => console.error('webviewAttachOpenHandler error:', e)) }, [webviewWcReady]) return ( -
- -
- - setInputUrl(e.target.value)} - onBlur={formatAndSaveUrl} - /> - {loading ? ( - } onClick={stopLoading} /> - ) : url === inputUrl && webviewLoadFailure === undefined ? ( - } type='submit' /> - ) : ( - } type='submit' /> - )} - } - onClick={goBack} - isLoading={loading} - isDisabled={!canGoBack} - /> - } - onClick={goForward} - isLoading={loading} - isDisabled={!canGoForward} - /> - } onClick={openDevTools} /> - -
-
- - - +
+ +
+ + setInputUrl(e.target.value)} + onBlur={formatAndSaveUrl} + /> + {loading ? ( + } onClick={stopLoading} /> + ) : url === inputUrl && webviewLoadFailure === undefined ? ( + } type='submit' /> + ) : ( + } type='submit' /> + )} + } + onClick={goBack} + isLoading={loading} + isDisabled={!canGoBack} + /> + } + onClick={goForward} + isLoading={loading} + isDisabled={!canGoForward} + /> + } onClick={openDevTools} /> + +
+
+ + + + - -
+
) } diff --git a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx index d8b7ecbde..193dda08d 100644 --- a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx +++ b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/components/DappRegistryGrid.tsx @@ -30,7 +30,7 @@ import { useHistory } from 'react-router' import type { RegistryItem } from '../types' import { PageInput } from './PageInput' - +const TAG = ' | DappRegistryGrid.tsx | ' const PAGE_SIZE = 20 const loadingImg = kkIconBlack @@ -106,8 +106,11 @@ export const DappRegistryGrid: FC = () => { const openDapp = useCallback( (app: RegistryItem) => { - dispatch({ type: WalletActions.SET_BROWSER_URL, payload: app.homepage }) + console.log(TAG,'openDapp app: ', app) history.push('/browser') + setTimeout(() => { + dispatch({ type: WalletActions.SET_BROWSER_URL, payload: app.homepage }) + }, 2000) }, [dispatch, history], ) diff --git a/packages/keepkey-desktop/package.json b/packages/keepkey-desktop/package.json index 962e8ef21..ab7bec717 100644 --- a/packages/keepkey-desktop/package.json +++ b/packages/keepkey-desktop/package.json @@ -1,6 +1,6 @@ { "name": "keepkey-desktop", - "version": "3.0.27", + "version": "3.0.28", "author": { "name": "KeepKey", "email": "support@keepkey.com"