forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit-example.ts
More file actions
94 lines (83 loc) · 2.49 KB
/
Copy pathsplit-example.ts
File metadata and controls
94 lines (83 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Injectable } from "@nestjs/common";
import { ActivitiesService } from "./activities.service";
/**
* Example 2: Split Creation Service Integration
* Track split lifecycle events
*/
@Injectable()
export class SplitServiceExample {
constructor(private readonly activitiesService: ActivitiesService) {}
async createSplit(
creatorId: string,
totalAmount: number,
description: string,
participants: string[]
) {
// Create split logic...
const splitId = "generated-uuid";
// Track split creation
await this.activitiesService.trackSplitCreated(creatorId, splitId, {
totalAmount,
description,
participantCount: participants.length,
currency: "USDC",
});
// Track participants added
for (const participantAddress of participants) {
// Creator gets notified about each participant
await this.activitiesService.trackParticipantAdded(
creatorId,
splitId,
participantAddress,
{ role: "participant" }
);
// Each participant also gets notified they were added
// (You might want to avoid this for the creator)
if (participantAddress !== creatorId) {
await this.activitiesService.trackParticipantAdded(
participantAddress,
splitId,
participantAddress,
{
role: "participant",
addedBy: creatorId,
}
);
}
}
return splitId;
}
async updateSplit(
userId: string,
splitId: string,
changes: { totalAmount?: number; description?: string }
) {
// Update split logic...
// Track the edit
await this.activitiesService.trackSplitEdited(userId, splitId, changes, {
editedAt: new Date().toISOString(),
});
// Optionally notify other participants about the change
// const participants = await this.getParticipants(splitId);
// for (const participant of participants) {
// if (participant.userId !== userId) {
// await this.activitiesService.trackSplitEdited(
// participant.userId,
// splitId,
// changes,
// { editedBy: userId }
// );
// }
// }
}
async completeSplit(splitId: string, participants: string[]) {
// Complete split logic...
// Notify all participants
for (const userId of participants) {
await this.activitiesService.trackSplitCompleted(userId, splitId, {
completedAt: new Date().toISOString(),
status: "fully_paid",
});
}
}
}