From 322daf50a1786c7fc3bd4c0f2dce96bc6250a62a Mon Sep 17 00:00:00 2001 From: Sosthene Date: Fri, 22 Nov 2024 16:11:31 +0100 Subject: [PATCH] Update handleApiReturn --- src/services/service.ts | 51 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index bd66d51..9ef2363 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -177,8 +177,33 @@ export default class Services { } private async handleApiReturn(apiReturn: ApiReturn) { - if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length) { - await this.sendCipherMessages(apiReturn.ciphers_to_send); + if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) { + await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send)); + } + + if (apiReturn.secrets) { + const unconfirmedSecrets = apiReturn.secrets.unconfirmed_secrets; + const confirmedSecrets = apiReturn.secrets.shared_secrets; + + console.log('confirmedSecrets:', confirmedSecrets); + const db = await Database.getInstance(); + for (const secret of unconfirmedSecrets) { + db.addObject({ + storeName: 'unconfirmed_secrets', + object: secret, + key: null, + }); + } + const entries = Object.entries(confirmedSecrets).map(([key, value]) => ({ key, value })); + for (const entry of entries) { + console.log('entry:', entry); + + db.addObject({ + storeName: 'shared_secrets', + object: entry, + key: null, + }); + } } setTimeout(async () => { @@ -208,27 +233,17 @@ export default class Services { } } - if (apiReturn.updated_cached_msg && apiReturn.updated_cached_msg.length) { - apiReturn.updated_cached_msg.forEach(async (msg, index) => { - // console.debug(`CachedMessage ${index}:`, msg); - // Save the message to local storage - localStorage.setItem(msg.id.toString(), JSON.stringify(msg)); - const db = await Database.getInstance(); - db.addObject({ - storeName: 'messages', - object: { id: msg.id.toString(), msg }, - key: msg.id.toString(), - }); - }); - } - if (apiReturn.commit_to_send) { const commit = apiReturn.commit_to_send; await this.sendCommitMessage(JSON.stringify(commit)); } - if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) { - await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send)); + if (apiReturn.decrypted_pcds && apiReturn.decrypted_pcds.length != 0) { + // TODO + } + + if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) { + await this.sendCipherMessages(apiReturn.ciphers_to_send); } }, 0); }