Fix pubkey sign in.
Added try/catch and updated awaits for async methods in regards to sign in attempts. This appears to resolve some race conditions with nos2x extension. More testing to be performed.
This commit is contained in:
parent
51ab5aae2a
commit
7ce72540cf
3 changed files with 21 additions and 12 deletions
|
@ -391,7 +391,7 @@ details.cw summary {
|
||||||
-webkit-backdrop-filter: blur(20px);
|
-webkit-backdrop-filter: blur(20px);
|
||||||
}
|
}
|
||||||
.modal.scrollable {
|
.modal.scrollable {
|
||||||
overflow: scroll;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
.modal.closed {
|
.modal.closed {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|
23
js/main.js
23
js/main.js
|
@ -30,19 +30,18 @@ addEventListener('DOMContentLoaded', (ev) => {
|
||||||
|
|
||||||
async function damus_web_init() {
|
async function damus_web_init() {
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
function init() {
|
const max_wait = 500;
|
||||||
// only wait for 500ms max
|
const interval = 20;
|
||||||
const max_wait = 500;
|
async function init() {
|
||||||
const interval = 20;
|
|
||||||
if (window.nostr || tries >= (max_wait/interval)) {
|
if (window.nostr || tries >= (max_wait/interval)) {
|
||||||
log_info("init after", tries);
|
log_info("init after", tries);
|
||||||
damus_web_init_ready();
|
await damus_web_init_ready();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tries++;
|
tries++;
|
||||||
setTimeout(init, interval);
|
await init();
|
||||||
}
|
}
|
||||||
init();
|
setTimeout(init, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function damus_web_init_ready() {
|
async function damus_web_init_ready() {
|
||||||
|
@ -60,13 +59,19 @@ async function damus_web_init_ready() {
|
||||||
|
|
||||||
async function signin() {
|
async function signin() {
|
||||||
const model = DAMUS;
|
const model = DAMUS;
|
||||||
model.pubkey = await get_pubkey();
|
try {
|
||||||
|
model.pubkey = await get_pubkey();
|
||||||
|
} catch (err) {
|
||||||
|
window.alert("An error occured trying to get your public key.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!model.pubkey) {
|
if (!model.pubkey) {
|
||||||
|
window.alert("No public key was aquired.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
find_node("#container-welcome").classList.add("hide");
|
find_node("#container-welcome").classList.add("hide");
|
||||||
find_node("#container-app").classList.remove("hide");
|
find_node("#container-app").classList.remove("hide");
|
||||||
webapp_init();
|
await webapp_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function webapp_init() {
|
async function webapp_init() {
|
||||||
|
|
|
@ -245,9 +245,13 @@ async function get_pubkey(use_prompt=true) {
|
||||||
return pubkey
|
return pubkey
|
||||||
if (window.nostr && window.nostr.getPublicKey) {
|
if (window.nostr && window.nostr.getPublicKey) {
|
||||||
log_debug("calling window.nostr.getPublicKey()...")
|
log_debug("calling window.nostr.getPublicKey()...")
|
||||||
const pubkey = await window.nostr.getPublicKey()
|
try {
|
||||||
|
pubkey = await window.nostr.getPublicKey()
|
||||||
|
return await handle_pubkey(pubkey)
|
||||||
|
} catch (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
log_debug("got %s pubkey from nos2x", pubkey)
|
log_debug("got %s pubkey from nos2x", pubkey)
|
||||||
return await handle_pubkey(pubkey)
|
|
||||||
}
|
}
|
||||||
if (!use_prompt)
|
if (!use_prompt)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue