diff --git a/static/components/edit-profile-dialog.js b/static/components/edit-profile-dialog.js index aacfefc..0736695 100644 --- a/static/components/edit-profile-dialog.js +++ b/static/components/edit-profile-dialog.js @@ -50,10 +50,16 @@ window.app.component('edit-profile-dialog', { this.adminkey, config ) + // Publish to Nostr + await LNbits.api.request( + 'PUT', + `/nostrmarket/api/v1/merchant/${this.merchantId}/nostr`, + this.adminkey + ) this.show = false this.$q.notify({ type: 'positive', - message: 'Profile updated!' + message: 'Profile saved and published to Nostr!' }) this.$emit('profile-updated') } catch (error) { diff --git a/static/js/index.js b/static/js/index.js index e570dde..7bad45b 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -18,6 +18,13 @@ window.app = Vue.createApp({ privateKey: null } }, + generateKeyDialog: { + show: false, + privateKey: null, + nsec: null, + npub: null, + showNsec: false + }, wsConnection: null, nostrStatus: { connected: false, @@ -41,9 +48,18 @@ window.app = Vue.createApp({ } }, methods: { - generateKeys: async function () { + generateKeys: function () { const privateKey = nostr.generatePrivateKey() - await this.createMerchant(privateKey) + const publicKey = nostr.getPublicKey(privateKey) + this.generateKeyDialog.privateKey = privateKey + this.generateKeyDialog.nsec = nostr.nip19.nsecEncode(privateKey) + this.generateKeyDialog.npub = nostr.nip19.npubEncode(publicKey) + this.generateKeyDialog.showNsec = false + this.generateKeyDialog.show = true + }, + confirmGenerateKey: async function () { + this.generateKeyDialog.show = false + await this.createMerchant(this.generateKeyDialog.privateKey) }, importKeys: async function () { this.importKeyDialog.show = false @@ -55,11 +71,21 @@ window.app = Vue.createApp({ if (privateKey.toLowerCase().startsWith('nsec')) { privateKey = nostr.nip19.decode(privateKey).data } + // Check if this key is already in use + const publicKey = nostr.getPublicKey(privateKey) + if (this.merchant?.public_key === publicKey) { + this.$q.notify({ + type: 'warning', + message: 'This key is already your current profile' + }) + return + } } catch (error) { this.$q.notify({ type: 'negative', message: `${error}` }) + return } await this.createMerchant(privateKey) }, diff --git a/templates/nostrmarket/components/edit-profile-dialog.html b/templates/nostrmarket/components/edit-profile-dialog.html index 27a4b1e..a447237 100644 --- a/templates/nostrmarket/components/edit-profile-dialog.html +++ b/templates/nostrmarket/components/edit-profile-dialog.html @@ -53,8 +53,13 @@ label="Lightning Address (lud16)" >