Address paste fix + closeConfirmationModal fix

This commit is contained in:
NicolasCantu 2024-10-24 15:19:55 +02:00
parent 126f850f9f
commit a620272dd9
3 changed files with 779 additions and 762 deletions

View File

@ -76,7 +76,7 @@ export default class Routing {
window.onclick = (event) => { window.onclick = (event) => {
const modal = document.getElementById('modal'); const modal = document.getElementById('modal');
if (event.target === modal) { if (event.target === modal) {
this.confirmPairing(); this.closeConfirmationModal();
} }
} }
} }
@ -109,6 +109,8 @@ export default class Routing {
} }
async closeConfirmationModal() { async closeConfirmationModal() {
const service = await Services.getInstance()
await service.unpairDevice()
const modal = document.getElementById('modal') const modal = document.getElementById('modal')
if (modal) modal.style.display = 'none'; if (modal) modal.style.display = 'none';
} }

View File

@ -27,10 +27,10 @@ export default class Services {
private websocketConnection: WebSocketClient | null = null; private websocketConnection: WebSocketClient | null = null;
private processes: IProcess[] | null = null; private processes: IProcess[] | null = null;
private notifications: INotification[] | null = null; private notifications: INotification[] | null = null;
private subscriptions: {element: Element; event: string; eventHandler: string;}[] = [] ; private subscriptions: { element: Element; event: string; eventHandler: string; }[] = [];
private database: any private database: any
// Private constructor to prevent direct instantiation from outside // Private constructor to prevent direct instantiation from outside
private constructor() {} private constructor() { }
// Method to access the singleton instance of Services // Method to access the singleton instance of Services
public static async getInstance(): Promise<Services> { public static async getInstance(): Promise<Services> {
@ -101,7 +101,7 @@ export default class Services {
} }
const copyBtn = document.getElementById('copyBtn'); const copyBtn = document.getElementById('copyBtn');
if (copyBtn) { if (copyBtn) {
copyBtn.addEventListener('click', () => this.copyToClipboard(text)); copyBtn.addEventListener('click', () => this.copyToClipboard(currentUrl + "?sp_address=" + text));
} }
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -158,7 +158,7 @@ export default class Services {
} }
//Get emojis from other device //Get emojis from other device
public async emojisPairingRequest () { public async emojisPairingRequest() {
try { try {
const container = document.getElementById('containerId'); const container = document.getElementById('containerId');
@ -174,7 +174,7 @@ export default class Services {
const emojiDisplay = container?.querySelector('.pairing-request'); const emojiDisplay = container?.querySelector('.pairing-request');
if (emojiDisplay) { if (emojiDisplay) {
emojiDisplay.textContent = "(Request from: " +emojis+")"; emojiDisplay.textContent = "(Request from: " + emojis + ")";
} }
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -209,8 +209,23 @@ export default class Services {
const okButton = document.getElementById('okButton'); const okButton = document.getElementById('okButton');
addressInput.addEventListener('input', async () => { addressInput.addEventListener('input', async () => {
const address = addressInput.value; let address = addressInput.value;
// Vérifie si l'adresse est une URL
try {
const url = new URL(address);
// Si c'est une URL valide, extraire le paramètre sp_address
const urlParams = new URLSearchParams(url.search);
const extractedAddress = urlParams.get('sp_address') || ''; // Prend sp_address ou une chaîne vide
if (extractedAddress) {
address = extractedAddress;
addressInput.value = address; // Met à jour l'input pour afficher uniquement l'adresse extraite
}
} catch (e) {
// Si ce n'est pas une URL valide, on garde l'adresse originale
console.log("Ce n'est pas une URL valide, on garde l'adresse originale.");
}
if (address) { if (address) {
const emojis = await this.addressToEmoji(address); const emojis = await this.addressToEmoji(address);
@ -235,7 +250,7 @@ export default class Services {
this.onOkButtonClick(); this.onOkButtonClick();
}); });
} }
} }
private async onOkButtonClick() { private async onOkButtonClick() {
const addressInput = (document.getElementById('addressInput') as HTMLInputElement).value; const addressInput = (document.getElementById('addressInput') as HTMLInputElement).value;
@ -266,7 +281,7 @@ export default class Services {
"roles": { "roles": {
"owner": { "owner": {
"members": "members":
[{sp_addresses: [myAddress, recipientAddress]}], [{ sp_addresses: [myAddress, recipientAddress] }],
"validation_rules": "validation_rules":
[ [
{ {
@ -312,7 +327,7 @@ export default class Services {
return return
} }
setTimeout( async () => { setTimeout(async () => {
const apiReturn = this.prepareProcessTx(localAddress, spAddress) const apiReturn = this.prepareProcessTx(localAddress, spAddress)
await this.handleApiReturn(apiReturn); await this.handleApiReturn(apiReturn);
}, 100) }, 100)
@ -373,7 +388,7 @@ export default class Services {
try { try {
// console.log('==============> sending txxxxxxx parser', tx) // console.log('==============> sending txxxxxxx parser', tx)
const parsedTx = await this.sdkClient.parse_new_tx(tx, 0, 0.0001) const parsedTx = await this.sdkClient.parse_new_tx(tx, 0, 0.0001)
if(parsedTx) { if (parsedTx) {
console.log("🚀 ~ Services ~ parseNewTx ~ parsedTx:", parsedTx) console.log("🚀 ~ Services ~ parseNewTx ~ parsedTx:", parsedTx)
try { try {
await this.handleApiReturn(parsedTx); await this.handleApiReturn(parsedTx);
@ -383,7 +398,7 @@ export default class Services {
console.error("Failed to update device with new tx"); console.error("Failed to update device with new tx");
} }
} }
} catch(e) { } catch (e) {
console.trace(e); console.trace(e);
} }
} }
@ -415,7 +430,7 @@ export default class Services {
} }
} }
if(apiReturn.updated_cached_msg && apiReturn.updated_cached_msg.length) { if (apiReturn.updated_cached_msg && apiReturn.updated_cached_msg.length) {
apiReturn.updated_cached_msg.forEach((msg, index) => { apiReturn.updated_cached_msg.forEach((msg, index) => {
// console.debug(`CachedMessage ${index}:`, msg); // console.debug(`CachedMessage ${index}:`, msg);
// Save the message to local storage // Save the message to local storage
@ -691,14 +706,14 @@ export default class Services {
document.head.appendChild(newScript).parentNode?.removeChild(newScript); document.head.appendChild(newScript).parentNode?.removeChild(newScript);
this.processes = await this.getProcesses(); this.processes = await this.getProcesses();
if(this.processes) { if (this.processes) {
this.setProcessesInSelectElement(this.processes) this.setProcessesInSelectElement(this.processes)
} }
} }
public async setProcessesInSelectElement(processList: any[]) { public async setProcessesInSelectElement(processList: any[]) {
const select = document.querySelector(".select-field"); const select = document.querySelector(".select-field");
if(select) { if (select) {
for (const process of processList) { for (const process of processList) {
const option = document.createElement("option"); const option = document.createElement("option");
option.setAttribute("value", process.name); option.setAttribute("value", process.name);
@ -707,11 +722,11 @@ export default class Services {
} }
} }
const optionList = document.querySelector('.autocomplete-list'); const optionList = document.querySelector('.autocomplete-list');
if(optionList) { if (optionList) {
const observer = new MutationObserver((mutations, observer) => { const observer = new MutationObserver((mutations, observer) => {
const options = optionList.querySelectorAll('li') const options = optionList.querySelectorAll('li')
if(options) { if (options) {
for(const option of options) { for (const option of options) {
this.addSubscription(option, 'click', 'showSelectedProcess') this.addSubscription(option, 'click', 'showSelectedProcess')
} }
} }
@ -730,7 +745,7 @@ export default class Services {
public async showSelectedProcess(event: MouseEvent) { public async showSelectedProcess(event: MouseEvent) {
const elem = event.target; const elem = event.target;
if(elem) { if (elem) {
const cardContent = document.querySelector(".card-content"); const cardContent = document.querySelector(".card-content");
@ -753,7 +768,7 @@ export default class Services {
this.addSubscription(zoneElement, 'click', 'goToProcessPage') this.addSubscription(zoneElement, 'click', 'goToProcessPage')
processDiv.appendChild(zoneElement); processDiv.appendChild(zoneElement);
} }
if(cardContent) cardContent.appendChild(processDiv); if (cardContent) cardContent.appendChild(processDiv);
} }
} }
} }
@ -762,8 +777,8 @@ export default class Services {
const target = event.target as HTMLDivElement; const target = event.target as HTMLDivElement;
const zoneId = target?.getAttribute('zone-id'); const zoneId = target?.getAttribute('zone-id');
const processList = document.querySelectorAll('.process-element'); const processList = document.querySelectorAll('.process-element');
if(processList) { if (processList) {
for(const process of processList) { for (const process of processList) {
process.classList.remove('selected') process.classList.remove('selected')
} }
} }
@ -848,11 +863,11 @@ export default class Services {
const badge = document.querySelector('.notification-badge') as HTMLDivElement const badge = document.querySelector('.notification-badge') as HTMLDivElement
const notifications = this.notifications const notifications = this.notifications
const noNotifications = document.querySelector('.no-notification') as HTMLDivElement const noNotifications = document.querySelector('.no-notification') as HTMLDivElement
if(notifications?.length) { if (notifications?.length) {
badge.innerText = notifications.length.toString() badge.innerText = notifications.length.toString()
const notificationBoard = document.querySelector('.notification-board') as HTMLDivElement const notificationBoard = document.querySelector('.notification-board') as HTMLDivElement
noNotifications.style.display = 'none' noNotifications.style.display = 'none'
for(const notif of notifications) { for (const notif of notifications) {
const notifElement = document.createElement("div"); const notifElement = document.createElement("div");
notifElement.className = "notification-element"; notifElement.className = "notification-element";
notifElement.setAttribute('notif-id', notif.id.toString()) notifElement.setAttribute('notif-id', notif.id.toString())