clean router ts
This commit is contained in:
parent
9b5f89ea39
commit
92ff48c9da
@ -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<boolean> {
|
||||
let isPaired = false;
|
||||
@ -78,18 +63,18 @@ async function init(): Promise<boolean> {
|
||||
}
|
||||
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
|
||||
|
||||
}
|
||||
}, 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');
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user