@ravnexchange/react 0.1.6 → 0.1.8

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.
@@ -9,9 +9,15 @@ export declare function isPermanentError(err: unknown): boolean;
9
9
  * `txHash` is set, as RAVN's node may be a block behind yours on that fee tx and a success it
10
10
  * answers before seeing it books no fee. */
11
11
  export declare function pollAgain(status: SettlementStatus, txHash: string | undefined, rechecked: boolean): boolean;
12
+ /** How long to wait before the next poll after `status`: an expired swap's refund can take hours
13
+ * (Across: a later settlement bundle), so it's asked about once a minute, not every few seconds. */
14
+ export declare function nextPollMs(status: SettlementStatus, intervalMs: number): number;
12
15
  /**
13
16
  * Polls /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
14
- * counts as terminal, it means the venue has no live tracker and never will for this swap).
17
+ * counts as terminal, it means the venue has no live tracker and never will for this swap;
18
+ * "expired" doesn't, a refund is due, and is polled once a minute until it lands; nor does
19
+ * "not_found", the venue has no record of this swap: brief right after sending, otherwise it
20
+ * stays so while mounted).
15
21
  * Pass `params: null` to not poll at all (e.g. before execution has produced a ref).
16
22
  * `txHash`: executeAndTrack's `statusTxHash`, or the fee payment a DEPOSIT's `fee.transaction`
17
23
  * 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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPermanentError = isPermanentError;
4
4
  exports.pollAgain = pollAgain;
5
+ exports.nextPollMs = nextPollMs;
5
6
  exports.useRavnStatus = useRavnStatus;
6
7
  const react_1 = require("react");
7
8
  const sdk_1 = require("@ravnexchange/sdk");
@@ -9,7 +10,7 @@ const polling_1 = require("./polling");
9
10
  // Codes the API itself defines as request-shaped, not transient: retrying with the exact same
10
11
  // arguments can never turn one of these into success. Anything else (RATE_LIMITED, INTERNAL, a
11
12
  // network failure) is worth retrying through.
12
- const PERMANENT_ERROR_CODES = new Set(["UNAUTHORIZED", "INVALID_REQUEST", "QUOTE_INVALID", "NOT_FOUND"]);
13
+ const PERMANENT_ERROR_CODES = new Set(["UNAUTHORIZED", "FORBIDDEN", "INVALID_REQUEST", "QUOTE_INVALID", "NOT_FOUND"]);
13
14
  function isPermanentError(err) {
14
15
  return err instanceof sdk_1.RavnApiError && PERMANENT_ERROR_CODES.has(err.code);
15
16
  }
@@ -19,9 +20,17 @@ function isPermanentError(err) {
19
20
  function pollAgain(status, txHash, rechecked) {
20
21
  return !(0, polling_1.isPollingTerminal)(status) || (status === "success" && !!txHash && !rechecked);
21
22
  }
23
+ /** How long to wait before the next poll after `status`: an expired swap's refund can take hours
24
+ * (Across: a later settlement bundle), so it's asked about once a minute, not every few seconds. */
25
+ function nextPollMs(status, intervalMs) {
26
+ return status === "expired" ? Math.max(intervalMs, 60000) : intervalMs;
27
+ }
22
28
  /**
23
29
  * Polls /v1/status until it reaches a terminal state (see isPollingTerminal: "unknown"
24
- * counts as terminal, it means the venue has no live tracker and never will for this swap).
30
+ * counts as terminal, it means the venue has no live tracker and never will for this swap;
31
+ * "expired" doesn't, a refund is due, and is polled once a minute until it lands; nor does
32
+ * "not_found", the venue has no record of this swap: brief right after sending, otherwise it
33
+ * stays so while mounted).
25
34
  * Pass `params: null` to not poll at all (e.g. before execution has produced a ref).
26
35
  * `txHash`: executeAndTrack's `statusTxHash`, or the fee payment a DEPOSIT's `fee.transaction`
27
36
  * 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.
@@ -49,7 +58,7 @@ function useRavnStatus(client, params, intervalMs = 4000) {
49
58
  setError(null);
50
59
  if (pollAgain(s.status, params.txHash, rechecked)) {
51
60
  rechecked || (rechecked = (0, polling_1.isPollingTerminal)(s.status));
52
- timer = setTimeout(poll, intervalMs);
61
+ timer = setTimeout(poll, nextPollMs(s.status, intervalMs));
53
62
  }
54
63
  })
55
64
  .catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ravnexchange/react",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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": ">=0.1.13",
17
+ "@ravnexchange/sdk": ">=0.2.0",
18
18
  "react": ">=18"
19
19
  },
20
20
  "devDependencies": {