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)" >
- SaveSave & Publish Cancel
diff --git a/templates/nostrmarket/components/merchant-tab.html b/templates/nostrmarket/components/merchant-tab.html index 5725de3..711f447 100644 --- a/templates/nostrmarket/components/merchant-tab.html +++ b/templates/nostrmarket/components/merchant-tab.html @@ -24,13 +24,6 @@ > Show Keys - Publish Saved Profiles - + - - - - - Multi-profile support coming soon - + + + Remove profile + @@ -87,23 +86,6 @@ Create a fresh nsec - - - - - - - Remove - - Remove this nPub from the DB - - + + + + +
Generate New Key
+
+
Public Key (npub)
+ + + +
+
+
+ + Private Key (nsec) +
+ + + +
+ + Never share your private key! +
+
+
+ Create Merchant + Cancel +
+
+
{% endblock%}{% block scripts %} {{ window_vars(user) }} diff --git a/views_api.py b/views_api.py index ad7659e..1e9f5c5 100644 --- a/views_api.py +++ b/views_api.py @@ -98,9 +98,6 @@ async def api_create_merchant( merchant = await get_merchant_by_pubkey(data.public_key) assert merchant is None, "A merchant already uses this public key" - merchant = await get_merchant_for_user(wallet.wallet.user) - assert merchant is None, "A merchant already exists for this user" - merchant = await create_merchant(wallet.wallet.user, data) await create_zone(