fix update outputs for user

This commit is contained in:
Sosthene00 2024-04-18 00:35:16 +02:00
parent c986324c68
commit 0f185c693f
2 changed files with 22 additions and 14 deletions

View File

@ -324,23 +324,22 @@ class Services {
} }
} }
public async updateOwnedOutputsForUser(preId: string): Promise<void> { public async updateOwnedOutputsForUser(): Promise<void> {
const services = await Services.getInstance(); const services = await Services.getInstance();
let latest_outputs: outputs_list; let latest_outputs: outputs_list;
try { try {
latest_outputs = services.sdkClient.get_outpoints_for_user(preId); latest_outputs = services.sdkClient.get_outpoints_for_user();
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return; return;
} }
try { try {
const indexedDB = await IndexedDB.getInstance(); let user = await services.getUserInfo();
const db = await indexedDB.getDb(); if (user) {
const storeName = indexedDB.getStoreList().AnkUser; user.outputs = latest_outputs;
let user = await indexedDB.getObject<User>(db, storeName, preId); await services.updateUser(user);
user.outputs = latest_outputs; }
await indexedDB.setObject(db, storeName, user, null);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -350,9 +349,9 @@ class Services {
const services = await Services.getInstance(); const services = await Services.getInstance();
try { try {
const updated_user: string = services.sdkClient.check_transaction_for_silent_payments(tx, blkheight, tweak_data); const txid = services.sdkClient.check_transaction_for_silent_payments(tx, blkheight, tweak_data);
await services.updateOwnedOutputsForUser(updated_user); await services.updateOwnedOutputsForUser();
return updated_user; return txid;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return null; return null;
@ -719,6 +718,16 @@ class Services {
return null; return null;
} }
public async updateUser(user: User): Promise<void> {
try {
const indexedDB = await IndexedDB.getInstance();
const db = await indexedDB.getDb();
await indexedDB.setObject(db, indexedDB.getStoreList().AnkUser, user, null);
} catch (error) {
throw error;
}
}
public async getUserInfo(): Promise<User | null> { public async getUserInfo(): Promise<User | null> {
try { try {
const indexedDB = await IndexedDB.getInstance(); const indexedDB = await IndexedDB.getInstance();
@ -736,8 +745,7 @@ class Services {
} }
} }
} catch (error) { } catch (error) {
console.error("Can't get user from db"); throw error;
return null;
} }
} }

View File

@ -32,7 +32,7 @@ class WebSocketClient {
if (res.topic === 'new_tx') { if (res.topic === 'new_tx') {
// we received a tx // we received a tx
window.alert(`New tx\n${res.message}`); window.alert(`New tx\n${res.message}`);
await services.updateOwnedOutputsForUser(res.message); await services.updateOwnedOutputsForUser();
} }
} }
} else { } else {