4
1
mirror of https://github.com/Qortal/qortal-ui.git synced 2025-02-11 17:55:51 +00:00

ability to save and read private data

This commit is contained in:
PhilReact 2023-10-29 21:44:43 +02:00
parent 58bf4aa7c9
commit fbe8b6aecb
2 changed files with 88 additions and 9 deletions

View File

@ -237,9 +237,11 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
changedProperties.has('editContent') &&
this.editContent
) {
this.bio = this.editContent.bio ?? '';
this.tagline = this.editContent.tagline ?? '';
this.wallets = this.editContent.wallets ?? {};
const {bio, tagline, wallets, customData} = this.editContent
this.bio = bio ?? '';
this.tagline = tagline ?? '';
this.wallets = wallets ?? {};
this.customData = {...customData}
this.requestUpdate();
}
}
@ -353,6 +355,7 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
tagline: this.tagline,
bio: this.bio,
wallets: this.wallets,
customData: this.customData
};
await this.onSubmit(data);
this.setIsOpen(false);
@ -378,6 +381,22 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
const copyObj = {...this.customData}
copyObj[this.newCustomDataKey] = this.newCustomDataField
this.customData = copyObj
this.newCustomDataKey = ""
this.newCustomDataField = {};
this.newFieldName = ''
this.isOpenCustomDataModal = false;
}
updateCustomData(key, data){
this.isOpenCustomDataModal = true
this.newCustomDataField = data
this.newCustomDataKey = key
}
removeCustomData(key){
const copyObj = {...this.customData}
delete copyObj[key]
this.customData = copyObj
}
render() {
@ -472,6 +491,40 @@ class ProfileModalUpdate extends connect(store)(LitElement) {
`;
})}
</div>
<div style="display: flex;flex-direction: column;">
${Object.keys(this.customData).map((key) => {
return html`
<div
style="display:flex;justify-content:center;flex-direction:column;gap:25px"
>
<div
style="display:flex;gap:15px;align-items:center"
>
<p
style="color: var(--black);font-size:16px"
>
${key}
</p>
<mwc-icon
@click=${() =>
this.updateCustomData(key,this.customData[key])}
style="color:var(--black);cursor:pointer"
>edit</mwc-icon
>
<mwc-icon
@click=${() =>
this.removeCustomData(key)}
style="color:var(--black);cursor:pointer"
>remove</mwc-icon
>
</div>
</div>
`;
})}
</div>
</div>
<div
style="display:flex;justify-content:space-between;align-items:center;margin-top:20px"

View File

@ -198,8 +198,34 @@ class ProfileQdn extends connect(store)(LitElement) {
async setValues(response, resource) {
console.log('hello', response)
if(response){
this.profileData = response
let data = {...response}
let customData = {}
for (const key of Object.keys(data.customData || {})) {
if (key.includes('-private')) {
try {
console.log('key', data.customData[key])
const decryptedData = decryptGroupData(data.customData[key]);
console.log({decryptedData})
if(decryptedData && !decryptedData.error){
const decryptedDataToBase64 = uint8ArrayToObject(decryptedData);
if(decryptedDataToBase64 && !decryptedDataToBase64.error){
customData[key] = decryptedDataToBase64;
}
}
} catch (error) {
console.log({error})
}
}
}
this.profileData = {
...response,
customData
}
}
}
@ -315,18 +341,18 @@ class ProfileQdn extends connect(store)(LitElement) {
const getArbitraryFee = await this.getArbitraryFee();
const feeAmount = getArbitraryFee.fee;
let newObject = {};
let newObject = {...data};
for (const key of Object.keys(data)) {
for (const key of Object.keys(newObject.customData || {})) {
if (key.includes('-private')) {
const toBase64 = await objectToBase64(newObject);
const toBase64 = await objectToBase64(newObject.customData[key]);
const encryptedData = encryptDataGroup({
data64: toBase64,
publicKeys: [],
});
newObject[key] = encryptedData;
newObject['customData'][key] = encryptedData;
} else {
newObject[key] = data[key];
newObject['customData'][key] = data[key];
}
}