forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: resolve cross-platform contactMethods JSON parsing inconsistencies
- Add platform-agnostic parseJsonField utility for contactMethods handling - Update contact export functions (contactsToExportJson, contactToCsvLine) - Fix contact storage in QR scan views (ContactQRScanShowView, ContactQRScanFullView) - Ensure consistent JSON string storage across web SQLite and Capacitor SQLite - Prevents "[object Object] is not valid JSON" errors when switching platforms - Maintains compatibility between auto-parsing web SQLite and raw string Capacitor SQLite Fixes: contactMethods parsing errors in export and QR scan functionality Related: searchBoxes field had similar issue (already fixed)
This commit is contained in:
@@ -44,7 +44,7 @@ import { logger } from "../utils/logger";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
import { sha256 } from "ethereum-cryptography/sha256";
|
||||
import { IIdentifier } from "@veramo/core";
|
||||
import { insertDidSpecificSettings } from "../db/databaseUtil";
|
||||
import { insertDidSpecificSettings, parseJsonField } from "../db/databaseUtil";
|
||||
|
||||
export interface GiverReceiverInputInfo {
|
||||
did?: string;
|
||||
@@ -865,7 +865,7 @@ export const contactToCsvLine = (contact: Contact): string => {
|
||||
|
||||
// Handle contactMethods array by stringifying it
|
||||
const contactMethodsStr = contact.contactMethods
|
||||
? escapeField(JSON.stringify(contact.contactMethods))
|
||||
? escapeField(JSON.stringify(parseJsonField(contact.contactMethods, [])))
|
||||
: "";
|
||||
|
||||
const fields = [
|
||||
@@ -910,7 +910,7 @@ export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
|
||||
did: contact.did,
|
||||
name: contact.name || null,
|
||||
contactMethods: contact.contactMethods
|
||||
? JSON.stringify(contact.contactMethods)
|
||||
? JSON.stringify(parseJsonField(contact.contactMethods, []))
|
||||
: null,
|
||||
nextPubKeyHashB64: contact.nextPubKeyHashB64 || null,
|
||||
notes: contact.notes || null,
|
||||
|
||||
Reference in New Issue
Block a user