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

View File

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