for scan on QR code screen, import and keep on that screen
This commit is contained in:
@@ -6,6 +6,8 @@ import { IIdentifier } from "@veramo/core";
|
||||
|
||||
import { Contact } from "@/db/tables/contacts";
|
||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
||||
import { NonsensitiveDexie } from "@/db/index";
|
||||
import { getIdentity } from "@/libs/util";
|
||||
|
||||
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
||||
// the object in RegisterAction claims
|
||||
@@ -706,6 +708,12 @@ export async function createAndSubmitClaim(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An AcceptAction is when someone accepts some contract or pledge.
|
||||
*
|
||||
* @param claim has properties '@context' & '@type'
|
||||
* @return true if the claim is a schema.org AcceptAction
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const isAccept = (claim: Record<string, any>) => {
|
||||
return (
|
||||
@@ -902,3 +910,42 @@ export const bvcMeetingJoinClaim = (did: string, startTime: string) => {
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export async function setVisibilityUtil(
|
||||
activeDid: string,
|
||||
apiServer: string,
|
||||
axios: Axios,
|
||||
db: NonsensitiveDexie,
|
||||
contact: Contact,
|
||||
visibility: boolean,
|
||||
) {
|
||||
if (!activeDid) {
|
||||
return { error: "Cannot set visibility without an identifier." };
|
||||
}
|
||||
const url =
|
||||
apiServer + "/api/report/" + (visibility ? "canSeeMe" : "cannotSeeMe");
|
||||
const identity = await getIdentity(activeDid);
|
||||
const headers = await getHeaders(identity);
|
||||
const payload = JSON.stringify({ did: contact.did });
|
||||
|
||||
try {
|
||||
const resp = await axios.post(url, payload, { headers });
|
||||
if (resp.status === 200) {
|
||||
contact.seesMe = visibility;
|
||||
db.contacts.update(contact.did, { seesMe: visibility });
|
||||
return { success: true };
|
||||
} else {
|
||||
console.error(
|
||||
"Got some bad server response when setting visibility: ",
|
||||
resp.status,
|
||||
resp,
|
||||
);
|
||||
const message =
|
||||
resp.data.error?.message || "Got some error setting visibility.";
|
||||
return { error: message };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Got some error when setting visibility:", err);
|
||||
return { error: "Check connectivity and try again." };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ export const getIdentity = async (activeDid: string): Promise<IIdentifier> => {
|
||||
|
||||
if (!identity) {
|
||||
throw new Error(
|
||||
`Attempted to load Offer records for DID ${activeDid} but no identifier was found`,
|
||||
`Attempted to load identity ${activeDid} but no identifier was found`,
|
||||
);
|
||||
}
|
||||
return identity;
|
||||
|
||||
Reference in New Issue
Block a user