forked from trent_larson/crowd-funder-for-time-pwa
fix some result types and refactor types themselves
This commit is contained in:
@@ -321,7 +321,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errorMessage = this.getGiveCreationErrorMessage(result);
|
const errorMessage = result.error;
|
||||||
logger.error("Error with give creation result:", result);
|
logger.error("Error with give creation result:", result);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
@@ -367,19 +367,6 @@ export default class GiftedDialog extends Vue {
|
|||||||
|
|
||||||
// Helper functions for readability
|
// Helper functions for readability
|
||||||
|
|
||||||
/**
|
|
||||||
* @param result direct response eg. ErrorResult or SuccessResult (potentially with embedded "data")
|
|
||||||
* @returns best guess at an error message
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
getGiveCreationErrorMessage(result: any) {
|
|
||||||
return (
|
|
||||||
result.error?.userMessage ||
|
|
||||||
result.error?.error ||
|
|
||||||
result.response?.data?.error?.message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
explainData() {
|
explainData() {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -250,7 +250,7 @@ export default class OfferDialog extends Vue {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errorMessage = this.getOfferCreationErrorMessage(result);
|
const errorMessage = result.error;
|
||||||
logger.error("Error with offer creation result:", result);
|
logger.error("Error with offer creation result:", result);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
@@ -290,21 +290,6 @@ export default class OfferDialog extends Vue {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions for readability
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param result direct response eg. ErrorResult or SuccessResult (potentially with embedded "data")
|
|
||||||
* @returns best guess at an error message
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
getOfferCreationErrorMessage(result: any) {
|
|
||||||
return (
|
|
||||||
serverMessageForUser(result) ||
|
|
||||||
result.error?.userMessage ||
|
|
||||||
result.error?.error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { AxiosResponse } from "axios";
|
|
||||||
import { GiverReceiverInputInfo } from "../libs/util";
|
import { GiverReceiverInputInfo } from "../libs/util";
|
||||||
import { ErrorResult, ResultWithType } from "./common";
|
|
||||||
|
|
||||||
export interface GiverOutputInfo {
|
export interface GiverOutputInfo {
|
||||||
action: string;
|
action: string;
|
||||||
@@ -47,12 +45,3 @@ export interface ProviderInfo {
|
|||||||
*/
|
*/
|
||||||
linkConfirmed: boolean;
|
linkConfirmed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type for createAndSubmitClaim result
|
|
||||||
export type CreateAndSubmitClaimResult = SuccessResult | ErrorResult;
|
|
||||||
|
|
||||||
// Update SuccessResult to use ClaimResult
|
|
||||||
export interface SuccessResult extends ResultWithType {
|
|
||||||
type: "success";
|
|
||||||
response: AxiosResponse<ClaimResult>;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ export interface GenericCredWrapper<T extends GenericVerifiableCredential> {
|
|||||||
publicUrls?: Record<string, string>;
|
publicUrls?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResultWithType {
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ErrorResponse {
|
export interface ErrorResponse {
|
||||||
error?: {
|
error?: {
|
||||||
message?: string;
|
message?: string;
|
||||||
@@ -30,11 +26,6 @@ export interface InternalError {
|
|||||||
userMessage?: string;
|
userMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ErrorResult extends ResultWithType {
|
|
||||||
type: "error";
|
|
||||||
error: InternalError;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface KeyMeta {
|
export interface KeyMeta {
|
||||||
did: string;
|
did: string;
|
||||||
publicKeyHex: string;
|
publicKeyHex: string;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export type {
|
export type {
|
||||||
// From common.ts
|
// From common.ts
|
||||||
|
CreateAndSubmitClaimResult,
|
||||||
GenericCredWrapper,
|
GenericCredWrapper,
|
||||||
GenericVerifiableCredential,
|
GenericVerifiableCredential,
|
||||||
KeyMeta,
|
KeyMeta,
|
||||||
@@ -18,11 +19,6 @@ export type {
|
|||||||
RegisterActionClaim,
|
RegisterActionClaim,
|
||||||
} from "./claims";
|
} from "./claims";
|
||||||
|
|
||||||
export type {
|
|
||||||
// From claims-result.ts
|
|
||||||
CreateAndSubmitClaimResult,
|
|
||||||
} from "./claims-result";
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
// From records.ts
|
// From records.ts
|
||||||
PlanSummaryRecord,
|
PlanSummaryRecord,
|
||||||
|
|||||||
@@ -979,7 +979,7 @@ export const createAndSubmitConfirmation = async (
|
|||||||
handleId: string | undefined,
|
handleId: string | undefined,
|
||||||
apiServer: string,
|
apiServer: string,
|
||||||
axios: Axios,
|
axios: Axios,
|
||||||
) => {
|
): Promise<CreateAndSubmitClaimResult> => {
|
||||||
const goodClaim = removeSchemaContext(
|
const goodClaim = removeSchemaContext(
|
||||||
removeVisibleToDids(
|
removeVisibleToDids(
|
||||||
addLastClaimOrHandleAsIdIfMissing(claim, lastClaimId, handleId),
|
addLastClaimOrHandleAsIdIfMissing(claim, lastClaimId, handleId),
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ export default class ClaimAddRawView extends Vue {
|
|||||||
this.apiServer,
|
this.apiServer,
|
||||||
this.axios,
|
this.axios,
|
||||||
);
|
);
|
||||||
if (result.type === "success") {
|
if (result.success) {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
|
|||||||
@@ -831,7 +831,7 @@ export default class ConfirmGiftView extends Vue {
|
|||||||
this.apiServer,
|
this.apiServer,
|
||||||
this.axios,
|
this.axios,
|
||||||
);
|
);
|
||||||
if (result.type === "success") {
|
if (result.success) {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
|
|||||||
@@ -826,7 +826,7 @@ export default class GiftedDetails extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errorMessage = this.getGiveCreationErrorMessage(result);
|
const errorMessage = result.error;
|
||||||
logger.error("Error with give creation result:", result);
|
logger.error("Error with give creation result:", result);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
@@ -899,19 +899,6 @@ export default class GiftedDetails extends Vue {
|
|||||||
|
|
||||||
// Helper functions for readability
|
// Helper functions for readability
|
||||||
|
|
||||||
/**
|
|
||||||
* @param result direct response eg. ErrorResult or SuccessResult (potentially with embedded "data")
|
|
||||||
* @returns best guess at an error message
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
getGiveCreationErrorMessage(result: any) {
|
|
||||||
return (
|
|
||||||
result.error?.userMessage ||
|
|
||||||
result.error?.error ||
|
|
||||||
result.response?.data?.error?.message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
explainData() {
|
explainData() {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1843,7 +1843,7 @@ export default class HomeView extends Vue {
|
|||||||
this.axios,
|
this.axios,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.type === "success") {
|
if (result.success) {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
|
|||||||
@@ -1433,7 +1433,7 @@ export default class ProjectViewView extends Vue {
|
|||||||
this.apiServer,
|
this.apiServer,
|
||||||
this.axios,
|
this.axios,
|
||||||
);
|
);
|
||||||
if (result.type === "success") {
|
if (result.success) {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
group: "alert",
|
group: "alert",
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ import { Contact } from "../db/tables/contacts";
|
|||||||
import {
|
import {
|
||||||
GenericCredWrapper,
|
GenericCredWrapper,
|
||||||
GenericVerifiableCredential,
|
GenericVerifiableCredential,
|
||||||
ErrorResult,
|
CreateAndSubmitClaimResult,
|
||||||
} from "../interfaces";
|
} from "../interfaces";
|
||||||
import {
|
import {
|
||||||
BVC_MEETUPS_PROJECT_CLAIM_ID,
|
BVC_MEETUPS_PROJECT_CLAIM_ID,
|
||||||
@@ -298,13 +298,13 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in parallel, make a confirmation for each selected claim and send them all to the server
|
// in parallel, make a confirmation for each selected claim and send them all to the server
|
||||||
const confirmResults = await Promise.allSettled(
|
const confirmResults: PromiseSettledResult<CreateAndSubmitClaimResult>[] = await Promise.allSettled(
|
||||||
this.claimsToConfirmSelected.map(async (jwtId) => {
|
this.claimsToConfirmSelected.map(async (jwtId) => {
|
||||||
const record = this.claimsToConfirm.find(
|
const record = this.claimsToConfirm.find(
|
||||||
(claim) => claim.id === jwtId,
|
(claim) => claim.id === jwtId,
|
||||||
);
|
);
|
||||||
if (!record) {
|
if (!record) {
|
||||||
return { type: "error", error: "Record not found." };
|
return { success: false, error: "Record not found." };
|
||||||
}
|
}
|
||||||
return createAndSubmitConfirmation(
|
return createAndSubmitConfirmation(
|
||||||
this.activeDid,
|
this.activeDid,
|
||||||
@@ -318,8 +318,8 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
);
|
);
|
||||||
// check for any rejected confirmations
|
// check for any rejected confirmations
|
||||||
const confirmsSucceeded = confirmResults.filter(
|
const confirmsSucceeded = confirmResults.filter(
|
||||||
(result) =>
|
// 'fulfilled' is the status in a successful PromiseFulfilledResult
|
||||||
result.status === "fulfilled" && result.value.type === "success",
|
(result) => result.status === "fulfilled" && result.value.success,
|
||||||
);
|
);
|
||||||
if (confirmsSucceeded.length < this.claimsToConfirmSelected.length) {
|
if (confirmsSucceeded.length < this.claimsToConfirmSelected.length) {
|
||||||
logger.error("Error sending confirmations:", confirmResults);
|
logger.error("Error sending confirmations:", confirmResults);
|
||||||
@@ -353,7 +353,7 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
undefined,
|
undefined,
|
||||||
BVC_MEETUPS_PROJECT_CLAIM_ID,
|
BVC_MEETUPS_PROJECT_CLAIM_ID,
|
||||||
);
|
);
|
||||||
giveSucceeded = giveResult.type === "success";
|
giveSucceeded = giveResult.success;
|
||||||
if (!giveSucceeded) {
|
if (!giveSucceeded) {
|
||||||
logger.error("Error sending give:", giveResult);
|
logger.error("Error sending give:", giveResult);
|
||||||
this.$notify(
|
this.$notify(
|
||||||
@@ -362,7 +362,7 @@ export default class QuickActionBvcBeginView extends Vue {
|
|||||||
type: "danger",
|
type: "danger",
|
||||||
title: "Error",
|
title: "Error",
|
||||||
text:
|
text:
|
||||||
(giveResult as ErrorResult)?.error?.userMessage ||
|
(giveResult as CreateAndSubmitClaimResult)?.error ||
|
||||||
"There was an error sending that give.",
|
"There was an error sending that give.",
|
||||||
},
|
},
|
||||||
5000,
|
5000,
|
||||||
|
|||||||
Reference in New Issue
Block a user