@calimero-network/mero-react 2.6.1 → 3.0.1

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/index.cjs CHANGED
@@ -2169,13 +2169,27 @@ function useUpgradeGroup() {
2169
2169
  );
2170
2170
  return { upgradeGroup, loading, error };
2171
2171
  }
2172
+ function useResyncContext() {
2173
+ const { mero } = useMero();
2174
+ const { loading, error, run } = useAsyncMutation();
2175
+ const resyncContext = react.useCallback(
2176
+ async (contextId, request = {}) => {
2177
+ if (!mero) return null;
2178
+ return run(() => mero.admin.resyncContext(contextId, request));
2179
+ },
2180
+ [mero, run]
2181
+ );
2182
+ return { resyncContext, loading, error };
2183
+ }
2172
2184
  function useGroupUpgradeStatus(groupId) {
2173
2185
  const { mero } = useMero();
2174
2186
  const [upgradeStatus, setUpgradeStatus] = react.useState(null);
2175
2187
  const [loading, setLoading] = react.useState(false);
2176
2188
  const [error, setError] = react.useState(null);
2177
2189
  const mountedRef = useMountedRef();
2190
+ const reqRef = react.useRef(0);
2178
2191
  const refetch = react.useCallback(async () => {
2192
+ const seq = ++reqRef.current;
2179
2193
  if (!mero || !groupId) {
2180
2194
  if (mountedRef.current) {
2181
2195
  setUpgradeStatus(null);
@@ -2190,20 +2204,25 @@ function useGroupUpgradeStatus(groupId) {
2190
2204
  }
2191
2205
  try {
2192
2206
  const result = await mero.admin.getGroupUpgradeStatus(groupId);
2193
- if (mountedRef.current) {
2207
+ if (mountedRef.current && seq === reqRef.current) {
2194
2208
  setUpgradeStatus(result);
2195
2209
  }
2196
2210
  } catch (err) {
2197
2211
  const errorValue = toError(err);
2198
- if (mountedRef.current) {
2212
+ if (mountedRef.current && seq === reqRef.current) {
2199
2213
  setError(errorValue);
2200
2214
  }
2201
2215
  } finally {
2202
- if (mountedRef.current) {
2216
+ if (mountedRef.current && seq === reqRef.current) {
2203
2217
  setLoading(false);
2204
2218
  }
2205
2219
  }
2206
2220
  }, [groupId, mero, mountedRef]);
2221
+ react.useEffect(() => {
2222
+ reqRef.current += 1;
2223
+ setUpgradeStatus(null);
2224
+ setError(null);
2225
+ }, [groupId]);
2207
2226
  react.useEffect(() => {
2208
2227
  void refetch();
2209
2228
  }, [refetch]);
@@ -2488,6 +2507,11 @@ function useMyAuthoredMigration(contextId) {
2488
2507
  } catch {
2489
2508
  }
2490
2509
  }, [mero, contextId, mountedRef]);
2510
+ react.useEffect(() => {
2511
+ reqRef.current += 1;
2512
+ setPendingCount(0);
2513
+ setSummary(null);
2514
+ }, [contextId]);
2491
2515
  react.useEffect(() => {
2492
2516
  void refresh();
2493
2517
  }, [refresh]);
@@ -2689,6 +2713,7 @@ exports.useNamespacesForApplication = useNamespacesForApplication;
2689
2713
  exports.useNestGroup = useNestGroup;
2690
2714
  exports.useRegisterGroupSigningKey = useRegisterGroupSigningKey;
2691
2715
  exports.useRemoveGroupMembers = useRemoveGroupMembers;
2716
+ exports.useResyncContext = useResyncContext;
2692
2717
  exports.useRetryGroupUpgrade = useRetryGroupUpgrade;
2693
2718
  exports.useSetContextMetadata = useSetContextMetadata;
2694
2719
  exports.useSetDefaultCapabilities = useSetDefaultCapabilities;