Browse Source

feat: move database migration link from account view to start view

- Remove database migration link from AccountViewView.vue
- Add new "Database Tools" section to StartView.vue
- Improve user flow by making database tools accessible from start page
- Maintain consistent styling and functionality
- Clean up account view to focus on account-specific settings

The database migration feature is now logically grouped with other
identity-related operations and more discoverable for users.
migrate-dexie-to-sqlite
Matthew Raymer 1 week ago
parent
commit
f375a4e11a
  1. 36
      src/libs/util.ts
  2. 6
      src/views/AccountViewView.vue
  3. 42
      src/views/ImportAccountView.vue
  4. 13
      src/views/StartView.vue

36
src/libs/util.ts

@ -45,6 +45,7 @@ import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
import { sha256 } from "ethereum-cryptography/sha256"; import { sha256 } from "ethereum-cryptography/sha256";
import { IIdentifier } from "@veramo/core"; import { IIdentifier } from "@veramo/core";
import { insertDidSpecificSettings, parseJsonField } from "../db/databaseUtil"; import { insertDidSpecificSettings, parseJsonField } from "../db/databaseUtil";
import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto";
export interface GiverReceiverInputInfo { export interface GiverReceiverInputInfo {
did?: string; did?: string;
@ -998,3 +999,38 @@ export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
}, },
}; };
}; };
/**
* Imports an account from a mnemonic phrase
* @param mnemonic - The seed phrase to import from
* @param derivationPath - The derivation path to use (defaults to DEFAULT_ROOT_DERIVATION_PATH)
* @param shouldErase - Whether to erase existing accounts before importing
* @returns Promise that resolves when import is complete
* @throws Error if mnemonic is invalid or import fails
*/
export async function importFromMnemonic(
mnemonic: string,
derivationPath: string = DEFAULT_ROOT_DERIVATION_PATH,
shouldErase: boolean = false,
): Promise<void> {
const mne: string = mnemonic.trim().toLowerCase();
// Derive address and keys from mnemonic
const [address, privateHex, publicHex] = deriveAddress(mne, derivationPath);
// Create new identifier
const newId = newIdentifier(address, publicHex, privateHex, derivationPath);
// Handle database operations
const accountsDB = await accountsDBPromise;
if (shouldErase) {
const platformService = PlatformServiceFactory.getInstance();
await platformService.dbExec("DELETE FROM accounts");
if (USE_DEXIE_DB) {
await accountsDB.accounts.clear();
}
}
// Save the new identity
await saveNewIdentity(newId, mne, derivationPath);
}

6
src/views/AccountViewView.vue

@ -953,12 +953,6 @@
> >
Logs Logs
</router-link> </router-link>
<router-link
:to="{ name: 'database-migration' }"
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mt-2"
>
Database Migration
</router-link>
<router-link <router-link
:to="{ name: 'test' }" :to="{ name: 'test' }"
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mt-2" class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mt-2"

42
src/views/ImportAccountView.vue

@ -88,17 +88,9 @@ import { Router } from "vue-router";
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app"; import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app";
import * as databaseUtil from "../db/databaseUtil"; import * as databaseUtil from "../db/databaseUtil";
import { import { retrieveSettingsForActiveAccount } from "../db/index";
accountsDBPromise, import { DEFAULT_ROOT_DERIVATION_PATH } from "../libs/crypto";
retrieveSettingsForActiveAccount, import { retrieveAccountCount, importFromMnemonic } from "../libs/util";
} from "../db/index";
import {
DEFAULT_ROOT_DERIVATION_PATH,
deriveAddress,
newIdentifier,
} from "../libs/crypto";
import { retrieveAccountCount, saveNewIdentity } from "../libs/util";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
@Component({ @Component({
@ -115,12 +107,9 @@ export default class ImportAccountView extends Vue {
$router!: Router; $router!: Router;
apiServer = ""; apiServer = "";
address = "";
derivationPath = DEFAULT_ROOT_DERIVATION_PATH; derivationPath = DEFAULT_ROOT_DERIVATION_PATH;
mnemonic = ""; mnemonic = "";
numAccounts = 0; numAccounts = 0;
privateHex = "";
publicHex = "";
showAdvanced = false; showAdvanced = false;
shouldErase = false; shouldErase = false;
@ -143,33 +132,16 @@ export default class ImportAccountView extends Vue {
} }
public async fromMnemonic() { public async fromMnemonic() {
const mne: string = this.mnemonic.trim().toLowerCase();
try { try {
[this.address, this.privateHex, this.publicHex] = deriveAddress( await importFromMnemonic(
mne, this.mnemonic,
this.derivationPath, this.derivationPath,
this.shouldErase,
); );
const newId = newIdentifier(
this.address,
this.publicHex,
this.privateHex,
this.derivationPath,
);
const accountsDB = await accountsDBPromise;
if (this.shouldErase) {
const platformService = PlatformServiceFactory.getInstance();
await platformService.dbExec("DELETE FROM accounts");
if (USE_DEXIE_DB) {
await accountsDB.accounts.clear();
}
}
await saveNewIdentity(newId, mne, this.derivationPath);
this.$router.push({ name: "account" }); this.$router.push({ name: "account" });
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) { } catch (err: any) {
logger.error("Error saving mnemonic & updating settings:", err); logger.error("Error importing from mnemonic:", err);
if (err == "Error: invalid mnemonic") { if (err == "Error: invalid mnemonic") {
this.$notify( this.$notify(
{ {

13
src/views/StartView.vue

@ -82,6 +82,19 @@
Derive new address from existing seed Derive new address from existing seed
</a> </a>
</div> </div>
<!-- Database Migration Section -->
<div class="mt-8 pt-6 border-t border-gray-200">
<p class="text-center text-lg font-light mb-4">Database Tools</p>
<div class="flex justify-center">
<router-link
:to="{ name: 'database-migration' }"
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md"
>
Database Migration
</router-link>
</div>
</div>
</div> </div>
</div> </div>
</section> </section>

Loading…
Cancel
Save