Update handleApiReturn
This commit is contained in:
parent
593b96884e
commit
322daf50a1
@ -177,8 +177,33 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleApiReturn(apiReturn: ApiReturn) {
|
private async handleApiReturn(apiReturn: ApiReturn) {
|
||||||
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length) {
|
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
|
||||||
await this.sendCipherMessages(apiReturn.ciphers_to_send);
|
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 () => {
|
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) {
|
if (apiReturn.commit_to_send) {
|
||||||
const commit = apiReturn.commit_to_send;
|
const commit = apiReturn.commit_to_send;
|
||||||
await this.sendCommitMessage(JSON.stringify(commit));
|
await this.sendCommitMessage(JSON.stringify(commit));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiReturn.new_tx_to_send && apiReturn.new_tx_to_send.transaction.length != 0) {
|
if (apiReturn.decrypted_pcds && apiReturn.decrypted_pcds.length != 0) {
|
||||||
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send));
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length != 0) {
|
||||||
|
await this.sendCipherMessages(apiReturn.ciphers_to_send);
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user