@trustless-work/blocks 0.0.5 → 0.0.7
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 +39 -13
- package/bin/index.js +1128 -1137
- package/package.json +44 -44
- package/templates/escrows/details/EscrowDetailDialog.tsx +3 -3
- package/templates/escrows/details/GeneralInformation.tsx +2 -2
- package/templates/escrows/details/SuccessReleaseDialog.tsx +2 -3
- package/templates/escrows/details/useDetailsEscrow.ts +2 -2
- package/templates/escrows/escrows-by-role/cards/EscrowsCards.tsx +42 -16
- package/templates/escrows/escrows-by-role/table/EscrowsTable.tsx +45 -18
- package/templates/escrows/escrows-by-role/useEscrowsByRole.shared.ts +39 -25
- package/templates/escrows/escrows-by-signer/cards/EscrowsCards.tsx +33 -16
- package/templates/escrows/escrows-by-signer/table/EscrowsTable.tsx +34 -17
- package/templates/escrows/escrows-by-signer/useEscrowsBySigner.shared.ts +38 -25
- package/templates/escrows/single-release/approve-milestone/button/ApproveMilestone.tsx +14 -1
- package/templates/escrows/single-release/approve-milestone/dialog/ApproveMilestone.tsx +1 -1
- package/templates/escrows/single-release/approve-milestone/form/ApproveMilestone.tsx +1 -1
- package/templates/escrows/single-release/approve-milestone/shared/useApproveMilestone.ts +14 -1
- package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx +16 -1
- package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx +1 -1
- package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx +1 -1
- package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts +14 -1
- package/templates/escrows/single-release/dispute-escrow/button/DisputeEscrow.tsx +13 -1
- package/templates/escrows/single-release/fund-escrow/button/FundEscrow.tsx +13 -1
- package/templates/escrows/single-release/fund-escrow/shared/useFundEscrow.ts +14 -1
- package/templates/escrows/single-release/initialize-escrow/shared/useInitializeEscrow.ts +17 -1
- package/templates/escrows/single-release/release-escrow/button/ReleaseEscrow.tsx +15 -3
- package/templates/escrows/single-release/resolve-dispute/button/ResolveDispute.tsx +13 -1
- package/templates/escrows/single-release/resolve-dispute/dialog/ResolveDispute.tsx +1 -1
- package/templates/escrows/single-release/resolve-dispute/shared/useResolveDispute.ts +14 -1
- package/templates/escrows/single-release/update-escrow/shared/useUpdateEscrow.ts +224 -211
- package/templates/handle-errors/handle.ts +16 -0
- package/templates/helpers/format.helper.ts +31 -0
- package/templates/helpers/useCopy.ts +5 -0
- package/templates/{escrows/escrow-context → providers}/EscrowAmountProvider.tsx +3 -0
- package/templates/providers/EscrowDialogsProvider.tsx +61 -0
- package/templates/{escrows/escrow-context → providers}/EscrowProvider.tsx +30 -0
- package/templates/providers/ReactQueryClientProvider.tsx +17 -1
- package/templates/tanstack/useEscrowsByRoleQuery.ts +14 -0
- package/templates/tanstack/useEscrowsBySignerQuery.ts +13 -0
- package/templates/tanstack/useEscrowsMutations.ts +36 -0
- package/templates/wallet-kit/trustlines.ts +7 -0
- package/templates/wallet-kit/validators.ts +6 -0
- package/templates/wallet-kit/wallet-kit.ts +13 -0
- package/templates/escrows/escrow-context/EscrowDialogsProvider.tsx +0 -108
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
import { FileX, Loader2, Wallet, RefreshCw, AlertTriangle } from "lucide-react";
|
|
26
26
|
import Filters from "./Filters";
|
|
27
27
|
import { useEscrowsBySigner } from "../useEscrowsBySigner.shared";
|
|
28
|
-
import { useEscrowDialogs } from "
|
|
29
|
-
import { useEscrowContext } from "
|
|
28
|
+
import { useEscrowDialogs } from "@/components/tw-blocks/providers/EscrowDialogsProvider";
|
|
29
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
30
30
|
import EscrowDetailDialog from "../../escrows-by-role/details/EscrowDetailDialog";
|
|
31
31
|
import { formatTimestamp } from "../../../helpers/format.helper";
|
|
32
32
|
|
|
@@ -73,6 +73,10 @@ export function EscrowsBySignerTable() {
|
|
|
73
73
|
const dialogStates = useEscrowDialogs();
|
|
74
74
|
const { setSelectedEscrow } = useEscrowContext();
|
|
75
75
|
|
|
76
|
+
const handleRefresh = React.useCallback(() => {
|
|
77
|
+
void refetch();
|
|
78
|
+
}, [refetch]);
|
|
79
|
+
|
|
76
80
|
const columns = React.useMemo<ColumnDef<Escrow>[]>(
|
|
77
81
|
() => [
|
|
78
82
|
{
|
|
@@ -184,7 +188,7 @@ export function EscrowsBySignerTable() {
|
|
|
184
188
|
),
|
|
185
189
|
},
|
|
186
190
|
],
|
|
187
|
-
[]
|
|
191
|
+
[dialogStates.second.setIsOpen, setSelectedEscrow]
|
|
188
192
|
);
|
|
189
193
|
|
|
190
194
|
const table = useReactTable({
|
|
@@ -199,7 +203,18 @@ export function EscrowsBySignerTable() {
|
|
|
199
203
|
enableSortingRemoval: true,
|
|
200
204
|
});
|
|
201
205
|
|
|
202
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Based on the provided roles -> https://docs.trustlesswork.com/trustless-work/technology-overview/roles-in-trustless-work
|
|
208
|
+
*
|
|
209
|
+
* You must pass one or more roles according to requirements
|
|
210
|
+
*
|
|
211
|
+
* For example:
|
|
212
|
+
* - If the user is a freelancer, you must pass the "serviceProvider" and "receiver" role
|
|
213
|
+
*
|
|
214
|
+
* Depending of the role, you'll have different actions buttons
|
|
215
|
+
*/
|
|
216
|
+
const activeRole: Role[] = React.useMemo(() => ["approver"] as Role[], []);
|
|
217
|
+
|
|
203
218
|
const escrows = data ?? [];
|
|
204
219
|
|
|
205
220
|
return (
|
|
@@ -220,18 +235,18 @@ export function EscrowsBySignerTable() {
|
|
|
220
235
|
setEngagementId={setEngagementId}
|
|
221
236
|
setIsActive={setIsActive}
|
|
222
237
|
setValidateOnChain={setValidateOnChain}
|
|
223
|
-
setType={
|
|
224
|
-
setStatus={
|
|
238
|
+
setType={setType}
|
|
239
|
+
setStatus={setStatus}
|
|
225
240
|
setMinAmount={setMinAmount}
|
|
226
241
|
setMaxAmount={setMaxAmount}
|
|
227
242
|
setDateRange={setDateRange}
|
|
228
243
|
onClearFilters={onClearFilters}
|
|
229
|
-
onRefresh={
|
|
244
|
+
onRefresh={handleRefresh}
|
|
230
245
|
isRefreshing={isFetching}
|
|
231
246
|
orderBy={orderBy}
|
|
232
247
|
orderDirection={orderDirection}
|
|
233
|
-
setOrderBy={
|
|
234
|
-
setOrderDirection={
|
|
248
|
+
setOrderBy={setOrderBy}
|
|
249
|
+
setOrderDirection={setOrderDirection}
|
|
235
250
|
/>
|
|
236
251
|
|
|
237
252
|
<Card className="w-full py-2 sm:py-4">
|
|
@@ -330,7 +345,7 @@ export function EscrowsBySignerTable() {
|
|
|
330
345
|
<Button
|
|
331
346
|
variant="outline"
|
|
332
347
|
size="sm"
|
|
333
|
-
onClick={
|
|
348
|
+
onClick={handleRefresh}
|
|
334
349
|
>
|
|
335
350
|
<RefreshCw className="h-4 w-4 mr-2" />
|
|
336
351
|
Retry
|
|
@@ -409,14 +424,16 @@ export function EscrowsBySignerTable() {
|
|
|
409
424
|
</div>
|
|
410
425
|
|
|
411
426
|
{/* Dialog */}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
427
|
+
{dialogStates.second.isOpen ? (
|
|
428
|
+
<EscrowDetailDialog
|
|
429
|
+
activeRole={activeRole}
|
|
430
|
+
isDialogOpen={dialogStates.second.isOpen}
|
|
431
|
+
setIsDialogOpen={dialogStates.second.setIsOpen}
|
|
432
|
+
setSelectedEscrow={setSelectedEscrow}
|
|
433
|
+
/>
|
|
434
|
+
) : null}
|
|
418
435
|
</>
|
|
419
436
|
);
|
|
420
437
|
}
|
|
421
438
|
|
|
422
|
-
export default EscrowsBySignerTable;
|
|
439
|
+
export default React.memo(EscrowsBySignerTable);
|
|
@@ -101,8 +101,8 @@ export function useEscrowsBySigner() {
|
|
|
101
101
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
102
|
}, []);
|
|
103
103
|
|
|
104
|
-
const
|
|
105
|
-
{
|
|
104
|
+
const stableSearchParams = React.useMemo(
|
|
105
|
+
() => ({
|
|
106
106
|
page,
|
|
107
107
|
orderBy,
|
|
108
108
|
orderDirection,
|
|
@@ -118,10 +118,28 @@ export function useEscrowsBySigner() {
|
|
|
118
118
|
? startOfDay(dateRange.from).toISOString()
|
|
119
119
|
: undefined,
|
|
120
120
|
endDate: dateRange.to ? endOfDay(dateRange.to).toISOString() : undefined,
|
|
121
|
-
},
|
|
122
|
-
|
|
121
|
+
}),
|
|
122
|
+
[
|
|
123
|
+
page,
|
|
124
|
+
orderBy,
|
|
125
|
+
orderDirection,
|
|
126
|
+
debouncedTitle,
|
|
127
|
+
debouncedEngagementId,
|
|
128
|
+
isActive,
|
|
129
|
+
validateOnChain,
|
|
130
|
+
type,
|
|
131
|
+
status,
|
|
132
|
+
debouncedMinAmount,
|
|
133
|
+
debouncedMaxAmount,
|
|
134
|
+
dateRange.from,
|
|
135
|
+
dateRange.to,
|
|
136
|
+
]
|
|
123
137
|
);
|
|
124
138
|
|
|
139
|
+
const debouncedSearchParams = useDebouncedValue(stableSearchParams, 200);
|
|
140
|
+
|
|
141
|
+
const lastQueryStringRef = React.useRef("");
|
|
142
|
+
|
|
125
143
|
React.useEffect(() => {
|
|
126
144
|
if (!pathname) return;
|
|
127
145
|
const qp = new URLSearchParams();
|
|
@@ -137,8 +155,10 @@ export function useEscrowsBySigner() {
|
|
|
137
155
|
qp.set("engagementId", debouncedSearchParams.engagementId);
|
|
138
156
|
qp.set("isActive", String(debouncedSearchParams.isActive));
|
|
139
157
|
qp.set("validateOnChain", String(debouncedSearchParams.validateOnChain));
|
|
140
|
-
if (type && type !== "all")
|
|
141
|
-
|
|
158
|
+
if (debouncedSearchParams.type && debouncedSearchParams.type !== "all")
|
|
159
|
+
qp.set("type", debouncedSearchParams.type);
|
|
160
|
+
if (debouncedSearchParams.status && debouncedSearchParams.status !== "all")
|
|
161
|
+
qp.set("status", debouncedSearchParams.status);
|
|
142
162
|
if (debouncedSearchParams.minAmount)
|
|
143
163
|
qp.set("minAmount", String(debouncedSearchParams.minAmount));
|
|
144
164
|
if (debouncedSearchParams.maxAmount)
|
|
@@ -147,25 +167,12 @@ export function useEscrowsBySigner() {
|
|
|
147
167
|
qp.set("startDate", String(debouncedSearchParams.startDate));
|
|
148
168
|
if (debouncedSearchParams.endDate)
|
|
149
169
|
qp.set("endDate", String(debouncedSearchParams.endDate));
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
debouncedSearchParams.orderBy,
|
|
157
|
-
debouncedSearchParams.orderDirection,
|
|
158
|
-
debouncedSearchParams.title,
|
|
159
|
-
debouncedSearchParams.engagementId,
|
|
160
|
-
debouncedSearchParams.isActive,
|
|
161
|
-
debouncedSearchParams.validateOnChain,
|
|
162
|
-
type,
|
|
163
|
-
status,
|
|
164
|
-
debouncedSearchParams.minAmount,
|
|
165
|
-
debouncedSearchParams.maxAmount,
|
|
166
|
-
debouncedSearchParams.startDate,
|
|
167
|
-
debouncedSearchParams.endDate,
|
|
168
|
-
]);
|
|
170
|
+
const newQs = qp.toString();
|
|
171
|
+
if (lastQueryStringRef.current !== newQs) {
|
|
172
|
+
lastQueryStringRef.current = newQs;
|
|
173
|
+
router.replace(`${pathname}?${newQs}`);
|
|
174
|
+
}
|
|
175
|
+
}, [pathname, router, debouncedSearchParams]);
|
|
169
176
|
|
|
170
177
|
const formattedRangeLabel = React.useMemo(() => {
|
|
171
178
|
if (!dateRange?.from && !dateRange?.to) return "Date range";
|
|
@@ -221,6 +228,12 @@ export function useEscrowsBySigner() {
|
|
|
221
228
|
dateRange,
|
|
222
229
|
]);
|
|
223
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Call the query to get the escrows from the Trustless Work Indexer
|
|
233
|
+
*
|
|
234
|
+
* @param params - The parameters for the query
|
|
235
|
+
* @returns The query result
|
|
236
|
+
*/
|
|
224
237
|
const query = useEscrowsBySignerQuery(params);
|
|
225
238
|
const nextPageQuery = useEscrowsBySignerQuery({ ...params, page: page + 1 });
|
|
226
239
|
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
13
|
|
|
14
14
|
type ApproveMilestoneButtonProps = {
|
|
@@ -27,6 +27,12 @@ export default function ApproveMilestoneButton({
|
|
|
27
27
|
try {
|
|
28
28
|
setIsSubmitting(true);
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Create the payload for the approve milestone mutation
|
|
32
|
+
*
|
|
33
|
+
* @param milestoneIndex - The index of the milestone to approve
|
|
34
|
+
* @returns The payload for the approve milestone mutation
|
|
35
|
+
*/
|
|
30
36
|
const payload: ApproveMilestonePayload = {
|
|
31
37
|
contractId: selectedEscrow?.contractId || "",
|
|
32
38
|
milestoneIndex: String(milestoneIndex),
|
|
@@ -34,6 +40,13 @@ export default function ApproveMilestoneButton({
|
|
|
34
40
|
newFlag: true,
|
|
35
41
|
};
|
|
36
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Call the approve milestone mutation
|
|
45
|
+
*
|
|
46
|
+
* @param payload - The payload for the approve milestone mutation
|
|
47
|
+
* @param type - The type of the escrow
|
|
48
|
+
* @param address - The address of the escrow
|
|
49
|
+
*/
|
|
37
50
|
await approveMilestone.mutateAsync({
|
|
38
51
|
payload,
|
|
39
52
|
type: "single-release",
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "__UI_BASE__/dialog";
|
|
18
18
|
import { Loader2 } from "lucide-react";
|
|
19
19
|
import { useApproveMilestone } from "./useApproveMilestone";
|
|
20
|
-
import { useEscrowContext } from "
|
|
20
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
21
21
|
import {
|
|
22
22
|
Select,
|
|
23
23
|
SelectContent,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import { Button } from "__UI_BASE__/button";
|
|
11
11
|
import { useApproveMilestone } from "./useApproveMilestone";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
|
-
import { useEscrowContext } from "
|
|
13
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
14
14
|
import {
|
|
15
15
|
Select,
|
|
16
16
|
SelectContent,
|
|
@@ -4,7 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
4
4
|
import { approveMilestoneSchema, type ApproveMilestoneValues } from "./schema";
|
|
5
5
|
import { toast } from "sonner";
|
|
6
6
|
import { ApproveMilestonePayload } from "@trustless-work/escrow";
|
|
7
|
-
import { useEscrowContext } from "
|
|
7
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
8
8
|
import { useEscrowsMutations } from "@/components/tw-blocks/tanstack/useEscrowsMutations";
|
|
9
9
|
import {
|
|
10
10
|
ErrorResponse,
|
|
@@ -31,6 +31,12 @@ export function useApproveMilestone() {
|
|
|
31
31
|
try {
|
|
32
32
|
setIsSubmitting(true);
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Create the final payload for the approve milestone mutation
|
|
36
|
+
*
|
|
37
|
+
* @param payload - The payload from the form
|
|
38
|
+
* @returns The final payload for the approve milestone mutation
|
|
39
|
+
*/
|
|
34
40
|
const finalPayload: ApproveMilestonePayload = {
|
|
35
41
|
contractId: selectedEscrow?.contractId || "",
|
|
36
42
|
milestoneIndex: payload.milestoneIndex,
|
|
@@ -38,6 +44,13 @@ export function useApproveMilestone() {
|
|
|
38
44
|
newFlag: true,
|
|
39
45
|
};
|
|
40
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Call the approve milestone mutation
|
|
49
|
+
*
|
|
50
|
+
* @param payload - The final payload for the approve milestone mutation
|
|
51
|
+
* @param type - The type of the escrow
|
|
52
|
+
* @param address - The address of the escrow
|
|
53
|
+
*/
|
|
41
54
|
await approveMilestone.mutateAsync({
|
|
42
55
|
payload: finalPayload,
|
|
43
56
|
type: "single-release",
|
package/templates/escrows/single-release/change-milestone-status/button/ChangeMilestoneStatus.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
13
|
|
|
14
14
|
type ChangeMilestoneStatusButtonProps = {
|
|
@@ -36,6 +36,14 @@ export default function ChangeMilestoneStatusButton({
|
|
|
36
36
|
|
|
37
37
|
setIsSubmitting(true);
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Create the payload for the change milestone status mutation
|
|
41
|
+
*
|
|
42
|
+
* @param status - The status to change
|
|
43
|
+
* @param evidence - The evidence to change
|
|
44
|
+
* @param milestoneIndex - The index of the milestone to change
|
|
45
|
+
* @returns The payload for the change milestone status mutation
|
|
46
|
+
*/
|
|
39
47
|
const payload: ChangeMilestoneStatusPayload = {
|
|
40
48
|
contractId: selectedEscrow?.contractId || "",
|
|
41
49
|
milestoneIndex: String(milestoneIndex),
|
|
@@ -44,6 +52,13 @@ export default function ChangeMilestoneStatusButton({
|
|
|
44
52
|
serviceProvider: walletAddress || "",
|
|
45
53
|
};
|
|
46
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Call the change milestone status mutation
|
|
57
|
+
*
|
|
58
|
+
* @param payload - The payload for the change milestone status mutation
|
|
59
|
+
* @param type - The type of the escrow
|
|
60
|
+
* @param address - The address of the escrow
|
|
61
|
+
*/
|
|
47
62
|
await changeMilestoneStatus.mutateAsync({
|
|
48
63
|
payload,
|
|
49
64
|
type: "single-release",
|
package/templates/escrows/single-release/change-milestone-status/dialog/ChangeMilestoneStatus.tsx
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from "__UI_BASE__/dialog";
|
|
20
20
|
import { Loader2 } from "lucide-react";
|
|
21
21
|
import { useChangeMilestoneStatus } from "./useChangeMilestoneStatus";
|
|
22
|
-
import { useEscrowContext } from "
|
|
22
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
23
23
|
import {
|
|
24
24
|
Select,
|
|
25
25
|
SelectContent,
|
package/templates/escrows/single-release/change-milestone-status/form/ChangeMilestoneStatus.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { Textarea } from "__UI_BASE__/textarea";
|
|
|
12
12
|
import { Button } from "__UI_BASE__/button";
|
|
13
13
|
import { useChangeMilestoneStatus } from "./useChangeMilestoneStatus";
|
|
14
14
|
import { Loader2 } from "lucide-react";
|
|
15
|
-
import { useEscrowContext } from "
|
|
15
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
16
16
|
import {
|
|
17
17
|
Select,
|
|
18
18
|
SelectContent,
|
package/templates/escrows/single-release/change-milestone-status/shared/useChangeMilestoneStatus.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./schema";
|
|
8
8
|
import { toast } from "sonner";
|
|
9
9
|
import { ChangeMilestoneStatusPayload } from "@trustless-work/escrow";
|
|
10
|
-
import { useEscrowContext } from "
|
|
10
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
11
11
|
import { useEscrowsMutations } from "@/components/tw-blocks/tanstack/useEscrowsMutations";
|
|
12
12
|
import {
|
|
13
13
|
ErrorResponse,
|
|
@@ -36,6 +36,12 @@ export function useChangeMilestoneStatus() {
|
|
|
36
36
|
try {
|
|
37
37
|
setIsSubmitting(true);
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Create the final payload for the change milestone status mutation
|
|
41
|
+
*
|
|
42
|
+
* @param payload - The payload from the form
|
|
43
|
+
* @returns The final payload for the change milestone status mutation
|
|
44
|
+
*/
|
|
39
45
|
const finalPayload: ChangeMilestoneStatusPayload = {
|
|
40
46
|
contractId: selectedEscrow?.contractId || "",
|
|
41
47
|
milestoneIndex: payload.milestoneIndex,
|
|
@@ -44,6 +50,13 @@ export function useChangeMilestoneStatus() {
|
|
|
44
50
|
serviceProvider: walletAddress || "",
|
|
45
51
|
};
|
|
46
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Call the change milestone status mutation
|
|
55
|
+
*
|
|
56
|
+
* @param payload - The final payload for the change milestone status mutation
|
|
57
|
+
* @param type - The type of the escrow
|
|
58
|
+
* @param address - The address of the escrow
|
|
59
|
+
*/
|
|
47
60
|
await changeMilestoneStatus.mutateAsync({
|
|
48
61
|
payload: finalPayload,
|
|
49
62
|
type: "single-release",
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
13
|
|
|
14
14
|
export default function DisputeEscrowButton() {
|
|
@@ -21,11 +21,23 @@ export default function DisputeEscrowButton() {
|
|
|
21
21
|
try {
|
|
22
22
|
setIsSubmitting(true);
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Create the payload for the dispute escrow mutation
|
|
26
|
+
*
|
|
27
|
+
* @returns The payload for the dispute escrow mutation
|
|
28
|
+
*/
|
|
24
29
|
const payload: SingleReleaseStartDisputePayload = {
|
|
25
30
|
contractId: selectedEscrow?.contractId || "",
|
|
26
31
|
signer: walletAddress || "",
|
|
27
32
|
};
|
|
28
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Call the dispute escrow mutation
|
|
36
|
+
*
|
|
37
|
+
* @param payload - The payload for the dispute escrow mutation
|
|
38
|
+
* @param type - The type of the escrow
|
|
39
|
+
* @param address - The address of the escrow
|
|
40
|
+
*/
|
|
29
41
|
await startDispute.mutateAsync({
|
|
30
42
|
payload,
|
|
31
43
|
type: "single-release",
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
13
|
|
|
14
14
|
type FundEscrowButtonProps = {
|
|
@@ -35,12 +35,24 @@ export default function FundEscrowButton({ amount }: FundEscrowButtonProps) {
|
|
|
35
35
|
|
|
36
36
|
setIsSubmitting(true);
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Create the payload for the fund escrow mutation
|
|
40
|
+
*
|
|
41
|
+
* @returns The payload for the fund escrow mutation
|
|
42
|
+
*/
|
|
38
43
|
const payload: FundEscrowPayload = {
|
|
39
44
|
amount: Number(amount),
|
|
40
45
|
contractId: selectedEscrow?.contractId || "",
|
|
41
46
|
signer: walletAddress || "",
|
|
42
47
|
};
|
|
43
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Call the fund escrow mutation
|
|
51
|
+
*
|
|
52
|
+
* @param payload - The payload for the fund escrow mutation
|
|
53
|
+
* @param type - The type of the escrow
|
|
54
|
+
* @param address - The address of the escrow
|
|
55
|
+
*/
|
|
44
56
|
await fundEscrow.mutateAsync({
|
|
45
57
|
payload,
|
|
46
58
|
type: "single-release",
|
|
@@ -4,7 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
4
4
|
import { fundEscrowSchema, type FundEscrowValues } from "./schema";
|
|
5
5
|
import { toast } from "sonner";
|
|
6
6
|
import { FundEscrowPayload } from "@trustless-work/escrow";
|
|
7
|
-
import { useEscrowContext } from "
|
|
7
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
8
8
|
import { useEscrowsMutations } from "@/components/tw-blocks/tanstack/useEscrowsMutations";
|
|
9
9
|
import {
|
|
10
10
|
ErrorResponse,
|
|
@@ -31,6 +31,12 @@ export function useFundEscrow() {
|
|
|
31
31
|
try {
|
|
32
32
|
setIsSubmitting(true);
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Create the final payload for the fund escrow mutation
|
|
36
|
+
*
|
|
37
|
+
* @param payload - The payload from the form
|
|
38
|
+
* @returns The final payload for the fund escrow mutation
|
|
39
|
+
*/
|
|
34
40
|
const finalPayload: FundEscrowPayload = {
|
|
35
41
|
amount:
|
|
36
42
|
typeof payload.amount === "string"
|
|
@@ -40,6 +46,13 @@ export function useFundEscrow() {
|
|
|
40
46
|
signer: walletAddress || "",
|
|
41
47
|
};
|
|
42
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Call the fund escrow mutation
|
|
51
|
+
*
|
|
52
|
+
* @param payload - The final payload for the fund escrow mutation
|
|
53
|
+
* @param type - The type of the escrow
|
|
54
|
+
* @param address - The address of the escrow
|
|
55
|
+
*/
|
|
43
56
|
await fundEscrow.mutateAsync({
|
|
44
57
|
payload: finalPayload,
|
|
45
58
|
type: "single-release",
|
|
@@ -14,12 +14,14 @@ import {
|
|
|
14
14
|
ErrorResponse,
|
|
15
15
|
handleError,
|
|
16
16
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
17
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
17
18
|
|
|
18
19
|
export function useInitializeEscrow() {
|
|
19
20
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
20
21
|
|
|
21
22
|
const { getSingleReleaseFormSchema } = useInitializeEscrowSchema();
|
|
22
23
|
const formSchema = getSingleReleaseFormSchema();
|
|
24
|
+
const { setSelectedEscrow } = useEscrowContext();
|
|
23
25
|
|
|
24
26
|
const { walletAddress } = useWalletContext();
|
|
25
27
|
const { deployEscrow } = useEscrowsMutations();
|
|
@@ -71,6 +73,12 @@ export function useInitializeEscrow() {
|
|
|
71
73
|
try {
|
|
72
74
|
setIsSubmitting(true);
|
|
73
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Create the final payload for the initialize escrow mutation
|
|
78
|
+
*
|
|
79
|
+
* @param payload - The payload from the form
|
|
80
|
+
* @returns The final payload for the initialize escrow mutation
|
|
81
|
+
*/
|
|
74
82
|
const finalPayload: InitializeSingleReleaseEscrowPayload = {
|
|
75
83
|
...payload,
|
|
76
84
|
amount:
|
|
@@ -86,6 +94,13 @@ export function useInitializeEscrow() {
|
|
|
86
94
|
milestones: payload.milestones,
|
|
87
95
|
};
|
|
88
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Call the initialize escrow mutation
|
|
99
|
+
*
|
|
100
|
+
* @param payload - The final payload for the initialize escrow mutation
|
|
101
|
+
* @param type - The type of the escrow
|
|
102
|
+
* @param address - The address of the escrow
|
|
103
|
+
*/
|
|
89
104
|
const response: InitializeSingleReleaseEscrowResponse =
|
|
90
105
|
(await deployEscrow.mutateAsync({
|
|
91
106
|
payload: finalPayload,
|
|
@@ -93,8 +108,9 @@ export function useInitializeEscrow() {
|
|
|
93
108
|
address: walletAddress || "",
|
|
94
109
|
})) as InitializeSingleReleaseEscrowResponse;
|
|
95
110
|
|
|
96
|
-
console.log("response", response);
|
|
97
111
|
toast.success("Escrow initialized successfully");
|
|
112
|
+
|
|
113
|
+
setSelectedEscrow(response);
|
|
98
114
|
} catch (error) {
|
|
99
115
|
toast.error(handleError(error as ErrorResponse).message);
|
|
100
116
|
} finally {
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
12
|
-
import { useEscrowDialogs } from "
|
|
13
|
-
import { useEscrowAmountContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
|
+
import { useEscrowDialogs } from "@/components/tw-blocks/providers/EscrowDialogsProvider";
|
|
13
|
+
import { useEscrowAmountContext } from "@/components/tw-blocks/providers/EscrowAmountProvider";
|
|
14
14
|
import { Loader2 } from "lucide-react";
|
|
15
15
|
|
|
16
16
|
export default function ReleaseEscrowButton() {
|
|
@@ -25,11 +25,23 @@ export default function ReleaseEscrowButton() {
|
|
|
25
25
|
try {
|
|
26
26
|
setIsSubmitting(true);
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Create the payload for the release escrow mutation
|
|
30
|
+
*
|
|
31
|
+
* @returns The payload for the release escrow mutation
|
|
32
|
+
*/
|
|
28
33
|
const payload: SingleReleaseReleaseFundsPayload = {
|
|
29
34
|
contractId: selectedEscrow?.contractId || "",
|
|
30
35
|
releaseSigner: walletAddress || "",
|
|
31
36
|
};
|
|
32
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Call the release escrow mutation
|
|
40
|
+
*
|
|
41
|
+
* @param payload - The payload for the release escrow mutation
|
|
42
|
+
* @param type - The type of the escrow
|
|
43
|
+
* @param address - The address of the escrow
|
|
44
|
+
*/
|
|
33
45
|
await releaseFunds.mutateAsync({
|
|
34
46
|
payload,
|
|
35
47
|
type: "single-release",
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ErrorResponse,
|
|
9
9
|
handleError,
|
|
10
10
|
} from "@/components/tw-blocks/handle-errors/handle";
|
|
11
|
-
import { useEscrowContext } from "
|
|
11
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
12
12
|
import { Loader2 } from "lucide-react";
|
|
13
13
|
|
|
14
14
|
type ResolveDisputeButtonProps = {
|
|
@@ -44,6 +44,11 @@ export default function ResolveDisputeButton({
|
|
|
44
44
|
|
|
45
45
|
setIsSubmitting(true);
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Create the payload for the resolve dispute mutation
|
|
49
|
+
*
|
|
50
|
+
* @returns The payload for the resolve dispute mutation
|
|
51
|
+
*/
|
|
47
52
|
const payload: SingleReleaseResolveDisputePayload = {
|
|
48
53
|
contractId: selectedEscrow?.contractId || "",
|
|
49
54
|
disputeResolver: walletAddress || "",
|
|
@@ -51,6 +56,13 @@ export default function ResolveDisputeButton({
|
|
|
51
56
|
receiverFunds: Number(receiverFunds),
|
|
52
57
|
};
|
|
53
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Call the resolve dispute mutation
|
|
61
|
+
*
|
|
62
|
+
* @param payload - The payload for the resolve dispute mutation
|
|
63
|
+
* @param type - The type of the escrow
|
|
64
|
+
* @param address - The address of the escrow
|
|
65
|
+
*/
|
|
54
66
|
await resolveDispute.mutateAsync({
|
|
55
67
|
payload,
|
|
56
68
|
type: "single-release",
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
} from "__UI_BASE__/dialog";
|
|
19
19
|
import { Loader2 } from "lucide-react";
|
|
20
20
|
import { useResolveDispute } from "./useResolveDispute";
|
|
21
|
-
import { useEscrowContext } from "
|
|
21
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
22
22
|
|
|
23
23
|
export default function ResolveDisputeDialog() {
|
|
24
24
|
const { form, handleSubmit, isSubmitting } = useResolveDispute();
|
|
@@ -4,7 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
4
4
|
import { resolveDisputeSchema, type ResolveDisputeValues } from "./schema";
|
|
5
5
|
import { toast } from "sonner";
|
|
6
6
|
import { SingleReleaseResolveDisputePayload } from "@trustless-work/escrow";
|
|
7
|
-
import { useEscrowContext } from "
|
|
7
|
+
import { useEscrowContext } from "@/components/tw-blocks/providers/EscrowProvider";
|
|
8
8
|
import { useEscrowsMutations } from "@/components/tw-blocks/tanstack/useEscrowsMutations";
|
|
9
9
|
import {
|
|
10
10
|
ErrorResponse,
|
|
@@ -32,6 +32,12 @@ export function useResolveDispute() {
|
|
|
32
32
|
try {
|
|
33
33
|
setIsSubmitting(true);
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Create the final payload for the resolve dispute mutation
|
|
37
|
+
*
|
|
38
|
+
* @param payload - The payload from the form
|
|
39
|
+
* @returns The final payload for the resolve dispute mutation
|
|
40
|
+
*/
|
|
35
41
|
const finalPayload: SingleReleaseResolveDisputePayload = {
|
|
36
42
|
contractId: selectedEscrow?.contractId || "",
|
|
37
43
|
disputeResolver: walletAddress || "",
|
|
@@ -39,6 +45,13 @@ export function useResolveDispute() {
|
|
|
39
45
|
receiverFunds: Number(payload.receiverFunds),
|
|
40
46
|
};
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Call the resolve dispute mutation
|
|
50
|
+
*
|
|
51
|
+
* @param payload - The final payload for the resolve dispute mutation
|
|
52
|
+
* @param type - The type of the escrow
|
|
53
|
+
* @param address - The address of the escrow
|
|
54
|
+
*/
|
|
42
55
|
await resolveDispute.mutateAsync({
|
|
43
56
|
payload: finalPayload,
|
|
44
57
|
type: "single-release",
|