forked from TrustUp-app/TrustUp-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
141 lines (123 loc) · 4.02 KB
/
Copy pathapi.ts
File metadata and controls
141 lines (123 loc) · 4.02 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* API types mirroring the TrustUp-API backend DTOs (source of truth).
* See TrustUp-API `src/modules/{reputation,loans,merchants}/dto`.
*
* The backend wraps most responses in an envelope `{ success, data, message }`,
* except `GET /merchants`, which returns its payload directly.
*/
/** Standard success envelope used by reputation and loans endpoints. */
export interface ApiEnvelope<T> {
success: boolean;
data: T;
message?: string;
}
// ─── Reputation ───────────────────────────────────────────────────────────────
/** Reputation tier as returned by the backend (NOT poor/fair/good/excellent). */
export type ReputationTier = 'gold' | 'silver' | 'bronze' | 'poor';
/** `GET /reputation/me` → data. */
export interface ReputationResponse {
wallet: string;
/** 0–100. */
score: number;
tier: ReputationTier;
/** Annual interest rate % for the tier. */
interestRate: number;
/** Max credit limit in USD for the tier. */
maxCredit: number;
/** ISO-8601 timestamp of the last on-chain read. */
lastUpdated: string;
}
/** `GET /loans/available-credit` → data. */
export interface AvailableCreditResponse {
reputationScore: number;
reputationTier: ReputationTier;
maxCreditLimit: number;
/** Outstanding balance across active loans, USD. */
creditUsed: number;
/** Remaining borrowing capacity, USD (never below zero). */
availableCredit: number;
activeLoans: number;
}
// ─── Loans ────────────────────────────────────────────────────────────────────
export type LoanListStatus = 'active' | 'completed' | 'defaulted';
export interface LoanListMerchant {
id: string | null;
name: string | null;
logo: string | null;
}
export interface LoanNextPayment {
dueDate: string | null;
amount: number | null;
}
/** One item of `GET /loans/my-loans`. */
export interface LoanListItem {
id: string;
loanId: string;
amount: number;
loanAmount: number;
guarantee: number;
interestRate: number;
totalRepayment: number;
totalPaid: number;
remainingBalance: number;
term: number;
status: LoanListStatus;
merchant: LoanListMerchant;
nextPayment: LoanNextPayment;
createdAt: string;
completedAt: string | null;
defaultedAt: string | null;
}
export interface LoanListPagination {
limit: number;
offset: number;
total: number;
}
/** `GET /loans/my-loans` → `{ success, data, pagination }`. */
export interface LoanListResponse {
data: LoanListItem[];
pagination: LoanListPagination;
}
/** Preview returned with a repayment's unsigned XDR. */
export interface LoanPaymentPreview {
paymentAmount: number;
currentBalance: number;
newBalance: number;
willComplete: boolean;
}
/** `POST /loans/:loanId/pay` → data. */
export interface LoanPaymentResponse {
/** Unsigned XDR for the Soroban repay_loan() call, to be signed + submitted. */
unsignedXdr: string;
preview: LoanPaymentPreview;
}
// ─── Merchants ──────────────────────────────────────────────────────────────
/** One item of `GET /merchants` (no rating / credit fields on the backend). */
export interface MerchantSummary {
id: string;
wallet: string;
name: string;
logo: string;
category: string;
isActive: boolean;
}
/** `GET /merchants` → returned directly (no success envelope). */
export interface MerchantListResponse {
merchants: MerchantSummary[];
total: number;
limit: number;
offset: number;
}
/** `GET /merchants/:id` → returned directly (no success envelope). */
export interface MerchantDetail {
id: string;
wallet: string;
name: string;
logo: string;
description?: string;
category?: string;
website?: string;
isActive: boolean;
createdAt: string;
updatedAt?: string;
}