From 3930c1e34527384d87bd839ef47a2d47399c35fe Mon Sep 17 00:00:00 2001 From: Amitoj Singh Date: Fri, 30 Jun 2023 03:11:44 +0300 Subject: [PATCH] change wc protocol (#655) * allow pairing with solana but reject and clear pairings * implement basic window.ethereum * make it dynamic * fix gas issue * wc improvements * update wc protocol * fix conflicts --- .../WalletConnectBridgeProvider.tsx | 1 - packages/keepkey-desktop/src/appListeners.ts | 14 +++++++++++--- packages/keepkey-desktop/src/helpers/utils.ts | 4 ++-- packages/keepkey-desktop/src/ipcListeners.ts | 5 +---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/WalletConnectBridgeProvider.tsx b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/WalletConnectBridgeProvider.tsx index dddef32fd..3fb993729 100644 --- a/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/WalletConnectBridgeProvider.tsx +++ b/packages/keepkey-desktop-app/src/plugins/walletConnectToDapps/WalletConnectBridgeProvider.tsx @@ -172,7 +172,6 @@ export const WalletConnectBridgeProvider: FC = ({ children }) } else { let protocolUrl = await ipcListeners.getProtocolLaunchUrl() if (protocolUrl) { - protocolUrl = protocolUrl.replace('keepkey://', '') if (protocolUrl.includes('wc')) { connectWithUri(protocolUrl) } diff --git a/packages/keepkey-desktop/src/appListeners.ts b/packages/keepkey-desktop/src/appListeners.ts index e0557d537..84095dcaa 100644 --- a/packages/keepkey-desktop/src/appListeners.ts +++ b/packages/keepkey-desktop/src/appListeners.ts @@ -11,7 +11,7 @@ import { walletConnectUrlInProtocolHandler, windows, } from './globalState' -import { createMainWindow } from './helpers/utils' +import { createMainWindow, getWalletConnectUri } from './helpers/utils' import { createUpdaterSplashWindow, skipUpdateCheck } from './updaterListeners' export const appReady = new Promise(resolve => { @@ -38,7 +38,11 @@ export const startAppListeners = () => { const protocolUrl = argv.find(arg => arg.startsWith('keepkey://')) if (protocolUrl) { setProtocolLaunchUrl(protocolUrl) - if (walletConnectUrlInProtocolHandler) walletConnectUrlInProtocolHandler(protocolUrl) + const wcUri = getWalletConnectUri(protocolUrl) + if (wcUri && wcUri.includes('wc')) { + setProtocolLaunchUrl(wcUri) + if (walletConnectUrlInProtocolHandler) walletConnectUrlInProtocolHandler(wcUri) + } } } if (windows.mainWindow) { @@ -57,7 +61,11 @@ export const startAppListeners = () => { e.preventDefault() if (url.startsWith('keepkey://')) { setProtocolLaunchUrl(url) - if (walletConnectUrlInProtocolHandler) walletConnectUrlInProtocolHandler(url) + const wcUri = getWalletConnectUri(url) + if (wcUri && wcUri.includes('wc')) { + setProtocolLaunchUrl(wcUri) + if (walletConnectUrlInProtocolHandler) walletConnectUrlInProtocolHandler(wcUri) + } } }) diff --git a/packages/keepkey-desktop/src/helpers/utils.ts b/packages/keepkey-desktop/src/helpers/utils.ts index b10b4a9f0..7ac086c4f 100644 --- a/packages/keepkey-desktop/src/helpers/utils.ts +++ b/packages/keepkey-desktop/src/helpers/utils.ts @@ -38,8 +38,8 @@ export const openSignTxWindow = async (signArgs: any) => { } } -export const getWallectConnectUri = (inputUri: string): string | undefined => { - const uri = inputUri.replace('keepkey://', '') +export const getWalletConnectUri = (inputUri: string): string | undefined => { + const uri = inputUri.replace('keepkey://launch/wc?uri=', '').replace('keepkey://wc?uri=', '') if (!uri.startsWith('wc')) return else return decodeURIComponent(uri.replace('wc/?uri=', '').replace('wc?uri=', '')) } diff --git a/packages/keepkey-desktop/src/ipcListeners.ts b/packages/keepkey-desktop/src/ipcListeners.ts index 72ca13f91..f87df4f78 100644 --- a/packages/keepkey-desktop/src/ipcListeners.ts +++ b/packages/keepkey-desktop/src/ipcListeners.ts @@ -354,10 +354,7 @@ export const ipcListeners: IpcListeners = { }, async handleWalletConnectUrlInProtocol(handler) { - setWalletConnectUrlInProtocolHandler(async uri => { - uri = uri.replace('keepkey://', '') - if (uri.includes('wc')) handler(uri) - }) + setWalletConnectUrlInProtocolHandler(handler) }, // async appUpdate() {