From 82d1f6b88894632ea9c0ef017b48753d4d6a2637 Mon Sep 17 00:00:00 2001 From: sairaj mote Date: Fri, 10 Mar 2023 03:03:47 +0530 Subject: [PATCH] code refactoring --- index.html | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index d459081..4fe19f4 100644 --- a/index.html +++ b/index.html @@ -1741,8 +1741,8 @@ getRef('contacts').classList.add('hide-on-mobile') getRef('main_navbar').classList.add('hide-on-mobile') } else { - if (activeChat.floID && !floGlobals.isMobileView) { - history.replaceState(null, null, `#/chat_page/messages?floId=${activeChat.floID}`); + if (activeChat.address && !floGlobals.isMobileView) { + history.replaceState(null, null, `#/chat_page/messages?floId=${activeChat.address}`); } else { history.replaceState(null, null, '#/chat_page'); getRef('chat_view').classList.add('hidden') @@ -2104,7 +2104,7 @@ if (document.visibilityState === "hidden") { // code if page is hidden } else { - if (activeChat.floID) { + if (activeChat.address) { if (!chatScrollInfo.isScrolledUp) { scrollToBottom() } @@ -2532,7 +2532,7 @@ } }).catch(error => console.error(error)) if (prepend) { - activeChat.floID = floID + activeChat.address = floID getRef('chats_list').querySelectorAll('.active').forEach(child => child.classList.remove('active')) } } @@ -2546,7 +2546,7 @@
${initial}
- ${type === 'pipeline' ? html`
${tag} Multisig
` : ''} + ${type === 'pipeline' ? html`
${tag} Multisig ${messenger.pipeline[floID].disabled ? ' - Completed' : ''}
` : ''}

${name}

${type === 'contact' ? html`

${floID}

` : ''} @@ -2664,10 +2664,13 @@

` break; case 'BROADCAST': + let redirectTo = `https://live.blockcypher.com/btc/tx/` + if (messenger.pipeline[activeChat.address].model === 'flo_multisig') + redirectTo = `https://flosight.ranchimall.net/tx/` return html.node`

Transaction approved

- View on blockchain + View on blockchain
` break; } @@ -2983,10 +2986,9 @@ fill: 'forwards' } for (let messageId in messagesData) { - console.log(messageId, messagesData[messageId]) const { category, floID, time, message, sender, groupID, admin, name, pipeID, unconfirmed } = messagesData[messageId] // code to run if a chat is opened - if (activeChat && activeChat.floID === (floID || groupID || pipeID)) { + if (activeChat && activeChat.address === (floID || groupID || pipeID)) { if (!sentByMe && sender && sender === floDapps.user.id) { // if message is sent by me, then dont add it to the chat } else { @@ -2997,7 +2999,7 @@ scrollToBottom() } // remove encryption badge if it exists - if (!groupID && floGlobals.pubKeys[activeChat.floID] && floID !== floDapps.user.id) { + if (!groupID && floGlobals.pubKeys[activeChat.address] && floID !== floDapps.user.id) { document.getElementById('warn_no_encryption')?.remove() } } @@ -3055,7 +3057,7 @@ if (chatCard.querySelector('.time')) chatCard.querySelector('.time').textContent = getFormattedTime(time, 'relative') - if (activeChat.floID === (floID || groupID || pipeID)) { + if (activeChat.address === (floID || groupID || pipeID)) { if (chatScrollInfo.isScrolledUp) getRef('scroll_to_bottom').classList.add('new-message') else { @@ -3226,7 +3228,7 @@ }) floGlobals.uiState = {} getRef('chat_details_button').addEventListener('click', e => { - floGlobals.activeFloID = activeChat.floID + floGlobals.activeFloID = activeChat.address openPopup('contact_details_popup') }) @@ -3646,7 +3648,7 @@ async function sendMessage() { if (!floGlobals.isMobileView) getRef('type_message').focusIn() - let receiver = activeChat.floID + let receiver = activeChat.address let message = getRef('type_message').value.trim(); getRef('type_message').value = '' if (message === '') return @@ -3716,7 +3718,7 @@ if (popupStack.items.find(elem => elem.popup.id === 'new_message_popup')) { renderContactList() } - if (activeChat.floID === floID) + if (activeChat.address === floID) updateChatHeaderName(name) }).catch(error => notify(error, "error")); } @@ -3772,10 +3774,10 @@ } function scrollToBottom(smooth = false) { - if (activeChat.floID) { - messenger.removeMark(activeChat.floID, 'unread') - if (getChatCard(activeChat.floID)) - getChatCard(activeChat.floID).classList.remove('unread') + if (activeChat.address) { + messenger.removeMark(activeChat.address, 'unread') + if (getChatCard(activeChat.address)) + getChatCard(activeChat.address).classList.remove('unread') } getRef('scroll_to_bottom').classList.remove('new-message') getRef('messages_container').scrollTo({ top: getRef('messages_container').scrollHeight, behavior: smooth ? 'smooth' : undefined }) @@ -3822,13 +3824,13 @@ renderedDates = {} // save typed message from previous chat if (getRef('type_message').value.trim() !== '') { - floGlobals.typedMessages[activeChat.floID] = getRef('type_message').value + floGlobals.typedMessages[activeChat.address] = getRef('type_message').value } else { - delete floGlobals.typedMessages[activeChat.floID] + delete floGlobals.typedMessages[activeChat.address] } // restore typed message if any getRef('type_message').value = floGlobals.typedMessages[floID] || '' - activeChat.floID = floID + activeChat.address = floID activeChat.type = getFloIdType(floID) updateChatHeaderName(getContactName(floID)); const chatCard = getChatCard(floID); @@ -3888,7 +3890,6 @@ details = await btcOperator.parseTransaction(floGlobals.pipelineTxHex) break; } - console.log(details) const { inputs, outputs, fee } = details const { s: signsDone, r: minSignsRequired, t: totalMembers } = inputs[0]?.signed || {} const pendingSigns = minSignsRequired - signsDone @@ -4152,12 +4153,12 @@ function updateChatCards({ name, floID }) { const type = getFloIdType(floID) - if (activeChat.floID && activeChat.floID === clickedContact.floID) { + if (activeChat.address && activeChat.address === clickedContact.floID) { updateChatHeaderName(name) } if (type === 'plain') { getRef('contact_initial').textContent = name.charAt(0) - if (activeChat.floID && activeChat.floID === clickedContact.floID) { + if (activeChat.address && activeChat.address === clickedContact.floID) { getRef('receiver_initial').textContent = name.charAt(0) } document.querySelectorAll(`.contact[data-flo-address="${floID}"]`).forEach(contact => {