Merging equivalent addresses in UI
This commit is contained in:
parent
ba4b081aa0
commit
a7025a712e
153
index.html
153
index.html
@ -769,9 +769,13 @@
|
|||||||
<p id="last_interaction_time"></p>
|
<p id="last_interaction_time"></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="popup-section">
|
<div class="popup-section">
|
||||||
<h5 id="flo_id_type">Address</h5>
|
<h5 id="flo_id_type"></h5>
|
||||||
<sm-copy id="contact_flo_id"></sm-copy>
|
<sm-copy id="contact_flo_id"></sm-copy>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="popup-section hidden">
|
||||||
|
<h5>BTC address</h5>
|
||||||
|
<sm-copy id="contact_btc_id"></sm-copy>
|
||||||
|
</div>
|
||||||
<div id="group_description_card" class="hidden">
|
<div id="group_description_card" class="hidden">
|
||||||
<h5>Group description</h5>
|
<h5>Group description</h5>
|
||||||
<text-field id="group_description"></text-field>
|
<text-field id="group_description"></text-field>
|
||||||
@ -1335,10 +1339,10 @@
|
|||||||
getRef('contact_details_popup').classList.add('is-group');
|
getRef('contact_details_popup').classList.add('is-group');
|
||||||
removeClass(['#group_members_card'], 'hidden')
|
removeClass(['#group_members_card'], 'hidden')
|
||||||
addClass(['#group_members_tip', '#group_description_card'], 'hidden')
|
addClass(['#group_members_tip', '#group_description_card'], 'hidden')
|
||||||
getRef('flo_id_type').textContent = 'Pipeline FLO address'
|
getRef('flo_id_type').textContent = 'Multisig group FLO address'
|
||||||
getRef("last_interaction_time").textContent = ``;
|
getRef("last_interaction_time").textContent = ``;
|
||||||
} else {
|
} else {
|
||||||
getRef('flo_id_type').textContent = 'Address'
|
getRef('flo_id_type').textContent = 'FLO address'
|
||||||
getRef('contact_name').disabled = false
|
getRef('contact_name').disabled = false
|
||||||
getRef('contact_initial').textContent = getContactName(floID).charAt(0)
|
getRef('contact_initial').textContent = getContactName(floID).charAt(0)
|
||||||
getRef("last_interaction_time").textContent = ``;
|
getRef("last_interaction_time").textContent = ``;
|
||||||
@ -1347,7 +1351,13 @@
|
|||||||
}
|
}
|
||||||
getRef('contact_initial').setAttribute('style', `--contact-color: var(${contactColor(floID)})`)
|
getRef('contact_initial').setAttribute('style', `--contact-color: var(${contactColor(floID)})`)
|
||||||
getRef('contact_name').value = getContactName(floID) === floID ? 'Unnamed' : getContactName(floID)
|
getRef('contact_name').value = getContactName(floID) === floID ? 'Unnamed' : getContactName(floID)
|
||||||
getRef('contact_flo_id').value = floID
|
getRef('contact_flo_id').value = floCrypto.toFloID(floID)
|
||||||
|
if (floIdType === 'plain') {
|
||||||
|
getRef('contact_btc_id').value = btcOperator.convert.legacy2bech(floCrypto.toFloID(floID))
|
||||||
|
getRef('contact_btc_id').parentNode.classList.remove('hidden')
|
||||||
|
} else {
|
||||||
|
getRef('contact_btc_id').parentNode.classList.add('hidden')
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'contacts_popup':
|
case 'contacts_popup':
|
||||||
const contacts = []
|
const contacts = []
|
||||||
@ -2973,6 +2983,29 @@
|
|||||||
updateMessageUI(data.messages)
|
updateMessageUI(data.messages)
|
||||||
renderMailList(data.mails, true)
|
renderMailList(data.mails, true)
|
||||||
}
|
}
|
||||||
|
// merge sorted arrays of objects by a key
|
||||||
|
function mergeSortedArrays(arr1 = [], arr2 = [], key) {
|
||||||
|
const merged = []
|
||||||
|
let i = 0, j = 0
|
||||||
|
while (i < arr1.length && j < arr2.length) {
|
||||||
|
if (arr1[i][key] < arr2[j][key]) {
|
||||||
|
merged.push(arr1[i])
|
||||||
|
i++
|
||||||
|
} else {
|
||||||
|
merged.push(arr2[j])
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (i < arr1.length) {
|
||||||
|
merged.push(arr1[i])
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
while (j < arr2.length) {
|
||||||
|
merged.push(arr2[j])
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
|
||||||
function renderGroupUI(data) {
|
function renderGroupUI(data) {
|
||||||
if (Object.keys(data.messages).length && appState.lastPage !== 'chat_page') {
|
if (Object.keys(data.messages).length && appState.lastPage !== 'chat_page') {
|
||||||
@ -3021,6 +3054,7 @@
|
|||||||
if (name)
|
if (name)
|
||||||
chatCard.querySelector('.name').textContent = name
|
chatCard.querySelector('.name').textContent = name
|
||||||
}
|
}
|
||||||
|
// move chat card to top if it is not already there
|
||||||
const topChatCard = getRef('chats_list').children[0]
|
const topChatCard = getRef('chats_list').children[0]
|
||||||
if (chatAddress !== topChatCard.dataset.floAddress || chatAddress !== floCrypto.toFloID(topChatCard.dataset.floAddress)) {
|
if (chatAddress !== topChatCard.dataset.floAddress || chatAddress !== floCrypto.toFloID(topChatCard.dataset.floAddress)) {
|
||||||
const cloneContact = chatCard.cloneNode(true)
|
const cloneContact = chatCard.cloneNode(true)
|
||||||
@ -3703,20 +3737,32 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addContact() {
|
function addContact() {
|
||||||
let floID = getRef('add_contact_floID').value.trim();
|
let addressToSave = getRef('add_contact_floID').value.trim();
|
||||||
let name = getRef('add_contact_name').value.trim();
|
let name = getRef('add_contact_name').value.trim();
|
||||||
if (floID === floDapps.user.id) {
|
if (addressToSave === floDapps.user.id) {
|
||||||
notify(`you can't add your own FLO/BTC address as contact`, 'error')
|
notify(`you can't add your own FLO/BTC address as contact`, 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (floGlobals.contacts.hasOwnProperty(floID)) {
|
if (floGlobals.contacts.hasOwnProperty(addressToSave)) {
|
||||||
notify(`Contact already saved`, 'error')
|
notify(`Contact already saved`, 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messenger.storeContact(floID, name).then(result => {
|
// check whether an equivalent BTC/FLO address is already ssaved
|
||||||
|
if (floCrypto.validateFloID(addressToSave)) {
|
||||||
|
const addrInBtc = btcOperator.convert.legacy2bech(addressToSave)
|
||||||
|
if (floGlobals.contacts.hasOwnProperty(addrInBtc))
|
||||||
|
notify(`Equivalnet Bitcoin address is already saved as ${getContactName(addrInBtc)}`, 'error')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
const addrInFlo = floCrypto.toFloID(addressToSave)
|
||||||
|
if (floGlobals.contacts.hasOwnProperty(addrInFlo))
|
||||||
|
notify(`Equivalnet FLO address is already saved as ${getContactName(addrInFlo)}`, 'error')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
messenger.storeContact(addressToSave, name).then(result => {
|
||||||
closePopup()
|
closePopup()
|
||||||
notify(`Added Contact: ${floID}`)
|
notify(`Added Contact: ${addressToSave}`)
|
||||||
const chatCard = getChatCard(floID)
|
const chatCard = getChatCard(addressToSave)
|
||||||
if (chatCard)
|
if (chatCard)
|
||||||
chatCard.querySelector('.name').textContent = name
|
chatCard.querySelector('.name').textContent = name
|
||||||
if (popupStack.peek().popup.id === 'contact_details_popup') {
|
if (popupStack.peek().popup.id === 'contact_details_popup') {
|
||||||
@ -3729,7 +3775,7 @@
|
|||||||
if (popupStack.items.find(elem => elem.popup.id === 'new_message_popup')) {
|
if (popupStack.items.find(elem => elem.popup.id === 'new_message_popup')) {
|
||||||
renderContactList()
|
renderContactList()
|
||||||
}
|
}
|
||||||
if (activeChat.address === floID)
|
if (activeChat.address === addressToSave)
|
||||||
updateChatHeaderName(name)
|
updateChatHeaderName(name)
|
||||||
}).catch(error => notify(error, "error"));
|
}).catch(error => notify(error, "error"));
|
||||||
}
|
}
|
||||||
@ -3762,8 +3808,33 @@
|
|||||||
renderElem(getRef('select_contacts_container'), html`${contacts}`)
|
renderElem(getRef('select_contacts_container'), html`${contacts}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderChatList(chatOrder) {
|
async function renderChatList(chatOrder = messenger.getChatOrder()) {
|
||||||
const chats = chatOrder.map(floID => {
|
const chatOrderLookup = new Set()
|
||||||
|
const mergedChatOrder = []
|
||||||
|
// merge equivalent addresses
|
||||||
|
chatOrder.forEach(address => {
|
||||||
|
let priorityAddress
|
||||||
|
if (floCrypto.validateFloID(address)) {
|
||||||
|
const addrInBtc = btcOperator.convert.legacy2bech(address)
|
||||||
|
if (floGlobals.contacts.hasOwnProperty(address))
|
||||||
|
priorityAddress = address
|
||||||
|
else if (floGlobals.contacts.hasOwnProperty(addrInBtc))
|
||||||
|
priorityAddress = addrInBtc
|
||||||
|
if (chatOrderLookup.has(addrInBtc)) return
|
||||||
|
} else {
|
||||||
|
const addrInFlo = floCrypto.toFloID(address)
|
||||||
|
if (floGlobals.contacts.hasOwnProperty(address))
|
||||||
|
priorityAddress = address
|
||||||
|
else if (floGlobals.contacts.hasOwnProperty(addrInFlo))
|
||||||
|
priorityAddress = addrInFlo
|
||||||
|
if (chatOrderLookup.has(addrInFlo)) return
|
||||||
|
}
|
||||||
|
if (!chatOrderLookup.has(priorityAddress || address)) {
|
||||||
|
mergedChatOrder.push(priorityAddress || address)
|
||||||
|
chatOrderLookup.add(priorityAddress || address)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const chats = mergedChatOrder.map(floID => {
|
||||||
const markUnread = messenger.marked[floID] ? messenger.marked[floID].includes('unread') : false;
|
const markUnread = messenger.marked[floID] ? messenger.marked[floID].includes('unread') : false;
|
||||||
let type
|
let type
|
||||||
if (messenger.chats[floID])
|
if (messenger.chats[floID])
|
||||||
@ -3798,33 +3869,37 @@
|
|||||||
let chatLazyLoader
|
let chatLazyLoader
|
||||||
function renderMessages(floID) {
|
function renderMessages(floID) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
messenger.getChat(floID).then(chat => {
|
let floChatID = floCrypto.toFloID(floID);
|
||||||
if (chatLazyLoader) {
|
let btcChatID = btcOperator.convert.legacy2bech(floChatID);
|
||||||
chatLazyLoader.update(Object.values(chat))
|
Promise.all([messenger.getChat(floChatID), messenger.getChat(btcChatID)])
|
||||||
} else {
|
.then(([floChat, btcChat]) => {
|
||||||
chatLazyLoader = new LazyLoader('#messages_container', Object.values(chat), render.messageBubble, {
|
let chat = mergeSortedArrays(Object.values(floChat), Object.values(btcChat), 'time')
|
||||||
bottomFirst: true,
|
if (chatLazyLoader) {
|
||||||
batchSize: 20,
|
chatLazyLoader.update(chat)
|
||||||
});
|
} else {
|
||||||
}
|
chatLazyLoader = new LazyLoader('#messages_container', chat, render.messageBubble, {
|
||||||
chatLazyLoader.init()
|
bottomFirst: true,
|
||||||
if (getFloIdType(floID) === 'pipeline') {
|
batchSize: 20,
|
||||||
if (!floGlobals.pipeSigns[floID])
|
});
|
||||||
floGlobals.pipeSigns[floID] = new Set()
|
}
|
||||||
for (const key in chat) {
|
chatLazyLoader.init()
|
||||||
const { type, sender, tx_hex } = chat[key]
|
if (getFloIdType(floID) === 'pipeline') {
|
||||||
if (type === 'TRANSACTION') {
|
if (!floGlobals.pipeSigns[floID])
|
||||||
floGlobals.pipeSigns[floID].add(sender)
|
floGlobals.pipeSigns[floID] = new Set()
|
||||||
if (tx_hex)
|
for (const key in chat) {
|
||||||
floGlobals.pipelineTxHex = tx_hex
|
const { type, sender, tx_hex } = chat[key]
|
||||||
|
if (type === 'TRANSACTION') {
|
||||||
|
floGlobals.pipeSigns[floID].add(sender)
|
||||||
|
if (tx_hex)
|
||||||
|
floGlobals.pipelineTxHex = tx_hex
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
resolve()
|
||||||
resolve()
|
}).catch(error => {
|
||||||
}).catch(error => {
|
console.log(error)
|
||||||
console.log(error)
|
reject(error)
|
||||||
reject(error)
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4237,7 +4312,7 @@
|
|||||||
notify('Address unblocked', 'success')
|
notify('Address unblocked', 'success')
|
||||||
closePopup()
|
closePopup()
|
||||||
render.blockedList()
|
render.blockedList()
|
||||||
renderChatList(messenger.getChatOrder())
|
renderChatList()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user