From 547671cc350715ddc22d01fb4208f3623dacaa2e Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sat, 21 Oct 2023 14:25:12 +0300 Subject: [PATCH] bug fixes --- core/language/us.json | 3 +- .../friends-view/add-friends-modal.js | 2 +- .../components/friends-view/friends-feed.js | 93 +-- .../friends-view/save-settings-qdn.js | 730 +++++++++++------- .../components/notification-view/popover.js | 5 +- core/src/components/show-plugin.js | 156 +++- core/src/redux/app/app-reducer.js | 4 +- plugins/plugins/core/components/ChatPage.js | 44 +- .../plugins/core/components/ChatScroller.js | 7 +- 9 files changed, 659 insertions(+), 385 deletions(-) diff --git a/core/language/us.json b/core/language/us.json index e3dcd6ee..9f17d22e 100644 --- a/core/language/us.json +++ b/core/language/us.json @@ -1203,6 +1203,7 @@ "save": { "saving1": "Unable to fetch saved settings", "saving2": "Nothing to save", - "saving3": "Save unsaved changes" + "saving3": "Save unsaved changes", + "saving4": "Undo changes" } } \ No newline at end of file diff --git a/core/src/components/friends-view/add-friends-modal.js b/core/src/components/friends-view/add-friends-modal.js index 4cf936a4..f89e36de 100644 --- a/core/src/components/friends-view/add-friends-modal.js +++ b/core/src/components/friends-view/add-friends-modal.js @@ -269,7 +269,6 @@ class AddFriendsModal extends connect(store)(LitElement) { this.willFollow = this.editContent.willFollow ?? true; this.alias = this.editContent.alias ?? ''; this.requestUpdate() - console.log('this.editContent', this.editContent ) } if ( changedProperties && @@ -420,6 +419,7 @@ class AddFriendsModal extends connect(store)(LitElement) { item.name === schema.name ); if (findIndex === -1) { + if(this.mySelectedFeeds.length > 4) return copymySelectedFeeds.push({ name: schema.name, identifier: schema.identifier, diff --git a/core/src/components/friends-view/friends-feed.js b/core/src/components/friends-view/friends-feed.js index 24f7dfbf..288d04d7 100644 --- a/core/src/components/friends-view/friends-feed.js +++ b/core/src/components/friends-view/friends-feed.js @@ -70,7 +70,6 @@ class FriendsFeed extends connect(store)(LitElement) { _updateFeeds(event) { const detail = event.detail - console.log('detail2', detail) this.mySelectedFeeds = detail this.reFetchFeedData() this.requestUpdate() @@ -78,7 +77,6 @@ class FriendsFeed extends connect(store)(LitElement) { connectedCallback() { super.connectedCallback() - console.log('callback') window.addEventListener('friends-my-selected-feeds-event', this._updateFeeds) } disconnectedCallback() { @@ -325,9 +323,7 @@ this.getFeedOnInterval() } if(newItem.schema){ const resource = newItem - // First, evaluate methods to get values for customParams - await updateCustomParamsWithMethods(newItem.schema, newResource); - // Now, generate your final URLs + let clickValue1 = newItem.schema.click; const resolvedClickValue1 = replacePlaceholders(clickValue1, resource, newItem.schema.customParams); @@ -445,95 +441,12 @@ export function constructUrl(base, search, dynamicVars) { return queryStrings.length > 0 ? `${base}&${queryStrings.join('&')}` : base; } -function validateMethodString(methodString) { - // Check for IIFE - const iifePattern = /^\(.*\)\s*\(\)/; - if (iifePattern.test(methodString)) { - throw new Error("IIFE detected!"); - } - - // Check for disallowed keywords - const disallowed = ["eval", "Function", "fetch", "XMLHttpRequest"]; - for (const keyword of disallowed) { - if (methodString.includes(keyword)) { - throw new Error(`Disallowed keyword detected: ${keyword}`); - } - } - - // ... Add more validation steps here ... - - return true; -} - -function executeMethodInWorker(methodString, externalArgs) { - return new Promise((resolve, reject) => { - if (!validateMethodString(methodString)) { - reject(new Error("Invalid method string provided.")); - return; - } - - const workerFunction = ` - self.onmessage = function(event) { - const methodFunction = new Function("resource", "${methodString}"); - const result = methodFunction(event.data.externalArgs); - - if (typeof result === 'string' || typeof result === 'number') { - self.postMessage(result); - } else { - self.postMessage(''); - } - } - `; - - const blob = new Blob([workerFunction], { type: 'application/javascript' }); - const blobURL = URL.createObjectURL(blob); - const worker = new Worker(blobURL); - - worker.onmessage = function(event) { - if (typeof event.data === 'string' || typeof event.data === 'number') { - resolve(event.data); - worker.terminate(); - URL.revokeObjectURL(blobURL); - } else { - resolve(""); - event.data = null - worker.terminate(); - URL.revokeObjectURL(blobURL); - } - - }; - - worker.onerror = function(error) { - reject(error); - worker.terminate(); - URL.revokeObjectURL(blobURL); - }; - - worker.postMessage({ externalArgs }); - }); -} -export async function updateCustomParamsWithMethods(schema,resource) { - for (const key in schema.customParams) { - const value = schema.customParams[key]; - if (value.startsWith("**methods.") && value.endsWith("**")) { - const methodInvocation = value.slice(10, -2).split('('); - const methodName = methodInvocation[0]; - if (schema.methods[methodName]) { - const newResource = { - identifier: resource.identifier, - name: resource.name, - service: resource.service - } - const methodResult = await executeMethodInWorker(schema.methods[methodName], newResource); - schema.customParams[key] = methodResult; - } - } - } -} + + export function replacePlaceholders(template, resource, customParams) { const dataSource = { resource, customParams }; diff --git a/core/src/components/friends-view/save-settings-qdn.js b/core/src/components/friends-view/save-settings-qdn.js index 4f2531f8..9923229f 100644 --- a/core/src/components/friends-view/save-settings-qdn.js +++ b/core/src/components/friends-view/save-settings-qdn.js @@ -3,45 +3,51 @@ import '@material/mwc-icon'; import './friends-side-panel.js'; import { connect } from 'pwa-helpers'; import { store } from '../../store.js'; -import WebWorker from 'web-worker:./computePowWorkerFile.src.js' -import '@polymer/paper-spinner/paper-spinner-lite.js' +import WebWorker from 'web-worker:./computePowWorkerFile.src.js'; +import '@polymer/paper-spinner/paper-spinner-lite.js'; import '@vaadin/tooltip'; +import { get, translate } from 'lit-translate'; import { - get -} from 'lit-translate'; -import { decryptGroupData, encryptDataGroup, objectToBase64, uint8ArrayToBase64, uint8ArrayToObject } from '../../../../plugins/plugins/core/components/qdn-action-encryption.js'; + decryptGroupData, + encryptDataGroup, + objectToBase64, + uint8ArrayToBase64, + uint8ArrayToObject, +} from '../../../../plugins/plugins/core/components/qdn-action-encryption.js'; import { publishData } from '../../../../plugins/plugins/utils/publish-image.js'; import { parentEpml } from '../show-plugin.js'; +import '../notification-view/popover.js'; -class SaveSettingsQdn extends connect(store)(LitElement) { +class SaveSettingsQdn extends connect(store)(LitElement) { static get properties() { return { - isOpen: {type: Boolean}, - syncPercentage: {type: Number}, - settingsRawData: {type: Object}, - valuesToBeSavedOnQdn: {type: Object}, - resourceExists: {type: Boolean}, - isSaving: {type: Boolean} + isOpen: { type: Boolean }, + syncPercentage: { type: Number }, + settingsRawData: { type: Object }, + valuesToBeSavedOnQdn: { type: Object }, + resourceExists: { type: Boolean }, + isSaving: { type: Boolean }, + fee: { type: Object }, }; } - constructor() { super(); - this.isOpen = false - this.getGeneralSettingsQdn = this.getGeneralSettingsQdn.bind(this) - this._updateTempSettingsData = this._updateTempSettingsData.bind(this) - this.setValues = this.setValues.bind(this) - this.saveToQdn = this.saveToQdn.bind(this) - this.syncPercentage = 0 - this.hasRetrievedResource = false - this.hasAttemptedToFetchResource = false - this.resourceExists = undefined - this.settingsRawData = null - this.nodeUrl = this.getNodeUrl() - this.myNode = this.getMyNode() - this.valuesToBeSavedOnQdn = {} - this.isSaving = false + this.isOpen = false; + this.getGeneralSettingsQdn = this.getGeneralSettingsQdn.bind(this); + this._updateTempSettingsData = this._updateTempSettingsData.bind(this); + this.setValues = this.setValues.bind(this); + this.saveToQdn = this.saveToQdn.bind(this); + this.syncPercentage = 0; + this.hasRetrievedResource = false; + this.hasAttemptedToFetchResource = false; + this.resourceExists = undefined; + this.settingsRawData = null; + this.nodeUrl = this.getNodeUrl(); + this.myNode = this.getMyNode(); + this.valuesToBeSavedOnQdn = {}; + this.isSaving = false; + this.fee = null; } static styles = css` .header { @@ -64,309 +70,491 @@ class SaveSettingsQdn extends connect(store)(LitElement) { .parent-side-panel { transform: translateX(100%); /* start from outside the right edge */ - transition: transform 0.3s ease-in-out; + transition: transform 0.3s ease-in-out; } .parent-side-panel.open { transform: translateX(0); /* slide in to its original position */ - } .notActive { opacity: 0.5; cursor: default; - color: var(--black) + color: var(--black); } .active { opacity: 1; cursor: pointer; color: green; } + .accept-button { + font-family: Roboto, sans-serif; + letter-spacing: 0.3px; + font-weight: 300; + padding: 8px 5px; + border-radius: 3px; + text-align: center; + color: var(--mdc-theme-primary); + transition: all 0.3s ease-in-out; + display: flex; + align-items: center; + gap: 10px; + font-size: 18px + } + + .accept-button:hover { + cursor: pointer; + background-color: #03a8f485; + } + + .undo-button { + font-family: Roboto, sans-serif; + letter-spacing: 0.3px; + font-weight: 300; + padding: 8px 5px; + border-radius: 3px; + text-align: center; + color: #f44336; + transition: all 0.3s ease-in-out; + display: flex; + align-items: center; + gap: 10px; + font-size: 18px + } + + .undo-button:hover { + cursor: pointer; + background-color: #f4433663; + } `; -getNodeUrl(){ - const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] - - const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port - return nodeUrl -} -getMyNode(){ - const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node] - - return myNode -} - -async getRawData (dataItem){ - const url = `${this.nodeUrl}/arbitrary/${dataItem.service}/${dataItem.name}/${dataItem.identifier}?encoding=base64`; - const res = await fetch(url) - const data = await res.text() - if(data.error) throw new Error('Cannot retrieve your data from qdn') - const decryptedData = decryptGroupData(data) - const decryptedDataToBase64 = uint8ArrayToObject(decryptedData) - return decryptedDataToBase64 -} - -async setValues(response, resource){ - this.settingsRawData = response - const rawDataTimestamp = resource.updated - - const tempSettingsData = JSON.parse(localStorage.getItem('temp-settings-data') || "{}") - if(tempSettingsData){ + getNodeUrl() { + const myNode = + window.parent.reduxStore.getState().app.nodeConfig.knownNodes[ + window.parent.reduxStore.getState().app.nodeConfig.node + ]; + const nodeUrl = + myNode.protocol + '://' + myNode.domain + ':' + myNode.port; + return nodeUrl; } - const userLists = response.userLists || [] - const friendsFeed = response.friendsFeed + getMyNode() { + const myNode = + window.parent.reduxStore.getState().app.nodeConfig.knownNodes[ + window.parent.reduxStore.getState().app.nodeConfig.node + ]; - this.valuesToBeSavedOnQdn = {} - if(userLists.length > 0 && (!tempSettingsData.userLists || (tempSettingsData.userLists && (tempSettingsData.userLists.timestamp < rawDataTimestamp)))){ - const friendList = userLists[0] - localStorage.setItem('friends-my-friend-list', JSON.stringify(friendList)); - this.dispatchEvent( - new CustomEvent('friends-my-friend-list-event', { - bubbles: true, - composed: true, - detail: friendList, - }), - ); - } else if(tempSettingsData.userLists && tempSettingsData.userLists.timestamp > rawDataTimestamp){ - this.valuesToBeSavedOnQdn = { - ...this.valuesToBeSavedOnQdn, - userLists: { - data: tempSettingsData.userLists.data - } + return myNode; + } + + async getRawData(dataItem) { + const url = `${this.nodeUrl}/arbitrary/${dataItem.service}/${dataItem.name}/${dataItem.identifier}?encoding=base64`; + const res = await fetch(url); + const data = await res.text(); + if (data.error) throw new Error('Cannot retrieve your data from qdn'); + const decryptedData = decryptGroupData(data); + const decryptedDataToBase64 = uint8ArrayToObject(decryptedData); + return decryptedDataToBase64; + } + + async setValues(response, resource) { + this.settingsRawData = response; + const rawDataTimestamp = resource.updated; + + const tempSettingsData = JSON.parse( + localStorage.getItem('temp-settings-data') || '{}' + ); + if (tempSettingsData) { + } + const userLists = response.userLists || []; + const friendsFeed = response.friendsFeed; + const myMenuPlugs = response.myMenuPlugs + + this.valuesToBeSavedOnQdn = {}; + if ( + userLists.length > 0 && + (!tempSettingsData.userLists || + (tempSettingsData.userLists && + tempSettingsData.userLists.timestamp < rawDataTimestamp)) + ) { + const friendList = userLists[0]; + localStorage.setItem( + 'friends-my-friend-list', + JSON.stringify(friendList) + ); + this.dispatchEvent( + new CustomEvent('friends-my-friend-list-event', { + bubbles: true, + composed: true, + detail: friendList, + }) + ); + } else if ( + tempSettingsData.userLists && + tempSettingsData.userLists.timestamp > rawDataTimestamp + ) { + this.valuesToBeSavedOnQdn = { + ...this.valuesToBeSavedOnQdn, + userLists: { + data: tempSettingsData.userLists.data, + }, + }; + } + + if ( + friendsFeed && + (!tempSettingsData.friendsFeed || + (tempSettingsData.friendsFeed && + tempSettingsData.friendsFeed.timestamp < rawDataTimestamp)) + ) { + localStorage.setItem( + 'friends-my-selected-feeds', + JSON.stringify(friendsFeed) + ); + this.dispatchEvent( + new CustomEvent('friends-my-selected-feeds-event', { + bubbles: true, + composed: true, + detail: friendsFeed, + }) + ); + } else if ( + tempSettingsData.friendsFeed && + tempSettingsData.friendsFeed.timestamp > rawDataTimestamp + ) { + this.valuesToBeSavedOnQdn = { + ...this.valuesToBeSavedOnQdn, + friendsFeed: { + data: tempSettingsData.friendsFeed.data, + }, + }; + } + + + if ( + myMenuPlugs && + (!tempSettingsData.myMenuPlugs || + (tempSettingsData.myMenuPlugs && + tempSettingsData.myMenuPlugs.timestamp < rawDataTimestamp)) + ) { + localStorage.setItem( + 'myMenuPlugs', + JSON.stringify(myMenuPlugs) + ); + this.dispatchEvent( + new CustomEvent('myMenuPlugs-event', { + bubbles: true, + composed: true, + detail: myMenuPlugs, + }) + ); + } else if ( + tempSettingsData.myMenuPlugs && + tempSettingsData.myMenuPlugs.timestamp > rawDataTimestamp + ) { + this.valuesToBeSavedOnQdn = { + ...this.valuesToBeSavedOnQdn, + myMenuPlugs: { + data: tempSettingsData.myMenuPlugs.data, + }, + }; } } - if(friendsFeed && (!tempSettingsData.friendsFeed || ( tempSettingsData.friendsFeed && (tempSettingsData.friendsFeed.timestamp < rawDataTimestamp)))){ - localStorage.setItem('friends-my-selected-feeds', JSON.stringify(friendsFeed)); - this.dispatchEvent( - new CustomEvent('friends-my-selected-feeds-event', { - bubbles: true, - composed: true, - detail: friendsFeed, - }), - ); - } else if(tempSettingsData.friendsFeed && tempSettingsData.friendsFeed.timestamp > rawDataTimestamp){ - this.valuesToBeSavedOnQdn = { - ...this.valuesToBeSavedOnQdn, - friendsFeed: { - data: tempSettingsData.friendsFeed.data - } - } - } -} + async getGeneralSettingsQdn() { + try { + const arbFee = await this.getArbitraryFee(); + this.fee = arbFee; + this.hasAttemptedToFetchResource = true; + let resource; + const nameObject = store.getState().app.accountInfo.names[0]; + if (!nameObject) throw new Error('no name'); + const name = nameObject.name; + this.error = ''; + const url = `${this.nodeUrl}/arbitrary/resources/search?service=DOCUMENT_PRIVATE&identifier=qortal_general_settings&name=${name}&prefix=true&exactmatchnames=true&excludeblocked=true&limit=20`; + const res = await fetch(url); + let data = ''; + try { + data = await res.json(); + if (Array.isArray(data)) { + data = data.filter( + (item) => item.identifier === 'qortal_general_settings' + ); -async getGeneralSettingsQdn(){ - try { - this.hasAttemptedToFetchResource = true - let resource - const name = "palmas" - this.error = '' - const url = `${this.nodeUrl}/arbitrary/resources/search?service=DOCUMENT_PRIVATE&identifier=qortal_general_settings&name=${name}&prefix=true&exactmatchnames=true&excludeblocked=true&limit=20` - const res = await fetch(url) - let data = '' - try { - data = await res.json() - if(Array.isArray(data)){ - data = data.filter((item)=> item.identifier === 'qortal_general_settings') - - if(data.length > 0){ - - this.resourceExists = true - const dataItem = data[0] - try { - const response = await this.getRawData(dataItem) - console.log({response}) - if(response.version){ - this.setValues(response, dataItem) - } else { - this.error = "Cannot get saved user settings" - } - } catch (error) { - console.log({error}) - this.error = "Cannot get saved user settings" + if (data.length > 0) { + this.resourceExists = true; + const dataItem = data[0]; + try { + const response = await this.getRawData(dataItem); + if (response.version) { + this.setValues(response, dataItem); + } else { + this.error = 'Cannot get saved user settings'; } - } else { - this.resourceExists = false + } catch (error) { + console.log({ error }); + this.error = 'Cannot get saved user settings'; } } else { - this.error = "Unable to perform query" - } - } catch (error) { - data = { - error: 'No resource found' + this.resourceExists = false; } + } else { + this.error = 'Unable to perform query'; } + } catch (error) { + data = { + error: 'No resource found', + }; + } - if(resource){ - this.hasRetrievedResource = true + if (resource) { + this.hasRetrievedResource = true; + } + } catch (error) { + console.log({ error }); } - } catch (error) { - console.log({error}) - } -} + stateChanged(state) { + if ( + state.app.accountInfo && state.app.accountInfo.names.length && state.app.nodeStatus && + state.app.nodeStatus.syncPercent !== this.syncPercentage + ) { + this.syncPercentage = state.app.nodeStatus.syncPercent; - -stateChanged(state) { - if(state.app.nodeStatus && state.app.nodeStatus.syncPercent !== this.syncPercentage){ - this.syncPercentage = state.app.nodeStatus.syncPercent - - if(!this.hasAttemptedToFetchResource && state.app.nodeStatus.syncPercent === 100){ - console.log('hello') - this.getGeneralSettingsQdn() + if ( + !this.hasAttemptedToFetchResource && + state.app.nodeStatus.syncPercent === 100 + ) { + this.getGeneralSettingsQdn(); + } } - } -} -async getArbitraryFee (){ - const timestamp = Date.now() - const url = `${this.nodeUrl}/transactions/unitfee?txType=ARBITRARY×tamp=${timestamp}` - const response = await fetch(url) - if (!response.ok) { - throw new Error('Error when fetching arbitrary fee'); + async getArbitraryFee() { + const timestamp = Date.now(); + const url = `${this.nodeUrl}/transactions/unitfee?txType=ARBITRARY×tamp=${timestamp}`; + const response = await fetch(url); + if (!response.ok) { + throw new Error('Error when fetching arbitrary fee'); + } + const data = await response.json(); + const arbitraryFee = (Number(data) / 1e8).toFixed(8); + return { + timestamp, + fee: Number(data), + feeToShow: arbitraryFee, + }; } - const data = await response.json() - const arbitraryFee = (Number(data) / 1e8).toFixed(8) - return { - timestamp, - fee : Number(data), - feeToShow: arbitraryFee - } -} -async saveToQdn(){ - try { - this.isSaving = true - if(this.resourceExists === true && this.error) throw new Error('Unable to save') - - console.log('info', store.getState()) - const nameObject = store.getState().app.accountInfo.names[0] - if(!nameObject) throw new Error('no name') - const name = nameObject.name - console.log({name}) - const identifer = 'qortal_general_settings' - const filename = 'qortal_general_settings.json' - const selectedAddress = store.getState().app.selectedAddress - console.log({selectedAddress}) - const getArbitraryFee = await this.getArbitraryFee() - const feeAmount = getArbitraryFee.fee - console.log({feeAmount}) - const friendsList = JSON.parse(localStorage.getItem('friends-my-friend-list') || "[]") - const friendsFeed = JSON.parse(localStorage.getItem('friends-my-selected-feeds') || "[]") - - let newObject + async saveToQdn() { + try { + this.isSaving = true; + if (this.resourceExists === true && this.error) + throw new Error('Unable to save'); - if(this.resourceExists === false){ - newObject = { + const nameObject = store.getState().app.accountInfo.names[0]; + if (!nameObject) throw new Error('no name'); + const name = nameObject.name; + const identifer = 'qortal_general_settings'; + const filename = 'qortal_general_settings.json'; + const selectedAddress = store.getState().app.selectedAddress; + const getArbitraryFee = await this.getArbitraryFee(); + const feeAmount = getArbitraryFee.fee; + const friendsList = JSON.parse( + localStorage.getItem('friends-my-friend-list') || '[]' + ); + const friendsFeed = JSON.parse( + localStorage.getItem('friends-my-selected-feeds') || '[]' + ); + + let newObject; + + if (this.resourceExists === false) { + newObject = { version: 1, userLists: [friendsList], - friendsFeed - } - } else if(this.settingsRawData) { - const tempSettingsData= JSON.parse(localStorage.getItem('temp-settings-data') || "{}") - console.log({tempSettingsData}) + friendsFeed, + }; + } else if (this.settingsRawData) { + const tempSettingsData = JSON.parse( + localStorage.getItem('temp-settings-data') || '{}' + ); newObject = { ...this.settingsRawData, - } + }; for (const key in tempSettingsData) { if (tempSettingsData[key].hasOwnProperty('data')) { newObject[key] = tempSettingsData[key].data; } } - } - - console.log({newObject}) + const newObjectToBase64 = await objectToBase64(newObject); - console.log({newObjectToBase64}) - const encryptedData = encryptDataGroup({data64: newObjectToBase64, publicKeys: []}) - - console.log({encryptedData}) + const encryptedData = encryptDataGroup({ + data64: newObjectToBase64, + publicKeys: [], + }); + const worker = new WebWorker(); - try { - const resPublish = await publishData({ - registeredName: encodeURIComponent(name), - file: encryptedData, - service: 'DOCUMENT_PRIVATE', - identifier: encodeURIComponent(identifer), - parentEpml: parentEpml, - uploadType: 'file', - selectedAddress: selectedAddress, - worker: worker, - isBase64: true, - filename: filename, - apiVersion: 2, - withFee: true, - feeAmount: feeAmount - }); + try { + const resPublish = await publishData({ + registeredName: encodeURIComponent(name), + file: encryptedData, + service: 'DOCUMENT_PRIVATE', + identifier: encodeURIComponent(identifer), + parentEpml: parentEpml, + uploadType: 'file', + selectedAddress: selectedAddress, + worker: worker, + isBase64: true, + filename: filename, + apiVersion: 2, + withFee: true, + feeAmount: feeAmount, + }); - this.resourceExists = true - this.setValues(newObject, { - updated: Date.now() - }) - localStorage.setItem('temp-settings-data', JSON.stringify({})); - this.valuesToBeSavedOnQdn = {} - worker.terminate(); - } catch (error) { - worker.terminate(); - - } - - - - } catch (error) { - console.log({error}) - } finally { - this.isSaving = false + this.resourceExists = true; + this.setValues(newObject, { + updated: Date.now(), + }); + localStorage.setItem('temp-settings-data', JSON.stringify({})); + this.valuesToBeSavedOnQdn = {}; + worker.terminate(); + } catch (error) { + worker.terminate(); + } + } catch (error) { + console.log({ error }); + } finally { + this.isSaving = false; + } } -} -_updateTempSettingsData(){ - this.valuesToBeSavedOnQdn = JSON.parse(localStorage.getItem('temp-settings-data') || "{}") + _updateTempSettingsData() { + this.valuesToBeSavedOnQdn = JSON.parse( + localStorage.getItem('temp-settings-data') || '{}' + ); + } -} + connectedCallback() { + super.connectedCallback(); + window.addEventListener( + 'temp-settings-data-event', + this._updateTempSettingsData + ); + } -connectedCallback() { - super.connectedCallback() - console.log('callback') - window.addEventListener('temp-settings-data-event', this._updateTempSettingsData) -} - -disconnectedCallback() { - window.removeEventListener('temp-settings-data-event', this._updateTempSettingsData) - super.disconnectedCallback() -} + disconnectedCallback() { + window.removeEventListener( + 'temp-settings-data-event', + this._updateTempSettingsData + ); + super.disconnectedCallback(); + } render() { - console.log('this.resourceExists', this.resourceExists) return html` - ${this.isSaving || (!this.error && this.resourceExists === undefined) ? html` - - - ` : html` - 0 || this.resourceExists === false ? 'active' : 'notActive'} @click=${()=> { - if(Object.values(this.valuesToBeSavedOnQdn).length > 0 || this.resourceExists === false ){ - this.saveToQdn() - } - // this.isOpen = !this.isOpen - }} style="user-select:none" - >save - 0 || this.resourceExists === false ? get('save.saving3') : get('save.saving2')}> - - `} - - - + ${this.isSaving || + (!this.error && this.resourceExists === undefined) + ? html` + + ` + : html` + 0 || this.resourceExists === false + ? 'active' + : 'notActive'} + @click=${() => { + if ( + Object.values(this.valuesToBeSavedOnQdn) + .length > 0 || + this.resourceExists === false + ) { + if (!this.fee) return; + // this.saveToQdn() + const target = + this.shadowRoot.getElementById( + 'popover-notification' + ); + const popover = + this.shadowRoot.querySelector( + 'popover-component' + ); + if (popover) { + popover.openPopover(target); + } + } + // this.isOpen = !this.isOpen + }} + style="user-select:none" + >save + 0 || + this.resourceExists === false + ? get('save.saving3') + : get('save.saving2')} + > + + +
+

${`${get('walletpage.wchange12')}: ${ + this.fee ? this.fee.feeToShow : '' + }`}

+
+
+
+ + ${translate('save.saving4')} +
+
+ + ${translate('browserpage.bchange28')} +
+
+
+ `} `; } - - } customElements.define('save-settings-qdn', SaveSettingsQdn); diff --git a/core/src/components/notification-view/popover.js b/core/src/components/notification-view/popover.js index 6b835d91..e44d2610 100644 --- a/core/src/components/notification-view/popover.js +++ b/core/src/components/notification-view/popover.js @@ -23,6 +23,8 @@ export class PopoverComponent extends LitElement { margin-left: 10px; color: var(--black) } + + `; static properties = { @@ -65,7 +67,8 @@ export class PopoverComponent extends LitElement { render() { return html` close -
info ${this.message}
+
info ${this.message} +
`; } } diff --git a/core/src/components/show-plugin.js b/core/src/components/show-plugin.js index 0b9097f4..079bbd14 100644 --- a/core/src/components/show-plugin.js +++ b/core/src/components/show-plugin.js @@ -344,6 +344,7 @@ class ShowPlugin extends connect(store)(LitElement) { return html`
${this.tabs.map((tab, index) => { + console.log({tab}) let title = '' let icon = '' let count = 0 @@ -433,9 +434,21 @@ class ShowPlugin extends connect(store)(LitElement) { @click="${() => { this.currentTab = index }}" + @mousedown="${(event) => { + if (event.button === 1) { + event.preventDefault(); + this.removeTab(index, tab.id); + } + }}" >
- ${icon} + ${tab.myPlugObj && tab.myPlugObj.url === "myapp" ? html` + + ` : html` + ${icon} + `} + +
${count ? html` @@ -1028,7 +1041,7 @@ class NavBar extends connect(store)(LitElement) { color: var(--black); --mdc-icon-size: 28px; cursor: pointer; - position: relative + position: relative; z-index: 1; } @@ -1190,6 +1203,7 @@ class NavBar extends connect(store)(LitElement) { this.myFollowedNamesList = [] this.searchContentString = '' this.searchNameResources = [] + this._updateMyMenuPlugins = this._updateMyMenuPlugins.bind(this) } render() { @@ -1456,6 +1470,46 @@ class NavBar extends connect(store)(LitElement) { await this.getMyFollowedNamesList() } + _updateMyMenuPlugins(event) { + const detail = event.detail + console.log({detailPlugs: detail}) + this.myMenuPlugins = detail + const addressInfo = this.addressInfo + const isMinter = addressInfo?.error !== 124 && +addressInfo?.level > 0 + const isSponsor = +addressInfo?.level >= 5 + + + if (!isMinter) { + this.newMenuList = this.myMenuPlugins.filter((minter) => { + return minter.url !== 'minting' + }) + } else { + this.newMenuList = this.myMenuPlugins.filter((minter) => { + return minter.url !== 'become-minter' + }) + } + + if (!isSponsor) { + this.myMenuList = this.newMenuList.filter((sponsor) => { + return sponsor.url !== 'sponsorship-list' + }) + } else { + this.myMenuList = this.newMenuList + } + + this.requestUpdate() + } + + connectedCallback() { + super.connectedCallback() + console.log('callback') + window.addEventListener('myMenuPlugs-event', this._updateMyMenuPlugins) } + + disconnectedCallback() { + window.removeEventListener('myMenuPlugs-event', this._updateMyMenuPlugins) + super.disconnectedCallback() + } + openImportDialog() { this.shadowRoot.getElementById('importTabMenutDialog').show() } @@ -1467,6 +1521,7 @@ class NavBar extends connect(store)(LitElement) { myFile = file const newTabMenu = JSON.parse((myFile) || "[]") localStorage.setItem("myMenuPlugs", JSON.stringify(newTabMenu)) + this.saveSettingToTemp(newTabMenu) this.shadowRoot.getElementById('importTabMenutDialog').close() this.myMenuPlugins = JSON.parse(localStorage.getItem("myMenuPlugs") || "[]") this.firstUpdated() @@ -1951,6 +2006,7 @@ class NavBar extends connect(store)(LitElement) { oldMenuPlugs.push(newMenuPlugsItem) localStorage.setItem("myMenuPlugs", JSON.stringify(oldMenuPlugs)) + this.saveSettingToTemp(oldMenuPlugs) let myplugstring2 = get("walletpage.wchange52") parentEpml.request('showSnackBar', `${myplugstring2}`) @@ -2014,7 +2070,7 @@ class NavBar extends connect(store)(LitElement) { oldMenuPlugs.push(newMenuPlugsItem) localStorage.setItem("myMenuPlugs", JSON.stringify(oldMenuPlugs)) - + this.saveSettingToTemp(oldMenuPlugs) let myplugstring2 = get("walletpage.wchange52") parentEpml.request('showSnackBar', `${myplugstring2}`) @@ -2084,7 +2140,7 @@ class NavBar extends connect(store)(LitElement) { oldMenuPlugs.push(newMenuPlugsItem) localStorage.setItem("myMenuPlugs", JSON.stringify(oldMenuPlugs)) - + this.saveSettingToTemp(oldMenuPlugs) let myplugstring2 = get("walletpage.wchange52") parentEpml.request('showSnackBar', `${myplugstring2}`) @@ -2150,7 +2206,10 @@ class NavBar extends connect(store)(LitElement) { return html`