create profile
This commit is contained in:
parent
cee31c1623
commit
3154a8511a
2 changed files with 70 additions and 17 deletions
|
|
@ -129,7 +129,7 @@ function debounce(func, wait) {
|
|||
};
|
||||
}
|
||||
|
||||
validateNymInput = debounce(() => {
|
||||
const validateNymInput = debounce(() => {
|
||||
const nymValue = nymInput.value.trim();
|
||||
const isValid = nymValue.length >= 3 && nymValue.length <= 128;
|
||||
if (isValid) {
|
||||
|
|
@ -139,7 +139,7 @@ validateNymInput = debounce(() => {
|
|||
}
|
||||
}, 500);
|
||||
|
||||
checkIfSubmittable = debounce((allInputs) => {
|
||||
const checkIfSubmittable = debounce((allInputs) => {
|
||||
const nymIsFilled = allInputs.nymInput.value !== '';
|
||||
let atLeastOneContactIsFilled = false;
|
||||
|
||||
|
|
@ -153,7 +153,37 @@ checkIfSubmittable = debounce((allInputs) => {
|
|||
submitProfileButton.disabled = buttonShouldBeDisabled;
|
||||
}, 1000);
|
||||
|
||||
function onLoadErrands(allInputs) {
|
||||
async function createProfile(allInputs) {
|
||||
const contactDetails = [];
|
||||
for (const someInput of allInputs.contactInputs) {
|
||||
contactDetails.push({
|
||||
type: someInput.getAttribute('data-type'),
|
||||
value: someInput.value,
|
||||
});
|
||||
}
|
||||
const encryptedContactDetails = await window.nostr.nip04.encrypt(
|
||||
await window.nostr.getPublicKey(),
|
||||
JSON.stringify(contactDetails)
|
||||
);
|
||||
await fetch('/api/set-contact-details', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ encryptedContactDetails }),
|
||||
});
|
||||
|
||||
const nym = allInputs.nymInput.value;
|
||||
await fetch('/api/set-nym', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ nym }),
|
||||
});
|
||||
}
|
||||
|
||||
function onLoadErrands(allInputs, submitProfileButton) {
|
||||
allInputs.nymInput.addEventListener('input', validateNymInput);
|
||||
|
||||
for (const someInput of allInputs.allInputs) {
|
||||
|
|
@ -163,6 +193,10 @@ function onLoadErrands(allInputs) {
|
|||
}
|
||||
|
||||
checkIfSubmittable(allInputs);
|
||||
|
||||
submitProfileButton.addEventListener('click', () => {
|
||||
createProfile(allInputs);
|
||||
});
|
||||
}
|
||||
|
||||
const nymInput = document.getElementById('nym-input');
|
||||
|
|
@ -198,4 +232,4 @@ const allInputs = {
|
|||
],
|
||||
};
|
||||
|
||||
onLoadErrands(allInputs);
|
||||
onLoadErrands(allInputs, submitProfileButton);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue