@@ -39,7 +39,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
3939 private webAuthenticatorUrl : string
4040 private buoyServiceUrl : string
4141 private buoyWs ?: WebSocket
42- private static promptCount = 0
42+ private manualPopupShown = false
4343
4444 constructor ( options : WebAuthenticatorOptions = { } ) {
4545 super ( )
@@ -88,62 +88,45 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
8888 ui ?: UserInterface
8989 ) : Promise < { payload : CallbackPayload } > {
9090 return new Promise ( ( resolve , reject ) => {
91- try {
92- // Show status message using WharfKit UI
93- ui ?. status ( 'Opening authenticator popup...' )
91+ // Show status message using WharfKit UI
92+ ui ?. status ( 'Opening authenticator popup...' )
9493
95- const t = ui ?. getTranslate ( this . id )
94+ const t = ui ?. getTranslate ( this . id )
9695
97- let popup : Window | null = null
96+ const popup = window . open ( url , 'Web Authenticator' , 'width=450,height=750' )
9897
99- popup = window . open ( url , 'Web Authenticator' , 'width=450,height=750' )
100-
101- if ( ! popup ) {
102- throw new Error ( 'Popup blocked - please enable popups for this site' )
103- }
104-
105- // Update status
106- const prompt = ui ?. prompt ( {
107- title : 'Approve' ,
108- body : 'Please approve the transaction in the popup that just opened' ,
109- elements : [ ] ,
110- } )
111-
112- waitForCallback ( receiveOptions , this . buoyWs , t )
98+ if ( ! popup ) {
99+ this . manualPopupShown = true
100+ return this . showManualPopupPrompt ( url , receiveOptions , ui )
113101 . then ( ( response ) => {
114- popup ?. close ( )
115- ui ?. status ( 'Transaction approved successfully' )
116- // Reset the prompt count on successful completion
117- WalletPluginWebAuthenticator . promptCount = 0
118- resolve ( { payload : response } )
102+ resolve ( response )
119103 } )
120- . catch ( ( ) => {
121- popup ?. close ( )
122- ui ?. status ( 'Transaction cancelled' )
123- reject ( new Error ( 'Transaction cancelled by user' ) )
104+ . catch ( ( error ) => {
105+ reject ( error )
124106 } )
125- } catch ( error ) {
126- // Show prompt only once, then just show the error
127- if ( WalletPluginWebAuthenticator . promptCount === 0 ) {
128- WalletPluginWebAuthenticator . promptCount ++
129-
130- this . showManualPopupPrompt ( url , receiveOptions , ui )
131- . then ( ( response ) => {
132- resolve ( response )
133- } )
134- . catch ( ( error ) => {
135- reject ( error )
136- } )
137- } else {
138- // Just show the error directly after the first prompt
139- const errorMessage = error instanceof Error ? error . message : String ( error )
140- ui ?. status ( errorMessage )
141- reject ( error instanceof Error ? error : new Error ( String ( error ) ) )
142- }
143- } finally {
144- // Reset the prompt count on successful completion
145- WalletPluginWebAuthenticator . promptCount = 0
146107 }
108+
109+ // Update status
110+ ui ?. prompt ( {
111+ title : 'Approve' ,
112+ body : 'Please approve the transaction in the popup that just opened' ,
113+ elements : [ ] ,
114+ } )
115+
116+ waitForCallback ( receiveOptions , this . buoyWs , t )
117+ . then ( ( response ) => {
118+ popup ?. close ( )
119+ ui ?. status ( 'Transaction approved successfully' )
120+ resolve ( { payload : response } )
121+ } )
122+ . catch ( ( ) => {
123+ popup ?. close ( )
124+ ui ?. status ( 'Transaction cancelled' )
125+ reject ( new Error ( 'Transaction cancelled by user' ) )
126+ } )
127+ . finally ( ( ) => {
128+ this . manualPopupShown = false
129+ } )
147130 } )
148131 }
149132
0 commit comments