11import { shorten } from '@did-network/dapp-sdk'
22import { useAccount , useConnect , useDisconnect , useNetwork } from 'wagmi'
33import { sendMessage } from 'webext-bridge/popup'
4+ import browser from 'webextension-polyfill'
45
56import type { Peer } from '../background/utils'
67import CircProgressBar from './CircProgressBar'
@@ -40,6 +41,13 @@ export const Status = ({
4041
4142 const [ peers , setPeers ] = useState < Peer [ ] > ( [ ] )
4243 const [ serviceNodes , setServiceNodes ] = useState < string [ ] > ( [ ] )
44+
45+ const forceReset = async ( ) => {
46+ await browser . storage . local . clear ( )
47+ await browser . storage . sync . clear ( )
48+ await browser . runtime . reload ( )
49+ }
50+
4351 const getPeers = useCallback ( async ( ) => {
4452 const res = await sendMessage ( 'get-peers' , null )
4553
@@ -58,6 +66,14 @@ export const Status = ({
5866 }
5967 } , [ getPeers ] )
6068
69+ // return status of connected node
70+ const connectedNodeStatus = ( ) => {
71+ if ( ! status ) return 'offline'
72+ if ( ! status . swarm ) return 'offline'
73+ if ( status . swarm ?. connections == 0 ) return 'offline'
74+ return status . swarm . connections [ 0 ] . state
75+ }
76+
6177 // This function will read global values.
6278 // connect status of PKI (E.g Metamask)
6379 const PKIConnectStatus = ( { className } : { className : string } ) => {
@@ -140,9 +156,7 @@ export const Status = ({
140156 < div className = "p-2.5 flex items-center justify-between text-xs border-solid border-b border-gray-300" >
141157 < span className = { `scale-80 origin-left` } >
142158 Network Status:{ ' ' }
143- < span className = { `${ clients . length ? 'text-#15CD96' : 'text-#fb7185 ' } ` } >
144- { clients . length ? `online` : 'offline' }
145- </ span >
159+ < span className = { `${ clients . length ? 'text-#15CD96' : 'text-#fb7185 ' } ` } > { connectedNodeStatus ( ) } </ span >
146160 </ span >
147161 < span
148162 className = "flex-1 text-right scale-80 origin-right cursor-pointer transition-all hover:translate-x-.25 underline underline-current"
@@ -210,6 +224,16 @@ export const Status = ({
210224 Configure
211225 </ span >
212226 </ div >
227+ < div className = "p-2.5 flex items-center justify-between text-xs border-solid border-t border-gray-300" >
228+ < span
229+ onClick = { ( ) => {
230+ forceReset ( )
231+ } }
232+ className = "cursor-pointer scale-80 origin-left transition-all hover:translate-x-.25 underline underline-current"
233+ >
234+ Force Reset
235+ </ span >
236+ </ div >
213237 </ div >
214238 )
215239 }
@@ -225,11 +249,7 @@ export const Status = ({
225249 clients . length ? 'text-red i-eos-icons:molecules' : 'text-gray i-eos-icons:molecules-outlined'
226250 } ${ loading ? 'scale-x-0' : '' } `}
227251 onClick = { ( ) => {
228- if ( ! clients . length ) {
229- connectHandler ( )
230- } else {
231- setShowModal ( ! showModal )
232- }
252+ setShowModal ( ! showModal )
233253 } }
234254 > </ span >
235255 < span
@@ -242,7 +262,7 @@ export const Status = ({
242262 )
243263 }
244264
245- const RingsBtn = ( ) => {
265+ const RingsBtn = ( { clients } : { clients : any [ ] } ) => {
246266 return (
247267 < div >
248268 < CircProgressBar
@@ -340,7 +360,7 @@ export const Status = ({
340360 < div className = "w-358px h-550px flex-col-center font-pixel antialiased" >
341361 < div className = "w-full h-full" >
342362 < Nav />
343- { currentTab === 'main' && < RingsBtn /> }
363+ { currentTab === 'main' && < RingsBtn clients = { clients } /> }
344364 { currentTab === 'config' && < ConfigFields /> }
345365 { currentTab === 'status' && < ConnectStatus /> }
346366 < TabBar />
0 commit comments