@echoxyz/sonar-react 0.7.0 → 0.8.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @echoxyz/sonar-react
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5b96860: Add listAvailableEntities / useSonarEntities
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [5b96860]
12
+ - Updated dependencies [ef7e0f9]
13
+ - @echoxyz/sonar-core@0.7.0
14
+
3
15
  ## 0.7.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -114,9 +114,10 @@ const ExampleEntityPanel = () => {
114
114
  </div>
115
115
  );
116
116
  };
117
-
118
117
  ```
119
118
 
119
+ If you want to fetch all entities associated with the logged in user, you can use the `useSonarEntities` hook.
120
+
120
121
  5. Implement the purchase flow
121
122
 
122
123
  ```tsx
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  SonarProvider: () => SonarProvider,
24
24
  useSonarAuth: () => useSonarAuth,
25
25
  useSonarClient: () => useSonarClient,
26
+ useSonarEntities: () => useSonarEntities,
26
27
  useSonarEntity: () => useSonarEntity,
27
28
  useSonarPurchase: () => useSonarPurchase
28
29
  });
@@ -191,6 +192,63 @@ function useSonarEntity(args) {
191
192
  error: state.error
192
193
  };
193
194
  }
195
+ function useSonarEntities(args) {
196
+ const { authenticated, ready } = useSonarAuth();
197
+ const client = useSonarClient();
198
+ if (!args.saleUUID) {
199
+ throw new Error("saleUUID is required");
200
+ }
201
+ const saleUUID = args.saleUUID;
202
+ const [state, setState] = (0, import_react2.useState)({
203
+ loading: false,
204
+ hasFetched: false
205
+ });
206
+ const fullyConnected = ready && authenticated;
207
+ const refetch = (0, import_react2.useCallback)(async () => {
208
+ if (!fullyConnected) {
209
+ return;
210
+ }
211
+ setState((s) => ({ ...s, loading: true }));
212
+ try {
213
+ const resp = await client.listAvailableEntities({
214
+ saleUUID
215
+ });
216
+ setState({
217
+ loading: false,
218
+ entities: resp.Entities,
219
+ error: void 0,
220
+ hasFetched: true
221
+ });
222
+ } catch (err) {
223
+ const error = err instanceof Error ? err : new Error(String(err));
224
+ setState({ loading: false, entities: void 0, error, hasFetched: true });
225
+ }
226
+ }, [client, saleUUID, fullyConnected]);
227
+ const reset = (0, import_react2.useCallback)(() => {
228
+ setState({
229
+ loading: false,
230
+ hasFetched: false,
231
+ entities: void 0,
232
+ error: void 0
233
+ });
234
+ }, []);
235
+ (0, import_react2.useEffect)(() => {
236
+ if (fullyConnected) {
237
+ refetch();
238
+ }
239
+ }, [fullyConnected, refetch]);
240
+ (0, import_react2.useEffect)(() => {
241
+ if (ready && !authenticated) {
242
+ reset();
243
+ }
244
+ }, [ready, authenticated, reset]);
245
+ return {
246
+ authenticated,
247
+ loading: state.loading,
248
+ entities: state.entities,
249
+ error: state.error
250
+ };
251
+ }
194
252
  function useSonarPurchase(args) {
195
253
  const saleUUID = args.saleUUID;
196
254
  const entityID = args.entityID;
@@ -255,6 +313,7 @@ function useSonarPurchase(args) {
255
313
  SonarProvider,
256
314
  useSonarAuth,
257
315
  useSonarClient,
316
+ useSonarEntities,
258
317
  useSonarEntity,
259
318
  useSonarPurchase
260
319
  });
package/dist/index.d.cts CHANGED
@@ -38,6 +38,16 @@ declare function useSonarEntity(args: {
38
38
  saleUUID: string;
39
39
  walletAddress?: string;
40
40
  }): UseSonarEntityResult;
