Code optimization

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

View File

@ -1366,29 +1366,25 @@
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') {
// Get pipeline origin multisig address try {
let floChatID = floCrypto.toFloID(floID); // Get pipeline origin multisig address
let btcChatID = btcOperator.convert.legacy2bech(floChatID); getTxHex(floID).then(async tx_hex => {
Promise.all([messenger.getChat(floChatID), messenger.getChat(btcChatID)]) let details
.then(async ([floChat, btcChat]) => { switch (messenger.pipeline[floID].model) {
const transaction = mergeSortedArrays(Object.values(floChat), Object.values(btcChat), 'time') case 'flo_multisig':
.find(message => message.tx_hex) details = await floBlockchainAPI.parseTransaction(tx_hex)
if (transaction) { break;
const { type, tx_hex } = transaction case 'btc_multisig':
let details details = await btcOperator.parseTransaction(tx_hex)
switch (messenger.pipeline[floID].model) { break;
case 'flo_multisig':
details = await floBlockchainAPI.parseTransaction(tx_hex)
break;
case 'btc_multisig':
details = await btcOperator.parseTransaction(tx_hex)
break;
}
getRef('contact_flo_id').value = details.inputs[0].address
} }
}).catch(error => { getRef('contact_flo_id').value = details.inputs[0].address
console.error(error) }).catch(e => {
console.error(e)
}) })
} 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') {