Rename save and getDevice function more explicitly
This commit is contained in:
parent
237331c67f
commit
06a5d8b467
@ -136,7 +136,7 @@ export async function init(): Promise<void> {
|
||||
(window as any).myService = services;
|
||||
await Database.getInstance();
|
||||
setTimeout(async () => {
|
||||
let device = await services.getDevice();
|
||||
let device = await services.getDeviceFromDatabase();
|
||||
console.log('🚀 ~ setTimeout ~ device:', device);
|
||||
|
||||
if (!device) {
|
||||
|
@ -77,8 +77,8 @@ export default class Services {
|
||||
public async unpairDevice(): Promise<void> {
|
||||
try {
|
||||
this.sdkClient.unpair_device();
|
||||
const newDevice = this.dumpDevice();
|
||||
await this.saveDevice(newDevice);
|
||||
const newDevice = this.dumpDeviceFromMemory();
|
||||
await this.saveDeviceInDatabase(newDevice);
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to unpair device: ${e}`);
|
||||
}
|
||||
@ -251,8 +251,8 @@ export default class Services {
|
||||
if (parsedTx) {
|
||||
try {
|
||||
await this.handleApiReturn(parsedTx);
|
||||
const newDevice = this.dumpDevice();
|
||||
await this.saveDevice(newDevice);
|
||||
const newDevice = this.dumpDeviceFromMemory();
|
||||
await this.saveDeviceInDatabase(newDevice);
|
||||
} catch (e) {
|
||||
console.error('Failed to update device with new tx');
|
||||
}
|
||||
@ -411,7 +411,7 @@ export default class Services {
|
||||
return await this.sdkClient.get_address();
|
||||
}
|
||||
|
||||
public dumpDevice(): string {
|
||||
public dumpDeviceFromMemory(): string {
|
||||
try {
|
||||
return this.sdkClient.dump_device();
|
||||
} catch (e) {
|
||||
@ -419,7 +419,7 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
async saveDevice(device: any): Promise<void> {
|
||||
async saveDeviceInDatabase(device: any): Promise<void> {
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
await db.addObject({
|
||||
@ -432,7 +432,7 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
async getDevice(): Promise<string | null> {
|
||||
async getDeviceFromDatabase(): Promise<string | null> {
|
||||
const db = await Database.getInstance();
|
||||
try {
|
||||
const dbRes = await db.getObject('wallet', '1');
|
||||
@ -463,9 +463,9 @@ export default class Services {
|
||||
let spAddress = '';
|
||||
try {
|
||||
spAddress = await this.sdkClient.create_new_device(0, 'regtest');
|
||||
const device = await this.dumpDevice();
|
||||
const device = this.dumpDeviceFromMemory();
|
||||
console.log('🚀 ~ Services ~ device:', device);
|
||||
await this.saveDevice(device);
|
||||
await this.saveDeviceInDatabase(device);
|
||||
} catch (e) {
|
||||
console.error('Services ~ Error:', e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user