Code optimization

This commit is contained in:
sairaj mote 2023-03-22 19:23:14 +05:30
parent c0e1dd4017
commit 69f1623bdb

View File

@ -1366,15 +1366,9 @@
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)
if (floIdType === 'pipeline') { if (floIdType === 'pipeline') {
try {
// Get pipeline origin multisig address // Get pipeline origin multisig address
let floChatID = floCrypto.toFloID(floID); getTxHex(floID).then(async tx_hex => {
let btcChatID = btcOperator.convert.legacy2bech(floChatID);
Promise.all([messenger.getChat(floChatID), messenger.getChat(btcChatID)])
.then(async ([floChat, btcChat]) => {
const transaction = mergeSortedArrays(Object.values(floChat), Object.values(btcChat), 'time')
.find(message => message.tx_hex)
if (transaction) {
const { type, tx_hex } = transaction
let details let details
switch (messenger.pipeline[floID].model) { switch (messenger.pipeline[floID].model) {
case 'flo_multisig': case 'flo_multisig':
@ -1385,10 +1379,12 @@
break; break;
} }
getRef('contact_flo_id').value = details.inputs[0].address getRef('contact_flo_id').value = details.inputs[0].address
} }).catch(e => {
}).catch(error => { console.error(e)
console.error(error)
}) })
} catch (e) {
console.error(e)
}
} else { } else {
getRef('contact_flo_id').value = floCrypto.toFloID(floID) getRef('contact_flo_id').value = floCrypto.toFloID(floID)
} }
@ -3079,6 +3075,31 @@
} }
return merged return merged
} }
const memoizedTxHex = {}
function getTxHex(chatID) {
return new Promise((resolve, reject) => {
if (memoizedTxHex[chatID]) {
resolve(memoizedTxHex[chatID])
}
let floChatID = floCrypto.toFloID(chatID);
let btcChatID = btcOperator.convert.legacy2bech(floChatID);
Promise.all([messenger.getChat(floChatID), messenger.getChat(btcChatID)])
.then(async ([floChat, btcChat]) => {
const transaction = mergeSortedArrays(Object.values(floChat), Object.values(btcChat), 'time')
.reverse()
.find(message => message.tx_hex)
if (transaction) {
memoizedTxHex[chatID] = transaction.tx_hex
resolve(transaction.tx_hex)
} else {
reject('No transaction found')
}
}).catch(error => {
console.error(error)
reject(error)
})
})
}
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') {