From 4d0c3e3f5633595d9c4b06601e4c36bf486eb3ff Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 7 Mar 2025 16:42:28 +0100 Subject: [PATCH] Add create accont Btn and update prepareAndSendPairingTx() --- src/utils/sp-address.utils.ts | 47 ++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/utils/sp-address.utils.ts b/src/utils/sp-address.utils.ts index 4405ef8..e6d02ed 100755 --- a/src/utils/sp-address.utils.ts +++ b/src/utils/sp-address.utils.ts @@ -104,6 +104,7 @@ export function initAddressInput() { const addressInput = container.querySelector('#addressInput') as HTMLInputElement; const emojiDisplay = container.querySelector('#emoji-display-2'); const okButton = container.querySelector('#okButton') as HTMLButtonElement; + const createButton = container.querySelector('#createButton') as HTMLButtonElement; addSubscription(addressInput, 'input', async () => { let address = addressInput.value; @@ -145,6 +146,12 @@ export function initAddressInput() { onOkButtonClick(); }); } + + if (createButton) { + addSubscription(createButton, 'click', () => { + onCreateButtonClick(); + }); + } } async function onOkButtonClick() { @@ -158,14 +165,22 @@ async function onOkButtonClick() { } } -export async function prepareAndSendPairingTx(secondDeviceAddress: string) { +async function onCreateButtonClick() { + try { + await prepareAndSendPairingTx(); + } catch (e) { + console.error(`onCreateButtonClick error: ${e}`); + } +} + +export async function prepareAndSendPairingTx() { const service = await Services.getInstance(); // Device 1 wait Device 2 - service.device1 = true; + // service.device1 = true; try { - await service.checkConnections([{ sp_addresses: [secondDeviceAddress] }]); + await service.checkConnections([]); } catch (e) { throw e; } @@ -183,7 +198,7 @@ export async function prepareAndSendPairingTx(secondDeviceAddress: string) { // Pass the userName as an additional parameter. const createPairingProcessReturn = await service.createPairingProcess( userName, - [secondDeviceAddress], + [], relayAddress[0].spAddress, 1, userName @@ -204,17 +219,21 @@ export async function generateQRCode(spAddress: string) { 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 = container.querySelector('#copyBtn'); - if (copyBtn) { - addSubscription(copyBtn, 'click', () => copyToClipboard(currentUrl + '?sp_address=' + spAddress)); - } } catch (err) { console.error(err); } } + +export async function generateCreateBtn() { + try{ + //Generate CreateBtn + const container = getCorrectDOM('login-4nk-component') as HTMLElement + const createBtn = container?.querySelector('.create-btn'); + if (createBtn) { + createBtn.textContent = 'CREATE'; + } + } catch (err) { + console.error(err); + } + +} \ No newline at end of file