wip: complete new onboarding

This commit is contained in:
2023-10-17 16:33:41 +07:00
parent 3aa4f294f9
commit 7fa1e89dc8
44 changed files with 580 additions and 732 deletions

View File

@@ -54,10 +54,13 @@ export const NDKInstance = () => {
async function initNDK() {
const explicitRelayUrls = await getExplicitRelays();
const outboxSetting = await db.getSettingValue('outbox');
const dexieAdapter = new NDKCacheAdapterDexie({ dbName: 'lume_ndkcache' });
const instance = new NDK({
explicitRelayUrls,
cacheAdapter: dexieAdapter,
outboxRelayUrls: ['wss://purplepag.es'],
enableOutboxModel: outboxSetting === '1',
});
try {

View File

@@ -24,6 +24,7 @@ export class LumeStorage {
public async secureLoad(key?: string) {
const value: string = await invoke('secure_load', { key });
if (!value) return null;
return value;
}
@@ -45,8 +46,8 @@ export class LumeStorage {
if (typeof account.follows === 'string')
account.follows = JSON.parse(account.follows);
if (typeof account.network === 'string')
account.network = JSON.parse(account.network);
if (typeof account.circles === 'string')
account.circles = JSON.parse(account.circles);
if (typeof account.last_login_at === 'string')
account.last_login_at = parseInt(account.last_login_at);
@@ -71,8 +72,8 @@ export class LumeStorage {
]);
} else {
await this.db.execute(
'INSERT OR IGNORE INTO accounts (npub, pubkey, privkey, is_active) VALUES ($1, $2, $3, $4);',
[npub, pubkey, 'privkey is stored in secure storage', 1]
'INSERT OR IGNORE INTO accounts (id, pubkey, is_active) VALUES ($1, $2, $3);',
[npub, pubkey, 1]
);
}
@@ -80,7 +81,7 @@ export class LumeStorage {
return account;
}
public async updateAccount(column: string, value: string | string[]) {
public async updateAccount(column: string, value: string) {
const insert = await this.db.execute(
`UPDATE accounts SET ${column} = $1 WHERE id = $2;`,
[value, this.account.id]
@@ -298,12 +299,22 @@ export class LumeStorage {
return await this.db.execute(`DELETE FROM relays WHERE relay = "${relay}";`);
}
public async removePrivkey() {
public async createSetting(key: string, value: string) {
return await this.db.execute(
`UPDATE accounts SET privkey = "privkey is stored in secure storage" WHERE id = "${this.account.id}";`
'INSERT OR IGNORE INTO settings (key, value) VALUES ($1, $2);',
[key, value]
);
}
public async getSettingValue(key: string) {
const results: { key: string; value: string }[] = await this.db.select(
'SELECT * FROM settings WHERE key = $1 ORDER BY id DESC LIMIT 1;',
[key]
);
if (results.length < 1) return null;
return results[0].value;
}
public async accountLogout() {
// update current account status
await this.db.execute("UPDATE accounts SET is_active = '0' WHERE id = $1;", [