Skip to content

Commit

Permalink
throw error if faucet fails
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed May 9, 2024
1 parent f27e871 commit cfce841
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
30 changes: 16 additions & 14 deletions e2e/roundtrip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,23 @@ test("rountrip receive and send", async ({ page }) => {
// The SVG's value property includes "lightning:l"
expect(value).toContain("lightning:l");

const lightningInvoice = value?.split("lightning:")[1];

// Post the lightning invoice to the server
const _response = await fetch(
"https://faucet.mutinynet.com/api/lightning",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
bolt11: lightningInvoice
})
}
);
const response = await fetch("https://faucet.mutinynet.com/api/lightning", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
bolt11: value
})
});

if (!response.ok) {
response.text().then((text) => {
throw new Error("failed to post invoice to faucet: " + text);
});
}

// Wait for an h1 to appear in the dom that says "Payment Received"
await page.waitForSelector("text=Payment Received", { timeout: 30000 });
Expand Down
2 changes: 1 addition & 1 deletion src/components/FederationPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function FederationPopup() {

return (
<SimpleDialog
title={i18n.t("activity.federation_message")}
title={`${i18n.t("activity.federation_message")}: ${state.expiration_warning?.federationName}`}
open={showFederationExpirationWarning()}
setOpen={(open: boolean) => {
if (!open) {
Expand Down
24 changes: 19 additions & 5 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export const makeMegaStoreContext = () => {
federations: undefined as MutinyFederationIdentity[] | undefined,
balanceView: localStorage.getItem("balanceView") || "sats",
expiration_warning: undefined as
| { expiresTimestamp: number; expiresMessage: string }
| {
expiresTimestamp: number;
expiresMessage: string;
federationName: string;
}
| undefined,
expiration_warning_seen: false
});
Expand Down Expand Up @@ -233,14 +237,19 @@ export const makeMegaStoreContext = () => {
const federations = await sw.list_federations();

let expiration_warning:
| { expiresTimestamp: number; expiresMessage: string }
| {
expiresTimestamp: number;
expiresMessage: string;
federationName: string;
}
| undefined = undefined;

federations.forEach((f) => {
if (f.popup_countdown_message && f.popup_end_timestamp) {
expiration_warning = {
expiresTimestamp: f.popup_end_timestamp,
expiresMessage: f.popup_countdown_message
expiresMessage: f.popup_countdown_message,
federationName: f.federation_name
};
}
});
Expand Down Expand Up @@ -485,14 +494,19 @@ export const makeMegaStoreContext = () => {
const federations = await sw.list_federations();

let expiration_warning:
| { expiresTimestamp: number; expiresMessage: string }
| {
expiresTimestamp: number;
expiresMessage: string;
federationName: string;
}
| undefined = undefined;

federations.forEach((f) => {
if (f.popup_countdown_message && f.popup_end_timestamp) {
expiration_warning = {
expiresTimestamp: f.popup_end_timestamp,
expiresMessage: f.popup_countdown_message
expiresMessage: f.popup_countdown_message,
federationName: f.federation_name
};
}
});
Expand Down

0 comments on commit cfce841

Please sign in to comment.