@avail-project/widgets 0.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.
Files changed (143) hide show
  1. package/README.md +34 -0
  2. package/dist/common/components/ErrorBoundary.d.ts +44 -0
  3. package/dist/common/components/ErrorBoundary.d.ts.map +1 -0
  4. package/dist/common/components/ErrorBoundary.js +65 -0
  5. package/dist/common/hooks/useDebouncedCallback.d.ts +13 -0
  6. package/dist/common/hooks/useDebouncedCallback.d.ts.map +1 -0
  7. package/dist/common/hooks/useDebouncedCallback.js +42 -0
  8. package/dist/common/hooks/useDebouncedValue.d.ts +5 -0
  9. package/dist/common/hooks/useDebouncedValue.d.ts.map +1 -0
  10. package/dist/common/hooks/useDebouncedValue.js +15 -0
  11. package/dist/common/hooks/useInterval.d.ts +11 -0
  12. package/dist/common/hooks/useInterval.d.ts.map +1 -0
  13. package/dist/common/hooks/useInterval.js +25 -0
  14. package/dist/common/hooks/useLatest.d.ts +12 -0
  15. package/dist/common/hooks/useLatest.d.ts.map +1 -0
  16. package/dist/common/hooks/useLatest.js +19 -0
  17. package/dist/common/hooks/useNexusError.d.ts +20 -0
  18. package/dist/common/hooks/useNexusError.d.ts.map +1 -0
  19. package/dist/common/hooks/useNexusError.js +120 -0
  20. package/dist/common/hooks/usePolling.d.ts +7 -0
  21. package/dist/common/hooks/usePolling.d.ts.map +1 -0
  22. package/dist/common/hooks/usePolling.js +29 -0
  23. package/dist/common/hooks/useStableCallback.d.ts +6 -0
  24. package/dist/common/hooks/useStableCallback.d.ts.map +1 -0
  25. package/dist/common/hooks/useStableCallback.js +13 -0
  26. package/dist/common/hooks/useStopwatch.d.ts +17 -0
  27. package/dist/common/hooks/useStopwatch.d.ts.map +1 -0
  28. package/dist/common/hooks/useStopwatch.js +44 -0
  29. package/dist/common/hooks/useTransactionExecution.d.ts +62 -0
  30. package/dist/common/hooks/useTransactionExecution.d.ts.map +1 -0
  31. package/dist/common/hooks/useTransactionExecution.js +273 -0
  32. package/dist/common/hooks/useTransactionFlow.d.ts +71 -0
  33. package/dist/common/hooks/useTransactionFlow.d.ts.map +1 -0
  34. package/dist/common/hooks/useTransactionFlow.js +435 -0
  35. package/dist/common/index.d.ts +17 -0
  36. package/dist/common/index.d.ts.map +1 -0
  37. package/dist/common/index.js +16 -0
  38. package/dist/common/tx/steps.d.ts +19 -0
  39. package/dist/common/tx/steps.d.ts.map +1 -0
  40. package/dist/common/tx/steps.js +89 -0
  41. package/dist/common/tx/types.d.ts +11 -0
  42. package/dist/common/tx/types.d.ts.map +1 -0
  43. package/dist/common/tx/types.js +19 -0
  44. package/dist/common/tx/useTransactionSteps.d.ts +21 -0
  45. package/dist/common/tx/useTransactionSteps.d.ts.map +1 -0
  46. package/dist/common/tx/useTransactionSteps.js +40 -0
  47. package/dist/common/types/transaction-flow.d.ts +48 -0
  48. package/dist/common/types/transaction-flow.d.ts.map +1 -0
  49. package/dist/common/types/transaction-flow.js +2 -0
  50. package/dist/common/utils/constant.d.ts +99 -0
  51. package/dist/common/utils/constant.d.ts.map +1 -0
  52. package/dist/common/utils/constant.js +370 -0
  53. package/dist/common/utils/token-pricing.d.ts +33 -0
  54. package/dist/common/utils/token-pricing.d.ts.map +1 -0
  55. package/dist/common/utils/token-pricing.js +255 -0
  56. package/dist/common/utils/transaction-flow.d.ts +35 -0
  57. package/dist/common/utils/transaction-flow.d.ts.map +1 -0
  58. package/dist/common/utils/transaction-flow.js +65 -0
  59. package/dist/index.d.ts +5 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +2 -0
  62. package/dist/lib/utils.d.ts +4 -0
  63. package/dist/lib/utils.d.ts.map +1 -0
  64. package/dist/lib/utils.js +8 -0
  65. package/dist/nexus/NexusProvider.d.ts +50 -0
  66. package/dist/nexus/NexusProvider.d.ts.map +1 -0
  67. package/dist/nexus/NexusProvider.js +572 -0
  68. package/dist/nexus-widget/components/address-identicon.d.ts +5 -0
  69. package/dist/nexus-widget/components/address-identicon.d.ts.map +1 -0
  70. package/dist/nexus-widget/components/address-identicon.js +39 -0
  71. package/dist/nexus-widget/components/amount-input-unified.d.ts +18 -0
  72. package/dist/nexus-widget/components/amount-input-unified.d.ts.map +1 -0
  73. package/dist/nexus-widget/components/amount-input-unified.js +88 -0
  74. package/dist/nexus-widget/components/deposit-idle-form.d.ts +29 -0
  75. package/dist/nexus-widget/components/deposit-idle-form.d.ts.map +1 -0
  76. package/dist/nexus-widget/components/deposit-idle-form.js +506 -0
  77. package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts +36 -0
  78. package/dist/nexus-widget/components/nexus-widget-progress-screen.d.ts.map +1 -0
  79. package/dist/nexus-widget/components/nexus-widget-progress-screen.js +737 -0
  80. package/dist/nexus-widget/components/pay-using-selector.d.ts +9 -0
  81. package/dist/nexus-widget/components/pay-using-selector.d.ts.map +1 -0
  82. package/dist/nexus-widget/components/pay-using-selector.js +37 -0
  83. package/dist/nexus-widget/components/pay-with-sources.d.ts +11 -0
  84. package/dist/nexus-widget/components/pay-with-sources.d.ts.map +1 -0
  85. package/dist/nexus-widget/components/pay-with-sources.js +266 -0
  86. package/dist/nexus-widget/components/receive-asset-selector.d.ts +28 -0
  87. package/dist/nexus-widget/components/receive-asset-selector.d.ts.map +1 -0
  88. package/dist/nexus-widget/components/receive-asset-selector.js +1178 -0
  89. package/dist/nexus-widget/components/recipient-input.d.ts +10 -0
  90. package/dist/nexus-widget/components/recipient-input.d.ts.map +1 -0
  91. package/dist/nexus-widget/components/recipient-input.js +44 -0
  92. package/dist/nexus-widget/components/send-idle-form.d.ts +29 -0
  93. package/dist/nexus-widget/components/send-idle-form.d.ts.map +1 -0
  94. package/dist/nexus-widget/components/send-idle-form.js +548 -0
  95. package/dist/nexus-widget/components/status-alerts.d.ts +7 -0
  96. package/dist/nexus-widget/components/status-alerts.d.ts.map +1 -0
  97. package/dist/nexus-widget/components/status-alerts.js +17 -0
  98. package/dist/nexus-widget/components/swap-asset-selector.d.ts +74 -0
  99. package/dist/nexus-widget/components/swap-asset-selector.d.ts.map +1 -0
  100. package/dist/nexus-widget/components/swap-asset-selector.js +1910 -0
  101. package/dist/nexus-widget/components/swap-idle-form.d.ts +29 -0
  102. package/dist/nexus-widget/components/swap-idle-form.d.ts.map +1 -0
  103. package/dist/nexus-widget/components/swap-idle-form.js +1289 -0
  104. package/dist/nexus-widget/components/swap-intent-preview.d.ts +95 -0
  105. package/dist/nexus-widget/components/swap-intent-preview.d.ts.map +1 -0
  106. package/dist/nexus-widget/components/swap-intent-preview.js +1050 -0
  107. package/dist/nexus-widget/nexus-widget.d.ts +4 -0
  108. package/dist/nexus-widget/nexus-widget.d.ts.map +1 -0
  109. package/dist/nexus-widget/nexus-widget.js +7819 -0
  110. package/dist/nexus-widget/sdk-types.d.ts +13 -0
  111. package/dist/nexus-widget/sdk-types.d.ts.map +1 -0
  112. package/dist/nexus-widget/sdk-types.js +1 -0
  113. package/dist/nexus-widget/theme.d.ts +156 -0
  114. package/dist/nexus-widget/theme.d.ts.map +1 -0
  115. package/dist/nexus-widget/theme.js +159 -0
  116. package/dist/nexus-widget/types.d.ts +141 -0
  117. package/dist/nexus-widget/types.d.ts.map +1 -0
  118. package/dist/nexus-widget/types.js +1 -0
  119. package/dist/nexus-widget/utils/citrea-tokens.d.ts +82 -0
  120. package/dist/nexus-widget/utils/citrea-tokens.d.ts.map +1 -0
  121. package/dist/nexus-widget/utils/citrea-tokens.js +136 -0
  122. package/dist/nexus-widget/utils/deposit-source-selection.d.ts +55 -0
  123. package/dist/nexus-widget/utils/deposit-source-selection.d.ts.map +1 -0
  124. package/dist/nexus-widget/utils/deposit-source-selection.js +219 -0
  125. package/dist/swaps/components/stacked-token-icons.d.ts +15 -0
  126. package/dist/swaps/components/stacked-token-icons.d.ts.map +1 -0
  127. package/dist/swaps/components/stacked-token-icons.js +38 -0
  128. package/dist/swaps/components/step-flow.d.ts +32 -0
  129. package/dist/swaps/components/step-flow.d.ts.map +1 -0
  130. package/dist/swaps/components/step-flow.js +54 -0
  131. package/dist/swaps/components/token-icon.d.ts +11 -0
  132. package/dist/swaps/components/token-icon.d.ts.map +1 -0
  133. package/dist/swaps/components/token-icon.js +16 -0
  134. package/dist/swaps/components/transaction-progress.d.ts +43 -0
  135. package/dist/swaps/components/transaction-progress.d.ts.map +1 -0
  136. package/dist/swaps/components/transaction-progress.js +94 -0
  137. package/dist/ui/button.d.ts +11 -0
  138. package/dist/ui/button.d.ts.map +1 -0
  139. package/dist/ui/button.js +34 -0
  140. package/dist/ui/dialog.d.ts +17 -0
  141. package/dist/ui/dialog.d.ts.map +1 -0
  142. package/dist/ui/dialog.js +47 -0
  143. package/package.json +60 -0
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @avail-project/widgets
2
+
3
+ Public npm distribution for Avail widgets.
4
+
5
+ Install from npm:
6
+
7
+ ```bash
8
+ pnpm add @avail-project/widgets
9
+ ```
10
+
11
+ For internal GitHub installs, the package runs its `prepare` script and builds `dist` after clone:
12
+
13
+ ```bash
14
+ pnpm add github:availproject/widgets
15
+ ```
16
+
17
+ ```tsx
18
+ import { NexusProvider, NexusWidget } from "@avail-project/widgets";
19
+
20
+ export function App() {
21
+ return (
22
+ <NexusProvider config={{ network: "mainnet", debug: false }}>
23
+ <NexusWidget config={{ mode: "swap" }} />
24
+ </NexusProvider>
25
+ );
26
+ }
27
+ ```
28
+
29
+ The shadcn registry remains the open source code-install path. Until the
30
+ namespace is listed in shadcn, install with:
31
+
32
+ ```bash
33
+ npx shadcn@latest add availproject/widgets/nexus
34
+ ```
@@ -0,0 +1,44 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from "react";
2
+ interface ErrorBoundaryProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
6
+ }
7
+ interface ErrorBoundaryState {
8
+ hasError: boolean;
9
+ error: Error | null;
10
+ }
11
+ /**
12
+ * Error boundary component that catches JavaScript errors in child components.
13
+ * Displays a fallback UI instead of crashing the entire widget.
14
+ *
15
+ * @example
16
+ * <ErrorBoundary
17
+ * fallback={<div>Something went wrong</div>}
18
+ * onError={(error) => console.error(error)}
19
+ * >
20
+ * <MyComponent />
21
+ * </ErrorBoundary>
22
+ */
23
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
24
+ constructor(props: ErrorBoundaryProps);
25
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
26
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
27
+ render(): ReactNode;
28
+ }
29
+ /**
30
+ * A more specific error boundary for widget containers with reset capability.
31
+ */
32
+ interface WidgetErrorBoundaryProps extends ErrorBoundaryProps {
33
+ widgetName?: string;
34
+ onReset?: () => void;
35
+ }
36
+ export declare class WidgetErrorBoundary extends Component<WidgetErrorBoundaryProps, ErrorBoundaryState> {
37
+ constructor(props: WidgetErrorBoundaryProps);
38
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
39
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
40
+ handleReset: () => void;
41
+ render(): ReactNode;
42
+ }
43
+ export {};
44
+ //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../.build-src/common/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElE,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CACxD;AAED,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAC1C,kBAAkB,EAClB,kBAAkB,CACnB;gBACa,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAK3D,MAAM,IAAI,SAAS;CA0BpB;AAED;;GAEG;AACH,UAAU,wBAAyB,SAAQ,kBAAkB;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,qBAAa,mBAAoB,SAAQ,SAAS,CAChD,wBAAwB,EACxB,kBAAkB,CACnB;gBACa,KAAK,EAAE,wBAAwB;IAK3C,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAS3D,WAAW,QAAO,IAAI,CAGpB;IAEF,MAAM,IAAI,SAAS;CA4BpB"}
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Component } from "react";
4
+ /**
5
+ * Error boundary component that catches JavaScript errors in child components.
6
+ * Displays a fallback UI instead of crashing the entire widget.
7
+ *
8
+ * @example
9
+ * <ErrorBoundary
10
+ * fallback={<div>Something went wrong</div>}
11
+ * onError={(error) => console.error(error)}
12
+ * >
13
+ * <MyComponent />
14
+ * </ErrorBoundary>
15
+ */
16
+ export class ErrorBoundary extends Component {
17
+ constructor(props) {
18
+ super(props);
19
+ this.state = { hasError: false, error: null };
20
+ }
21
+ static getDerivedStateFromError(error) {
22
+ return { hasError: true, error };
23
+ }
24
+ componentDidCatch(error, errorInfo) {
25
+ console.error("ErrorBoundary caught an error:", error, errorInfo);
26
+ this.props.onError?.(error, errorInfo);
27
+ }
28
+ render() {
29
+ if (this.state.hasError) {
30
+ if (this.props.fallback) {
31
+ return this.props.fallback;
32
+ }
33
+ return (_jsxs("div", { className: "flex flex-col items-center justify-center p-6 text-center", children: [_jsx("div", { className: "text-destructive font-medium mb-2", children: "Something went wrong" }), _jsx("p", { className: "text-muted-foreground text-sm mb-4", children: "An unexpected error occurred. Please try again." }), _jsx("button", { onClick: () => this.setState({ hasError: false, error: null }), className: "px-4 py-2 text-sm font-medium text-primary-foreground bg-primary rounded-md hover:bg-primary/90 transition-colors", children: "Try again" })] }));
34
+ }
35
+ return this.props.children;
36
+ }
37
+ }
38
+ export class WidgetErrorBoundary extends Component {
39
+ constructor(props) {
40
+ super(props);
41
+ this.handleReset = () => {
42
+ this.props.onReset?.();
43
+ this.setState({ hasError: false, error: null });
44
+ };
45
+ this.state = { hasError: false, error: null };
46
+ }
47
+ static getDerivedStateFromError(error) {
48
+ return { hasError: true, error };
49
+ }
50
+ componentDidCatch(error, errorInfo) {
51
+ console.error(`WidgetErrorBoundary [${this.props.widgetName ?? "Unknown"}]:`, error, errorInfo);
52
+ this.props.onError?.(error, errorInfo);
53
+ }
54
+ render() {
55
+ if (this.state.hasError) {
56
+ if (this.props.fallback) {
57
+ return this.props.fallback;
58
+ }
59
+ return (_jsxs("div", { className: "flex flex-col items-center justify-center p-6 text-center bg-destructive/5 rounded-lg border border-destructive/20", children: [_jsx("div", { className: "text-destructive font-medium mb-2", children: this.props.widgetName
60
+ ? `${this.props.widgetName} encountered an error`
61
+ : "Widget error" }), _jsx("p", { className: "text-muted-foreground text-sm mb-4", children: this.state.error?.message || "An unexpected error occurred." }), _jsx("button", { onClick: this.handleReset, className: "px-4 py-2 text-sm font-medium text-primary-foreground bg-primary rounded-md hover:bg-primary/90 transition-colors", children: "Reset widget" })] }));
62
+ }
63
+ return this.props.children;
64
+ }
65
+ }
@@ -0,0 +1,13 @@
1
+ type AnyFn = (...args: any[]) => any;
2
+ export interface Debounced<T extends AnyFn> {
3
+ (...args: Parameters<T>): void;
4
+ cancel: () => void;
5
+ flush: () => void;
6
+ }
7
+ /**
8
+ * Returns a debounced function that delays invoking `fn` until after `delay`
9
+ * milliseconds have elapsed since the last call.
10
+ */
11
+ export declare function useDebouncedCallback<T extends AnyFn>(fn: T, delay: number): Debounced<T>;
12
+ export {};
13
+ //# sourceMappingURL=useDebouncedCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedCallback.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useDebouncedCallback.ts"],"names":[],"mappings":"AAGA,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAErC,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,KAAK;IACxC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,KAAK,EAClD,EAAE,EAAE,CAAC,EACL,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,CAAC,CAAC,CAyCd"}
@@ -0,0 +1,42 @@
1
+ import { useEffect, useMemo, useRef } from "react";
2
+ import { useStableCallback } from "./useStableCallback";
3
+ /**
4
+ * Returns a debounced function that delays invoking `fn` until after `delay`
5
+ * milliseconds have elapsed since the last call.
6
+ */
7
+ export function useDebouncedCallback(fn, delay) {
8
+ const latest = useStableCallback(fn);
9
+ const timerRef = useRef(null);
10
+ const lastArgsRef = useRef(null);
11
+ const cancel = () => {
12
+ if (timerRef.current) {
13
+ clearTimeout(timerRef.current);
14
+ timerRef.current = null;
15
+ }
16
+ };
17
+ const flush = () => {
18
+ if (timerRef.current && lastArgsRef.current) {
19
+ clearTimeout(timerRef.current);
20
+ timerRef.current = null;
21
+ latest(...lastArgsRef.current);
22
+ lastArgsRef.current = null;
23
+ }
24
+ };
25
+ // cancel when delay changes/unmounts
26
+ useEffect(() => cancel, [delay]);
27
+ return useMemo(() => {
28
+ const debounced = ((...args) => {
29
+ lastArgsRef.current = args;
30
+ cancel();
31
+ timerRef.current = setTimeout(() => {
32
+ latest(...lastArgsRef.current);
33
+ lastArgsRef.current = null;
34
+ timerRef.current = null;
35
+ }, delay);
36
+ });
37
+ debounced.cancel = cancel;
38
+ debounced.flush = flush;
39
+ return debounced;
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, [delay, latest]);
42
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Derives a debounced value from an input value and delay.
3
+ */
4
+ export declare function useDebouncedValue<T>(value: T, delay: number): T;
5
+ //# sourceMappingURL=useDebouncedValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebouncedValue.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useDebouncedValue.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAW/D"}
@@ -0,0 +1,15 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useDebouncedCallback } from "./useDebouncedCallback";
3
+ /**
4
+ * Derives a debounced value from an input value and delay.
5
+ */
6
+ export function useDebouncedValue(value, delay) {
7
+ const [debounced, setDebounced] = useState(value);
8
+ const setter = useDebouncedCallback((v) => setDebounced(v), delay);
9
+ useEffect(() => {
10
+ setter(value);
11
+ return setter.cancel;
12
+ // eslint-disable-next-line react-hooks/exhaustive-deps
13
+ }, [value, delay]);
14
+ return debounced;
15
+ }
@@ -0,0 +1,11 @@
1
+ interface UseIntervalOptions {
2
+ enabled?: boolean;
3
+ immediate?: boolean;
4
+ }
5
+ /**
6
+ * Declarative setInterval with pause/resume and latest-callback semantics.
7
+ * Pass delay=null to pause.
8
+ */
9
+ export declare function useInterval(callback: () => void, delay: number | null, options?: UseIntervalOptions): void;
10
+ export {};
11
+ //# sourceMappingURL=useInterval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useInterval.ts"],"names":[],"mappings":"AAGA,UAAU,kBAAkB;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,IAAI,EACpB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,GAAE,kBAAuB,QAmBjC"}
@@ -0,0 +1,25 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { useStableCallback } from "./useStableCallback";
3
+ /**
4
+ * Declarative setInterval with pause/resume and latest-callback semantics.
5
+ * Pass delay=null to pause.
6
+ */
7
+ export function useInterval(callback, delay, options = {}) {
8
+ const { enabled = true, immediate = false } = options;
9
+ const savedCallback = useStableCallback(callback);
10
+ const intervalRef = useRef(null);
11
+ useEffect(() => {
12
+ if (!enabled || delay == null)
13
+ return;
14
+ if (immediate) {
15
+ savedCallback();
16
+ }
17
+ intervalRef.current = setInterval(savedCallback, delay);
18
+ return () => {
19
+ if (intervalRef.current) {
20
+ clearInterval(intervalRef.current);
21
+ intervalRef.current = null;
22
+ }
23
+ };
24
+ }, [delay, enabled, immediate, savedCallback]);
25
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Returns a ref that always contains the latest value.
3
+ * Useful for accessing current values in callbacks without causing re-renders.
4
+ *
5
+ * @example
6
+ * const countRef = useLatest(count);
7
+ * const handleClick = useCallback(() => {
8
+ * console.log(countRef.current); // Always the latest count
9
+ * }, []); // No dependency needed!
10
+ */
11
+ export declare function useLatest<T>(value: T): React.MutableRefObject<T>;
12
+ //# sourceMappingURL=useLatest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLatest.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useLatest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAShE"}
@@ -0,0 +1,19 @@
1
+ import { useRef, useLayoutEffect } from "react";
2
+ /**
3
+ * Returns a ref that always contains the latest value.
4
+ * Useful for accessing current values in callbacks without causing re-renders.
5
+ *
6
+ * @example
7
+ * const countRef = useLatest(count);
8
+ * const handleClick = useCallback(() => {
9
+ * console.log(countRef.current); // Always the latest count
10
+ * }, []); // No dependency needed!
11
+ */
12
+ export function useLatest(value) {
13
+ const ref = useRef(value);
14
+ // Use useLayoutEffect to update synchronously before any effects run
15
+ useLayoutEffect(() => {
16
+ ref.current = value;
17
+ });
18
+ return ref;
19
+ }
@@ -0,0 +1,20 @@
1
+ declare function handler(err: unknown): {
2
+ code: string;
3
+ message: string;
4
+ context: undefined;
5
+ details: undefined;
6
+ } | {
7
+ code: import("@avail-project/nexus-core").ErrorCode;
8
+ message: string;
9
+ context: {
10
+ operation?: import("@avail-project/nexus-core").OperationName;
11
+ service: "wallet" | "hook" | "rpc" | "middleware" | "lifi" | "bebop" | "fibrous" | "zerox" | "coinbase" | undefined;
12
+ stepId?: string;
13
+ stepType?: string;
14
+ chainId?: number | bigint;
15
+ };
16
+ details: Record<string, unknown> | undefined;
17
+ };
18
+ export declare function useNexusError(): typeof handler;
19
+ export {};
20
+ //# sourceMappingURL=useNexusError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNexusError.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useNexusError.ts"],"names":[],"mappings":"AAoHA,iBAAS,OAAO,CAAC,GAAG,EAAE,OAAO;;;;;;;;;;;;;;;;EAuC5B;AAED,wBAAgB,aAAa,mBAE5B"}
@@ -0,0 +1,120 @@
1
+ import { ERROR_CODES, NexusError } from "@avail-project/nexus-core";
2
+ const DEFAULT_ERROR_MESSAGE = "Oops! Something went wrong. Please try again.";
3
+ const USER_REJECTED_MESSAGE = "Transaction was rejected in your wallet.";
4
+ const EMPTY_ERROR_MESSAGE = "Unable to determine transaction state. Please refresh and try again.";
5
+ const ERROR_MESSAGE_BY_CODE = {
6
+ [ERROR_CODES.INVALID_VALUES_ALLOWANCE_HOOK]: "Invalid allowance selection. Please review allowance values and try again.",
7
+ [ERROR_CODES.SDK_NOT_INITIALIZED]: "Nexus SDK is not initialized. Reconnect your wallet and try again.",
8
+ [ERROR_CODES.SDK_INIT_STATE_NOT_EXPECTED]: "Nexus is still initializing. Please wait a few seconds and retry.",
9
+ [ERROR_CODES.CHAIN_NOT_FOUND]: "Selected chain is not supported for this route.",
10
+ [ERROR_CODES.CHAIN_DATA_NOT_FOUND]: "Chain metadata is unavailable for this route. Please try another chain.",
11
+ [ERROR_CODES.ASSET_NOT_FOUND]: "Requested asset was not found in your balances.",
12
+ [ERROR_CODES.TOKEN_NOT_SUPPORTED]: "Selected token is not supported for this route.",
13
+ [ERROR_CODES.UNIVERSE_NOT_SUPPORTED]: "Selected chain universe is not supported yet.",
14
+ [ERROR_CODES.ENVIRONMENT_NOT_SUPPORTED]: "Selected environment is not supported yet.",
15
+ [ERROR_CODES.ENVIRONMENT_NOT_KNOWN]: "Selected environment is not recognized.",
16
+ [ERROR_CODES.INTERNAL_UNKNOWN_SIGNATURE]: "Unsupported signature type for this transaction.",
17
+ [ERROR_CODES.USER_INTENT_HOOK_DENIED]: USER_REJECTED_MESSAGE,
18
+ [ERROR_CODES.USER_ALLOWANCE_APPROVAL_DENIED]: USER_REJECTED_MESSAGE,
19
+ [ERROR_CODES.USER_INTENT_SIGNATURE_DENIED]: USER_REJECTED_MESSAGE,
20
+ [ERROR_CODES.USER_SIWE_SIGNATURE_DENIED]: USER_REJECTED_MESSAGE,
21
+ [ERROR_CODES.INSUFFICIENT_BALANCE]: "Insufficient balance to proceed.",
22
+ [ERROR_CODES.WALLET_NOT_CONNECTED]: "Wallet is not connected. Connect your wallet and try again.",
23
+ [ERROR_CODES.EXEC_GAS_PRICE_FETCH_FAILED]: "Unable to estimate gas right now. Please retry.",
24
+ [ERROR_CODES.SIMULATION_ERROR]: "Simulation failed. Please review your inputs and try again.",
25
+ [ERROR_CODES.BACKEND_GET_QUOTE_FAILED]: "Unable to fetch a quote right now. Please retry.",
26
+ [ERROR_CODES.VAULT_CONTRACT_NOT_FOUND]: "Required vault contract is unavailable on this chain.",
27
+ [ERROR_CODES.EXEC_SLIPPAGE_EXCEEDED]: "Slippage exceeded tolerance. Refresh quote and retry.",
28
+ [ERROR_CODES.EXTERNAL_RATES_DRIFT_EXCEEDED]: "Rates changed beyond tolerance. Review and retry.",
29
+ [ERROR_CODES.INVALID_INPUT]: "Some transaction inputs are invalid. Please review and try again.",
30
+ [ERROR_CODES.INVALID_ADDRESS_LENGTH]: "Address format is invalid for the selected chain.",
31
+ [ERROR_CODES.NO_BALANCE_FOR_ADDRESS]: "No balance found for this wallet on supported source chains.",
32
+ [ERROR_CODES.EXEC_TX_RECEIPT_WAIT_TIMEOUT]: "Transaction is taking longer than expected. Check your wallet and explorer.",
33
+ [ERROR_CODES.EXEC_TX_ONCHAIN_REVERTED]: "Transaction reverted on-chain. Please verify inputs and retry.",
34
+ [ERROR_CODES.INTERNAL_DESTINATION_REQUEST_HASH_NOT_FOUND]: "Could not finalize destination request. Please retry.",
35
+ };
36
+ function isRecord(value) {
37
+ return typeof value === "object" && value !== null;
38
+ }
39
+ function getErrorMessage(value) {
40
+ if (!isRecord(value))
41
+ return undefined;
42
+ const message = value.message;
43
+ return typeof message === "string" ? message : undefined;
44
+ }
45
+ function getErrorCode(value) {
46
+ if (!isRecord(value))
47
+ return undefined;
48
+ const code = value.code;
49
+ if (typeof code === "string" || typeof code === "number") {
50
+ return code;
51
+ }
52
+ return undefined;
53
+ }
54
+ function looksLikeUserRejection(err) {
55
+ if (err instanceof NexusError) {
56
+ return (err.code === ERROR_CODES.USER_ALLOWANCE_APPROVAL_DENIED ||
57
+ err.code === ERROR_CODES.USER_INTENT_HOOK_DENIED ||
58
+ err.code === ERROR_CODES.USER_INTENT_SIGNATURE_DENIED ||
59
+ err.code === ERROR_CODES.USER_SIWE_SIGNATURE_DENIED);
60
+ }
61
+ const code = getErrorCode(err);
62
+ if (code === 4001 || code === "ACTION_REJECTED") {
63
+ return true;
64
+ }
65
+ const message = getErrorMessage(err)?.toLowerCase();
66
+ if (!message)
67
+ return false;
68
+ return (message.includes("user denied") ||
69
+ message.includes("user rejected") ||
70
+ message.includes("rejected request") ||
71
+ message.includes("denied transaction signature"));
72
+ }
73
+ function sanitizeMessage(message) {
74
+ if (!message)
75
+ return DEFAULT_ERROR_MESSAGE;
76
+ const cleaned = message
77
+ .replace(/^Internal error:\s*/i, "")
78
+ .replace(/^COSMOS:\s*/i, "")
79
+ .trim();
80
+ return cleaned || DEFAULT_ERROR_MESSAGE;
81
+ }
82
+ function handler(err) {
83
+ if (err === null || err === undefined) {
84
+ console.error("Unexpected empty error from Nexus SDK:", err);
85
+ return {
86
+ code: "unexpected_error",
87
+ message: EMPTY_ERROR_MESSAGE,
88
+ context: undefined,
89
+ details: undefined,
90
+ };
91
+ }
92
+ if (looksLikeUserRejection(err)) {
93
+ return {
94
+ code: ERROR_CODES.USER_INTENT_HOOK_DENIED,
95
+ message: USER_REJECTED_MESSAGE,
96
+ context: undefined,
97
+ details: undefined,
98
+ };
99
+ }
100
+ if (err instanceof NexusError) {
101
+ const mappedMessage = ERROR_MESSAGE_BY_CODE[err.code] ?? sanitizeMessage(err.message);
102
+ return {
103
+ code: err.code,
104
+ message: mappedMessage,
105
+ context: err.context,
106
+ details: err.details,
107
+ };
108
+ }
109
+ const unknownMessage = sanitizeMessage(getErrorMessage(err));
110
+ console.error("Unexpected error:", err);
111
+ return {
112
+ code: String(getErrorCode(err) ?? "unexpected_error"),
113
+ message: unknownMessage || DEFAULT_ERROR_MESSAGE,
114
+ context: undefined,
115
+ details: undefined,
116
+ };
117
+ }
118
+ export function useNexusError() {
119
+ return handler;
120
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Declarative polling with in-flight protection (no overlap).
3
+ * When enabled becomes true, an immediate run is executed,
4
+ * followed by interval-based runs.
5
+ */
6
+ export declare function usePolling(enabled: boolean, fn: () => Promise<void> | void, intervalMs: number): void;
7
+ //# sourceMappingURL=usePolling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePolling.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/usePolling.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAC9B,UAAU,EAAE,MAAM,QAmBnB"}
@@ -0,0 +1,29 @@
1
+ import { useRef } from "react";
2
+ import { useInterval } from "./useInterval";
3
+ import { useStableCallback } from "./useStableCallback";
4
+ /**
5
+ * Declarative polling with in-flight protection (no overlap).
6
+ * When enabled becomes true, an immediate run is executed,
7
+ * followed by interval-based runs.
8
+ */
9
+ export function usePolling(enabled, fn, intervalMs) {
10
+ const inFlightRef = useRef(false);
11
+ const wrapped = useStableCallback(async () => {
12
+ if (inFlightRef.current)
13
+ return;
14
+ try {
15
+ inFlightRef.current = true;
16
+ await fn();
17
+ }
18
+ catch (error) {
19
+ console.error(error);
20
+ }
21
+ finally {
22
+ inFlightRef.current = false;
23
+ }
24
+ });
25
+ useInterval(wrapped, enabled ? intervalMs : null, {
26
+ enabled,
27
+ immediate: enabled,
28
+ });
29
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns a stable function identity that always calls the latest implementation.
3
+ * Useful when passing callbacks to memoized children without re-creating handlers.
4
+ */
5
+ export declare function useStableCallback<Args extends readonly unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
6
+ //# sourceMappingURL=useStableCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStableCallback.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useStableCallback.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,SAAS,OAAO,EAAE,EAAE,MAAM,EACvE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GAC5B,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAa3B"}
@@ -0,0 +1,13 @@
1
+ import { useCallback, useRef } from "react";
2
+ /**
3
+ * Returns a stable function identity that always calls the latest implementation.
4
+ * Useful when passing callbacks to memoized children without re-creating handlers.
5
+ */
6
+ export function useStableCallback(fn) {
7
+ const fnRef = useRef(fn);
8
+ fnRef.current = fn;
9
+ const stable = useCallback(((...args) => {
10
+ return fnRef.current(...args);
11
+ }), []);
12
+ return stable;
13
+ }
@@ -0,0 +1,17 @@
1
+ interface UseStopwatchOptions {
2
+ running?: boolean;
3
+ intervalMs?: number;
4
+ }
5
+ /**
6
+ * Simple stopwatch that increments elapsed seconds while running.
7
+ * Designed to replace scattered timer effects.
8
+ */
9
+ export declare function useStopwatch(options?: UseStopwatchOptions): {
10
+ seconds: number;
11
+ start: () => void;
12
+ stop: () => void;
13
+ reset: () => void;
14
+ running: boolean;
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=useStopwatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStopwatch.d.ts","sourceRoot":"","sources":["../../../.build-src/common/hooks/useStopwatch.ts"],"names":[],"mappings":"AAEA,UAAU,mBAAmB;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB;;;;;;EAyC7D"}
@@ -0,0 +1,44 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ /**
3
+ * Simple stopwatch that increments elapsed seconds while running.
4
+ * Designed to replace scattered timer effects.
5
+ */
6
+ export function useStopwatch(options = {}) {
7
+ const { running = false, intervalMs = 100 } = options;
8
+ const [elapsedSeconds, setElapsedSeconds] = useState(0);
9
+ const timerRef = useRef(null);
10
+ const reset = () => {
11
+ setElapsedSeconds(0);
12
+ };
13
+ const stop = () => {
14
+ if (timerRef.current) {
15
+ clearInterval(timerRef.current);
16
+ timerRef.current = null;
17
+ }
18
+ };
19
+ const start = () => {
20
+ if (timerRef.current)
21
+ return;
22
+ timerRef.current = setInterval(() => {
23
+ // 1s == 1000ms; we add fractional seconds per tick
24
+ setElapsedSeconds((prev) => prev + intervalMs / 1000);
25
+ }, intervalMs);
26
+ };
27
+ useEffect(() => {
28
+ if (running) {
29
+ start();
30
+ }
31
+ else {
32
+ stop();
33
+ }
34
+ return stop;
35
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ }, [running, intervalMs]);
37
+ return {
38
+ seconds: elapsedSeconds,
39
+ start,
40
+ stop,
41
+ reset,
42
+ running: Boolean(timerRef.current),
43
+ };
44
+ }