feat: Added modal and fixed brave wallet errors
All checks were successful
Build Docker / Build Image (push) Successful in 24s

This commit is contained in:
Nathan Woodburn 2024-02-27 17:37:31 +11:00
parent 049141966a
commit 6123c6956c
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
5 changed files with 72 additions and 15 deletions

2
dist/bundle.js vendored

File diff suppressed because one or more lines are too long

View File

@ -374,7 +374,6 @@ def timeLeft():
info = get_vote_info() info = get_vote_info()
end = utc_now.strptime(info["end"], "%Y-%m-%d") end = utc_now.strptime(info["end"], "%Y-%m-%d")
left = end - utc_now left = end - utc_now
print(left)
return left return left
def endTime(): def endTime():

View File

@ -6,8 +6,6 @@ def votes():
with open('data/votes.json') as file: with open('data/votes.json') as file:
votes = json.load(file) votes = json.load(file)
print(votes)
options = {} options = {}
for vote in votes: for vote in votes:
# Check if message is json # Check if message is json

View File

@ -133,8 +133,7 @@ document.addEventListener('DOMContentLoaded', async function() {
return; return;
} }
document.getElementById('signMessageForm').addEventListener('submit', async function(event) { async function submitVote() {
event.preventDefault();
// Get all inputs in #advancedOptions // Get all inputs in #advancedOptions
const inputs = document.querySelectorAll('#advancedOptions input'); const inputs = document.querySelectorAll('#advancedOptions input');
@ -164,7 +163,6 @@ document.addEventListener('DOMContentLoaded', async function() {
return; return;
} }
const vote = JSON.stringify(options); const vote = JSON.stringify(options);
// Encode the message as a buffer-like object // Encode the message as a buffer-like object
const messageUint8Array = new TextEncoder().encode(vote); const messageUint8Array = new TextEncoder().encode(vote);
// Request signature from Phantom // Request signature from Phantom
@ -176,20 +174,21 @@ document.addEventListener('DOMContentLoaded', async function() {
display: "utf8" display: "utf8"
}, },
}); });
const url = 'http://localhost:5000/vote'; // Update the URL as needed const url = 'http://localhost:5000/vote'; // Update the URL as needed
const sigUint8Array = new Uint8Array(signature);
// Convert signature to readable format // Convert signature to readable format
const sig = base58.encode(signature); const sig = base58.encode(sigUint8Array);
console.log(sig); 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)}` 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) { } catch (error) {
console.error('Error submitting vote:', 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();
}); });
}); });

View File

@ -103,7 +103,68 @@
<div class="mb-3"> <div class="mb-3">
<p>Select your vote or split your votes between options.</p>{{options|safe}} <p>Select your vote or split your votes between options.</p>{{options|safe}}
</div> </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> </form>
</div> </div>
</div> </div>