fix update outputs for user
This commit is contained in:
parent
c986324c68
commit
0f185c693f
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user