@trustless-work/blocks 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -0
- package/bin/index.js +1123 -0
- package/package.json +44 -0
- package/templates/deps.json +29 -0
- package/templates/escrows/details/Actions.tsx +149 -0
- package/templates/escrows/details/Entities.tsx +48 -0
- package/templates/escrows/details/EntityCard.tsx +98 -0
- package/templates/escrows/details/EscrowDetailDialog.tsx +154 -0
- package/templates/escrows/details/GeneralInformation.tsx +329 -0
- package/templates/escrows/details/MilestoneCard.tsx +254 -0
- package/templates/escrows/details/MilestoneDetailDialog.tsx +276 -0
- package/templates/escrows/details/Milestones.tsx +87 -0
- package/templates/escrows/details/ProgressEscrow.tsx +191 -0
- package/templates/escrows/details/StatisticsCard.tsx +79 -0
- package/templates/escrows/details/SuccessReleaseDialog.tsx +101 -0
- package/templates/escrows/details/useDetailsEscrow.ts +126 -0
- package/templates/escrows/escrow-context/EscrowAmountProvider.tsx +86 -0
- package/templates/escrows/escrow-context/EscrowDialogsProvider.tsx +108 -0
- package/templates/escrows/escrow-context/EscrowProvider.tsx +124 -0
- package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +503 -0
- package/templates/escrows/escrows-by-role/cards/Filters.tsx +421 -0
- package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +427 -0
- package/templates/escrows/escrows-by-role/table/Filters.tsx +421 -0
- package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +336 -0
- package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +502 -0
- package/templates/escrows/escrows-by-signer/cards/Filters.tsx +389 -0
- package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +422 -0
- package/templates/escrows/escrows-by-signer/table/Filters.tsx +389 -0
- package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +320 -0
- package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +78 -0
- package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +102 -0
- package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +80 -0
- package/templates/escrows/single-release/approve-milestone/shared/schema.ts +9 -0
- package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +67 -0
- package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +78 -0
- package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +167 -0
- package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +114 -0
- package/templates/escrows/single-release/change-milestone-status/shared/schema.ts +15 -0
- package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +77 -0
- package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +68 -0
- package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +84 -0
- package/templates/escrows/single-release/fund-escrow/dialog/FundEscrow.tsx +77 -0
- package/templates/escrows/single-release/fund-escrow/form/FundEscrow.tsx +54 -0
- package/templates/escrows/single-release/fund-escrow/shared/schema.ts +10 -0
- package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +66 -0
- package/templates/escrows/single-release/initialize-escrow/dialog/InitializeEscrow.tsx +526 -0
- package/templates/escrows/single-release/initialize-escrow/form/InitializeEscrow.tsx +504 -0
- package/templates/escrows/single-release/initialize-escrow/shared/schema.ts +232 -0
- package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +115 -0
- package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +80 -0
- package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +94 -0
- package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +123 -0
- package/templates/escrows/single-release/resolve-dispute/form/ResolveDispute.tsx +82 -0
- package/templates/escrows/single-release/resolve-dispute/shared/schema.ts +82 -0
- package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +58 -0
- package/templates/escrows/single-release/update-escrow/dialog/UpdateEscrow.tsx +485 -0
- package/templates/escrows/single-release/update-escrow/form/UpdateEscrow.tsx +463 -0
- package/templates/escrows/single-release/update-escrow/shared/schema.ts +139 -0
- package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +211 -0
- package/templates/handle-errors/errors.enum.ts +6 -0
- package/templates/handle-errors/handle.ts +47 -0
- package/templates/helpers/format.helper.ts +27 -0
- package/templates/helpers/useCopy.ts +13 -0
- package/templates/providers/ReactQueryClientProvider.tsx +28 -0
- package/templates/providers/TrustlessWork.tsx +30 -0
- package/templates/tanstak/useEscrowsByRoleQuery.ts +87 -0
- package/templates/tanstak/useEscrowsBySignerQuery.ts +78 -0
- package/templates/tanstak/useEscrowsMutations.ts +411 -0
- package/templates/wallet-kit/WalletButtons.tsx +116 -0
- package/templates/wallet-kit/WalletProvider.tsx +94 -0
- package/templates/wallet-kit/trustlines.ts +40 -0
- package/templates/wallet-kit/useWallet.ts +77 -0
- package/templates/wallet-kit/validators.ts +12 -0
- package/templates/wallet-kit/wallet-kit.ts +30 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Form,
|
|
4
|
+
FormField,
|
|
5
|
+
FormItem,
|
|
6
|
+
FormLabel,
|
|
7
|
+
FormControl,
|
|
8
|
+
FormMessage,
|
|
9
|
+
} from "__UI_BASE__/form";
|
|
10
|
+
import { Input } from "__UI_BASE__/input";
|
|
11
|
+
import { Button } from "__UI_BASE__/button";
|
|
12
|
+
import { useResolveDispute } from "./useResolveDispute";
|
|
13
|
+
import { Loader2 } from "lucide-react";
|
|
14
|
+
|
|
15
|
+
export default function ResolveDisputeForm() {
|
|
16
|
+
const { form, handleSubmit, isSubmitting } = useResolveDispute();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Form {...form}>
|
|
20
|
+
<form onSubmit={handleSubmit}>
|
|
21
|
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
|
22
|
+
<FormField
|
|
23
|
+
control={form.control}
|
|
24
|
+
name="approverFunds"
|
|
25
|
+
render={({ field }) => (
|
|
26
|
+
<FormItem>
|
|
27
|
+
<FormLabel>Approver Funds</FormLabel>
|
|
28
|
+
<FormControl>
|
|
29
|
+
<Input
|
|
30
|
+
type="text"
|
|
31
|
+
inputMode="decimal"
|
|
32
|
+
placeholder="Enter approver funds"
|
|
33
|
+
value={field.value as unknown as string}
|
|
34
|
+
onChange={(e) => field.onChange(e.target.value)}
|
|
35
|
+
/>
|
|
36
|
+
</FormControl>
|
|
37
|
+
<FormMessage />
|
|
38
|
+
</FormItem>
|
|
39
|
+
)}
|
|
40
|
+
/>
|
|
41
|
+
|
|
42
|
+
<FormField
|
|
43
|
+
control={form.control}
|
|
44
|
+
name="receiverFunds"
|
|
45
|
+
render={({ field }) => (
|
|
46
|
+
<FormItem>
|
|
47
|
+
<FormLabel>Receiver Funds</FormLabel>
|
|
48
|
+
<FormControl>
|
|
49
|
+
<Input
|
|
50
|
+
type="text"
|
|
51
|
+
inputMode="decimal"
|
|
52
|
+
placeholder="Enter receiver funds"
|
|
53
|
+
value={field.value as unknown as string}
|
|
54
|
+
onChange={(e) => field.onChange(e.target.value)}
|
|
55
|
+
/>
|
|
56
|
+
</FormControl>
|
|
57
|
+
<FormMessage />
|
|
58
|
+
</FormItem>
|
|
59
|
+
)}
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div className="mt-4">
|
|
64
|
+
<Button
|
|
65
|
+
type="submit"
|
|
66
|
+
disabled={isSubmitting}
|
|
67
|
+
className="cursor-pointer"
|
|
68
|
+
>
|
|
69
|
+
{isSubmitting ? (
|
|
70
|
+
<div className="flex items-center">
|
|
71
|
+
<Loader2 className="h-5 w-5 animate-spin" />
|
|
72
|
+
<span className="ml-2">Resolving...</span>
|
|
73
|
+
</div>
|
|
74
|
+
) : (
|
|
75
|
+
"Resolve"
|
|
76
|
+
)}
|
|
77
|
+
</Button>
|
|
78
|
+
</div>
|
|
79
|
+
</form>
|
|
80
|
+
</Form>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const getFormSchema = () => {
|
|
4
|
+
return z.object({
|
|
5
|
+
approverFunds: z
|
|
6
|
+
.union([z.string(), z.number()])
|
|
7
|
+
.refine(
|
|
8
|
+
(val) => {
|
|
9
|
+
if (typeof val === "string") {
|
|
10
|
+
if (val === "" || val === "." || val.endsWith(".")) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const numVal = Number(val);
|
|
14
|
+
return !isNaN(numVal) && numVal >= 0;
|
|
15
|
+
}
|
|
16
|
+
return val >= 0;
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
message: "Approver funds must be 0 or greater.",
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
.refine(
|
|
23
|
+
(val) => {
|
|
24
|
+
if (typeof val === "string") {
|
|
25
|
+
if (val === "" || val === "." || val.endsWith(".")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const numVal = Number(val);
|
|
29
|
+
if (isNaN(numVal)) return false;
|
|
30
|
+
const decimalPlaces = (numVal.toString().split(".")[1] || "")
|
|
31
|
+
.length;
|
|
32
|
+
return decimalPlaces <= 2;
|
|
33
|
+
}
|
|
34
|
+
const decimalPlaces = (val.toString().split(".")[1] || "").length;
|
|
35
|
+
return decimalPlaces <= 2;
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
message: "Approver funds can have a maximum of 2 decimal places.",
|
|
39
|
+
}
|
|
40
|
+
),
|
|
41
|
+
receiverFunds: z
|
|
42
|
+
.union([z.string(), z.number()])
|
|
43
|
+
.refine(
|
|
44
|
+
(val) => {
|
|
45
|
+
if (typeof val === "string") {
|
|
46
|
+
if (val === "" || val === "." || val.endsWith(".")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const numVal = Number(val);
|
|
50
|
+
return !isNaN(numVal) && numVal >= 0;
|
|
51
|
+
}
|
|
52
|
+
return val >= 0;
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
message: "Receiver funds must be 0 or greater.",
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
.refine(
|
|
59
|
+
(val) => {
|
|
60
|
+
if (typeof val === "string") {
|
|
61
|
+
if (val === "" || val === "." || val.endsWith(".")) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const numVal = Number(val);
|
|
65
|
+
if (isNaN(numVal)) return false;
|
|
66
|
+
const decimalPlaces = (numVal.toString().split(".")[1] || "")
|
|
67
|
+
.length;
|
|
68
|
+
return decimalPlaces <= 2;
|
|
69
|
+
}
|
|
70
|
+
const decimalPlaces = (val.toString().split(".")[1] || "").length;
|
|
71
|
+
return decimalPlaces <= 2;
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
message: "Receiver funds can have a maximum of 2 decimal places.",
|
|
75
|
+
}
|
|
76
|
+
),
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const resolveDisputeSchema = getFormSchema();
|
|
81
|
+
|
|
82
|
+
export type ResolveDisputeValues = z.infer<typeof resolveDisputeSchema>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useForm } from "react-hook-form";
|
|
3
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
4
|
+
import { resolveDisputeSchema, type ResolveDisputeValues } from "./schema";
|
|
5
|
+
import { toast } from "sonner";
|
|
6
|
+
import { SingleReleaseResolveDisputePayload } from "@trustless-work/escrow";
|
|
7
|
+
import { useEscrowContext } from "../../../escrow-context/EscrowProvider";
|
|
8
|
+
import { useEscrowsMutations } from "@/components/tw-blocks/tanstak/useEscrowsMutations";
|
|
9
|
+
import {
|
|
10
|
+
ErrorResponse,
|
|
11
|
+
handleError,
|
|
12
|
+
} from "@/components/tw-blocks/handle-errors/handle";
|
|
13
|
+
import { useWalletContext } from "@/components/tw-blocks/wallet-kit/WalletProvider";
|
|
14
|
+
|
|
15
|
+
export function useResolveDispute() {
|
|
16
|
+
const { resolveDispute } = useEscrowsMutations();
|
|
17
|
+
const { selectedEscrow } = useEscrowContext();
|
|
18
|
+
const { walletAddress } = useWalletContext();
|
|
19
|
+
|
|
20
|
+
const form = useForm<ResolveDisputeValues>({
|
|
21
|
+
resolver: zodResolver(resolveDisputeSchema),
|
|
22
|
+
defaultValues: {
|
|
23
|
+
approverFunds: 0,
|
|
24
|
+
receiverFunds: 0,
|
|
25
|
+
},
|
|
26
|
+
mode: "onChange",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
30
|
+
|
|
31
|
+
const handleSubmit = form.handleSubmit(async (payload) => {
|
|
32
|
+
try {
|
|
33
|
+
setIsSubmitting(true);
|
|
34
|
+
|
|
35
|
+
const finalPayload: SingleReleaseResolveDisputePayload = {
|
|
36
|
+
contractId: selectedEscrow?.contractId || "",
|
|
37
|
+
disputeResolver: walletAddress || "",
|
|
38
|
+
approverFunds: Number(payload.approverFunds),
|
|
39
|
+
receiverFunds: Number(payload.receiverFunds),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
await resolveDispute.mutateAsync({
|
|
43
|
+
payload: finalPayload,
|
|
44
|
+
type: "single-release",
|
|
45
|
+
address: walletAddress || "",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
toast.success("Dispute resolved successfully");
|
|
49
|
+
} catch (error) {
|
|
50
|
+
toast.error(handleError(error as ErrorResponse).message);
|
|
51
|
+
} finally {
|
|
52
|
+
setIsSubmitting(false);
|
|
53
|
+
form.reset();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return { form, handleSubmit, isSubmitting };
|
|
58
|
+
}
|