Skip to content

Commit

Permalink
change wc protocol (#655)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
amitojsingh366 authored Jun 30, 2023
1 parent 2bf3b39 commit 3930c1e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export const WalletConnectBridgeProvider: FC<PropsWithChildren> = ({ children })
} else {
let protocolUrl = await ipcListeners.getProtocolLaunchUrl()
if (protocolUrl) {
protocolUrl = protocolUrl.replace('keepkey://', '')
if (protocolUrl.includes('wc')) {
connectWithUri(protocolUrl)
}
Expand Down
14 changes: 11 additions & 3 deletions packages/keepkey-desktop/src/appListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(resolve => {
Expand All @@ -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) {
Expand All @@ -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)
}
}
})

Expand Down
4 changes: 2 additions & 2 deletions packages/keepkey-desktop/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=', ''))
}
Expand Down
5 changes: 1 addition & 4 deletions packages/keepkey-desktop/src/ipcListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3930c1e

Please sign in to comment.