@medialane/ui 0.154.0 → 0.156.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/components/fast-mint/fast-mint.cjs +4 -4
- package/dist/components/fast-mint/fast-mint.cjs.map +1 -1
- package/dist/components/fast-mint/fast-mint.d.cts +2 -2
- package/dist/components/fast-mint/fast-mint.d.ts +2 -2
- package/dist/components/fast-mint/fast-mint.js +4 -4
- package/dist/components/fast-mint/fast-mint.js.map +1 -1
- package/dist/data/drop-create-schema.d.cts +8 -8
- package/dist/data/drop-create-schema.d.ts +8 -8
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/ipfs-upload.cjs +46 -19
- package/dist/utils/ipfs-upload.cjs.map +1 -1
- package/dist/utils/ipfs-upload.d.cts +21 -3
- package/dist/utils/ipfs-upload.d.ts +21 -3
- package/dist/utils/ipfs-upload.js +44 -19
- package/dist/utils/ipfs-upload.js.map +1 -1
- package/dist/utils/sync-transaction.cjs +61 -0
- package/dist/utils/sync-transaction.cjs.map +1 -0
- package/dist/utils/sync-transaction.d.cts +8 -0
- package/dist/utils/sync-transaction.d.ts +8 -0
- package/dist/utils/sync-transaction.js +37 -0
- package/dist/utils/sync-transaction.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import { BuildAssetMetadataInput } from '@medialane/sdk';
|
|
2
|
+
|
|
1
3
|
interface UploadedIpfsFile {
|
|
2
4
|
cid: string;
|
|
3
5
|
uri: string;
|
|
4
6
|
}
|
|
5
|
-
|
|
6
|
-
declare function
|
|
7
|
+
type SignedUploadKind = "image" | "document" | "media";
|
|
8
|
+
declare function uploadFileToIpfs(file: File, kind?: SignedUploadKind): Promise<UploadedIpfsFile>;
|
|
9
|
+
declare function uploadJsonToIpfs(payload: unknown): Promise<string>;
|
|
10
|
+
declare function uploadDirectoryToIpfs(files: {
|
|
11
|
+
name: string;
|
|
12
|
+
content: unknown;
|
|
13
|
+
}[]): Promise<{
|
|
14
|
+
cid: string;
|
|
15
|
+
baseUri: string;
|
|
16
|
+
}>;
|
|
7
17
|
declare function isUserRejection(err: unknown): boolean;
|
|
8
18
|
declare function uploadFailureToast(err: unknown): {
|
|
9
19
|
title: string;
|
|
10
20
|
description?: string;
|
|
11
21
|
};
|
|
22
|
+
interface PinAssetMetadataInput extends Omit<BuildAssetMetadataInput, "registrationDate"> {
|
|
23
|
+
imageFile?: File | null;
|
|
24
|
+
}
|
|
25
|
+
interface PinnedAsset {
|
|
26
|
+
uri: string;
|
|
27
|
+
imageUri: string | null;
|
|
28
|
+
}
|
|
29
|
+
declare function pinAssetMetadata(input: PinAssetMetadataInput): Promise<PinnedAsset>;
|
|
12
30
|
|
|
13
|
-
export { type UploadedIpfsFile, isUserRejection, uploadFailureToast, uploadFileToIpfs, uploadJsonToIpfs };
|
|
31
|
+
export { type PinAssetMetadataInput, type PinnedAsset, type SignedUploadKind, type UploadedIpfsFile, isUserRejection, pinAssetMetadata, uploadDirectoryToIpfs, uploadFailureToast, uploadFileToIpfs, uploadJsonToIpfs };
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
async function uploadFileToIpfs(file, token, kind = "image") {
|
|
5
|
-
const signedRes = await fetch("/api/pinata/signed-url", {
|
|
6
|
-
method: "POST",
|
|
7
|
-
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
8
|
-
body: JSON.stringify({ kind })
|
|
9
|
-
});
|
|
1
|
+
import { buildAssetMetadata } from "@medialane/sdk";
|
|
2
|
+
async function uploadFileToIpfs(file, kind = "image") {
|
|
3
|
+
const signedRes = await fetch(`/api/proxy/v1/metadata/signed-url?kind=${kind}`);
|
|
10
4
|
const signed = await signedRes.json().catch(() => ({}));
|
|
11
|
-
|
|
5
|
+
const signedUrl = signed.data?.url;
|
|
6
|
+
if (!signedRes.ok || !signedUrl) {
|
|
12
7
|
throw new Error(signed.error ?? "Failed to prepare the upload");
|
|
13
8
|
}
|
|
14
9
|
const formData = new FormData();
|
|
15
10
|
formData.append("file", file, file.name);
|
|
16
11
|
formData.append("network", "public");
|
|
17
12
|
formData.append("name", file.name);
|
|
18
|
-
const uploadRes = await fetch(
|
|
13
|
+
const uploadRes = await fetch(signedUrl, { method: "POST", body: formData });
|
|
19
14
|
const uploadJson = await uploadRes.json().catch(() => ({}));
|
|
20
15
|
const cid = uploadJson.data?.cid;
|
|
21
16
|
if (!uploadRes.ok || !cid) {
|
|
@@ -23,17 +18,30 @@ async function uploadFileToIpfs(file, token, kind = "image") {
|
|
|
23
18
|
}
|
|
24
19
|
return { cid, uri: `ipfs://${cid}` };
|
|
25
20
|
}
|
|
26
|
-
async function uploadJsonToIpfs(payload
|
|
27
|
-
const res = await fetch("/api/
|
|
21
|
+
async function uploadJsonToIpfs(payload) {
|
|
22
|
+
const res = await fetch("/api/proxy/v1/metadata/upload", {
|
|
28
23
|
method: "POST",
|
|
29
|
-
headers: { "Content-Type": "application/json"
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
30
25
|
body: JSON.stringify(payload)
|
|
31
26
|
});
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const body = await res.json().catch(() => ({}));
|
|
28
|
+
const uri = body.data?.url;
|
|
29
|
+
if (!res.ok || !uri) {
|
|
30
|
+
throw new Error(body.error ?? "Metadata upload failed");
|
|
35
31
|
}
|
|
36
|
-
return
|
|
32
|
+
return uri;
|
|
33
|
+
}
|
|
34
|
+
async function uploadDirectoryToIpfs(files) {
|
|
35
|
+
const res = await fetch("/api/proxy/v1/metadata/upload-directory", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ files })
|
|
39
|
+
});
|
|
40
|
+
const body = await res.json().catch(() => ({}));
|
|
41
|
+
if (!res.ok || !body.data?.baseUri || !body.data.cid) {
|
|
42
|
+
throw new Error(body.error ?? "Directory pin failed");
|
|
43
|
+
}
|
|
44
|
+
return { cid: body.data.cid, baseUri: body.data.baseUri };
|
|
37
45
|
}
|
|
38
46
|
function isUserRejection(err) {
|
|
39
47
|
const msg = err instanceof Error ? err.message : String(err ?? "");
|
|
@@ -43,7 +51,7 @@ function uploadFailureToast(err) {
|
|
|
43
51
|
if (isUserRejection(err)) {
|
|
44
52
|
return {
|
|
45
53
|
title: "Signature declined",
|
|
46
|
-
description: "
|
|
54
|
+
description: "Try again and approve the request in your wallet."
|
|
47
55
|
};
|
|
48
56
|
}
|
|
49
57
|
return {
|
|
@@ -51,8 +59,25 @@ function uploadFailureToast(err) {
|
|
|
51
59
|
description: err instanceof Error ? err.message : void 0
|
|
52
60
|
};
|
|
53
61
|
}
|
|
62
|
+
async function pinAssetMetadata(input) {
|
|
63
|
+
const { imageFile, ...fields } = input;
|
|
64
|
+
let imageUri = fields.imageUri ?? null;
|
|
65
|
+
if (!imageUri && imageFile && imageFile.size > 0) {
|
|
66
|
+
imageUri = (await uploadFileToIpfs(imageFile)).uri;
|
|
67
|
+
}
|
|
68
|
+
const uri = await uploadJsonToIpfs(
|
|
69
|
+
buildAssetMetadata({
|
|
70
|
+
...fields,
|
|
71
|
+
imageUri,
|
|
72
|
+
externalUrl: fields.externalUrl || "https://medialane.io"
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
return { uri, imageUri };
|
|
76
|
+
}
|
|
54
77
|
export {
|
|
55
78
|
isUserRejection,
|
|
79
|
+
pinAssetMetadata,
|
|
80
|
+
uploadDirectoryToIpfs,
|
|
56
81
|
uploadFailureToast,
|
|
57
82
|
uploadFileToIpfs,
|
|
58
83
|
uploadJsonToIpfs
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/ipfs-upload.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/ipfs-upload.ts"],"sourcesContent":["import { buildAssetMetadata, type BuildAssetMetadataInput } from \"@medialane/sdk\";\n\nexport interface UploadedIpfsFile {\n cid: string;\n uri: string;\n}\n\nexport type SignedUploadKind = \"image\" | \"document\" | \"media\";\n\nexport async function uploadFileToIpfs(\n file: File,\n kind: SignedUploadKind = \"image\",\n): Promise<UploadedIpfsFile> {\n const signedRes = await fetch(`/api/proxy/v1/metadata/signed-url?kind=${kind}`);\n const signed = (await signedRes.json().catch(() => ({}))) as {\n data?: { url?: string };\n error?: string;\n };\n const signedUrl = signed.data?.url;\n if (!signedRes.ok || !signedUrl) {\n throw new Error(signed.error ?? \"Failed to prepare the upload\");\n }\n\n const formData = new FormData();\n formData.append(\"file\", file, file.name);\n formData.append(\"network\", \"public\");\n formData.append(\"name\", file.name);\n\n const uploadRes = await fetch(signedUrl, { method: \"POST\", body: formData });\n const uploadJson = (await uploadRes.json().catch(() => ({}))) as { data?: { cid?: string } };\n const cid = uploadJson.data?.cid;\n if (!uploadRes.ok || !cid) {\n throw new Error(\"Upload to IPFS failed\");\n }\n\n return { cid, uri: `ipfs://${cid}` };\n}\n\nexport async function uploadJsonToIpfs(payload: unknown): Promise<string> {\n const res = await fetch(\"/api/proxy/v1/metadata/upload\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(payload),\n });\n const body = (await res.json().catch(() => ({}))) as {\n data?: { url?: string };\n error?: string;\n };\n const uri = body.data?.url;\n if (!res.ok || !uri) {\n throw new Error(body.error ?? \"Metadata upload failed\");\n }\n\n return uri;\n}\n\nexport async function uploadDirectoryToIpfs(\n files: { name: string; content: unknown }[],\n): Promise<{ cid: string; baseUri: string }> {\n const res = await fetch(\"/api/proxy/v1/metadata/upload-directory\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ files }),\n });\n const body = (await res.json().catch(() => ({}))) as {\n data?: { cid?: string; baseUri?: string };\n error?: string;\n };\n if (!res.ok || !body.data?.baseUri || !body.data.cid) {\n throw new Error(body.error ?? \"Directory pin failed\");\n }\n return { cid: body.data.cid, baseUri: body.data.baseUri };\n}\n\nexport function isUserRejection(err: unknown): boolean {\n const msg = err instanceof Error ? err.message : String(err ?? \"\");\n return /reject|denied|declin|abort|cancel|refus/i.test(msg);\n}\n\nexport function uploadFailureToast(err: unknown): { title: string; description?: string } {\n if (isUserRejection(err)) {\n return {\n title: \"Signature declined\",\n description: \"Try again and approve the request in your wallet.\",\n };\n }\n return {\n title: \"Upload failed\",\n description: err instanceof Error ? err.message : undefined,\n };\n}\n\nexport interface PinAssetMetadataInput extends Omit<BuildAssetMetadataInput, \"registrationDate\"> {\n imageFile?: File | null;\n}\n\nexport interface PinnedAsset {\n uri: string;\n imageUri: string | null;\n}\n\nexport async function pinAssetMetadata(input: PinAssetMetadataInput): Promise<PinnedAsset> {\n const { imageFile, ...fields } = input;\n\n let imageUri = fields.imageUri ?? null;\n if (!imageUri && imageFile && imageFile.size > 0) {\n imageUri = (await uploadFileToIpfs(imageFile)).uri;\n }\n\n const uri = await uploadJsonToIpfs(\n buildAssetMetadata({\n ...fields,\n imageUri,\n externalUrl: fields.externalUrl || \"https://medialane.io\",\n }),\n );\n\n return { uri, imageUri };\n}\n"],"mappings":"AAAA,SAAS,0BAAwD;AASjE,eAAsB,iBACpB,MACA,OAAyB,SACE;AAC3B,QAAM,YAAY,MAAM,MAAM,0CAA0C,IAAI,EAAE;AAC9E,QAAM,SAAU,MAAM,UAAU,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AAIvD,QAAM,YAAY,OAAO,MAAM;AAC/B,MAAI,CAAC,UAAU,MAAM,CAAC,WAAW;AAC/B,UAAM,IAAI,MAAM,OAAO,SAAS,8BAA8B;AAAA,EAChE;AAEA,QAAM,WAAW,IAAI,SAAS;AAC9B,WAAS,OAAO,QAAQ,MAAM,KAAK,IAAI;AACvC,WAAS,OAAO,WAAW,QAAQ;AACnC,WAAS,OAAO,QAAQ,KAAK,IAAI;AAEjC,QAAM,YAAY,MAAM,MAAM,WAAW,EAAE,QAAQ,QAAQ,MAAM,SAAS,CAAC;AAC3E,QAAM,aAAc,MAAM,UAAU,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AAC3D,QAAM,MAAM,WAAW,MAAM;AAC7B,MAAI,CAAC,UAAU,MAAM,CAAC,KAAK;AACzB,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACzC;AAEA,SAAO,EAAE,KAAK,KAAK,UAAU,GAAG,GAAG;AACrC;AAEA,eAAsB,iBAAiB,SAAmC;AACxE,QAAM,MAAM,MAAM,MAAM,iCAAiC;AAAA,IACvD,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU,OAAO;AAAA,EAC9B,CAAC;AACD,QAAM,OAAQ,MAAM,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AAI/C,QAAM,MAAM,KAAK,MAAM;AACvB,MAAI,CAAC,IAAI,MAAM,CAAC,KAAK;AACnB,UAAM,IAAI,MAAM,KAAK,SAAS,wBAAwB;AAAA,EACxD;AAEA,SAAO;AACT;AAEA,eAAsB,sBACpB,OAC2C;AAC3C,QAAM,MAAM,MAAM,MAAM,2CAA2C;AAAA,IACjE,QAAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU,EAAE,MAAM,CAAC;AAAA,EAChC,CAAC;AACD,QAAM,OAAQ,MAAM,IAAI,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AAI/C,MAAI,CAAC,IAAI,MAAM,CAAC,KAAK,MAAM,WAAW,CAAC,KAAK,KAAK,KAAK;AACpD,UAAM,IAAI,MAAM,KAAK,SAAS,sBAAsB;AAAA,EACtD;AACA,SAAO,EAAE,KAAK,KAAK,KAAK,KAAK,SAAS,KAAK,KAAK,QAAQ;AAC1D;AAEO,SAAS,gBAAgB,KAAuB;AACrD,QAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,OAAO,EAAE;AACjE,SAAO,2CAA2C,KAAK,GAAG;AAC5D;AAEO,SAAS,mBAAmB,KAAuD;AACxF,MAAI,gBAAgB,GAAG,GAAG;AACxB,WAAO;AAAA,MACL,OAAO;AAAA,MACP,aAAa;AAAA,IACf;AAAA,EACF;AACA,SAAO;AAAA,IACL,OAAO;AAAA,IACP,aAAa,eAAe,QAAQ,IAAI,UAAU;AAAA,EACpD;AACF;AAWA,eAAsB,iBAAiB,OAAoD;AACzF,QAAM,EAAE,WAAW,GAAG,OAAO,IAAI;AAEjC,MAAI,WAAW,OAAO,YAAY;AAClC,MAAI,CAAC,YAAY,aAAa,UAAU,OAAO,GAAG;AAChD,gBAAY,MAAM,iBAAiB,SAAS,GAAG;AAAA,EACjD;AAEA,QAAM,MAAM,MAAM;AAAA,IAChB,mBAAmB;AAAA,MACjB,GAAG;AAAA,MACH;AAAA,MACA,aAAa,OAAO,eAAe;AAAA,IACrC,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,KAAK,SAAS;AACzB;","names":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var sync_transaction_exports = {};
|
|
21
|
+
__export(sync_transaction_exports, {
|
|
22
|
+
syncTransaction: () => syncTransaction
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sync_transaction_exports);
|
|
25
|
+
const SYNC_PATH = "/api/proxy/v1/tx/sync";
|
|
26
|
+
const DEFAULT_TIMEOUT_MS = 6e3;
|
|
27
|
+
async function syncTransaction(txHash, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
let timer;
|
|
30
|
+
const timeout = new Promise((resolve) => {
|
|
31
|
+
timer = setTimeout(() => {
|
|
32
|
+
controller.abort();
|
|
33
|
+
resolve(null);
|
|
34
|
+
}, timeoutMs);
|
|
35
|
+
});
|
|
36
|
+
const request = (async () => {
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(SYNC_PATH, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "Content-Type": "application/json" },
|
|
41
|
+
body: JSON.stringify({ txHash }),
|
|
42
|
+
signal: controller.signal
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok) return null;
|
|
45
|
+
const body = await res.json().catch(() => null);
|
|
46
|
+
return body?.data ?? null;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
try {
|
|
52
|
+
return await Promise.race([request, timeout]);
|
|
53
|
+
} finally {
|
|
54
|
+
if (timer) clearTimeout(timer);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
syncTransaction
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=sync-transaction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sync-transaction.ts"],"sourcesContent":["\"use client\";\n\nconst SYNC_PATH = \"/api/proxy/v1/tx/sync\";\nconst DEFAULT_TIMEOUT_MS = 6000;\n\nexport interface SyncTransactionResult {\n applied: number;\n contracts: string[];\n pending: boolean;\n}\n\nexport async function syncTransaction(\n txHash: string,\n timeoutMs = DEFAULT_TIMEOUT_MS,\n): Promise<SyncTransactionResult | null> {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const timeout = new Promise<null>((resolve) => {\n timer = setTimeout(() => {\n controller.abort();\n resolve(null);\n }, timeoutMs);\n });\n\n const request = (async (): Promise<SyncTransactionResult | null> => {\n try {\n const res = await fetch(SYNC_PATH, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ txHash }),\n signal: controller.signal,\n });\n if (!res.ok) return null;\n const body = (await res.json().catch(() => null)) as { data?: SyncTransactionResult } | null;\n return body?.data ?? null;\n } catch {\n return null;\n }\n })();\n\n try {\n return await Promise.race([request, timeout]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,MAAM,YAAY;AAClB,MAAM,qBAAqB;AAQ3B,eAAsB,gBACpB,QACA,YAAY,oBAC2B;AACvC,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI;AAEJ,QAAM,UAAU,IAAI,QAAc,CAAC,YAAY;AAC7C,YAAQ,WAAW,MAAM;AACvB,iBAAW,MAAM;AACjB,cAAQ,IAAI;AAAA,IACd,GAAG,SAAS;AAAA,EACd,CAAC;AAED,QAAM,WAAW,YAAmD;AAClE,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,WAAW;AAAA,QACjC,QAAQ;AAAA,QACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAC9C,MAAM,KAAK,UAAU,EAAE,OAAO,CAAC;AAAA,QAC/B,QAAQ,WAAW;AAAA,MACrB,CAAC;AACD,UAAI,CAAC,IAAI,GAAI,QAAO;AACpB,YAAM,OAAQ,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI;AAC/C,aAAO,MAAM,QAAQ;AAAA,IACvB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AAEH,MAAI;AACF,WAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,OAAO,CAAC;AAAA,EAC9C,UAAE;AACA,QAAI,MAAO,cAAa,KAAK;AAAA,EAC/B;AACF;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface SyncTransactionResult {
|
|
2
|
+
applied: number;
|
|
3
|
+
contracts: string[];
|
|
4
|
+
pending: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function syncTransaction(txHash: string, timeoutMs?: number): Promise<SyncTransactionResult | null>;
|
|
7
|
+
|
|
8
|
+
export { type SyncTransactionResult, syncTransaction };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface SyncTransactionResult {
|
|
2
|
+
applied: number;
|
|
3
|
+
contracts: string[];
|
|
4
|
+
pending: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function syncTransaction(txHash: string, timeoutMs?: number): Promise<SyncTransactionResult | null>;
|
|
7
|
+
|
|
8
|
+
export { type SyncTransactionResult, syncTransaction };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const SYNC_PATH = "/api/proxy/v1/tx/sync";
|
|
3
|
+
const DEFAULT_TIMEOUT_MS = 6e3;
|
|
4
|
+
async function syncTransaction(txHash, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
5
|
+
const controller = new AbortController();
|
|
6
|
+
let timer;
|
|
7
|
+
const timeout = new Promise((resolve) => {
|
|
8
|
+
timer = setTimeout(() => {
|
|
9
|
+
controller.abort();
|
|
10
|
+
resolve(null);
|
|
11
|
+
}, timeoutMs);
|
|
12
|
+
});
|
|
13
|
+
const request = (async () => {
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch(SYNC_PATH, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { "Content-Type": "application/json" },
|
|
18
|
+
body: JSON.stringify({ txHash }),
|
|
19
|
+
signal: controller.signal
|
|
20
|
+
});
|
|
21
|
+
if (!res.ok) return null;
|
|
22
|
+
const body = await res.json().catch(() => null);
|
|
23
|
+
return body?.data ?? null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
try {
|
|
29
|
+
return await Promise.race([request, timeout]);
|
|
30
|
+
} finally {
|
|
31
|
+
if (timer) clearTimeout(timer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
syncTransaction
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=sync-transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/sync-transaction.ts"],"sourcesContent":["\"use client\";\n\nconst SYNC_PATH = \"/api/proxy/v1/tx/sync\";\nconst DEFAULT_TIMEOUT_MS = 6000;\n\nexport interface SyncTransactionResult {\n applied: number;\n contracts: string[];\n pending: boolean;\n}\n\nexport async function syncTransaction(\n txHash: string,\n timeoutMs = DEFAULT_TIMEOUT_MS,\n): Promise<SyncTransactionResult | null> {\n const controller = new AbortController();\n let timer: ReturnType<typeof setTimeout> | undefined;\n\n const timeout = new Promise<null>((resolve) => {\n timer = setTimeout(() => {\n controller.abort();\n resolve(null);\n }, timeoutMs);\n });\n\n const request = (async (): Promise<SyncTransactionResult | null> => {\n try {\n const res = await fetch(SYNC_PATH, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ txHash }),\n signal: controller.signal,\n });\n if (!res.ok) return null;\n const body = (await res.json().catch(() => null)) as { data?: SyncTransactionResult } | null;\n return body?.data ?? null;\n } catch {\n return null;\n }\n })();\n\n try {\n return await Promise.race([request, timeout]);\n } finally {\n if (timer) clearTimeout(timer);\n }\n}\n"],"mappings":";AAEA,MAAM,YAAY;AAClB,MAAM,qBAAqB;AAQ3B,eAAsB,gBACpB,QACA,YAAY,oBAC2B;AACvC,QAAM,aAAa,IAAI,gBAAgB;AACvC,MAAI;AAEJ,QAAM,UAAU,IAAI,QAAc,CAAC,YAAY;AAC7C,YAAQ,WAAW,MAAM;AACvB,iBAAW,MAAM;AACjB,cAAQ,IAAI;AAAA,IACd,GAAG,SAAS;AAAA,EACd,CAAC;AAED,QAAM,WAAW,YAAmD;AAClE,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,WAAW;AAAA,QACjC,QAAQ;AAAA,QACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,QAC9C,MAAM,KAAK,UAAU,EAAE,OAAO,CAAC;AAAA,QAC/B,QAAQ,WAAW;AAAA,MACrB,CAAC;AACD,UAAI,CAAC,IAAI,GAAI,QAAO;AACpB,YAAM,OAAQ,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI;AAC/C,aAAO,MAAM,QAAQ;AAAA,IACvB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AAEH,MAAI;AACF,WAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,OAAO,CAAC;AAAA,EAC9C,UAAE;AACA,QAAI,MAAO,cAAa,KAAK;AAAA,EAC/B;AACF;","names":[]}
|