put subscription to event in a list to clean them properly
This commit is contained in:
parent
4a59424d05
commit
41b3ba552f
@ -40,7 +40,8 @@ export async function initHeader() {
|
||||
if (currentRoute === 'home') {
|
||||
hideSomeFunctionnalities();
|
||||
} else {
|
||||
launchNotificationWorker()
|
||||
fetchNotifications()
|
||||
setInterval(fetchNotifications, 2 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,19 +81,9 @@ async function setNotification(notifications: INotification[]): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function launchNotificationWorker() {
|
||||
if (window.Worker) {
|
||||
// Initialize the worker
|
||||
const worker = new Worker('/src/workers/notification.worker.ts', { type: 'module' });
|
||||
|
||||
// Listen for messages from the worker
|
||||
worker.addEventListener('message', (event) => {
|
||||
const data = event.data;
|
||||
console.log('Received data from worker:', data);
|
||||
setNotification(data);
|
||||
});
|
||||
} else {
|
||||
console.error('Your browser doesn\'t support web workers.');
|
||||
}
|
||||
async function fetchNotifications() {
|
||||
const service = await Services.getInstance()
|
||||
const data = service.getNotifications();
|
||||
setNotification(data)
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { Html5QrcodeScanner } from 'html5-qrcode';
|
||||
import Routing from '../../services/modal.service';
|
||||
import Services from '../../services/service';
|
||||
import { addSubscription } from '../../utils/subscription.utils';
|
||||
import { displayEmojis } from '../../utils/sp-address.utils';
|
||||
import { displayEmojis, generateQRCode } from '../../utils/sp-address.utils';
|
||||
|
||||
let resultContainer = document.getElementById('qr-reader-results');
|
||||
let lastResult: any,
|
||||
@ -11,18 +11,18 @@ let lastResult: any,
|
||||
export async function initHomePage(): Promise<void> {
|
||||
console.log('INIT');
|
||||
document.querySelectorAll('.tab').forEach((tab) => {
|
||||
tab.addEventListener('click', () => {
|
||||
addSubscription(tab, 'click', () => {
|
||||
document.querySelectorAll('.tab').forEach((t) => t.classList.remove('active'));
|
||||
tab.classList.add('active');
|
||||
|
||||
document.querySelectorAll('.tab-content').forEach((content) => content.classList.remove('active'));
|
||||
document.getElementById(tab.getAttribute('data-tab') as string)?.classList.add('active');
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
const service = await Services.getInstance();
|
||||
const spAddress = await service.getDeviceAddress()
|
||||
service.generateQRCode(spAddress)
|
||||
generateQRCode(spAddress)
|
||||
displayEmojis(spAddress)
|
||||
|
||||
const notifBell = document.getElementById('notification-bell')
|
||||
|
@ -88,7 +88,7 @@ async function init(): Promise<void> {
|
||||
if (pairingAddress) {
|
||||
setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000);
|
||||
}
|
||||
await navigate('process');
|
||||
await navigate('home');
|
||||
}
|
||||
}, 200);
|
||||
} catch (error) {
|
||||
|
@ -9,7 +9,6 @@ import { addressToEmoji } from '../utils/sp-address.utils';
|
||||
|
||||
export default class ModalService {
|
||||
private static instance: ModalService;
|
||||
private sdkClient: any;
|
||||
private currentPrd: any;
|
||||
private currentOutpoint?: string;
|
||||
private constructor() {}
|
||||
|
@ -3,11 +3,9 @@ import { INotification } from '~/models/notification.model';
|
||||
import { IProcess } from '~/models/process.model';
|
||||
// import Database from './database';
|
||||
import { WebSocketClient } from '../websockets';
|
||||
import QRCode from 'qrcode';
|
||||
import { ApiReturn, Member } from '../../dist/pkg/sdk_client';
|
||||
import ModalService from './modal.service';
|
||||
import { navigate } from '../router';
|
||||
import { copyToClipboard } from '../utils/sp-address.utils';
|
||||
|
||||
type ProcessesCache = {
|
||||
[key: string]: any;
|
||||
@ -67,28 +65,6 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
generateQRCode = async (text: string) => {
|
||||
try {
|
||||
const container = document.getElementById('containerId');
|
||||
const currentUrl = 'https://' + window.location.host;
|
||||
const url = await QRCode.toDataURL(currentUrl + '?sp_address=' + text);
|
||||
const qrCode = container?.querySelector('.qr-code img');
|
||||
qrCode?.setAttribute('src', url);
|
||||
|
||||
//Generate Address CopyBtn
|
||||
const address = container?.querySelector('.sp-address-btn');
|
||||
if (address) {
|
||||
address.textContent = 'Copy address';
|
||||
}
|
||||
const copyBtn = document.getElementById('copyBtn');
|
||||
if (copyBtn) {
|
||||
copyBtn.addEventListener('click', () => copyToClipboard(currentUrl + '?sp_address=' + text));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
|
||||
public isPaired(): boolean | undefined {
|
||||
try {
|
||||
return this.sdkClient.is_linking();
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Services from "../services/service";
|
||||
import { addSubscription } from "./subscription.utils";
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
//Copy Address
|
||||
export async function copyToClipboard(fullAddress: string) {
|
||||
@ -139,7 +140,7 @@ async function emojisPairingRequest() {
|
||||
})
|
||||
|
||||
if (okButton) {
|
||||
okButton.addEventListener('click', () => {
|
||||
addSubscription(okButton, 'click', () => {
|
||||
onOkButtonClick();
|
||||
});
|
||||
}
|
||||
@ -150,3 +151,25 @@ async function onOkButtonClick() {
|
||||
const addressInput = (document.getElementById('addressInput') as HTMLInputElement).value;
|
||||
await service.sendPairingTx(addressInput);
|
||||
}
|
||||
|
||||
export async function generateQRCode(spAddress: string) {
|
||||
try {
|
||||
const container = document.getElementById('containerId');
|
||||
const currentUrl = 'https://' + window.location.host;
|
||||
const url = await QRCode.toDataURL(currentUrl + '?sp_address=' + spAddress);
|
||||
const qrCode = container?.querySelector('.qr-code img');
|
||||
qrCode?.setAttribute('src', url);
|
||||
|
||||
//Generate Address CopyBtn
|
||||
const address = container?.querySelector('.sp-address-btn');
|
||||
if (address) {
|
||||
address.textContent = 'Copy address';
|
||||
}
|
||||
const copyBtn = document.getElementById('copyBtn');
|
||||
if (copyBtn) {
|
||||
addSubscription(copyBtn, 'click', () => copyToClipboard(currentUrl + '?sp_address=' + spAddress))
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user