Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix: only allow using alby shared balance to fund a channel if runnin…
Browse files Browse the repository at this point in the history
…g LDK backend (#557)
  • Loading branch information
rolznz authored Jul 2, 2024
1 parent 202daef commit 9294553
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions frontend/src/screens/onboarding/MigrateAlbyFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function MigrateAlbyFunds() {
const { data: albyMe } = useAlbyMe();
const { data: albyBalance } = useAlbyBalance();
const { data: csrf } = useCSRF();
const { data: info } = useInfo();
const { data: channels } = useChannels(true);
const { mutate: refetchInfo } = useInfo();
const { toast } = useToast();
Expand All @@ -44,6 +45,17 @@ export default function MigrateAlbyFunds() {
const requestWrappedInvoice = React.useCallback(
async (amount: number) => {
try {
if (!info) {
throw new Error("Info not loaded");
}
// other node implementations may not work / may not support 0-conf.
// so for now we are not allowing other backend types.
// They can open a channel with a different method and then migrate
// their shared funds once they have enough receiving capacity.
if (info.backendType !== "LDK") {
throw new Error("Only LDK backend is supported");
}

if (!channels) {
throw new Error("Channels not loaded");
}
Expand Down Expand Up @@ -77,7 +89,7 @@ export default function MigrateAlbyFunds() {
setError("Failed to connect to request wrapped invoice: " + error);
}
},
[channels, csrf]
[channels, csrf, info]
);

const payWrappedInvoice = React.useCallback(
Expand Down Expand Up @@ -114,7 +126,7 @@ export default function MigrateAlbyFunds() {
);

React.useEffect(() => {
if (hasRequestedInvoice || !channels || !albyMe || !albyBalance) {
if (hasRequestedInvoice || !info || !channels || !albyMe || !albyBalance) {
return;
}
setRequestedInvoice(true);
Expand All @@ -129,6 +141,7 @@ export default function MigrateAlbyFunds() {
albyBalance,
channels,
albyMe,
info,
requestWrappedInvoice,
]);

Expand Down

0 comments on commit 9294553

Please sign in to comment.