Skip to content

Commit a7c701f

Browse files
committed
fix: fetch fees even if milestones endpoint missing
1 parent 1bed594 commit a7c701f

1 file changed

Lines changed: 87 additions & 80 deletions

File tree

app/ClientPage.tsx

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -772,63 +772,20 @@ export default function ClientPage() {
772772
}
773773
}
774774

775+
// Admin/config reads should not be all-or-nothing. Older contracts might not
776+
// expose every endpoint; prices should still load when possible.
775777
try {
776-
const [
777-
milestonesCV,
778-
infernoFeeCV,
779-
infernoUriCV,
780-
stormFeeCV,
781-
stormUriCV,
782-
] = await Promise.all([
783-
fetchCallReadOnlyFunction({
784-
contractAddress: CONTRACT_ADDRESS,
785-
contractName: CONTRACT_NAME,
786-
functionName: "get-milestones",
787-
functionArgs: [],
788-
network: STACKS_NETWORK_OBJ,
789-
client: { baseUrl: stacksApiBase },
790-
senderAddress: caller,
791-
}),
792-
fetchCallReadOnlyFunction({
793-
contractAddress: CONTRACT_ADDRESS,
794-
contractName: CONTRACT_NAME,
795-
functionName: "get-mint-fee-kind",
796-
functionArgs: [uintCV(INFERNO_PULSE.kind)],
797-
network: STACKS_NETWORK_OBJ,
798-
client: { baseUrl: stacksApiBase },
799-
senderAddress: caller,
800-
}),
801-
fetchCallReadOnlyFunction({
802-
contractAddress: CONTRACT_ADDRESS,
803-
contractName: CONTRACT_NAME,
804-
functionName: "get-badge-uri",
805-
functionArgs: [uintCV(INFERNO_PULSE.kind)],
806-
network: STACKS_NETWORK_OBJ,
807-
client: { baseUrl: stacksApiBase },
808-
senderAddress: caller,
809-
}),
810-
fetchCallReadOnlyFunction({
811-
contractAddress: CONTRACT_ADDRESS,
812-
contractName: CONTRACT_NAME,
813-
functionName: "get-mint-fee-kind",
814-
functionArgs: [uintCV(STORM_ASSASIN.kind)],
815-
network: STACKS_NETWORK_OBJ,
816-
client: { baseUrl: stacksApiBase },
817-
senderAddress: caller,
818-
}),
819-
fetchCallReadOnlyFunction({
820-
contractAddress: CONTRACT_ADDRESS,
821-
contractName: CONTRACT_NAME,
822-
functionName: "get-badge-uri",
823-
functionArgs: [uintCV(STORM_ASSASIN.kind)],
824-
network: STACKS_NETWORK_OBJ,
825-
client: { baseUrl: stacksApiBase },
826-
senderAddress: caller,
827-
}),
828-
]);
778+
const milestonesCV = await fetchCallReadOnlyFunction({
779+
contractAddress: CONTRACT_ADDRESS,
780+
contractName: CONTRACT_NAME,
781+
functionName: "get-milestones",
782+
functionArgs: [],
783+
network: STACKS_NETWORK_OBJ,
784+
client: { baseUrl: stacksApiBase },
785+
senderAddress: caller,
786+
});
829787

830788
const ms = cvToValue(milestonesCV) as unknown;
831-
832789
if (Array.isArray(ms)) {
833790
const parsed = ms
834791
.map((v) => (typeof v === "bigint" ? Number(v) : Number(v)))
@@ -838,7 +795,20 @@ export default function ClientPage() {
838795
} else {
839796
setMilestones(null);
840797
}
798+
} catch {
799+
setMilestones(null);
800+
}
841801

802+
try {
803+
const infernoFeeCV = await fetchCallReadOnlyFunction({
804+
contractAddress: CONTRACT_ADDRESS,
805+
contractName: CONTRACT_NAME,
806+
functionName: "get-mint-fee-kind",
807+
functionArgs: [uintCV(INFERNO_PULSE.kind)],
808+
network: STACKS_NETWORK_OBJ,
809+
client: { baseUrl: stacksApiBase },
810+
senderAddress: caller,
811+
});
842812
const feeUnwrapped = unwrapCvToValue(cvToValue(infernoFeeCV) as unknown);
843813
const fee =
844814
feeUnwrapped === null
@@ -849,10 +819,36 @@ export default function ClientPage() {
849819
? feeUnwrapped
850820
: null;
851821
setInfernoFeeUstx(fee);
822+
} catch {
823+
setInfernoFeeUstx(null);
824+
}
852825

826+
try {
827+
const infernoUriCV = await fetchCallReadOnlyFunction({
828+
contractAddress: CONTRACT_ADDRESS,
829+
contractName: CONTRACT_NAME,
830+
functionName: "get-badge-uri",
831+
functionArgs: [uintCV(INFERNO_PULSE.kind)],
832+
network: STACKS_NETWORK_OBJ,
833+
client: { baseUrl: stacksApiBase },
834+
senderAddress: caller,
835+
});
853836
const uriUnwrapped = unwrapCvToValue(cvToValue(infernoUriCV) as unknown);
854837
setInfernoUri(typeof uriUnwrapped === "string" ? uriUnwrapped : null);
838+
} catch {
839+
setInfernoUri(null);
840+
}
855841

842+
try {
843+
const stormFeeCV = await fetchCallReadOnlyFunction({
844+
contractAddress: CONTRACT_ADDRESS,
845+
contractName: CONTRACT_NAME,
846+
functionName: "get-mint-fee-kind",
847+
functionArgs: [uintCV(STORM_ASSASIN.kind)],
848+
network: STACKS_NETWORK_OBJ,
849+
client: { baseUrl: stacksApiBase },
850+
senderAddress: caller,
851+
});
856852
const stormFeeUnwrapped = unwrapCvToValue(cvToValue(stormFeeCV) as unknown);
857853
const stormFee =
858854
stormFeeUnwrapped === null
@@ -863,37 +859,48 @@ export default function ClientPage() {
863859
? stormFeeUnwrapped
864860
: null;
865861
setStormFeeUstx(stormFee);
862+
} catch {
863+
setStormFeeUstx(null);
864+
}
866865

866+
try {
867+
const stormUriCV = await fetchCallReadOnlyFunction({
868+
contractAddress: CONTRACT_ADDRESS,
869+
contractName: CONTRACT_NAME,
870+
functionName: "get-badge-uri",
871+
functionArgs: [uintCV(STORM_ASSASIN.kind)],
872+
network: STACKS_NETWORK_OBJ,
873+
client: { baseUrl: stacksApiBase },
874+
senderAddress: caller,
875+
});
867876
const stormUriUnwrapped = unwrapCvToValue(cvToValue(stormUriCV) as unknown);
868877
setStormUri(typeof stormUriUnwrapped === "string" ? stormUriUnwrapped : null);
878+
} catch {
879+
setStormUri(null);
880+
}
869881

870-
try {
871-
const kindsToLoad = BADGE_MILESTONES.map((m) => m.kind);
872-
const uriPairs = await Promise.all(
873-
kindsToLoad.map(async (kind) => {
874-
const v = await fetchCallReadOnlyFunction({
875-
contractAddress: CONTRACT_ADDRESS,
876-
contractName: CONTRACT_NAME,
877-
functionName: "get-badge-uri",
878-
functionArgs: [uintCV(kind)],
879-
network: STACKS_NETWORK_OBJ,
880-
client: { baseUrl: stacksApiBase },
881-
senderAddress: caller,
882-
});
883-
const u = unwrapCvToValue(cvToValue(v) as unknown);
884-
return [kind, typeof u === "string" ? u : null] as const;
885-
})
886-
);
887-
const nextMap: Record<number, string | null> = {};
888-
for (const [k, u] of uriPairs) nextMap[k] = u;
889-
setBadgeUris(nextMap);
890-
} catch {
891-
// ignore
892-
}
893-
882+
try {
883+
const kindsToLoad = BADGE_MILESTONES.map((m) => m.kind);
884+
const uriPairs = await Promise.all(
885+
kindsToLoad.map(async (kind) => {
886+
const v = await fetchCallReadOnlyFunction({
887+
contractAddress: CONTRACT_ADDRESS,
888+
contractName: CONTRACT_NAME,
889+
functionName: "get-badge-uri",
890+
functionArgs: [uintCV(kind)],
891+
network: STACKS_NETWORK_OBJ,
892+
client: { baseUrl: stacksApiBase },
893+
senderAddress: caller,
894+
});
895+
const u = unwrapCvToValue(cvToValue(v) as unknown);
896+
return [kind, typeof u === "string" ? u : null] as const;
897+
})
898+
);
899+
const nextMap: Record<number, string | null> = {};
900+
for (const [k, u] of uriPairs) nextMap[k] = u;
901+
setBadgeUris(nextMap);
894902
} catch {
895-
// Older contracts might not expose these admin read-only endpoints.
896-
setMilestones(null);
903+
// ignore
897904
}
898905

899906
const ownedSender = senderOverride || address;

0 commit comments

Comments
 (0)