Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wharfkit/wallet-plugin-web-authenticator",
"description": "A Web Authenticator wallet plugin for use with @wharfkit/session.",
"version": "0.5.1",
"version": "0.5.2",
"homepage": "https://github.com/wharfkit/wallet-plugin-web-authenticator",
"license": "BSD-3-Clause",
"main": "lib/wallet-plugin-web-authenticator.js",
Expand Down
27 changes: 17 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ import WebSocket from 'isomorphic-ws'

import defaultTranslations from './translations'

export function openPopupWindow(url: string): Window | null {
const width = 450
const height = 750
const left = Math.round(window.screenX + (window.outerWidth - width) / 2)
const top = Math.round(window.screenY + (window.outerHeight - height) / 2)
return window.open(
url,
'web-authenticator',
`width=${width},height=${height},left=${left},top=${top}`
)
}

export function openWallet(url: string): Window | null {
return openPopupWindow(url)
}

interface WebAuthenticatorOptions {
/** The URLs for the web authenticator service, keyed by chain ID */
urls: Record<string, string>
Expand Down Expand Up @@ -117,16 +133,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
// Show status message using WharfKit UI
ui?.status('Opening wallet window...')

const popupWidth = 450
const popupHeight = 750
const left = Math.round(window.screenX + (window.outerWidth - popupWidth) / 2)
const top = Math.round(window.screenY + (window.outerHeight - popupHeight) / 2)

const popup: Window | null = window.open(
url,
'Web Authenticator',
`width=${popupWidth},height=${popupHeight},left=${left},top=${top}`
)
const popup = openPopupWindow(url)

if (!popup) {
return this.showManualPopupPrompt(url, receiveOptions, ui)
Expand Down