diff --git a/src/router.ts b/src/router.ts index a8169ac..60a0893 100644 --- a/src/router.ts +++ b/src/router.ts @@ -11,16 +11,12 @@ export async function navigate(path: string) { path = path.replace(/^\//, ''); if (!routes[path]) { path = 'home'; - } else { } await handleLocation(path); } async function handleLocation(path: string) { - const isPaired = await init() - console.log("🚀 ~ handleLocation ~ isPaired:", isPaired) - // if(!isPaired) path = 'home' const routeHtml = routes[path] || routes['home']; const content = document.getElementById('containerId'); @@ -41,17 +37,6 @@ async function handleLocation(path: string) { } window.onpopstate = () => handleLocation('home'); -window.onclick = (event: MouseEvent) => { - const target = event.target as HTMLElement; - if (target.tagName === 'A') { - event.preventDefault(); - const path = target.getAttribute('href'); - if (path) { - navigate(path); - } - } -}; - async function init(): Promise { let isPaired = false; @@ -78,18 +63,18 @@ async function init(): Promise { } if (services.isPaired()) { isPaired = true; + console.log("🚀 ~ setTimeout ~ isPaired:", isPaired) await navigate('process'); - } - else { + return isPaired + } else { const queryString = window.location.search; const urlParams = new URLSearchParams(queryString) const pairingAddress = urlParams.get('sp_address') if(pairingAddress) { setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000) } + return isPaired } - return isPaired - }, 200); } catch (error) { console.error(error); @@ -100,5 +85,7 @@ return isPaired } (async () => { + const isPaired = await init() + console.log("🚀 ~ handleLocation ~ isPaired:", isPaired) await navigate('home'); })();