Skip to content

Commit 160de4a

Browse files
committed
fix: retry onchain reads and clarify mint config
1 parent 9c4a34a commit 160de4a

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

app/ClientPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ export default function ClientPage() {
12251225
<span>
12261226
{infernoUri
12271227
? "Configured"
1228-
: "Not configured (owner must set the badge URI on-chain)"}
1228+
: "Not loaded / not configured"}
12291229
</span>
12301230
</div>
12311231
{featuredDrops.inferno ? (
@@ -1273,7 +1273,7 @@ export default function ClientPage() {
12731273
<span>
12741274
{stormUri
12751275
? "Configured"
1276-
: "Not configured (owner must set the badge URI on-chain)"}
1276+
: "Not loaded / not configured"}
12771277
</span>
12781278
</div>
12791279
{featuredDrops.storm ? (

functions/api/onchain.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,32 @@ async function callReadOnly(opts: {
129129
functionArgs: ClarityValue[];
130130
senderAddress: string;
131131
}): Promise<unknown> {
132-
const cv = await fetchCallReadOnlyFunction({
133-
contractAddress: opts.contractAddress,
134-
contractName: opts.contractName,
135-
functionName: opts.functionName,
136-
functionArgs: opts.functionArgs,
137-
network: STACKS_NETWORK_OBJ,
138-
client: { baseUrl: STACKS_API_BASE },
139-
senderAddress: opts.senderAddress,
140-
});
141-
return unwrapCvToValue(cvToValue(cv) as unknown);
132+
const tries = 3;
133+
for (let attempt = 1; attempt <= tries; attempt += 1) {
134+
try {
135+
const cv = await fetchCallReadOnlyFunction({
136+
contractAddress: opts.contractAddress,
137+
contractName: opts.contractName,
138+
functionName: opts.functionName,
139+
functionArgs: opts.functionArgs,
140+
network: STACKS_NETWORK_OBJ,
141+
client: { baseUrl: STACKS_API_BASE },
142+
senderAddress: opts.senderAddress,
143+
});
144+
return unwrapCvToValue(cvToValue(cv) as unknown);
145+
} catch (err) {
146+
const message =
147+
err instanceof Error ? err.message : typeof err === "string" ? err : "";
148+
const looksRateLimited =
149+
message.includes("429") ||
150+
message.toLowerCase().includes("too many requests");
151+
152+
if (!looksRateLimited || attempt >= tries) throw err;
153+
await sleep(250 * attempt);
154+
}
155+
}
156+
157+
return null;
142158
}
143159

144160
async function getContractOwner(): Promise<string | null> {

0 commit comments

Comments
 (0)