@@ -78,6 +78,8 @@ let currentState = States.DISCONNECTED
7878let walletAddress = null
7979let eventSource = null
8080const requestQueue = new Map ( )
81+ let isWalletDetected = false
82+ let isWalletDetectionLogged = false
8183
8284// eslint-disable-next-line no-undef
8385const arweave = Arweave . init ( {
@@ -270,6 +272,18 @@ async function sendResponse(id, result, error = null) {
270272 } )
271273}
272274
275+ async function sendWalletInfo ( walletName , walletVersion ) {
276+ try {
277+ await fetch ( '/wallet-info' , {
278+ method : 'POST' ,
279+ headers : { 'Content-Type' : 'application/json' } ,
280+ body : JSON . stringify ( { name : walletName , version : walletVersion } ) ,
281+ } )
282+ } catch ( error ) {
283+ console . error ( 'Failed to send wallet info:' , error )
284+ }
285+ }
286+
273287/**
274288 * Check if a wallet API method is supported
275289 * @param {string } methodName - The name of the wallet API method to check
@@ -689,21 +703,46 @@ function startEventStream() {
689703}
690704
691705// ==================== Initialization ====================
692- window . addEventListener ( 'load' , ( ) => {
693- cacheDOMElements ( )
694- initTheme ( )
695- startEventStream ( )
706+ async function handleWalletDetection ( ) {
707+ if ( isWalletDetected && isWalletDetectionLogged ) return
696708
697- setTimeout ( ( ) => {
698- if ( window . arweaveWallet ) {
699- log ( `${ window . arweaveWallet ?. name || 'Arweave' } wallet extension detected. Waiting for connection request...` )
700- setState ( States . DISCONNECTED , '⏳ Waiting for connection request...' )
701- } else {
709+ if ( ! window . arweaveWallet ) {
710+ if ( dom . log && ! isWalletDetectionLogged ) {
702711 setState (
703712 States . ERROR ,
704713 'No Arweave wallet extension detected<br><small>Please install Wander or any other compatible wallet and refresh this page</small>' ,
705714 )
706715 log ( 'Please install Wander or any other compatible wallet extension' , 'error' )
716+ isWalletDetectionLogged = true
707717 }
708- } , 500 )
718+ return
719+ }
720+
721+ const name = window . arweaveWallet ?. walletName || 'Unknown Wallet'
722+ const version = window . arweaveWallet ?. walletVersion || '1.0.0'
723+
724+ if ( dom . log && ! isWalletDetectionLogged ) {
725+ log ( `${ name } (v${ version } ) detected. Waiting for connection request...` )
726+ setState ( States . DISCONNECTED , '⏳ Waiting for connection request...' )
727+ isWalletDetectionLogged = true
728+ }
729+
730+ if ( isWalletDetected ) return
731+ isWalletDetected = true
732+ await sendWalletInfo ( name , version )
733+ }
734+
735+ // Initialize on load
736+ window . addEventListener ( 'load' , ( ) => {
737+ cacheDOMElements ( )
738+ initTheme ( )
739+ startEventStream ( )
740+
741+ if ( window . arweaveWallet ) {
742+ handleWalletDetection ( )
743+ } else {
744+ setTimeout ( handleWalletDetection , 500 )
745+ }
709746} )
747+
748+ window . addEventListener ( 'arweaveWalletLoaded' , handleWalletDetection )
0 commit comments