@@ -40,11 +40,11 @@ export default function Home() {
40
40
const exists = protoNames . get ( conn . remotePeer . toString ( ) )
41
41
const dedupedProtonames = [ ...new Set ( conn . remoteAddr . protoNames ( ) ) ]
42
42
43
- if ( exists ) {
44
- const namesToAdd = exists . filter (
45
- ( name ) => ! dedupedProtonames . includes ( name ) ,
46
- )
43
+ if ( exists ?. length ) {
44
+ const namesToAdd = dedupedProtonames . filter ( ( name ) => ! exists . includes ( name ) )
45
+ console . log ( 'namesToAdd: ' , namesToAdd )
47
46
protoNames . set ( conn . remotePeer . toString ( ) , [ ...exists , ...namesToAdd ] )
47
+
48
48
} else {
49
49
protoNames . set ( conn . remotePeer . toString ( ) , dedupedProtonames )
50
50
}
@@ -109,60 +109,65 @@ export default function Home() {
109
109
</ div >
110
110
</ header >
111
111
< main >
112
- < div className = "my-6 w-1/2" >
113
- < label
114
- htmlFor = "peer-id"
115
- className = "block text-sm font-medium leading-6 text-gray-900"
116
- >
117
- multiaddr to connect to
118
- </ label >
119
- < div className = "mt-2" >
120
- < input
121
- value = { maddr }
122
- type = "text"
123
- name = "peer-id"
124
- id = "peer-id"
125
- className = "block w-full rounded-md border-0 py-1.5 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
126
- placeholder = "12D3Koo..."
127
- aria-describedby = "multiaddr-id-description"
128
- onChange = { handleMultiaddrChange }
129
- />
112
+ < div className = "mx-auto max-w-7xl px-4 sm:px-6 lg:px-8" >
113
+ < ul className = "my-2 space-y-2 break-all" >
114
+ < li className = "" > This PeerID: { libp2p . peerId . toString ( ) } </ li >
115
+ </ ul >
116
+ < div className = "my-6 w-1/2" >
117
+ < label
118
+ htmlFor = "peer-id"
119
+ className = "block text-sm font-medium leading-6 text-gray-900"
120
+ >
121
+ multiaddr to connect to
122
+ </ label >
123
+ < div className = "mt-2" >
124
+ < input
125
+ value = { maddr }
126
+ type = "text"
127
+ name = "peer-id"
128
+ id = "peer-id"
129
+ className = "block w-full rounded-md border-0 py-1.5 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
130
+ placeholder = "12D3Koo..."
131
+ aria-describedby = "multiaddr-id-description"
132
+ onChange = { handleMultiaddrChange }
133
+ />
134
+ </ div >
135
+ < button
136
+ type = "button"
137
+ className = "rounded-md bg-indigo-600 my-2 py-2 px-3 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
138
+ onClick = { handleConnectToMultiaddr }
139
+ >
140
+ Connect to multiaddr
141
+ </ button >
130
142
</ div >
131
- < button
132
- type = "button"
133
- className = "rounded-md bg-indigo-600 my-2 py-2 px-3 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
134
- onClick = { handleConnectToMultiaddr }
135
- >
136
- Connect to multiaddr
137
- </ button >
138
- </ div >
139
143
140
144
141
- < div className = "my-4 inline-flex items-center text-xl" >
142
- Connected:{ ' ' }
143
- { peerStats . connected ? (
144
- < CheckCircleIcon className = "inline w-6 h-6 text-green-500" />
145
- ) : (
146
- < XCircleIcon className = "w-6 h-6 text-red-500" />
147
- ) }
148
- </ div >
149
- < div >
150
- { peerStats . peerIds . length > 0 ? (
151
- < >
152
- < h3 className = "text-xl" >
153
- { ' ' }
154
- Connected peers ({ getFormattedConnections ( peerStats . connections ) . length } ) 👇
155
- </ h3 >
156
- < pre className = "px-2" >
157
- { getFormattedConnections ( peerStats . connections )
158
- . map (
159
- ( pair ) =>
160
- `${ pair . peerId } (${ pair . protocols . join ( ', ' ) } )` ,
161
- )
162
- . join ( '\n' ) }
163
- </ pre >
164
- </ >
165
- ) : null }
145
+ < div className = "my-4 inline-flex items-center text-xl" >
146
+ Connected:{ ' ' }
147
+ { peerStats . connected ? (
148
+ < CheckCircleIcon className = "inline w-6 h-6 text-green-500" />
149
+ ) : (
150
+ < XCircleIcon className = "w-6 h-6 text-red-500" />
151
+ ) }
152
+ </ div >
153
+ < div >
154
+ { peerStats . peerIds . length > 0 ? (
155
+ < >
156
+ < h3 className = "text-xl" >
157
+ { ' ' }
158
+ Connected peers ({ getFormattedConnections ( peerStats . connections ) . length } ) 👇
159
+ </ h3 >
160
+ < pre className = "px-2" >
161
+ { getFormattedConnections ( peerStats . connections )
162
+ . map (
163
+ ( pair ) =>
164
+ `${ pair . peerId } (${ pair . protocols . join ( ', ' ) } )` ,
165
+ )
166
+ . join ( '\n' ) }
167
+ </ pre >
168
+ </ >
169
+ ) : null }
170
+ </ div >
166
171
</ div >
167
172
</ main >
168
173
</ div >
0 commit comments