log command results.

This commit is contained in:
fiatjaf
2023-06-16 17:29:08 -03:00
parent 5ee33f07b8
commit b390540b00
2 changed files with 31 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "nos2x", "name": "nos2x",
"description": "Nostr Signer Extension", "description": "Nostr Signer Extension",
"version": "2.0.3", "version": "2.1.0",
"homepage_url": "https://github.com/fiatjaf/nos2x", "homepage_url": "https://github.com/fiatjaf/nos2x",
"manifest_version": 3, "manifest_version": 3,
"icons": { "icons": {

View File

@@ -27,8 +27,23 @@ window.nostr = {
}, },
_call(type, params) { _call(type, params) {
let id = Math.random().toString().slice(-4)
console.log(
'%c[nos2x:%c' +
id +
'%c]%c calling %c' +
type +
'%c with %c' +
JSON.stringify(params || {}),
'background-color:#f1b912;font-weight:bold;color:white',
'background-color:#f1b912;font-weight:bold;color:#a92727',
'background-color:#f1b912;color:white;font-weight:bold',
'color:auto',
'font-weight:bold;color:#08589d;font-family:monospace',
'color:auto',
'font-weight:bold;color:#90b12d;font-family:monospace'
)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let id = Math.random().toString().slice(4)
this._requests[id] = {resolve, reject} this._requests[id] = {resolve, reject}
window.postMessage( window.postMessage(
{ {
@@ -61,6 +76,20 @@ window.addEventListener('message', message => {
window.nostr._requests[message.data.id].resolve(message.data.response) window.nostr._requests[message.data.id].resolve(message.data.response)
} }
console.log(
'%c[nos2x:%c' +
message.data.id +
'%c]%c result: %c' +
JSON.stringify(
message?.data?.response || message?.data?.response?.error?.message || {}
),
'background-color:#f1b912;font-weight:bold;color:white',
'background-color:#f1b912;font-weight:bold;color:#a92727',
'background-color:#f1b912;color:white;font-weight:bold',
'color:auto',
'font-weight:bold;color:#08589d'
)
delete window.nostr._requests[message.data.id] delete window.nostr._requests[message.data.id]
}) })