feat: Added modal and fixed brave wallet errors
All checks were successful
Build Docker / Build Image (push) Successful in 24s
All checks were successful
Build Docker / Build Image (push) Successful in 24s
This commit is contained in:
parent
049141966a
commit
6123c6956c
2
dist/bundle.js
vendored
2
dist/bundle.js
vendored
File diff suppressed because one or more lines are too long
1
main.py
1
main.py
@ -374,7 +374,6 @@ def timeLeft():
|
||||
info = get_vote_info()
|
||||
end = utc_now.strptime(info["end"], "%Y-%m-%d")
|
||||
left = end - utc_now
|
||||
print(left)
|
||||
return left
|
||||
|
||||
def endTime():
|
||||
|
@ -6,8 +6,6 @@ def votes():
|
||||
with open('data/votes.json') as file:
|
||||
votes = json.load(file)
|
||||
|
||||
print(votes)
|
||||
|
||||
options = {}
|
||||
for vote in votes:
|
||||
# Check if message is json
|
||||
|
17
src/index.js
17
src/index.js
@ -133,8 +133,7 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('signMessageForm').addEventListener('submit', async function(event) {
|
||||
event.preventDefault();
|
||||
async function submitVote() {
|
||||
// Get all inputs in #advancedOptions
|
||||
const inputs = document.querySelectorAll('#advancedOptions input');
|
||||
|
||||
@ -164,7 +163,6 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
return;
|
||||
}
|
||||
const vote = JSON.stringify(options);
|
||||
|
||||
// Encode the message as a buffer-like object
|
||||
const messageUint8Array = new TextEncoder().encode(vote);
|
||||
// Request signature from Phantom
|
||||
@ -176,20 +174,21 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
display: "utf8"
|
||||
},
|
||||
});
|
||||
|
||||
const url = 'http://localhost:5000/vote'; // Update the URL as needed
|
||||
|
||||
const sigUint8Array = new Uint8Array(signature);
|
||||
|
||||
// Convert signature to readable format
|
||||
const sig = base58.encode(signature);
|
||||
|
||||
|
||||
const sig = base58.encode(sigUint8Array);
|
||||
console.log(sig);
|
||||
|
||||
|
||||
window.location.href = `/vote?message=${encodeURIComponent(vote)}&signature=${encodeURIComponent(sig)}&walletAddress=${encodeURIComponent(solana.publicKey.toBase58())}&votes=${encodeURIComponent(balance)}&percent=${encodeURIComponent((balance / supply) * 100)}`
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error submitting vote:', error);
|
||||
}
|
||||
}
|
||||
document.getElementById('confirmButton').addEventListener('click', async function() {
|
||||
// You can perform any action here, such as submitting the form
|
||||
await submitVote();
|
||||
});
|
||||
});
|
||||
|
@ -103,7 +103,68 @@
|
||||
<div class="mb-3">
|
||||
<p>Select your vote or split your votes between options.</p>{{options|safe}}
|
||||
</div>
|
||||
<div class="mb-3"><button class="btn btn-primary" type="submit" style="margin-top: 25px;" {% if not enabled %}disabled{% endif %}>Vote</button></div>
|
||||
<div class="mb-3"><button type="button" style="margin-top: 25px;" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#confirmationModal" {% if not enabled %}disabled{% endif %}>Vote</button>
|
||||
<!-- <button class="btn btn-primary" type="submit" style="margin-top: 25px;" {% if not enabled %}disabled{% endif %}>Vote</button> -->
|
||||
|
||||
|
||||
<div class="modal fade" id="confirmationModal" tabindex="-1" aria-labelledby="confirmationModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content" style="background-color:black;">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="confirmationModalLabel">Confirmation</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you sure you want to submit your vote?
|
||||
<p>Your vote is:</p>
|
||||
<span id="voteContent"></span>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
|
||||
<button id="confirmButton" type="button" class="btn btn-primary" data-bs-dismiss="modal">Yes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('confirmationModal').addEventListener('show.bs.modal', function(event) {
|
||||
const inputs = document.querySelectorAll('#advancedOptions input');
|
||||
|
||||
// Store values in json with matching names
|
||||
const options = {};
|
||||
inputs.forEach(input => {
|
||||
if (input.value.trim() === '') {
|
||||
input.value = '0';
|
||||
}
|
||||
|
||||
options[input.name] = input.value;
|
||||
}
|
||||
);
|
||||
// Make sure the votes total 100
|
||||
let total = 0;
|
||||
let vote = "";
|
||||
for (const key in options) {
|
||||
if (options.hasOwnProperty(key)) {
|
||||
const element = options[key];
|
||||
total += parseInt(element);
|
||||
// If value less than 0 or greater than 100, alert and return
|
||||
if (element < 0 || element > 100) {
|
||||
alert('Votes must be between 0 and 100');
|
||||
return;
|
||||
}
|
||||
vote += "<br>" + element + "% for " +key;
|
||||
}
|
||||
}
|
||||
if (total > 100) {
|
||||
alert('Votes must be less than or equal to 100');
|
||||
return;
|
||||
}
|
||||
vote += "<br><br>"+total+"% of voting power used";
|
||||
|
||||
document.getElementById('voteContent').innerHTML = vote;
|
||||
});
|
||||
</script></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user