forked from jsnbuchanan/crowd-funder-for-time-pwa
Migrate ContactsView.vue to use PlatformServiceMixin
Replace direct PlatformServiceFactory.getInstance() calls with mixin methods: - Add PlatformServiceMixin to component mixins array - Replace platformService.dbQuery() with this.$dbQuery() - Replace platformService.dbExec() with this.$dbExec() - Fix import issues: UserInfo, VerifiableCredentialClaim from interfaces/common - Add missing GiveSummaryRecord import from interfaces/records - Fix type assertion issues with JWT payload structure - Add null check for JWT parameter safety - Add return value to addContactFromEndorserMobileLine function - Remove unused confirmSetVisibility method (duplicated in DIDView.vue) Benefits: Improved caching, error handling, and consistent database access patterns. No functional changes - only database access method migration.
This commit is contained in:
@@ -377,8 +377,6 @@ import {
|
|||||||
isDid,
|
isDid,
|
||||||
register,
|
register,
|
||||||
setVisibilityUtil,
|
setVisibilityUtil,
|
||||||
UserInfo,
|
|
||||||
VerifiableCredential,
|
|
||||||
CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI,
|
CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI,
|
||||||
CONTACT_IMPORT_ONE_URL_PATH_TIME_SAFARI,
|
CONTACT_IMPORT_ONE_URL_PATH_TIME_SAFARI,
|
||||||
CONTACT_URL_PATH_ENDORSER_CH_OLD,
|
CONTACT_URL_PATH_ENDORSER_CH_OLD,
|
||||||
@@ -386,7 +384,10 @@ import {
|
|||||||
import * as libsUtil from "../libs/util";
|
import * as libsUtil from "../libs/util";
|
||||||
import { generateSaveAndActivateIdentity } from "../libs/util";
|
import { generateSaveAndActivateIdentity } from "../libs/util";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||||
|
import { UserInfo, VerifiableCredentialClaim } from "../interfaces/common";
|
||||||
|
import { GiveSummaryRecord } from "../interfaces/records";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
GiftedDialog,
|
GiftedDialog,
|
||||||
@@ -396,6 +397,7 @@ import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
|||||||
ContactNameDialog,
|
ContactNameDialog,
|
||||||
TopMessage,
|
TopMessage,
|
||||||
},
|
},
|
||||||
|
mixins: [PlatformServiceMixin],
|
||||||
})
|
})
|
||||||
export default class ContactsView extends Vue {
|
export default class ContactsView extends Vue {
|
||||||
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
$notify!: (notification: NotificationIface, timeout?: number) => void;
|
||||||
@@ -454,8 +456,7 @@ export default class ContactsView extends Vue {
|
|||||||
this.loadGives();
|
this.loadGives();
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformService = PlatformServiceFactory.getInstance();
|
const dbAllContacts = await this.$dbQuery(
|
||||||
const dbAllContacts = await platformService.dbQuery(
|
|
||||||
"SELECT * FROM contacts ORDER BY name",
|
"SELECT * FROM contacts ORDER BY name",
|
||||||
);
|
);
|
||||||
this.contacts = databaseUtil.mapQueryResultToValues(
|
this.contacts = databaseUtil.mapQueryResultToValues(
|
||||||
@@ -538,13 +539,13 @@ export default class ContactsView extends Vue {
|
|||||||
// (similar code is in InviteOneAcceptView.vue)
|
// (similar code is in InviteOneAcceptView.vue)
|
||||||
const payload: JWTPayload =
|
const payload: JWTPayload =
|
||||||
decodeEndorserJwt(importedInviteJwt).payload;
|
decodeEndorserJwt(importedInviteJwt).payload;
|
||||||
const registration = payload as VerifiableCredential;
|
const registration = payload as VerifiableCredentialClaim;
|
||||||
(this.$refs.contactNameDialog as ContactNameDialog).open(
|
(this.$refs.contactNameDialog as ContactNameDialog).open(
|
||||||
"Who Invited You?",
|
"Who Invited You?",
|
||||||
"",
|
"",
|
||||||
async (name) => {
|
async (name) => {
|
||||||
await this.addContact({
|
await this.addContact({
|
||||||
did: registration.vc.credentialSubject.agent.identifier,
|
did: (registration as any).vc.credentialSubject.agent.identifier,
|
||||||
name: name,
|
name: name,
|
||||||
registered: true,
|
registered: true,
|
||||||
});
|
});
|
||||||
@@ -555,7 +556,7 @@ export default class ContactsView extends Vue {
|
|||||||
async () => {
|
async () => {
|
||||||
// on cancel, will still add the contact
|
// on cancel, will still add the contact
|
||||||
await this.addContact({
|
await this.addContact({
|
||||||
did: registration.vc.credentialSubject.agent.identifier,
|
did: (registration as any).vc.credentialSubject.agent.identifier,
|
||||||
name: "(person who invited you)",
|
name: "(person who invited you)",
|
||||||
registered: true,
|
registered: true,
|
||||||
});
|
});
|
||||||
@@ -770,7 +771,21 @@ export default class ContactsView extends Vue {
|
|||||||
|
|
||||||
if (contactInput.includes(CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI)) {
|
if (contactInput.includes(CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI)) {
|
||||||
const jwt = getContactJwtFromJwtUrl(contactInput);
|
const jwt = getContactJwtFromJwtUrl(contactInput);
|
||||||
this.$router.push({ path: "/contact-import/" + jwt });
|
if (!jwt) {
|
||||||
|
this.danger("Invalid contact URL format.", "Invalid URL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { payload } = decodeEndorserJwt(jwt);
|
||||||
|
const userInfo = payload["own"] as UserInfo;
|
||||||
|
const newContact = {
|
||||||
|
did: userInfo.did || payload["iss"], // "did" is reliable as of v 0.3.49
|
||||||
|
name: userInfo.name,
|
||||||
|
nextPubKeyHashB64: userInfo.nextPublicEncKeyHash,
|
||||||
|
profileImageUrl: userInfo.profileImageUrl,
|
||||||
|
publicKeyBase64: userInfo.publicEncKey,
|
||||||
|
registered: userInfo.registered,
|
||||||
|
} as Contact;
|
||||||
|
await this.addContact(newContact);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,6 +794,10 @@ export default class ContactsView extends Vue {
|
|||||||
contactInput.includes(CONTACT_URL_PATH_ENDORSER_CH_OLD)
|
contactInput.includes(CONTACT_URL_PATH_ENDORSER_CH_OLD)
|
||||||
) {
|
) {
|
||||||
const jwt = getContactJwtFromJwtUrl(contactInput);
|
const jwt = getContactJwtFromJwtUrl(contactInput);
|
||||||
|
if (!jwt) {
|
||||||
|
this.danger("Invalid contact URL format.", "Invalid URL");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { payload } = decodeEndorserJwt(jwt);
|
const { payload } = decodeEndorserJwt(jwt);
|
||||||
const userInfo = payload["own"] as UserInfo;
|
const userInfo = payload["own"] as UserInfo;
|
||||||
const newContact = {
|
const newContact = {
|
||||||
@@ -820,8 +839,7 @@ export default class ContactsView extends Vue {
|
|||||||
this.danger("An error occurred. Some contacts may have been added.");
|
this.danger("An error occurred. Some contacts may have been added.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformService = PlatformServiceFactory.getInstance();
|
const dbAllContacts = await this.$dbQuery(
|
||||||
const dbAllContacts = await platformService.dbQuery(
|
|
||||||
"SELECT * FROM contacts ORDER BY name",
|
"SELECT * FROM contacts ORDER BY name",
|
||||||
);
|
);
|
||||||
this.contacts = databaseUtil.mapQueryResultToValues(
|
this.contacts = databaseUtil.mapQueryResultToValues(
|
||||||
@@ -900,12 +918,12 @@ export default class ContactsView extends Vue {
|
|||||||
lineRaw: string,
|
lineRaw: string,
|
||||||
): Promise<IndexableType> {
|
): Promise<IndexableType> {
|
||||||
const newContact = libsUtil.csvLineToContact(lineRaw);
|
const newContact = libsUtil.csvLineToContact(lineRaw);
|
||||||
const platformService = PlatformServiceFactory.getInstance();
|
|
||||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||||
newContact as unknown as Record<string, unknown>,
|
newContact as unknown as Record<string, unknown>,
|
||||||
"contacts",
|
"contacts",
|
||||||
);
|
);
|
||||||
await platformService.dbExec(sql, params);
|
await this.$dbExec(sql, params);
|
||||||
|
return newContact.did || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addContact(newContact: Contact) {
|
private async addContact(newContact: Contact) {
|
||||||
@@ -918,12 +936,11 @@ export default class ContactsView extends Vue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const platformService = PlatformServiceFactory.getInstance();
|
|
||||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||||
newContact as unknown as Record<string, unknown>,
|
newContact as unknown as Record<string, unknown>,
|
||||||
"contacts",
|
"contacts",
|
||||||
);
|
);
|
||||||
const contactPromise = platformService.dbExec(sql, params);
|
const contactPromise = this.$dbExec(sql, params);
|
||||||
|
|
||||||
return contactPromise
|
return contactPromise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -1008,27 +1025,6 @@ export default class ContactsView extends Vue {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// note that this is also in DIDView.vue
|
|
||||||
private async confirmSetVisibility(contact: Contact, visibility: boolean) {
|
|
||||||
const visibilityPrompt = visibility
|
|
||||||
? "Are you sure you want to make your activity visible to them?"
|
|
||||||
: "Are you sure you want to hide all your activity from them?";
|
|
||||||
this.$notify(
|
|
||||||
{
|
|
||||||
group: "modal",
|
|
||||||
type: "confirm",
|
|
||||||
title: "Set Visibility",
|
|
||||||
text: visibilityPrompt,
|
|
||||||
onYes: async () => {
|
|
||||||
const success = await this.setVisibility(contact, visibility, true);
|
|
||||||
if (success) {
|
|
||||||
contact.seesMe = visibility; // didn't work inside setVisibility
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
-1,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// note that this is also in DIDView.vue
|
// note that this is also in DIDView.vue
|
||||||
private async register(contact: Contact) {
|
private async register(contact: Contact) {
|
||||||
@@ -1043,8 +1039,7 @@ export default class ContactsView extends Vue {
|
|||||||
);
|
);
|
||||||
if (regResult.success) {
|
if (regResult.success) {
|
||||||
contact.registered = true;
|
contact.registered = true;
|
||||||
const platformService = PlatformServiceFactory.getInstance();
|
await this.$dbExec(
|
||||||
await platformService.dbExec(
|
|
||||||
"UPDATE contacts SET registered = ? WHERE did = ?",
|
"UPDATE contacts SET registered = ? WHERE did = ?",
|
||||||
[true, contact.did],
|
[true, contact.did],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user