Skip to content

Commit

Permalink
handle case where user denies permission to sign event
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSamskies committed May 16, 2023
1 parent 21dd16b commit 896e838
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ you can specify relays that you'd like the zap receipt published to using a `dat

Add this script tag right before the bottom closing body tag.
```js
<script src="https://cdn.jsdelivr.net/npm/[email protected].6"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].7"></script>
```

Example Sandbox: https://codesandbox.io/s/nostr-zap-from-anywhere-poc-wiyzgm
60 changes: 33 additions & 27 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,20 @@ const renderAmountDialog = async (npub, relays) => {
const dialogHeaderContainer = amountDialog.querySelector(
".dialog-header-container"
);
const handleError = (error) => {
amountDialog.close();

const errorDialog = renderErrorDialog(error, npub);

errorDialog.showModal();
};

getDialogHeader()
.then((htmlString) => {
dialogHeaderContainer.innerHTML = htmlString;
zapButtton.disabled = false;
})
.catch((error) => {
amountDialog.close();

const errorDialog = renderErrorDialog(error, npub);

errorDialog.showModal();
});
.catch(handleError);

const setZapButtonToLoadingState = () => {
zapButtton.disabled = true;
Expand Down Expand Up @@ -194,27 +195,32 @@ const renderAmountDialog = async (npub, relays) => {

const amount = Number(amountInput.value) * 1000;
const comment = commentInput.value;
const zapEvent = await makeZapEvent({
profile: authorId,
amount,
relays: normalizedRelays,
comment,
});
const invoice = await fetchInvoice({
zapEvent,
zapEndpoint: await zapEndpoint,
amount,
comment,
});
const invoiceDialog = renderInvoiceDialog({
dialogHeader: await getDialogHeader(),
invoice,
});
const openWalletButton = invoiceDialog.querySelector(".cta-button");

amountDialog.close();
invoiceDialog.showModal();
openWalletButton.focus();
try {
const zapEvent = await makeZapEvent({
profile: authorId,
amount,
relays: normalizedRelays,
comment,
});
const invoice = await fetchInvoice({
zapEvent,
zapEndpoint: await zapEndpoint,
amount,
comment,
});
const invoiceDialog = renderInvoiceDialog({
dialogHeader: await getDialogHeader(),
invoice,
});
const openWalletButton = invoiceDialog.querySelector(".cta-button");

amountDialog.close();
invoiceDialog.showModal();
openWalletButton.focus();
} catch (error) {
handleError(error);
}
});

return amountDialog;
Expand Down

0 comments on commit 896e838

Please sign in to comment.