mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-17 06:14:21 +01:00
Fixes for olympus swaps
This commit is contained in:
committed by
Tony Giorgio
parent
549a810dfd
commit
737280ad37
@@ -47,6 +47,7 @@ export function SwapLightning() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [amountSats, setAmountSats] = createSignal(0n);
|
const [amountSats, setAmountSats] = createSignal(0n);
|
||||||
|
const [invoice, setInvoice] = createSignal("");
|
||||||
const [feeSats, setFeeSats] = createSignal(0n);
|
const [feeSats, setFeeSats] = createSignal(0n);
|
||||||
const [maxFederationBalanceBeforeSwap, setMaxFederationBalanceBeforeSwap] =
|
const [maxFederationBalanceBeforeSwap, setMaxFederationBalanceBeforeSwap] =
|
||||||
createSignal(0n);
|
createSignal(0n);
|
||||||
@@ -69,15 +70,11 @@ export function SwapLightning() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setFeeEstimateWarning(undefined);
|
setFeeEstimateWarning(undefined);
|
||||||
|
|
||||||
if (isMax()) {
|
const result = await sw.sweep_federation_balance_to_invoice(
|
||||||
const result = await sw.sweep_federation_balance(undefined);
|
undefined,
|
||||||
|
invoice()
|
||||||
setSweepResult({ result: result });
|
);
|
||||||
} else {
|
setSweepResult({ result: result });
|
||||||
const result = await sw.sweep_federation_balance(amountSats());
|
|
||||||
|
|
||||||
setSweepResult({ result: result });
|
|
||||||
}
|
|
||||||
|
|
||||||
await vibrateSuccess();
|
await vibrateSuccess();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -129,12 +126,20 @@ export function SwapLightning() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
setFeeEstimateWarning(undefined);
|
setFeeEstimateWarning(undefined);
|
||||||
|
|
||||||
const fee = await sw.estimate_sweep_federation_fee(
|
const mutinyInvoice = await sw.create_sweep_federation_invoice(
|
||||||
isMax() ? undefined : amountSats()
|
isMax() ? undefined : amountSats()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fee) {
|
if (mutinyInvoice.bolt11) {
|
||||||
setFeeSats(fee);
|
setInvoice(mutinyInvoice.bolt11);
|
||||||
|
} else {
|
||||||
|
console.error("No invoice created");
|
||||||
|
// this should never happen
|
||||||
|
throw new Error("No invoice created");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mutinyInvoice.fees_paid) {
|
||||||
|
setFeeSats(mutinyInvoice.fees_paid);
|
||||||
}
|
}
|
||||||
setMaxFederationBalanceBeforeSwap(calculateMaxFederation());
|
setMaxFederationBalanceBeforeSwap(calculateMaxFederation());
|
||||||
|
|
||||||
|
|||||||
@@ -85,24 +85,24 @@ export function Transfer() {
|
|||||||
if (!fromFed()) throw new Error("No from federation");
|
if (!fromFed()) throw new Error("No from federation");
|
||||||
if (!toFed()) throw new Error("No to federation");
|
if (!toFed()) throw new Error("No to federation");
|
||||||
|
|
||||||
if (isMax()) {
|
const mutinyInvoice = await sw.create_sweep_federation_invoice(
|
||||||
const result = await sw.sweep_federation_balance(
|
isMax() ? undefined : amountSats(),
|
||||||
undefined,
|
fromFed()?.federation_id,
|
||||||
fromFed()?.federation_id,
|
toFed()?.federation_id
|
||||||
toFed()?.federation_id
|
);
|
||||||
);
|
|
||||||
|
|
||||||
setTransferResult({ result: result });
|
if (!mutinyInvoice.bolt11) {
|
||||||
} else {
|
// this should never happen
|
||||||
const result = await sw.sweep_federation_balance(
|
throw new Error("No invoice created");
|
||||||
amountSats(),
|
|
||||||
fromFed()?.federation_id,
|
|
||||||
toFed()?.federation_id
|
|
||||||
);
|
|
||||||
|
|
||||||
setTransferResult({ result: result });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = await sw.sweep_federation_balance_to_invoice(
|
||||||
|
fromFed()?.federation_id,
|
||||||
|
mutinyInvoice.bolt11
|
||||||
|
);
|
||||||
|
|
||||||
|
setTransferResult({ result: result });
|
||||||
|
|
||||||
await vibrateSuccess();
|
await vibrateSuccess();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = eify(e);
|
const error = eify(e);
|
||||||
|
|||||||
@@ -1588,18 +1588,17 @@ export async function estimate_sweep_channel_open_fee(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sweep the federation balance into a lightning channel
|
* Sweep the federation balance into a lightning channel
|
||||||
* @param {bigint | undefined} [amount]
|
* @param {string | undefined} [from_federation_id]
|
||||||
|
* @param {string} [invoice]
|
||||||
* @returns {Promise<FedimintSweepResult>}
|
* @returns {Promise<FedimintSweepResult>}
|
||||||
*/
|
*/
|
||||||
export async function sweep_federation_balance(
|
export async function sweep_federation_balance_to_invoice(
|
||||||
amount?: bigint,
|
from_federation_id: string | undefined,
|
||||||
from_federation_id?: string,
|
invoice: string
|
||||||
to_federation_id?: string
|
|
||||||
): Promise<FedimintSweepResult> {
|
): Promise<FedimintSweepResult> {
|
||||||
const result = await wallet!.sweep_federation_balance(
|
const result = await wallet!.sweep_federation_balance_to_invoice(
|
||||||
amount,
|
|
||||||
from_federation_id,
|
from_federation_id,
|
||||||
to_federation_id
|
invoice
|
||||||
);
|
);
|
||||||
return { ...result.value } as FedimintSweepResult;
|
return { ...result.value } as FedimintSweepResult;
|
||||||
}
|
}
|
||||||
@@ -1607,12 +1606,21 @@ export async function sweep_federation_balance(
|
|||||||
/**
|
/**
|
||||||
* Estimate the fee before trying to sweep from federation
|
* Estimate the fee before trying to sweep from federation
|
||||||
* @param {bigint | undefined} [amount]
|
* @param {bigint | undefined} [amount]
|
||||||
* @returns {Promise<bigint | undefined>}
|
* @param {string | undefined} [from_federation_id]
|
||||||
|
* @param {string | undefined} [to_federation_id]
|
||||||
|
* @returns {Promise<MutinyInvoice>}
|
||||||
*/
|
*/
|
||||||
export async function estimate_sweep_federation_fee(
|
export async function create_sweep_federation_invoice(
|
||||||
amount?: bigint
|
amount?: bigint,
|
||||||
): Promise<bigint | undefined> {
|
from_federation_id?: string,
|
||||||
return await wallet!.estimate_sweep_federation_fee(amount);
|
to_federation_id?: string
|
||||||
|
): Promise<MutinyInvoice> {
|
||||||
|
const invoice = await wallet!.create_sweep_federation_invoice(
|
||||||
|
amount,
|
||||||
|
from_federation_id,
|
||||||
|
to_federation_id
|
||||||
|
);
|
||||||
|
return destructureInvoice(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function parse_params(params: string): Promise<PaymentParams> {
|
export async function parse_params(params: string): Promise<PaymentParams> {
|
||||||
|
|||||||
Reference in New Issue
Block a user