forked from Cylo-Traders/Agrocylo-PIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfallback.ts
More file actions
209 lines (201 loc) · 6.1 KB
/
Copy pathfallback.ts
File metadata and controls
209 lines (201 loc) · 6.1 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* Local fallback dataset served when the backend API is disabled
* (`VITE_USE_BACKEND_API` off) or unreachable / not implemented yet. This keeps
* dashboards and activity feeds rendering against realistic, schema-shaped data
* before the backend ships its REST endpoints.
*
* The records here mirror the response DTOs in `types.ts` exactly (BigInt
* columns as decimal strings, DateTime columns as ISO strings), so swapping to
* real backend data is a no-op for consumers.
*/
import type { Campaign, Investment, Order, Transaction, User } from './types';
const FARMER_ADDRESS =
'GFARMER00000000000000000000000000000000000000000000000A1';
const INVESTOR_ADDRESS =
'GINVESTOR000000000000000000000000000000000000000000000B2';
const BUYER_ADDRESS =
'GBUYER0000000000000000000000000000000000000000000000000C3';
const TOKEN_ADDRESS =
'CTOKEN0000000000000000000000000000000000000000000000000D4';
const CAMPAIGNS: readonly Campaign[] = [
{
id: 'camp-101',
farmer: FARMER_ADDRESS,
title: 'Organic Maize Irrigation & Harvesting PIP',
description:
'Drip irrigation and harvesting for a 40-acre organic maize farm.',
targetAmount: '10000',
tokenAddress: TOKEN_ADDRESS,
deadline: '1793000000',
status: 'Funding',
totalFunded: '2500',
escrowContract: 'CESCROW000000000000000000000000000000000000000000000101',
trancheCount: 3,
harvestOutcome: null,
harvestReportedAt: null,
refundable: '0',
createdAt: '1789000000',
updatedAt: '2026-07-15T10:00:00.000Z',
},
{
id: 'camp-102',
farmer: FARMER_ADDRESS,
title: 'Solar-Powered Cold Chain Logistics PIP',
description: 'Solar cold storage to reduce post-harvest losses in transit.',
targetAmount: '5000',
tokenAddress: TOKEN_ADDRESS,
deadline: '1788000000',
status: 'Settled',
totalFunded: '5000',
escrowContract: 'CESCROW000000000000000000000000000000000000000000000102',
trancheCount: 2,
harvestOutcome: 'Success',
harvestReportedAt: '1790500000',
refundable: '0',
createdAt: '1785000000',
updatedAt: '2026-06-01T14:30:00.000Z',
},
{
id: 'camp-103',
farmer: FARMER_ADDRESS,
title: 'Bio-Organic Fertilizer Expansion PIP',
description: 'Scaling a bio-organic fertilizer line for smallholder farms.',
targetAmount: '4000',
tokenAddress: TOKEN_ADDRESS,
deadline: '1787000000',
status: 'Failed',
totalFunded: '1500',
escrowContract: 'CESCROW000000000000000000000000000000000000000000000103',
trancheCount: null,
harvestOutcome: null,
harvestReportedAt: null,
refundable: '1500',
createdAt: '1783000000',
updatedAt: '2026-05-20T09:15:00.000Z',
},
];
const INVESTMENTS: readonly Investment[] = [
{
id: 'inv-1',
campaignId: 'camp-101',
investor: INVESTOR_ADDRESS,
amount: '2500',
txHash: 'a1b2c3d4e5f60718293a4b5c6d7e8f90112233445566778899aabbccddeeff00',
timestamp: '1789100000',
createdAt: '2026-07-15T10:05:00.000Z',
},
{
id: 'inv-2',
campaignId: 'camp-102',
investor: INVESTOR_ADDRESS,
amount: '5000',
txHash: 'b2c3d4e5f60718293a4b5c6d7e8f90112233445566778899aabbccddeeff0011',
timestamp: '1785200000',
createdAt: '2026-06-01T14:35:00.000Z',
},
{
id: 'inv-3',
campaignId: 'camp-103',
investor: INVESTOR_ADDRESS,
amount: '1500',
txHash: null,
timestamp: '1783300000',
createdAt: '2026-05-20T09:20:00.000Z',
},
];
const ORDERS: readonly Order[] = [
{
id: 'order-1',
campaignId: 'camp-102',
buyer: BUYER_ADDRESS,
amount: '1000',
status: 'Confirmed',
confirmedAt: '1790600000',
txHash: 'c3d4e5f60718293a4b5c6d7e8f90112233445566778899aabbccddeeff001122',
createdAt: '2026-06-10T08:00:00.000Z',
updatedAt: '2026-06-11T08:00:00.000Z',
},
{
id: 'order-2',
campaignId: 'camp-101',
buyer: BUYER_ADDRESS,
amount: '500',
status: 'Pending',
confirmedAt: null,
txHash: null,
createdAt: '2026-07-16T08:00:00.000Z',
updatedAt: '2026-07-16T08:00:00.000Z',
},
];
const USERS: readonly User[] = [
{
address: INVESTOR_ADDRESS,
name: 'Demo Investor',
firstSeenAt: '1783300000',
createdAt: '2026-05-20T09:20:00.000Z',
updatedAt: '2026-07-15T10:05:00.000Z',
},
{
address: FARMER_ADDRESS,
name: 'Demo Farmer',
firstSeenAt: '1783000000',
createdAt: '2026-05-20T09:00:00.000Z',
updatedAt: '2026-07-15T10:00:00.000Z',
},
];
const TRANSACTIONS: readonly Transaction[] = [
{
id: 'tx-1',
type: 'Investment',
campaignId: 'camp-101',
userId: INVESTOR_ADDRESS,
amount: '2500',
txHash: 'a1b2c3d4e5f60718293a4b5c6d7e8f90112233445566778899aabbccddeeff00',
status: 'Confirmed',
timestamp: '1789100000',
data: '{}',
createdAt: '2026-07-15T10:05:00.000Z',
},
{
id: 'tx-2',
type: 'Refund',
campaignId: 'camp-103',
userId: INVESTOR_ADDRESS,
amount: '1500',
txHash: null,
status: 'Pending',
timestamp: '1783300000',
data: '{"reason":"campaign_failed"}',
createdAt: '2026-05-20T09:20:00.000Z',
},
];
/** Deep clone so callers can't mutate the shared fallback dataset. */
function clone<T>(value: T): T {
return value === undefined ? value : (JSON.parse(JSON.stringify(value)) as T);
}
export const localData = {
campaigns(): Campaign[] {
return clone([...CAMPAIGNS]);
},
campaign(id: string): Campaign | undefined {
return clone(CAMPAIGNS.find((c) => c.id === id));
},
campaignInvestments(campaignId: string): Investment[] {
return clone(INVESTMENTS.filter((i) => i.campaignId === campaignId));
},
investmentsByUser(address: string): Investment[] {
return clone(INVESTMENTS.filter((i) => i.investor === address));
},
campaignOrders(campaignId: string): Order[] {
return clone(ORDERS.filter((o) => o.campaignId === campaignId));
},
order(id: string): Order | undefined {
return clone(ORDERS.find((o) => o.id === id));
},
user(address: string): User | undefined {
return clone(USERS.find((u) => u.address === address));
},
transactionsByUser(address: string): Transaction[] {
return clone(TRANSACTIONS.filter((t) => t.userId === address));
},
};