@glowlabs-org/utils 0.2.3 → 0.2.4
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 +70 -0
- package/dist/cjs/browser.d.ts +4 -0
- package/dist/cjs/browser.js +1023 -2
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/lib/hooks/use-control-api.d.ts +20 -0
- package/dist/cjs/lib/hooks/use-regions.d.ts +10 -0
- package/dist/cjs/lib/region-metadata.d.ts +5 -0
- package/dist/cjs/lib/types/index.d.ts +117 -0
- package/dist/esm/browser.d.ts +4 -0
- package/dist/esm/browser.js +1019 -0
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/lib/hooks/use-control-api.d.ts +20 -0
- package/dist/esm/lib/hooks/use-regions.d.ts +10 -0
- package/dist/esm/lib/region-metadata.d.ts +5 -0
- package/dist/esm/lib/types/index.d.ts +117 -0
- package/package.json +1 -1
- package/src/browser.ts +4 -0
- package/src/lib/hooks/use-control-api.ts +262 -0
- package/src/lib/hooks/use-regions.ts +155 -0
- package/src/lib/region-metadata.ts +675 -0
- package/src/lib/types/index.ts +153 -0
package/README.md
CHANGED
@@ -67,6 +67,76 @@ console.log("Tx hash:", forwarder.isProcessing ? "pending…" : "sent");
|
|
67
67
|
|
68
68
|
See `src/lib/hooks/use-forwarder.ts` for all available helpers (`approveToken`, `checkTokenBalance`, `estimateGasForForward`, etc.).
|
69
69
|
|
70
|
+
---
|
71
|
+
|
72
|
+
### Control-API SDK (framework-agnostic)
|
73
|
+
|
74
|
+
All on-chain accounting and staking data can be accessed through the plain-TypeScript helper exported from `src/lib/hooks/use-control-api.ts`.
|
75
|
+
|
76
|
+
```typescript
|
77
|
+
import { useControlApi } from "@glowlabs-org/utils";
|
78
|
+
|
79
|
+
// Base URL of your deployed Control-API instance (can be relative or absolute)
|
80
|
+
const controlApi = useControlApi("https://control-api.glowlabs.org");
|
81
|
+
|
82
|
+
// Read-only queries
|
83
|
+
const balance = await controlApi.fetchGctlBalance("0xYourWallet");
|
84
|
+
const price = await controlApi.fetchGctlPrice();
|
85
|
+
const regions = await controlApi.fetchRegions();
|
86
|
+
|
87
|
+
// Mutations
|
88
|
+
await controlApi.stakeGctl(
|
89
|
+
"0xYourWallet",
|
90
|
+
/* regionId */ 42,
|
91
|
+
/* amount */ "1000000"
|
92
|
+
);
|
93
|
+
|
94
|
+
if (controlApi.isStaking) {
|
95
|
+
console.log("staking in progress…");
|
96
|
+
}
|
97
|
+
```
|
98
|
+
|
99
|
+
Refer to the source file for the full surface (`fetchMintedEvents`, `unstakeGctl`, `retryFailedOperation`, etc.). All methods are promise-based and contain zero React dependencies – usable in Node, Deno or the browser.
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
### Regions-API SDK (framework-agnostic)
|
104
|
+
|
105
|
+
This tiny helper wraps region CRUD endpoints and provides in-memory caching.
|
106
|
+
|
107
|
+
```typescript
|
108
|
+
import { useRegionsApi } from "@glowlabs-org/utils";
|
109
|
+
|
110
|
+
const regionsApi = useRegionsApi("https://control-api.glowlabs.org");
|
111
|
+
|
112
|
+
// Fetch & cache
|
113
|
+
await regionsApi.fetchRegions();
|
114
|
+
console.table(regionsApi.regions);
|
115
|
+
|
116
|
+
// Create a new region
|
117
|
+
await regionsApi.createRegion({
|
118
|
+
code: "FR",
|
119
|
+
name: "France",
|
120
|
+
isUs: false,
|
121
|
+
});
|
122
|
+
|
123
|
+
console.log("isCreatingRegion", regionsApi.isCreatingRegion);
|
124
|
+
```
|
125
|
+
|
126
|
+
`getRegionByCode()` also merges locally-bundled metadata (flag, description, etc.) from `src/lib/region-metadata.ts`.
|
127
|
+
|
128
|
+
The metadata file re-exports handy arrays:
|
129
|
+
|
130
|
+
```typescript
|
131
|
+
import {
|
132
|
+
allRegions,
|
133
|
+
usStates,
|
134
|
+
countries,
|
135
|
+
} from "@glowlabs-org/utils/dist/region-metadata";
|
136
|
+
```
|
137
|
+
|
138
|
+
---
|
139
|
+
|
70
140
|
## Contributions
|
71
141
|
|
72
142
|
For contributions, feel free to open a PR or raise an issue.
|
package/dist/cjs/browser.d.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
export * from "./lib/hooks/use-forwarder";
|
2
|
+
export * from "./lib/hooks/use-control-api";
|
3
|
+
export * from "./lib/hooks/use-regions";
|
4
|
+
export * from "./lib/types";
|
5
|
+
export * from "./lib/region-metadata";
|
2
6
|
export * from "./constants/addresses";
|
3
7
|
export * from "./constants/weights";
|
4
8
|
export * from "./constants/urls";
|