@naculus/connect-appkit-vue 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -2973,27 +2973,53 @@ function useTxMonitor(hash, chainId, monitor) {
2973
2973
  const entry = (0, import_vue47.shallowRef)(null);
2974
2974
  const isLoading = (0, import_vue47.shallowRef)(false);
2975
2975
  const isWatching = (0, import_vue47.shallowRef)(false);
2976
- const error = (0, import_vue47.shallowRef)(null);
2976
+ const guard = useActionGuard();
2977
+ const error = guard.error;
2977
2978
  let generation = 0;
2979
+ let refreshed = [];
2980
+ const currentInputs = () => [
2981
+ (0, import_vue47.toValue)(monitor),
2982
+ (0, import_vue47.toValue)(hash),
2983
+ (0, import_vue47.toValue)(chainId)
2984
+ ];
2985
+ const sameInputs = (a, b) => a.every((value, i) => Object.is(value, b[i]));
2978
2986
  const refresh = async () => {
2979
2987
  const activeMonitor = (0, import_vue47.toValue)(monitor);
2980
2988
  const activeHash = (0, import_vue47.toValue)(hash);
2981
2989
  const activeChainId = (0, import_vue47.toValue)(chainId);
2982
2990
  if (!activeMonitor || !activeHash) return;
2991
+ const started = [activeMonitor, activeHash, activeChainId];
2992
+ refreshed = started;
2983
2993
  isLoading.value = true;
2984
- error.value = null;
2985
- try {
2986
- await activeMonitor.refreshTx(activeHash, activeChainId ?? void 0);
2987
- const current = activeMonitor.getTxStatus(
2988
- activeHash,
2989
- activeChainId ?? void 0
2990
- );
2991
- if (current) entry.value = current;
2992
- } catch (err) {
2993
- error.value = err instanceof Error ? err : new Error("Failed to refresh transaction");
2994
- } finally {
2995
- isLoading.value = false;
2996
- }
2994
+ await guard.run(
2995
+ async (commit) => {
2996
+ try {
2997
+ await activeMonitor.refreshTx(
2998
+ activeHash,
2999
+ activeChainId ?? void 0
3000
+ );
3001
+ } catch (err) {
3002
+ if (!sameInputs(started, currentInputs())) return;
3003
+ throw err;
3004
+ }
3005
+ if (!sameInputs(started, currentInputs())) return;
3006
+ const current = activeMonitor.getTxStatus(
3007
+ activeHash,
3008
+ activeChainId ?? void 0
3009
+ );
3010
+ commit(() => {
3011
+ entry.value = current ?? null;
3012
+ });
3013
+ },
3014
+ "Failed to refresh transaction",
3015
+ void 0,
3016
+ {
3017
+ onSettled: () => {
3018
+ isLoading.value = false;
3019
+ }
3020
+ }
3021
+ ).catch(() => {
3022
+ });
2997
3023
  };
2998
3024
  const stopWatching = () => {
2999
3025
  const activeMonitor = (0, import_vue47.toValue)(monitor);
@@ -3007,6 +3033,9 @@ function useTxMonitor(hash, chainId, monitor) {
3007
3033
  [() => (0, import_vue47.toValue)(monitor), () => (0, import_vue47.toValue)(hash), () => (0, import_vue47.toValue)(chainId)],
3008
3034
  ([activeMonitor, activeHash, activeChainId], _previous, onCleanup) => {
3009
3035
  const mine = ++generation;
3036
+ if (!sameInputs([activeMonitor, activeHash, activeChainId], refreshed)) {
3037
+ guard.invalidate();
3038
+ }
3010
3039
  if (!activeMonitor || !activeHash || !activeChainId) {
3011
3040
  entry.value = null;
3012
3041
  isLoading.value = false;
@@ -3028,8 +3057,7 @@ function useTxMonitor(hash, chainId, monitor) {
3028
3057
  isWatching.value = true;
3029
3058
  isLoading.value = true;
3030
3059
  error.value = null;
3031
- const current = activeMonitor.getTxStatus(activeHash, activeChainId);
3032
- if (current) entry.value = current;
3060
+ entry.value = activeMonitor.getTxStatus(activeHash, activeChainId) ?? null;
3033
3061
  activeMonitor.watchTx(activeHash, activeChainId, {}).then((initial) => {
3034
3062
  if (cancelled || mine !== generation) return;
3035
3063
  entry.value = initial;