@@ -26,6 +26,8 @@ import {PrivateKey, PublicKey, UInt64} from '@wharfkit/antelope'
2626import { sealMessage } from '@wharfkit/sealed-messages'
2727import WebSocket from 'isomorphic-ws'
2828
29+ import defaultTranslations from './translations'
30+
2931interface WebAuthenticatorOptions {
3032 /** The URL of the web authenticator service */
3133 webAuthenticatorUrl ?: string
@@ -79,6 +81,11 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
7981 return 'web-authenticator'
8082 }
8183
84+ /**
85+ * The translations for this plugin
86+ */
87+ translations = defaultTranslations
88+
8289 /**
8390 * Opens a popup window with the given URL and waits for it to complete
8491 */
@@ -93,17 +100,10 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
93100 // Show status message using WharfKit UI
94101 ui ?. status ( 'Opening authenticator popup...' )
95102
96- const popup = window . open ( url , 'Web Authenticator' , 'width=450,height=750' )
103+ let popup : Window | null = window . open ( url , 'Web Authenticator' , 'width=450,height=750' )
97104
98105 if ( ! popup ) {
99- this . manualPopupShown = true
100- return this . showManualPopupPrompt ( url , receiveOptions , ui )
101- . then ( ( response ) => {
102- resolve ( response )
103- } )
104- . catch ( ( error ) => {
105- reject ( error )
106- } )
106+ throw new Error ( 'Popup blocked - please enable popups for this site' )
107107 }
108108
109109 // Update status
@@ -113,6 +113,29 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
113113 elements : [ ] ,
114114 } )
115115
116+ const checkClosed = setInterval ( ( ) => {
117+ if ( popup ?. closed ) {
118+ clearInterval ( checkClosed )
119+ ui ?. status ( 'Transaction cancelled' )
120+ reject ( new Error ( 'Transaction cancelled by user' ) )
121+ }
122+ } , 1000 )
123+
124+ waitForCallback ( receiveOptions , this . buoyWs , t )
125+ . then ( ( response ) => {
126+ resolve ( { payload : response } )
127+ } )
128+ . catch ( ( error ) => {
129+ reject ( error )
130+ } )
131+
132+ // Update status
133+ ui ?. prompt ( {
134+ title : 'Approve' ,
135+ body : 'Please approve the transaction in the popup that just opened' ,
136+ elements : [ ] ,
137+ } )
138+
116139 const checkClosedInterval = setInterval ( ( ) => {
117140 if ( popup ?. closed ) {
118141 clearInterval ( checkClosedInterval )
@@ -275,7 +298,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
275298
276299 const signUrl = `${ this . webAuthenticatorUrl } /sign?sealed=${ sealedRequest . toString (
277300 'hex'
278- ) } &nonce=${ nonce . toString ( ) } &chain=${ context . chain ?. name } &accountName=${
301+ ) } &nonce=${ nonce . toString ( ) } &chain=${ context . chain ?. id } &accountName=${
279302 context . accountName
280303 } &permissionName=${ context . permissionName } &appName=${
281304 context . appName
0 commit comments