From 85448fb7a5a6f7e7a5b1358522830be53ce1e5f1 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Tue, 3 Oct 2023 13:53:25 -0500 Subject: [PATCH] fixes --- src/i18n/en/translations.ts | 7 ++- src/routes/Gift.tsx | 93 +++++++++++++++++++++++++---------- src/routes/settings/Gift.tsx | 18 +++++-- src/routes/settings/index.tsx | 9 ++-- 4 files changed, 94 insertions(+), 33 deletions(-) diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index a5fad6ec..86a4f5d9 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -465,13 +465,16 @@ export default { already_claimed: "This gift has already been claimed", sender_is_poor: "The sender doesn't have enough balance to pay this gift.", + sender_timed_out: + "Gift payment timed out. The sender may be offline, or this gift has already been claimed.", sender_generic_error: "Sender sent error: {{error}}", receive_header: "You've been gifted some sats!", receive_description: - "You must be pretty special. To claim your money just hit the big button. Funds will be added to your balance the next time your gifter is online.", + "You must be pretty special. To claim your money just hit the big button. Funds will be added to this wallet the next time your gifter is online.", receive_claimed: "Gift claimed! You should see the gift hit your balance shortly.", receive_cta: "Claim Gift", + receive_try_again: "Try Again", send_header: "Create Gift", send_explainer: "Give the gift of sats. Create a Mutiny gift URL that can be claimed by anyone with a web browser.", @@ -489,6 +492,8 @@ export default { send_delete_button: "Delete Gift", send_delete_confirm: "Are you sure you want to delete this gift? Is this your rugpull moment?", + send_tip: + "Your copy of Mutiny Wallet needs to be open for the gift to be redeemed.", need_plus: "Upgrade to Mutiny+ to enable gifting. Gifting allows you to create a Mutiny gift URL that can be claimed by anyone with a web browser." } diff --git a/src/routes/Gift.tsx b/src/routes/Gift.tsx index 773e9239..29f6459a 100644 --- a/src/routes/Gift.tsx +++ b/src/routes/Gift.tsx @@ -1,4 +1,12 @@ -import { createResource, createSignal, Match, Show, Switch } from "solid-js"; +import { + createMemo, + createResource, + createSignal, + Match, + Show, + Suspense, + Switch +} from "solid-js"; import { useSearchParams } from "solid-start"; import treasureClosed from "~/assets/treasure-closed.png"; @@ -6,6 +14,7 @@ import treasure from "~/assets/treasure.gif"; import { AmountFiat, AmountSats, + BackLink, Button, ButtonLink, DefaultMain, @@ -24,39 +33,37 @@ import { Network } from "~/logic/mutinyWalletSetup"; import { useMegaStore } from "~/state/megaStore"; import { eify } from "~/utils"; -export default function GiftPage() { +function InboundWarning() { const [state, _] = useMegaStore(); const i18n = useI18n(); - - const [claimSuccess, setClaimSuccess] = createSignal(false); - const [error, setError] = createSignal(); - const [loading, setLoading] = createSignal(false); - const [searchParams] = useSearchParams(); const [inboundCapacity] = createResource(async () => { try { const channels = await state.mutiny_wallet?.list_channels(); - let inbound = 0; + let inbound = 0n; for (const channel of channels) { - inbound += channel.size - (channel.balance + channel.reserve); + inbound = + inbound + + BigInt(channel.size) - + BigInt(channel.balance + channel.reserve); } return inbound; } catch (e) { console.error(e); - return 0; + return 0n; } }); - const warningText = () => { - const amount = Number(searchParams.amount); - - if (isNaN(amount)) { + const warningText = createMemo(() => { + if (isNaN(Number(searchParams.amount))) { return undefined; } + const amount = BigInt(searchParams.amount); + const network = state.mutiny_wallet?.get_network() as Network; const threshold = network === "bitcoin" ? 50000 : 10000; @@ -68,12 +75,31 @@ export default function GiftPage() { }); } - if (amount > (inboundCapacity() || 0)) { + if (inboundCapacity() && inboundCapacity()! > amount) { + return undefined; + } else { return i18n.t("settings.gift.setup_fee_lightning"); } + }); + + return ( + + + {warningText()} + + + ); +} + +export default function GiftPage() { + const [state, _] = useMegaStore(); + const i18n = useI18n(); - return undefined; - }; + const [claimSuccess, setClaimSuccess] = createSignal(false); + const [error, setError] = createSignal(); + const [loading, setLoading] = createSignal(false); + + const [searchParams] = useSearchParams(); async function claim() { const amount = Number(searchParams.amount); @@ -84,7 +110,6 @@ export default function GiftPage() { BigInt(amount), nwc ); - console.log("claim result", claimResult); if (claimResult === "Already Claimed") { throw new Error(i18n.t("settings.gift.already_claimed")); } @@ -105,16 +130,27 @@ export default function GiftPage() { setClaimSuccess(true); } catch (e) { console.error(e); - setError(eify(e)); + const err = eify(e); + if (err.message === "Payment timed out.") { + setError(new Error(i18n.t("settings.gift.sender_timed_out"))); + } else { + setError(err); + } } finally { setLoading(false); } } + async function tryAgain() { + setError(undefined); + await claim(); + } + return ( + @@ -173,12 +209,10 @@ export default function GiftPage() { "settings.gift.receive_description" )} - - - {warningText()} - + + + + @@ -188,6 +222,15 @@ export default function GiftPage() { {i18n.t("common.dangit")} + diff --git a/src/routes/settings/Gift.tsx b/src/routes/settings/Gift.tsx index 3aeef28c..eb41b70e 100644 --- a/src/routes/settings/Gift.tsx +++ b/src/routes/settings/Gift.tsx @@ -55,7 +55,13 @@ export function SingleGift(props: { const i18n = useI18n(); const [state, _actions] = useMegaStore(); - const baseUrl = window.location.origin; + const network = state.mutiny_wallet?.get_network(); + + const baseUrl = + network === "bitcoin" + ? "https://app.mutinywallet.com" + : "https://signet-app.mutinywallet.com"; + const sharableUrl = () => baseUrl.concat(props.profile.url_suffix || ""); const amount = () => props.profile.budget_amount?.toString() || "0"; @@ -198,12 +204,15 @@ export default function GiftPage() { return Number(getValue(giftForm, "amount")) < 50000; }; + const selfHosted = state.mutiny_wallet?.get_network() === "signet"; + const canGift = state.mutiny_plus || selfHosted; + return ( - + {i18n.t("settings.gift.send_header")} @@ -236,6 +245,9 @@ export default function GiftPage() { "settings.gift.send_instructions" )} + + {i18n.t("settings.gift.send_tip")} + - + {i18n.t("settings.gift.send_header")} diff --git a/src/routes/settings/index.tsx b/src/routes/settings/index.tsx index d9ce417e..0d543416 100644 --- a/src/routes/settings/index.tsx +++ b/src/routes/settings/index.tsx @@ -72,13 +72,15 @@ export default function Settings() { // @ts-ignore const COMMIT_HASH = import.meta.env.__COMMIT_HASH__; + const selfHosted = state.settings?.selfhosted === "true"; + return ( {i18n.t("settings.header")} - +