forked from trent_larson/crowd-funder-for-time-pwa
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.
This commit is contained in:
@@ -45,6 +45,7 @@ import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import { sha256 } from "ethereum-cryptography/sha256";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
import { insertDidSpecificSettings, parseJsonField } from "../db/databaseUtil";
|
||||
import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto";
|
||||
|
||||
export interface GiverReceiverInputInfo {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -953,12 +953,6 @@
|
||||
>
|
||||
Logs
|
||||
</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
|
||||
: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"
|
||||
|
||||
@@ -88,17 +88,9 @@ import { Router } from "vue-router";
|
||||
|
||||
import { AppString, NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import {
|
||||
accountsDBPromise,
|
||||
retrieveSettingsForActiveAccount,
|
||||
} 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 { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import { DEFAULT_ROOT_DERIVATION_PATH } from "../libs/crypto";
|
||||
import { retrieveAccountCount, importFromMnemonic } from "../libs/util";
|
||||
import { logger } from "../utils/logger";
|
||||
|
||||
@Component({
|
||||
@@ -115,12 +107,9 @@ export default class ImportAccountView extends Vue {
|
||||
$router!: Router;
|
||||
|
||||
apiServer = "";
|
||||
address = "";
|
||||
derivationPath = DEFAULT_ROOT_DERIVATION_PATH;
|
||||
mnemonic = "";
|
||||
numAccounts = 0;
|
||||
privateHex = "";
|
||||
publicHex = "";
|
||||
showAdvanced = false;
|
||||
shouldErase = false;
|
||||
|
||||
@@ -143,33 +132,16 @@ export default class ImportAccountView extends Vue {
|
||||
}
|
||||
|
||||
public async fromMnemonic() {
|
||||
const mne: string = this.mnemonic.trim().toLowerCase();
|
||||
try {
|
||||
[this.address, this.privateHex, this.publicHex] = deriveAddress(
|
||||
mne,
|
||||
await importFromMnemonic(
|
||||
this.mnemonic,
|
||||
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" });
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (err: any) {
|
||||
logger.error("Error saving mnemonic & updating settings:", err);
|
||||
logger.error("Error importing from mnemonic:", err);
|
||||
if (err == "Error: invalid mnemonic") {
|
||||
this.$notify(
|
||||
{
|
||||
|
||||
@@ -82,6 +82,19 @@
|
||||
Derive new address from existing seed
|
||||
</a>
|
||||
</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>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user