From 97cc7a3e17dba03652f5e2210ac920c44d6cb728 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 18 Jul 2023 17:08:17 +0300 Subject: [PATCH] feat: user logout and data clear --- .../components/user-config/user-config.html | 47 +++++++++++++++++-- static/components/user-config/user-config.js | 16 ++++++- static/js/market.js | 30 +++++++----- templates/nostrmarket/market.html | 3 +- 4 files changed, 77 insertions(+), 19 deletions(-) diff --git a/static/components/user-config/user-config.html b/static/components/user-config/user-config.html index 50da910..ecd5975 100644 --- a/static/components/user-config/user-config.html +++ b/static/components/user-config/user-config.html @@ -1,8 +1,47 @@ -
-
- User Config + +
+
+ + + +
+ +
+ +
-
+ +
+
+ + + +
+ +
+ +
+
+ + + +
+ + +
+
+ No Account +
+
+ \ No newline at end of file diff --git a/static/components/user-config/user-config.js b/static/components/user-config/user-config.js index ae04746..85695d2 100644 --- a/static/components/user-config/user-config.js +++ b/static/components/user-config/user-config.js @@ -2,15 +2,27 @@ async function userConfig(path) { const template = await loadTemplateAsync(path) Vue.component('user-config', { name: 'user-config', - props: ['user',], + props: ['account'], template, data: function () { return { + clearAllData: false } }, methods: { - + logout: async function () { + LNbits.utils + .confirmDialog( + 'Please make sure you save your private key! You will not be able to recover it later!' + ) + .onOk(async () => { + this.$emit('logout', { clearAllData: this.clearAllData }) + }) + }, + copyText(text) { + this.$emit('copy-text', text) + } }, created: async function () { diff --git a/static/js/market.js b/static/js/market.js index a08375d..a56755f 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -306,16 +306,6 @@ const market = async () => { } }, - async deleteAccount() { - await LNbits.utils - .confirmDialog( - `This will delete all stored data. If you didn't backup the Key Pair (Private and Public Keys), you will lose it. Continue?` - ) - .onOk(() => { - window.localStorage.removeItem('nostrmarket.account') - this.account = null - }) - }, async createAccount(useExtension = false) { let nip07 if (useExtension) { @@ -328,9 +318,14 @@ const market = async () => { let { type, data } = NostrTools.nip19.decode(key) key = data } + const privkey = watchOnly ? null : key + const pubkey = watchOnly ? key : NostrTools.getPublicKey(key) this.$q.localStorage.set('nostrmarket.account', { - privkey: watchOnly ? null : key, - pubkey: watchOnly ? key : NostrTools.getPublicKey(key), + privkey, + pubkey, + nsec: NostrTools.nip19.nsecEncode(key), + npub: NostrTools.nip19.npubEncode(pubkey), + useExtension: nip07 ?? false }) this.accountDialog.data = { @@ -929,6 +924,17 @@ const market = async () => { relays: Array.from(this.relays) }) this.copyText(naddr) + }, + + logout(opts) { + window.localStorage.removeItem('nostrmarket.account') + this.account = null + if (opts?.clearAllData) { + this.$q.localStorage.getAllKeys().forEach(key => window.localStorage.removeItem(key)) + window.location.href = window.location.origin + window.location.pathname; + } + + } } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index e30c688..828973d 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -134,7 +134,8 @@ @remove-merchant="removeMerchant" :relays="relays" @add-relay="addRelay" @remove-relay="removeRelay" :config-ui="config?.opts" @ui-config-update="updateUiConfig" @publish-naddr="publishNaddr"> - +