forked from trent_larson/crowd-funder-for-time-pwa
add expiration inside JWANT & refactor getHeaders to move toward supporting did:peer
This commit is contained in:
@@ -807,32 +807,6 @@ export default class AccountViewView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves headers for HTTP requests.
|
||||
*
|
||||
* @param {IIdentifier} identity - The identity object for which to generate the headers.
|
||||
* @returns {Promise<Record<string,string>>} A Promise that resolves to an object containing the headers.
|
||||
*
|
||||
* @throws Will throw an error if unable to generate an access token.
|
||||
*/
|
||||
public async getHeaders(
|
||||
identity: IIdentifier,
|
||||
): Promise<Record<string, string>> {
|
||||
try {
|
||||
const token = await accessToken(identity);
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
};
|
||||
|
||||
return headers;
|
||||
} catch (error) {
|
||||
console.error("Failed to get headers:", error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
// call fn, copy text to the clipboard, then redo fn after 2 seconds
|
||||
doCopyTwoSecRedo(text: string, fn: () => void) {
|
||||
fn();
|
||||
@@ -884,7 +858,7 @@ export default class AccountViewView extends Vue {
|
||||
this.publicHex = identity.keys[0].publicKeyHex;
|
||||
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
||||
this.derivationPath = identity.keys[0].meta?.derivationPath as string;
|
||||
this.checkLimitsFor(identity);
|
||||
this.checkLimitsFor(this.activeDid);
|
||||
} else {
|
||||
// Handle the case where any of these are null or undefined
|
||||
}
|
||||
@@ -1238,9 +1212,8 @@ export default class AccountViewView extends Vue {
|
||||
}
|
||||
|
||||
async checkLimits() {
|
||||
const identity = await this.getIdentity(this.activeDid);
|
||||
if (identity) {
|
||||
this.checkLimitsFor(identity);
|
||||
if (this.activeDid) {
|
||||
this.checkLimitsFor(this.activeDid);
|
||||
} else {
|
||||
this.limitsMessage =
|
||||
"You have no identifier, or your data has been corrupted.";
|
||||
@@ -1252,7 +1225,7 @@ export default class AccountViewView extends Vue {
|
||||
*
|
||||
* Updates component state variables `limits`, `limitsMessage`, and `loadingLimits`.
|
||||
*/
|
||||
public async checkLimitsFor(identity: IIdentifier) {
|
||||
public async checkLimitsFor(did: string) {
|
||||
this.loadingLimits = true;
|
||||
this.limitsMessage = "";
|
||||
|
||||
@@ -1260,7 +1233,7 @@ export default class AccountViewView extends Vue {
|
||||
const resp = await fetchEndorserRateLimits(
|
||||
this.apiServer,
|
||||
this.axios,
|
||||
identity,
|
||||
did,
|
||||
);
|
||||
if (resp.status === 200) {
|
||||
this.endorserLimits = resp.data;
|
||||
@@ -1288,7 +1261,7 @@ export default class AccountViewView extends Vue {
|
||||
const imageResp = await fetchImageRateLimits(
|
||||
this.apiServer,
|
||||
this.axios,
|
||||
identity,
|
||||
did,
|
||||
);
|
||||
if (imageResp.status === 200) {
|
||||
this.imageLimits = imageResp.data;
|
||||
|
||||
Reference in New Issue
Block a user