Skip to content

Instantly share code, notes, and snippets.

@resilience-me
Last active May 16, 2024 10:49
Show Gist options
  • Save resilience-me/3f44d4b07a87ac9ae50fb4477a7207fe to your computer and use it in GitHub Desktop.
Save resilience-me/3f44d4b07a87ac9ae50fb4477a7207fe to your computer and use it in GitHub Desktop.
async function fetchAccountInfo(address, bitpeople) {
try {
const isMetamask = bitpeople instanceof Bitpeople;
const response = await fetch(apiURL + address);
const data = await response.json();
responseDisplay.style.display = 'block';
if(data.schedule.currentSchedule.quarter < 2) {
handleQuarterOneAndTwo(address, data, isMetamask, bitpeople);
} else if(data.schedule.currentSchedule.quarter == 2) {
handleQuarterThree(address, data, isMetamask, bitpeople);
} else if(data.schedule.currentSchedule.quarter == 3) {
handleQuarterFour(address, data, isMetamask, bitpeople);
}
} catch (error) {
console.error('Error fetching account info:', error);
}
}
function handleQuarterOneAndTwo(address, data, isMetamask, bitpeople) {
}
function handleQuarterThree(address, data, isMetamask, bitpeople) {
if(isCommitSet(data)) {
}
}
function handleQuarterFour(address, data, isMetamask, bitpeople) {
if (helper.isRegistered(data)) {
if(!data.contracts.bitpeople.currentData.account.shuffler) {
responseDisplay.innerHTML += '<p>It is time to shuffle. After you have shuffled, you can contact the person in your pair to agree on a video channel. </p>';
setupShuffleButton();
} else if (helper.isPaired(data)) {
if (isMetamask) {
const baseUrl = "https://chat.blockscan.com/";
const path = "index";
const url = new URL(path, baseUrl);
url.searchParams.append('a', data.contracts.bitpeople.currentData.account.pair.partner);
responseDisplay.innerHTML += '<p>Contact the person in your pair to agree on a video channel: ' + '<a href="' + url.href + '">' + url.href + '</a></p>';
const courtsToJudgeCount = helper.isOptInJudge(data);
if (courtsToJudgeCount > 0) {
let courtDynamicText = 'a "court"';
if (courtsToJudgeCount == 2) {
courtDynamicText = 'two "courts"';
}
responseDisplay.innerHTML += `<p>You have been assigned to judge ${courtDynamicText}. They can contact you on ${baseUrl} too.</p>`;
}
} else {
responseDisplay.innerHTML += '<p>Log in with a wallet to contact the person in the pair</p>';
}
} else if (isMetamask) {
responseDisplay.innerHTML += '<p>You are not paired yet. Wait until shuffling is complete. You can shuffle again to speed things up. </p>';
setupShuffleButton();
}
} else if (helper.isOptIn(data)) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment