Skip to content

Commit

Permalink
feat: error catch amount too low
Browse files Browse the repository at this point in the history
  • Loading branch information
benalleng authored and futurepaul committed Oct 17, 2023
1 parent 951872b commit 1d1fb0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export default {
spendable: "Spendable",
channel_size: "Channel size",
channel_reserve: "- Channel reserve",
error_under_min_lightning:
"Defaulting to On-chain. Amount is too small for your initial Lightning receive.",
error_creating_unified:
"Defaulting to On-chain. Something went wrong when creating the unified address",
error_creating_address:
"Something went wrong when creating the on-chain address",
amount_editable: {
receive_too_small:
"Your first lightning receive needs to be {{amount}} SATS or greater. A setup fee will be deducted from the requested amount.",
Expand Down
15 changes: 12 additions & 3 deletions src/routes/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
VStack
} from "~/components";
import { useI18n } from "~/i18n/context";
import { matchError } from "~/logic/errorDispatch";
import { Network } from "~/logic/mutinyWalletSetup";
import { useMegaStore } from "~/state/megaStore";
import {
Expand Down Expand Up @@ -140,6 +139,7 @@ export default function Receive() {

// loading state for the continue button
const [loading, setLoading] = createSignal(false);
const [error, setError] = createSignal<string>("");

const RECEIVE_FLAVORS = [
{
Expand Down Expand Up @@ -253,8 +253,12 @@ export default function Receive() {
setLoading(false);
return `bitcoin:${raw?.address}?${params}`;
} catch (e) {
showToast(matchError(e));
console.error(e);
if (e === "Satoshi amount is invalid") {
setError(i18n.t("receive.error_under_min_lightning"));
} else {
setError(i18n.t("receive.error_creating_unified"));
}
}

// If we didn't return before this, that means create_bip21 failed
Expand All @@ -271,7 +275,7 @@ export default function Receive() {
return raw?.address;
} catch (e) {
// If THAT failed we're really screwed
showToast(matchError(e));
showToast(eify(i18n.t("receive.error_creating_address")));
console.error(e);
} finally {
setLoading(false);
Expand Down Expand Up @@ -414,6 +418,11 @@ export default function Receive() {
</Match>
<Match when={unified() && receiveState() === "show"}>
<FeeWarning fee={lspFee()} flavor={flavor()} />
<Show when={error()}>
<InfoBox accent="red">
<p>{error()}</p>
</InfoBox>
</Show>
<IntegratedQr
value={receiveString() ?? ""}
amountSats={amount() || "0"}
Expand Down

0 comments on commit 1d1fb0a

Please sign in to comment.