Browse Source

refactor(settings): simplify $getSettings to $getMasterSettings

- Rename $getSettings to $getMasterSettings for clarity
- Remove unused account-specific logic (never called with accountDid)
- Simplify method signature by removing unused key parameter
- Update all 8 call sites and interface definitions
- Maintain backward compatibility for all existing functionality

All calls to $getSettings used MASTER_SETTINGS_KEY, so the complex
branching logic for account-specific settings was unnecessary.
pull/170/head
Matthew Raymer 2 weeks ago
parent
commit
98f97f2dc9
  1. 56
      src/utils/PlatformServiceMixin.ts
  2. 4
      src/views/ContactAmountsView.vue

56
src/utils/PlatformServiceMixin.ts

@ -437,30 +437,18 @@ export const PlatformServiceMixin = {
}, },
/** /**
* Utility method for retrieving and parsing settings * Utility method for retrieving master settings
* Common pattern used across many components * Common pattern used across many components
*/ */
async $getSettings( async $getMasterSettings(
key: string,
fallback: Settings | null = null, fallback: Settings | null = null,
): Promise<Settings | null> { ): Promise<Settings | null> {
try { try {
// FIXED: Use specific queries instead of ambiguous OR condition // Master settings: query by id
let result; const result = await this.$dbQuery(
"SELECT * FROM settings WHERE id = ?",
// Check if this is a master settings key (numeric or "1") [MASTER_SETTINGS_KEY],
if (key === MASTER_SETTINGS_KEY || key === "1" || !isNaN(Number(key))) { );
// Master settings: query by id
result = await this.$dbQuery("SELECT * FROM settings WHERE id = ?", [
key,
]);
} else {
// Account settings: query by accountDid
result = await this.$dbQuery(
"SELECT * FROM settings WHERE accountDid = ?",
[key],
);
}
if (!result?.values?.length) { if (!result?.values?.length) {
return fallback; return fallback;
@ -484,8 +472,7 @@ export const PlatformServiceMixin = {
return settings; return settings;
} catch (error) { } catch (error) {
logger.error(`[Settings Trace] ❌ Failed to get settings:`, { logger.error(`[Settings Trace] ❌ Failed to get master settings:`, {
key,
error, error,
}); });
return fallback; return fallback;
@ -503,10 +490,7 @@ export const PlatformServiceMixin = {
): Promise<Settings> { ): Promise<Settings> {
try { try {
// Get default settings // Get default settings
const defaultSettings = await this.$getSettings( const defaultSettings = await this.$getMasterSettings(defaultFallback);
defaultKey,
defaultFallback,
);
// If no account DID, return defaults // If no account DID, return defaults
if (!accountDid) { if (!accountDid) {
@ -769,7 +753,7 @@ export const PlatformServiceMixin = {
* @returns Fresh settings object from database * @returns Fresh settings object from database
*/ */
async $settings(defaults: Settings = {}): Promise<Settings> { async $settings(defaults: Settings = {}): Promise<Settings> {
const settings = await this.$getSettings(MASTER_SETTINGS_KEY, defaults); const settings = await this.$getMasterSettings(defaults);
if (!settings) { if (!settings) {
return defaults; return defaults;
@ -802,10 +786,7 @@ export const PlatformServiceMixin = {
): Promise<Settings> { ): Promise<Settings> {
try { try {
// Get default settings first // Get default settings first
const defaultSettings = await this.$getSettings( const defaultSettings = await this.$getMasterSettings(defaults);
MASTER_SETTINGS_KEY,
defaults,
);
if (!defaultSettings) { if (!defaultSettings) {
return defaults; return defaults;
@ -1590,10 +1571,7 @@ export const PlatformServiceMixin = {
async $debugMergedSettings(did: string): Promise<void> { async $debugMergedSettings(did: string): Promise<void> {
try { try {
// Get default settings // Get default settings
const defaultSettings = await this.$getSettings( const defaultSettings = await this.$getMasterSettings({});
MASTER_SETTINGS_KEY,
{},
);
logger.info( logger.info(
`[PlatformServiceMixin] Default settings:`, `[PlatformServiceMixin] Default settings:`,
defaultSettings, defaultSettings,
@ -1640,10 +1618,7 @@ export interface IPlatformServiceMixin {
): Promise<QueryExecResult | undefined>; ): Promise<QueryExecResult | undefined>;
$dbExec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>; $dbExec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>;
$dbGetOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>; $dbGetOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
$getSettings( $getMasterSettings(fallback?: Settings | null): Promise<Settings | null>;
key: string,
fallback?: Settings | null,
): Promise<Settings | null>;
$getMergedSettings( $getMergedSettings(
defaultKey: string, defaultKey: string,
accountDid?: string, accountDid?: string,
@ -1765,10 +1740,7 @@ declare module "@vue/runtime-core" {
sql: string, sql: string,
params?: unknown[], params?: unknown[],
): Promise<unknown[] | undefined>; ): Promise<unknown[] | undefined>;
$getSettings( $getMasterSettings(defaults?: Settings | null): Promise<Settings | null>;
key: string,
defaults?: Settings | null,
): Promise<Settings | null>;
$getMergedSettings( $getMergedSettings(
key: string, key: string,
did?: string, did?: string,

4
src/views/ContactAmountsView.vue

@ -124,7 +124,7 @@ import {
NOTIFY_CONFIRMATION_RESTRICTION, NOTIFY_CONFIRMATION_RESTRICTION,
} from "../constants/notifications"; } from "../constants/notifications";
import { Contact } from "../db/tables/contacts"; import { Contact } from "../db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "../db/tables/settings";
import { GiveSummaryRecord, GiveActionClaim } from "../interfaces"; import { GiveSummaryRecord, GiveActionClaim } from "../interfaces";
import { AgreeActionClaim } from "../interfaces/claims"; import { AgreeActionClaim } from "../interfaces/claims";
import { import {
@ -223,7 +223,7 @@ export default class ContactAmountssView extends Vue {
const contact = await this.$getContact(contactDid); const contact = await this.$getContact(contactDid);
this.contact = contact; this.contact = contact;
const settings = await this.$getSettings(MASTER_SETTINGS_KEY); const settings = await this.$getMasterSettings();
this.activeDid = settings?.activeDid || ""; this.activeDid = settings?.activeDid || "";
this.apiServer = settings?.apiServer || ""; this.apiServer = settings?.apiServer || "";

Loading…
Cancel
Save