Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Renamed some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-andysign committed May 7, 2024
1 parent 65f5936 commit d55e64f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions scripts/initialise_demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -215,23 +215,22 @@ async function issueCertificate(
// const bodyStrEmpty = JSON.stringify({})

const hardcodedFactor = (gap) => Math.random() * (gap[1] - gap[0]) + gap[0]

const getHardcodedEco2 = (e) => Math.floor(hardcodedFactor([0.03, 0.11]) * e)
const hardcodedEco2 = (e) => Math.floor(hardcodedFactor([0.03, 0.11]) * e)
// const bodyStrHardCodedFactor = JSON.stringify({
// embodied_co2: getHardcodedEco2(energy_consumed_wh),
// })

const optionsEmptyBody = {
const defaultCertOptions = {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({}),
}

const optionsHardcodedBody = {
const hardcodedCertOptions = {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
embodied_co2: getHardcodedEco2(energy_consumed_wh),
embodied_co2: hardcodedEco2(energy_consumed_wh),
}),
}

Expand All @@ -257,12 +256,12 @@ async function issueCertificate(
return fetch(carbonIntensityApiUrl)
.then(async () => {
// Handle successful response
return issueAndWaitForComplete(optionsEmptyBody) // waitForComplete
return issueAndWaitForComplete(defaultCertOptions)
})
.catch(async () => {
// Handle failure response
console.log('Detected off-line mode when using fetch. Using random vals.')
return issueAndWaitForComplete(optionsHardcodedBody) // waitForComplete
return issueAndWaitForComplete(hardcodedCertOptions)
})
}

Expand Down

0 comments on commit d55e64f

Please sign in to comment.