41
+ type UseSonarEntitiesResult = {
42
+ authenticated: boolean;
43
+ loading: boolean;
44
+ entities?: EntityDetails[];
45
+ error?: Error;
46
+ };
47
+ declare function useSonarEntities(args: {
48
+ saleUUID: string;
49
+ walletAddress?: string;
50
+ }): UseSonarEntitiesResult;
41
51
  type UseSonarPurchaseResultReadyToPurchase = {
42
52
  loading: false;
43
53
  readyToPurchase: true;
@@ -68,4 +78,4 @@ declare function useSonarPurchase(args: {
68
78
  walletAddress: string;
69
79
  }): UseSonarPurchaseResult;
70
80
 
71
- export { SonarProvider, type SonarProviderConfig, type UseSonarEntityResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useSonarAuth, useSonarClient, useSonarEntity, useSonarPurchase };
81
+ export { SonarProvider, type SonarProviderConfig, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarPurchase };
package/dist/index.d.ts CHANGED
@@ -38,6 +38,16 @@ declare function useSonarEntity(args: {
38
38
  saleUUID: string;
39
39
  walletAddress?: string;
40
40
  }): UseSonarEntityResult;
41
+ type UseSonarEntitiesResult = {
42
+ authenticated: boolean;
43
+ loading: boolean;
44
+ entities?: EntityDetails[];
45
+ error?: Error;
46
+ };
47
+ declare function useSonarEntities(args: {
48
+ saleUUID: string;
49
+ walletAddress?: string;
50
+ }): UseSonarEntitiesResult;
41
51
  type UseSonarPurchaseResultReadyToPurchase = {
42
52
  loading: false;
43
53
  readyToPurchase: true;
@@ -68,4 +78,4 @@ declare function useSonarPurchase(args: {
68
78
  walletAddress: string;
69
79
  }): UseSonarPurchaseResult;
70
80
 
71
- export { SonarProvider, type SonarProviderConfig, type UseSonarEntityResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useSonarAuth, useSonarClient, useSonarEntity, useSonarPurchase };
81
+ export { SonarProvider, type SonarProviderConfig, type UseSonarEntitiesResult, type UseSonarEntityResult, type UseSonarPurchaseResult, type UseSonarPurchaseResultError, type UseSonarPurchaseResultLoading, type UseSonarPurchaseResultNotReadyToPurchase, type UseSonarPurchaseResultReadyToPurchase, useSonarAuth, useSonarClient, useSonarEntities, useSonarEntity, useSonarPurchase };
package/dist/index.js CHANGED
@@ -163,6 +163,63 @@ function useSonarEntity(args) {
163
163
  error: state.error
164
164
  };
165
165
  }
166
+ function useSonarEntities(args) {
167
+ const { authenticated, ready } = useSonarAuth();
168
+ const client = useSonarClient();
169
+ if (!args.saleUUID) {
170
+ throw new Error("saleUUID is required");
171
+ }
172
+ const saleUUID = args.saleUUID;
173
+ const [state, setState] = useState2({
174
+ loading: false,
175
+ hasFetched: false
176
+ });
177
+ const fullyConnected = ready && authenticated;
178
+ const refetch = useCallback2(async () => {
179
+ if (!fullyConnected) {
180
+ return;
181
+ }
182
+ setState((s) => ({ ...s, loading: true }));
183
+ try {
184
+ const resp = await client.listAvailableEntities({
185
+ saleUUID
186
+ });
187
+ setState({
188
+ loading: false,
189
+ entities: resp.Entities,
190
+ error: void 0,
191
+ hasFetched: true
192
+ });
193
+ } catch (err) {
194
+ const error = err instanceof Error ? err : new Error(String(err));
195
+ setState({ loading: false, entities: void 0, error, hasFetched: true });
196
+ }
197
+ }, [client, saleUUID, fullyConnected]);
198
+ const reset = useCallback2(() => {
199
+ setState({
200
+ loading: false,
201
+ hasFetched: false,
202
+ entities: void 0,
203
+ error: void 0
204
+ });
205
+ }, []);
206
+ useEffect2(() => {
207
+ if (fullyConnected) {
208
+ refetch();
209
+ }
210
+ }, [fullyConnected, refetch]);
211
+ useEffect2(() => {
212
+ if (ready && !authenticated) {
213
+ reset();
214
+ }
215
+ }, [ready, authenticated, reset]);
216
+ return {
217
+ authenticated,
218
+ loading: state.loading,
219
+ entities: state.entities,
220
+ error: state.error
221
+ };
222
+ }
166
223
  function useSonarPurchase(args) {
167
224
  const saleUUID = args.saleUUID;
168
225
  const entityID = args.entityID;
@@ -226,6 +283,7 @@ export {
226
283
  SonarProvider,
227
284
  useSonarAuth,
228
285
  useSonarClient,
286
+ useSonarEntities,
229
287
  useSonarEntity,
230
288
  useSonarPurchase
231
289
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@echoxyz/sonar-react",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "react": ">=18"
17
17
  },
18
18
  "dependencies": {
19
- "@echoxyz/sonar-core": "0.6.0"
19
+ "@echoxyz/sonar-core": "0.7.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@testing-library/react": "^16.0.0",