From 0fe9712b45c8591d8161b36a157c38441a40f2d5 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 13 Mar 2023 15:48:32 +0000 Subject: [PATCH] allow for nip19 for account --- static/js/market.js | 15 +++++++++++---- templates/nostrmarket/market.html | 5 +++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/static/js/market.js b/static/js/market.js index 575d905..ff5a07f 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -91,9 +91,12 @@ const market = async () => { return window.nostr }, isValidKey() { - return this.accountDialog.data.key - ?.toLowerCase() - ?.match(/^[0-9a-f]{64}$/) + let key = this.accountDialog.data.key + if (key && key.startsWith('n')) { + let {type, data} = NostrTools.nip19.decode(key) + key = data + } + return key?.toLowerCase()?.match(/^[0-9a-f]{64}$/) } }, async created() { @@ -176,6 +179,10 @@ const market = async () => { } if (this.isValidKey) { let {key, watchOnly} = this.accountDialog.data + if (key.startsWith('n')) { + let {type, data} = NostrTools.nip19.decode(key) + key = data + } this.$q.localStorage.set('diagonAlley.account', { privkey: watchOnly ? null : key, pubkey: watchOnly ? key : NostrTools.getPublicKey(key), @@ -247,7 +254,7 @@ const market = async () => { this.events.map(eventToObj).map(e => { if (e.kind == 0) { this.profiles.set(e.pubkey, e.content) - if (e.pubkey == this.account.pubkey) { + if (e.pubkey == this.account?.pubkey) { this.accountMetadata = this.profiles.get(this.account.pubkey) } return diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index fa95ac7..4784483 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -216,11 +216,12 @@