fix fetch arrr balance

This commit is contained in:
PhilReact 2025-01-09 03:12:59 +02:00
parent 06c68dd8e8
commit cc92b7d9bd

View File

@ -1058,6 +1058,41 @@ export const publishQDNResource = async (
}
};
export const checkArrrSyncStatus = async (seed) => {
const _url = await createEndpoint(`/crosschain/arrr/syncstatus`);
let tries = 0; // Track the number of attempts
while (tries < 36) {
const response = await fetch(_url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: seed,
});
let res;
try {
res = await response.clone().json();
} catch (e) {
res = await response.text();
}
if (res.indexOf('<') > -1 || res !== "Synchronized") {
// Wait 2 seconds before trying again
await new Promise((resolve) => setTimeout(resolve, 2000));
tries += 1;
} else {
// If the response doesn't meet the two conditions, exit the function
return;
}
}
// If we exceed 6 tries, throw an error
throw new Error("Failed to synchronize after 36 attempts");
};
export const publishMultipleQDNResources = async (
data: any,
sender,
@ -1928,6 +1963,7 @@ export const getWalletBalance = async (
_body = parsedData.rvnPublicKey;
break;
case "ARRR":
await checkArrrSyncStatus(parsedData.arrrSeed58)
_url = await createEndpoint(`/crosschain/arrr/walletbalance`);
_body = parsedData.arrrSeed58;
break;
@ -1971,6 +2007,7 @@ const getPirateWallet = async (arrrSeed58)=> {
throw new Error("Retrieving PIRATECHAIN balance is not allowed through a gateway.");
}
const bodyToString = arrrSeed58;
await checkArrrSyncStatus(bodyToString)
const url = await createEndpoint(`/crosschain/arrr/walletaddress`);
const response = await fetch(url, {
method: "POST",