minor fixes and cleanup

This commit is contained in:
Anton Livaja 2024-10-12 15:37:08 -04:00
parent 6464e2fc4a
commit 2d35b2b5e9
Signed by: anton
GPG Key ID: 44A86CFF1FDF0E85
3 changed files with 44 additions and 20 deletions

View File

@ -33,4 +33,3 @@
</div> </div>
</div> </div>
</header> </header>
<script type="text/javascript" src="/assets/js/main.js"></script>

View File

@ -148,6 +148,7 @@
<label>What threshold would you like to use for the KYC recovery method? (2/3, 3/5, 4/7 etc)</label> <label>What threshold would you like to use for the KYC recovery method? (2/3, 3/5, 4/7 etc)</label>
<br> <br>
<input type="text" id="kyc_threshold" name="kyc_threshold"> <input type="text" id="kyc_threshold" name="kyc_threshold">
<div class="error-field" id="kyc_threshold_error"></div>
<p> <p>
Please select KYC data for individuals who can Please select KYC data for individuals who can
@ -166,9 +167,11 @@
id_images = ["<base_64_encoded_image>", "<base_64_encoded_image>", ...] id_images = ["<base_64_encoded_image>", "<base_64_encoded_image>", ...]
country_of_birth = "US" country_of_birth = "US"
</code> </code>
</pre> </pre>
<input type="file" id="kyc_data" name="files[]" multiple> <input type="file" id="kyc_data" name="files[]" multiple>
<br>
<div class="error-field" id="kyc_data_error"></div>
</div> </div>
</section> </section>

View File

@ -23,19 +23,18 @@ function applyTheme() {
} }
} }
toggleButton.addEventListener('click', () => { // toggleButton.addEventListener('click', () => {
if (htmlElement.classList.contains('dark-theme')) { // if (htmlElement.classList.contains('dark-theme')) {
htmlElement.classList.remove('dark-theme'); // htmlElement.classList.remove('dark-theme');
localStorage.setItem('theme', 'light'); // localStorage.setItem('theme', 'light');
} else { // } else {
htmlElement.classList.add('dark-theme'); // htmlElement.classList.add('dark-theme');
localStorage.setItem('theme', 'dark'); // localStorage.setItem('theme', 'dark');
} // }
}); // });
// Load the saved theme on page load // Load the saved theme on page load
window.onload = () => { window.onload = () => {
console.log('ih')
// applyTheme(); // applyTheme();
resetFormFields() resetFormFields()
}; };
@ -105,7 +104,6 @@ async function extractValues() {
const pubKeysEl = document.getElementById('pub_keys'); const pubKeysEl = document.getElementById('pub_keys');
const pubKeys = pubKeysEl.files; const pubKeys = pubKeysEl.files;
let pubKeyData = []; let pubKeyData = [];
for (let i = 0; i < pubKeys.length; i++) { for (let i = 0; i < pubKeys.length; i++) {
const pubKeyFile = pubKeys[i]; const pubKeyFile = pubKeys[i];
@ -132,8 +130,14 @@ async function extractValues() {
} }
const kycDataEl = document.getElementById('kyc_data'); const kycDataEl = document.getElementById('kyc_data');
const kycData = kycDataEl.files; const kycDataFiles = kycDataEl.files;
if (kycData) { let kycData = [];
for (let i = 0; i < kycDataFiles.length; i++) {
const kycDataFile = kycDataFiles[i];
const fileText = await readFileAsText(kycDataFile);
kycData.push(fileText);
}
if (kycData.length) {
policy.kyc_data = kycData; policy.kyc_data = kycData;
console.log(kycData); console.log(kycData);
} }
@ -173,10 +177,8 @@ function validateThreshold(threshold) {
threshold, threshold,
}; };
console.log('threshold', threshold)
if (valid) { if (valid) {
const numbers = threshold.split('/'); const numbers = threshold.split('/');
console.log('numbers', numbers)
if (Number(numbers[0]) > Number(numbers[1])) { if (Number(numbers[0]) > Number(numbers[1])) {
res.error = "Error: first number has to be lesser than second."; res.error = "Error: first number has to be lesser than second.";
} else { } else {
@ -318,19 +320,39 @@ remoteThresholdEl.addEventListener('input', function () {
} }
}); });
const kycThresholdEl = document.getElementById('kyc_threshold');
kycThresholdEl.addEventListener('input', function () {
const kycThresholdErrorEl = document.getElementById('kyc_threshold_error');
kycThresholdErrorEl.innerText = "";
const currentValue = kycThresholdEl.value;
const thresholdRes = validateThreshold(currentValue)
if (thresholdRes.error) {
kycThresholdErrorEl.innerText = thresholdRes.error;
}
});
const pubKeysErrorEl = document.getElementById('pub_keys_error'); const pubKeysErrorEl = document.getElementById('pub_keys_error');
const pubKeys = document.getElementById('pub_keys') const pubKeys = document.getElementById('pub_keys')
pubKeys.addEventListener('change', function () { pubKeys.addEventListener('change', function () {
pubKeysErrorEl.innerText = ""; pubKeysErrorEl.innerText = "";
const res = validateThreshold(remoteThresholdEl.value); const res = validateThreshold(remoteThresholdEl.value);
console.log(res, remoteThresholdEl)
if (pubKeys.files.length < res.threshold.split('/')[1] || !res || !res.threshold) { if (pubKeys.files.length < res.threshold.split('/')[1] || !res || !res.threshold) {
console.log('uhoh') pubKeysErrorEl.innerText = "Please select a valid threshold or upload the correct number of public key files.";
pubKeysErrorEl.innerText = "Please select a valid threshold";
pubKeys.value = ""; pubKeys.value = "";
} }
}); });
const kycDataErrorEl = document.getElementById('kyc_data_error');
const kycData = document.getElementById('kyc_data')
kycData.addEventListener('change', function () {
kycDataErrorEl.innerText = "";
const res = validateThreshold(kycThresholdEl.value);
if (kycData.files.length < res.threshold.split('/')[1] || !res || !res.threshold) {
kycDataErrorEl.innerText = "Please select a valid threshold or upload the correct number of public key files.";
kycData.value = "";
}
});
let kycAvailableEl = document.getElementById('kyc_available'); let kycAvailableEl = document.getElementById('kyc_available');
kycAvailableEl.addEventListener('input', function () { kycAvailableEl.addEventListener('input', function () {
let currentValue = kycAvailableEl.value; let currentValue = kycAvailableEl.value;