@@ -34,8 +34,6 @@ import {
3434 BROWSER_TIMEOUT ,
3535 DEFAULT_HOST ,
3636 DEFAULT_PORT ,
37- HEARTBEAT_CHECK_INTERVAL ,
38- HEARTBEAT_TIMEOUT ,
3937 REQUEST_TIMEOUT ,
4038 SHUTDOWN_DELAY ,
4139} from './constants'
@@ -60,8 +58,6 @@ export class NodeArweaveWallet {
6058
6159 private address : string | null = null
6260 private browserConnected = false
63- private lastHeartbeat = Date . now ( )
64- private heartbeatInterval : NodeJS . Timeout | null = null
6561 private complete = false
6662
6763 constructor ( config : NodeArweaveWalletConfig = { } ) {
@@ -99,7 +95,6 @@ export class NodeArweaveWallet {
9995 console . log ( '📱 Opening browser for wallet connection...\n' )
10096
10197 this . openBrowser ( `http://localhost:${ this . port } ` )
102- this . startHeartbeatChecker ( )
10398
10499 resolve ( )
105100 } )
@@ -760,11 +755,6 @@ export class NodeArweaveWallet {
760755 this . markComplete ( status )
761756 }
762757
763- if ( this . heartbeatInterval ) {
764- clearInterval ( this . heartbeatInterval )
765- this . heartbeatInterval = null
766- }
767-
768758 await new Promise ( resolve => setTimeout ( resolve , SHUTDOWN_DELAY ) )
769759
770760 // Close SSE connection if open
@@ -784,31 +774,6 @@ export class NodeArweaveWallet {
784774 }
785775
786776 // ==================== Private Methods ====================
787- private startHeartbeatChecker ( ) : void {
788- this . heartbeatInterval = setInterval ( ( ) => {
789- const timeSinceLastHeartbeat = Date . now ( ) - this . lastHeartbeat
790-
791- // Only check if we have pending requests - no need to check if nothing is pending
792- if ( this . browserConnected && this . pendingRequests . size > 0 && timeSinceLastHeartbeat > HEARTBEAT_TIMEOUT ) {
793- const timeoutMinutes = Math . floor ( HEARTBEAT_TIMEOUT / 60000 )
794- console . log ( `\n⚠️ Browser connection timeout - no response for ${ timeoutMinutes } minutes` )
795- console . log ( '💡 The browser tab may have been closed.' )
796- console . log ( '💡 Tip: Keep the browser window open while signing transactions.' )
797- this . browserConnected = false
798-
799- // Reject pending requests with a helpful error message
800- for ( const [ id , pending ] of this . pendingRequests . entries ( ) ) {
801- pending . reject (
802- new Error (
803- `Browser connection timeout after ${ timeoutMinutes } minutes. ` +
804- 'Please ensure the browser window stays open during signing operations.' ,
805- ) ,
806- )
807- this . pendingRequests . delete ( id )
808- }
809- }
810- } , HEARTBEAT_CHECK_INTERVAL )
811- }
812777
813778 private handleRequest ( req : http . IncomingMessage , res : http . ServerResponse ) : void {
814779 this . setCORSHeaders ( res )
@@ -857,7 +822,6 @@ export class NodeArweaveWallet {
857822 } )
858823
859824 // Mark browser as connected
860- this . lastHeartbeat = Date . now ( )
861825 if ( ! this . browserConnected ) {
862826 this . browserConnected = true
863827 }
@@ -877,7 +841,7 @@ export class NodeArweaveWallet {
877841 }
878842 }
879843
880- // Handle client disconnect
844+ // Handle client disconnect - this fires immediately when browser tab closes
881845 res . on ( 'close' , ( ) => {
882846 if ( this . sseClient === res ) {
883847 this . sseClient = null
@@ -950,14 +914,13 @@ export class NodeArweaveWallet {
950914
951915 private async waitForBrowserConnection ( timeout = BROWSER_TIMEOUT ) : Promise < void > {
952916 const startTime = Date . now ( )
953- const initialHeartbeat = this . lastHeartbeat
954917 const checkInterval = 100 // Check every 100ms
955918
956- while ( this . lastHeartbeat === initialHeartbeat && Date . now ( ) - startTime < timeout ) {
919+ while ( ! this . browserConnected && Date . now ( ) - startTime < timeout ) {
957920 await new Promise ( resolve => setTimeout ( resolve , checkInterval ) )
958921 }
959922
960- if ( this . lastHeartbeat === initialHeartbeat ) {
923+ if ( ! this . browserConnected ) {
961924 throw new Error ( 'Browser page not responding. Please ensure the browser window is open.' )
962925 }
963926
@@ -1033,8 +996,8 @@ export class NodeArweaveWallet {
1033996 const __filename = fileURLToPath ( import . meta. url )
1034997 const __dirname = dirname ( __filename )
1035998
1036- const htmlPath = join ( __dirname , 'signer.html' )
1037- const jsPath = join ( __dirname , 'signer.js' )
999+ const htmlPath = join ( __dirname , 'signer' , 'signer .html')
1000+ const jsPath = join ( __dirname , 'signer' , 'signer .js')
10381001
10391002 const html = readFileSync ( htmlPath , 'utf-8' )
10401003 const js = readFileSync ( jsPath , 'utf-8' )
0 commit comments