@ravnexchange/react 0.1.4 → 0.1.6

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.
@@ -1,16 +1,23 @@
1
- import { type RavnClient, type StatusDTO } from "@ravnexchange/sdk";
1
+ import { type RavnClient, type SettlementStatus, type StatusDTO } from "@ravnexchange/sdk";
2
2
  export interface UseRavnStatusResult {
3
3
  status: StatusDTO | null;
4
4
  isLoading: boolean;
5
5
  error: unknown;
6
6
  }
7
7
  export declare function isPermanentError(err: unknown): boolean;
8
+ /** Whether to poll again after `status`: until it's terminal, then once more after a success when
9
+ * `txHash` is set, as RAVN's node may be a block behind yours on that fee tx and a success it
10
+ * answers before seeing it books no fee. */
11
+ export declare function pollAgain(status: SettlementStatus, txHash: string | undefined, rechecked: boolean): boolean;
8
12
  /**
9
- * Polls GET /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
13
+ * Polls /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
10
14
  * counts as terminal, it means the venue has no live tracker and never will for this swap).
11
15
  * Pass `params: null` to not poll at all (e.g. before execution has produced a ref).
16
+ * `txHash`: executeAndTrack's `statusTxHash`, or the fee payment a DEPOSIT's `fee.transaction`
17
+ * asked for (or a two-hop route's hop-1 tx). Without it the swap's status still arrives, but its fee is never proven and nothing is owed.
12
18
  */
13
19
  export declare function useRavnStatus(client: RavnClient, params: {
14
20
  quoteToken: string;
15
21
  ref: string;
22
+ txHash?: string;
16
23
  } | null, intervalMs?: number): UseRavnStatusResult;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPermanentError = isPermanentError;
4
+ exports.pollAgain = pollAgain;
4
5
  exports.useRavnStatus = useRavnStatus;
5
6
  const react_1 = require("react");
6
7
  const sdk_1 = require("@ravnexchange/sdk");
@@ -12,10 +13,18 @@ const PERMANENT_ERROR_CODES = new Set(["UNAUTHORIZED", "INVALID_REQUEST", "QUOTE
12
13
  function isPermanentError(err) {
13
14
  return err instanceof sdk_1.RavnApiError && PERMANENT_ERROR_CODES.has(err.code);
14
15
  }
16
+ /** Whether to poll again after `status`: until it's terminal, then once more after a success when
17
+ * `txHash` is set, as RAVN's node may be a block behind yours on that fee tx and a success it
18
+ * answers before seeing it books no fee. */
19
+ function pollAgain(status, txHash, rechecked) {
20
+ return !(0, polling_1.isPollingTerminal)(status) || (status === "success" && !!txHash && !rechecked);
21
+ }
15
22
  /**
16
- * Polls GET /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
23
+ * Polls /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
17
24
  * counts as terminal, it means the venue has no live tracker and never will for this swap).
18
25
  * Pass `params: null` to not poll at all (e.g. before execution has produced a ref).
26
+ * `txHash`: executeAndTrack's `statusTxHash`, or the fee payment a DEPOSIT's `fee.transaction`
27
+ * asked for (or a two-hop route's hop-1 tx). Without it the swap's status still arrives, but its fee is never proven and nothing is owed.
19
28
  */
20
29
  function useRavnStatus(client, params, intervalMs = 4000) {
21
30
  const [status, setStatus] = (0, react_1.useState)(null);
@@ -27,17 +36,19 @@ function useRavnStatus(client, params, intervalMs = 4000) {
27
36
  return;
28
37
  }
29
38
  let cancelled = false;
39
+ let rechecked = false;
30
40
  let timer;
31
41
  const poll = () => {
32
42
  setIsLoading(true);
33
43
  client
34
- .getStatus(params.quoteToken, params.ref)
44
+ .getStatus(params.quoteToken, params.ref, params.txHash)
35
45
  .then((s) => {
36
46
  if (cancelled)
37
47
  return;
38
48
  setStatus(s);
39
49
  setError(null);
40
- if (!(0, polling_1.isPollingTerminal)(s.status)) {
50
+ if (pollAgain(s.status, params.txHash, rechecked)) {
51
+ rechecked || (rechecked = (0, polling_1.isPollingTerminal)(s.status));
41
52
  timer = setTimeout(poll, intervalMs);
42
53
  }
43
54
  })
@@ -64,6 +75,6 @@ function useRavnStatus(client, params, intervalMs = 4000) {
64
75
  if (timer)
65
76
  clearTimeout(timer);
66
77
  };
67
- }, [client, params?.quoteToken, params?.ref, intervalMs]);
78
+ }, [client, params?.quoteToken, params?.ref, params?.txHash, intervalMs]);
68
79
  return { status, isLoading, error };
69
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ravnexchange/react",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "React hooks for @ravnexchange/sdk: quote/execute/status state management. Bring your own wallet.",
5
5
  "keywords": ["ravn", "cross-chain", "swap", "swap-api", "dex-aggregator", "bitcoin", "native-btc", "solana", "evm", "crypto", "defi", "react", "react-hooks", "typescript"],
6
6
  "main": "./dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "build": "tsc -p tsconfig.build.json"
15
15
  },
16
16
  "peerDependencies": {
17
- "@ravnexchange/sdk": "*",
17
+ "@ravnexchange/sdk": ">=0.1.13",
18
18
  "react": ">=18"
19
19
  },
20
20
  "devDependencies": {