@unlink-xyz/react 0.1.3-canary.d8d7aa3 → 0.1.3-canary.fa60920
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.d.ts +4 -4
- package/dist/index.js +38 -20
- package/dist/index.js.map +1 -1
- package/dist/multisig/index.js +22 -13
- package/dist/multisig/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -462,8 +462,8 @@ declare function useUnlinkBalances(): {
|
|
|
462
462
|
declare function useTxStatus(txId: string | null): UseTxStatusResult;
|
|
463
463
|
|
|
464
464
|
type UseOperationMutationResult<TInput, TOutput> = {
|
|
465
|
-
/** Execute the
|
|
466
|
-
|
|
465
|
+
/** Execute the operation */
|
|
466
|
+
execute: (input: TInput) => Promise<TOutput>;
|
|
467
467
|
/** Last successful result */
|
|
468
468
|
data: TOutput | null;
|
|
469
469
|
/** Whether the mutation is currently running */
|
|
@@ -487,10 +487,10 @@ type UseOperationMutationResult<TInput, TOutput> = {
|
|
|
487
487
|
* ```tsx
|
|
488
488
|
* function DepositButton() {
|
|
489
489
|
* const { requestDeposit } = useUnlink();
|
|
490
|
-
* const {
|
|
490
|
+
* const { execute, isPending, error } = useOperationMutation(requestDeposit);
|
|
491
491
|
*
|
|
492
492
|
* return (
|
|
493
|
-
* <button onClick={() =>
|
|
493
|
+
* <button onClick={() => execute(params)} disabled={isPending}>
|
|
494
494
|
* {isPending ? "Depositing..." : "Deposit"}
|
|
495
495
|
* </button>
|
|
496
496
|
* );
|
package/dist/index.js
CHANGED
|
@@ -35647,29 +35647,41 @@ function createJsonHttpClient(baseUrl, deps) {
|
|
|
35647
35647
|
fetch: fetchImpl,
|
|
35648
35648
|
// Disable ky's automatic error throwing to prevent browser DevTools
|
|
35649
35649
|
// from logging expected 404s as network errors
|
|
35650
|
-
throwHttpErrors: false
|
|
35650
|
+
throwHttpErrors: false,
|
|
35651
|
+
retry: 0
|
|
35651
35652
|
});
|
|
35653
|
+
const RETRYABLE_STATUSES = [502, 503, 504];
|
|
35654
|
+
const MAX_RETRIES = 3;
|
|
35655
|
+
const BASE_DELAY_MS = 500;
|
|
35652
35656
|
return {
|
|
35653
35657
|
async request(opts) {
|
|
35654
35658
|
let res;
|
|
35655
|
-
|
|
35656
|
-
|
|
35657
|
-
|
|
35658
|
-
|
|
35659
|
-
|
|
35660
|
-
|
|
35661
|
-
|
|
35662
|
-
|
|
35663
|
-
|
|
35664
|
-
|
|
35665
|
-
|
|
35666
|
-
|
|
35659
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
35660
|
+
try {
|
|
35661
|
+
res = await api(opts.path.replace(/^\//, ""), {
|
|
35662
|
+
method: opts.method,
|
|
35663
|
+
searchParams: opts.query,
|
|
35664
|
+
json: opts.json,
|
|
35665
|
+
body: opts.body,
|
|
35666
|
+
headers: opts.headers,
|
|
35667
|
+
signal: opts.signal
|
|
35668
|
+
});
|
|
35669
|
+
} catch (err) {
|
|
35670
|
+
if (err instanceof TimeoutError) {
|
|
35671
|
+
throw new HttpError("HTTP timeout", 408, null);
|
|
35672
|
+
}
|
|
35673
|
+
throw new HttpError(
|
|
35674
|
+
err instanceof Error ? err.message : "Network error",
|
|
35675
|
+
0,
|
|
35676
|
+
null
|
|
35677
|
+
);
|
|
35667
35678
|
}
|
|
35668
|
-
|
|
35669
|
-
|
|
35670
|
-
|
|
35671
|
-
|
|
35672
|
-
|
|
35679
|
+
if (RETRYABLE_STATUSES.includes(res.status) && attempt < MAX_RETRIES) {
|
|
35680
|
+
const delay2 = BASE_DELAY_MS * 2 ** attempt + Math.random() * 200;
|
|
35681
|
+
await new Promise((r2) => setTimeout(r2, delay2));
|
|
35682
|
+
continue;
|
|
35683
|
+
}
|
|
35684
|
+
break;
|
|
35673
35685
|
}
|
|
35674
35686
|
if (!res.ok) {
|
|
35675
35687
|
const body = await readErrorBodySafe(res);
|
|
@@ -35919,6 +35931,11 @@ function parseChainConfig(chain2, value) {
|
|
|
35919
35931
|
"artifactVersion",
|
|
35920
35932
|
raw.artifactVersion
|
|
35921
35933
|
).replace(/^\/+|\/+$/g, "");
|
|
35934
|
+
const frostUrl = parseOptionalString(
|
|
35935
|
+
chain2,
|
|
35936
|
+
"frostUrl",
|
|
35937
|
+
raw.frostUrl
|
|
35938
|
+
)?.replace(/\/+$/, "");
|
|
35922
35939
|
const artifactBaseUrl = parseOptionalString(
|
|
35923
35940
|
chain2,
|
|
35924
35941
|
"artifactBaseUrl",
|
|
@@ -35927,6 +35944,7 @@ function parseChainConfig(chain2, value) {
|
|
|
35927
35944
|
return {
|
|
35928
35945
|
chainId,
|
|
35929
35946
|
gatewayUrl,
|
|
35947
|
+
...frostUrl !== void 0 ? { frostUrl } : {},
|
|
35930
35948
|
poolAddress,
|
|
35931
35949
|
artifactVersion,
|
|
35932
35950
|
...artifactBaseUrl !== void 0 ? { artifactBaseUrl } : { artifactBaseUrl: DEFAULT_ARTIFACT_BASE_URL }
|
|
@@ -58182,7 +58200,7 @@ function useOperationMutation(operation) {
|
|
|
58182
58200
|
const [isError2, setIsError] = useState4(false);
|
|
58183
58201
|
const pendingRef = useRef3(false);
|
|
58184
58202
|
const generationRef = useRef3(0);
|
|
58185
|
-
const
|
|
58203
|
+
const execute = useCallback4(
|
|
58186
58204
|
async (input) => {
|
|
58187
58205
|
if (pendingRef.current) {
|
|
58188
58206
|
throw new Error("Operation already in progress");
|
|
@@ -58225,7 +58243,7 @@ function useOperationMutation(operation) {
|
|
|
58225
58243
|
setIsSuccess(false);
|
|
58226
58244
|
setIsError(false);
|
|
58227
58245
|
}, []);
|
|
58228
|
-
return {
|
|
58246
|
+
return { execute, data, isPending, isSuccess, isError: isError2, error, reset };
|
|
58229
58247
|
}
|
|
58230
58248
|
|
|
58231
58249
|
// src/useDeposit.ts
|