Skip to content

Commit 77a7ab8

Browse files
authored
Merge pull request #170 from lnbits/ui_tweaks
fix: frontend page
2 parents 7771201 + 754003e commit 77a7ab8

File tree

3 files changed

+93
-25
lines changed

3 files changed

+93
-25
lines changed

static/components/merchant-tab.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ window.app.component('merchant-tab', {
3131
},
3232
computed: {
3333
marketClientUrl: function () {
34-
return '/nostrmarket/market'
34+
if (!this.publicKey) {
35+
return '/nostrmarket/market'
36+
}
37+
38+
const url = new URL('/nostrmarket/market', window.location.origin)
39+
url.searchParams.set('merchant', this.publicKey)
40+
return url.pathname + url.search
3541
}
3642
},
3743
methods: {

static/market/js/utils.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
11
var NostrTools = window.NostrTools
22

3+
;(function ensureRandomUUID() {
4+
if (!globalThis.crypto) {
5+
globalThis.crypto = {}
6+
}
7+
if (!globalThis.crypto.randomUUID) {
8+
globalThis.crypto.randomUUID = function () {
9+
const getRandomValues = globalThis.crypto.getRandomValues
10+
if (getRandomValues) {
11+
const bytes = new Uint8Array(16)
12+
getRandomValues.call(globalThis.crypto, bytes)
13+
bytes[6] = (bytes[6] & 0x0f) | 0x40
14+
bytes[8] = (bytes[8] & 0x3f) | 0x80
15+
const hex = Array.from(bytes, b =>
16+
b.toString(16).padStart(2, '0')
17+
).join('')
18+
return (
19+
hex.slice(0, 8) +
20+
'-' +
21+
hex.slice(8, 12) +
22+
'-' +
23+
hex.slice(12, 16) +
24+
'-' +
25+
hex.slice(16, 20) +
26+
'-' +
27+
hex.slice(20)
28+
)
29+
}
30+
31+
let d = Date.now()
32+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
33+
const r = (d + Math.random() * 16) % 16 | 0
34+
d = Math.floor(d / 16)
35+
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16)
36+
})
37+
}
38+
}
39+
})()
40+
341
var defaultRelays = [
442
'wss://relay.damus.io',
543
'wss://relay.snort.social',
@@ -44,13 +82,24 @@ function confirm(message) {
4482

4583

4684
async function hash(string) {
47-
const utf8 = new TextEncoder().encode(string)
48-
const hashBuffer = await crypto.subtle.digest('SHA-256', utf8)
49-
const hashArray = Array.from(new Uint8Array(hashBuffer))
50-
const hashHex = hashArray
51-
.map(bytes => bytes.toString(16).padStart(2, '0'))
52-
.join('')
53-
return hashHex
85+
const subtle = globalThis.crypto && globalThis.crypto.subtle
86+
if (subtle && subtle.digest) {
87+
const utf8 = new TextEncoder().encode(string)
88+
const hashBuffer = await subtle.digest('SHA-256', utf8)
89+
const hashArray = Array.from(new Uint8Array(hashBuffer))
90+
return hashArray.map(bytes => bytes.toString(16).padStart(2, '0')).join('')
91+
}
92+
93+
// Fallback for non-secure contexts where crypto.subtle is unavailable.
94+
return fallbackHash(string)
95+
}
96+
97+
function fallbackHash(string) {
98+
let hash = 5381
99+
for (let i = 0; i < string.length; i++) {
100+
hash = ((hash << 5) + hash) + string.charCodeAt(i)
101+
}
102+
return (hash >>> 0).toString(16).padStart(8, '0')
54103
}
55104

56105
function isJson(str) {

templates/nostrmarket/components/merchant-tab.html

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@
99
</div>
1010
</div>
1111
<div class="row q-mb-md q-gutter-sm">
12-
<q-btn
13-
outline
14-
color="primary"
15-
@click="showEditProfileDialog = true"
16-
icon="edit"
17-
>Edit</q-btn
18-
>
19-
<q-btn
20-
outline
21-
color="primary"
22-
icon="qr_code"
23-
@click="showKeysDialog = true"
24-
>
25-
<q-tooltip>Show Keys</q-tooltip>
26-
</q-btn>
2712
<q-btn-dropdown
2813
split
2914
outline
3015
color="primary"
31-
icon="swap_horiz"
32-
label="Switch"
16+
icon="vpn_key"
17+
label="Keys"
3318
>
3419
<q-list>
20+
<q-item clickable v-close-popup @click="showKeysDialog = true">
21+
<q-item-section avatar>
22+
<q-icon name="vpn_key" color="primary"></q-icon>
23+
</q-item-section>
24+
<q-item-section>
25+
<q-item-label>View Keys</q-item-label>
26+
<q-item-label caption
27+
>Show public/private keys</q-item-label
28+
>
29+
</q-item-section>
30+
</q-item>
31+
<q-separator></q-separator>
3532
<q-item-label header>Saved Profiles</q-item-label>
3633
<q-item>
3734
<q-item-section avatar>
@@ -88,6 +85,13 @@
8885
</q-item>
8986
</q-list>
9087
</q-btn-dropdown>
88+
<q-btn
89+
outline
90+
color="primary"
91+
@click="showEditProfileDialog = true"
92+
icon="edit"
93+
label="Edit Profile"
94+
></q-btn>
9195
<q-btn-dropdown
9296
split
9397
outline
@@ -140,6 +144,15 @@
140144
</q-item>
141145
</q-list>
142146
</q-btn-dropdown>
147+
<q-btn
148+
outline
149+
color="primary"
150+
icon="storefront"
151+
label="Marketplace"
152+
:href="marketClientUrl"
153+
target="_blank"
154+
rel="noopener"
155+
></q-btn>
143156
</div>
144157
</q-card-section>
145158

0 commit comments

Comments
 (0)