@glowlabs-org/utils 0.2.86 → 0.2.88
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/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/constants/addresses.d.ts +1 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/control-api/farms-router.d.ts +4 -0
- package/dist/cjs/lib/hooks/use-forwarder.d.ts +1 -1
- package/dist/cjs/lib/types/index.d.ts +12 -1
- package/dist/cjs/wallets-router-QMdVxcdl.js.map +1 -1
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/constants/addresses.d.ts +1 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +37 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/control-api/farms-router.d.ts +4 -0
- package/dist/esm/lib/hooks/use-forwarder.d.ts +1 -1
- package/dist/esm/lib/types/index.d.ts +12 -1
- package/dist/esm/wallets-router-kIhkVAED.js.map +1 -1
- package/package.json +1 -1
- package/src/constants/addresses.ts +1 -1
- package/src/index.ts +1 -0
- package/src/lib/control-api/farms-router.ts +44 -0
- package/src/lib/types/index.ts +14 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,3 +11,4 @@ export { ControlRouter } from "./lib/control-api/control-router";
|
|
|
11
11
|
export { RegionRouter } from "./lib/control-api/region-router";
|
|
12
12
|
export { KickstarterRouter } from "./lib/control-api/kickstarter-router";
|
|
13
13
|
export { WalletsRouter } from "./lib/control-api/wallets-router";
|
|
14
|
+
export { FarmsRouter } from "./lib/control-api/farms-router";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import type { SponsoredFarm } from "../types";
|
|
4
|
+
import type { SponsoredFarmsResponse } from "../types";
|
|
5
|
+
|
|
6
|
+
function parseApiError(error: unknown): string {
|
|
7
|
+
if (!error) return "Unknown error";
|
|
8
|
+
if (error instanceof Error) return error.message;
|
|
9
|
+
const possible: any = error;
|
|
10
|
+
return possible?.error?.message ?? possible?.message ?? "Unknown error";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FarmsRouter(baseUrl: string) {
|
|
14
|
+
if (!baseUrl) throw new Error("CONTROL API base URL is not set");
|
|
15
|
+
|
|
16
|
+
const request = async <T>(path: string, init?: RequestInit): Promise<T> => {
|
|
17
|
+
const res = await fetch(`${baseUrl}${path}`, init);
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
const errData = await res.json().catch(() => ({}));
|
|
20
|
+
throw new Error(errData?.error || `Request to ${path} failed`);
|
|
21
|
+
}
|
|
22
|
+
return (await res.json()) as T;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const fetchSponsoredFarms = async (
|
|
26
|
+
sponsorWallet?: string
|
|
27
|
+
): Promise<SponsoredFarm[]> => {
|
|
28
|
+
try {
|
|
29
|
+
const query = sponsorWallet
|
|
30
|
+
? `?sponsorWallet=${encodeURIComponent(sponsorWallet)}`
|
|
31
|
+
: "";
|
|
32
|
+
const data = await request<SponsoredFarmsResponse>(
|
|
33
|
+
`/farms/sponsored${query}`
|
|
34
|
+
);
|
|
35
|
+
return data.farms ?? [];
|
|
36
|
+
} catch (error) {
|
|
37
|
+
throw new Error(parseApiError(error));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
fetchSponsoredFarms,
|
|
43
|
+
} as const;
|
|
44
|
+
}
|
package/src/lib/types/index.ts
CHANGED
|
@@ -278,19 +278,27 @@ export interface ActivationEvent {
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
// ----------------------------- Region VCR View ------------------------------
|
|
281
|
+
export interface FarmRewardSplit {
|
|
282
|
+
walletAddress: string;
|
|
283
|
+
glowSplitPercent6Decimals: string;
|
|
284
|
+
depositSplitPercent6Decimals: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
281
287
|
export interface SponsoredFarm {
|
|
282
288
|
farmId: string;
|
|
289
|
+
regionId: number;
|
|
283
290
|
name: string;
|
|
284
291
|
location: string;
|
|
285
292
|
certifiedInstallerId: string | null;
|
|
286
293
|
kwhCapacity: string;
|
|
287
294
|
solarPanelsQuantity: number;
|
|
288
295
|
adjustedWeeklyCarbonCredits: string;
|
|
296
|
+
protocolDepositUSDC6Decimals: string;
|
|
289
297
|
protocolDepositPaidAmount: string;
|
|
290
298
|
protocolDepositPaidCurrency: string;
|
|
291
299
|
protocolDepositPayerWallet: string | null;
|
|
292
300
|
builtEpoch: number;
|
|
293
|
-
isPurchased: boolean;
|
|
301
|
+
isPurchased: boolean | null;
|
|
294
302
|
builtAt?: string;
|
|
295
303
|
sponsorWallet: string | null;
|
|
296
304
|
afterInstallPictures: {
|
|
@@ -299,6 +307,7 @@ export interface SponsoredFarm {
|
|
|
299
307
|
url: string;
|
|
300
308
|
isShowingSolarPanels: boolean;
|
|
301
309
|
}[];
|
|
310
|
+
rewardSplits: FarmRewardSplit[];
|
|
302
311
|
}
|
|
303
312
|
|
|
304
313
|
export interface SolarFarmApplication {
|
|
@@ -339,6 +348,10 @@ export interface RegionSolarFarmsResponse {
|
|
|
339
348
|
sponsoredFarms: SponsoredFarm[];
|
|
340
349
|
}
|
|
341
350
|
|
|
351
|
+
export interface SponsoredFarmsResponse {
|
|
352
|
+
farms: SponsoredFarm[];
|
|
353
|
+
}
|
|
354
|
+
|
|
342
355
|
export interface FetchRegionsParams {
|
|
343
356
|
isActive?: boolean;
|
|
344
357
|
}
|