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(/^\//, '');
|
path = path.replace(/^\//, '');
|
||||||
if (!routes[path]) {
|
if (!routes[path]) {
|
||||||
path = 'home';
|
path = 'home';
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await handleLocation(path);
|
await handleLocation(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleLocation(path: string) {
|
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 routeHtml = routes[path] || routes['home'];
|
||||||
|
|
||||||
const content = document.getElementById('containerId');
|
const content = document.getElementById('containerId');
|
||||||
@ -41,17 +37,6 @@ async function handleLocation(path: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.onpopstate = () => handleLocation('home');
|
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> {
|
async function init(): Promise<boolean> {
|
||||||
let isPaired = false;
|
let isPaired = false;
|
||||||
@ -78,18 +63,18 @@ async function init(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
if (services.isPaired()) {
|
if (services.isPaired()) {
|
||||||
isPaired = true;
|
isPaired = true;
|
||||||
|
console.log("🚀 ~ setTimeout ~ isPaired:", isPaired)
|
||||||
await navigate('process');
|
await navigate('process');
|
||||||
}
|
return isPaired
|
||||||
else {
|
} else {
|
||||||
const queryString = window.location.search;
|
const queryString = window.location.search;
|
||||||
const urlParams = new URLSearchParams(queryString)
|
const urlParams = new URLSearchParams(queryString)
|
||||||
const pairingAddress = urlParams.get('sp_address')
|
const pairingAddress = urlParams.get('sp_address')
|
||||||
if(pairingAddress) {
|
if(pairingAddress) {
|
||||||
setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000)
|
setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return isPaired
|
return isPaired
|
||||||
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -100,5 +85,7 @@ return isPaired
|
|||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const isPaired = await init()
|
||||||
|
console.log("🚀 ~ handleLocation ~ isPaired:", isPaired)
|
||||||
await navigate('home');
|
await navigate('home');
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user