aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-05 16:44:55 -0800
committerAdam Soltys <[email protected]>2026-02-11 15:34:32 -0800
commitcf1d8029efc1f9497bcef71b5c959c42794f3566 (patch)
treeb3a9658e7e426a82a545477df0414bc6b61509f2 /src/lib
parented4d86167d32503ad8813c81dda9591d1b1b8190 (diff)
downloadcoinos-ui-cf1d8029efc1f9497bcef71b5c959c42794f3566.tar.gz
coinos-ui-cf1d8029efc1f9497bcef71b5c959c42794f3566.zip
payment forwarding
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ark.ts29
-rw-r--r--src/lib/parse.ts2
2 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/ark.ts b/src/lib/ark.ts
index 26c16a93..25122a8c 100644
--- a/src/lib/ark.ts
+++ b/src/lib/ark.ts
@@ -53,11 +53,38 @@ export const syncTransactions = async (aid: string) => {
return post("/post/ark/sync", { transactions, aid });
};
+export const vtxoKey = (v: { txid: string; vout: number }) =>
+ `${v.txid}:${v.vout}`;
+
+export const getProcessedVtxos = (): Set<string> => {
+ try {
+ return new Set(
+ JSON.parse(localStorage.getItem("processedArkVtxos") || "[]"),
+ );
+ } catch {
+ return new Set();
+ }
+};
+
+export const addProcessedVtxos = (keys: string[]) => {
+ const processed = getProcessedVtxos();
+ for (const k of keys) processed.add(k);
+ const arr = [...processed].slice(-200);
+ localStorage.setItem("processedArkVtxos", JSON.stringify(arr));
+};
+
export const sendArk = async (address: string, amount: number) => {
const wallet = await getWallet();
if (!wallet) throw new Error("Ark wallet not available");
- return wallet.sendBitcoin({ address, amount });
+ const txid = await wallet.sendBitcoin({ address, amount });
+
+ // Mark post-send VTXOs as processed so notifyIncomingFunds
+ // ignores change VTXOs from this send
+ const vtxos = await wallet.getVtxos({ spendableOnly: false });
+ if (vtxos?.length) addProcessedVtxos(vtxos.map(vtxoKey));
+
+ return txid;
};
export const settle = async () => {
diff --git a/src/lib/parse.ts b/src/lib/parse.ts
index 8520c27a..3249b9db 100644
--- a/src/lib/parse.ts
+++ b/src/lib/parse.ts
@@ -72,8 +72,10 @@ export default async (s, host, cookies) => {
invoice = { id: iid };
} else if (t.toLowerCase().startsWith("ln")) {
try {
+ const aid = cookies.get("aid");
invoice = await get(`/invoice/${t}`);
if (invoice.user.username === "mint") throw new Error("mint payment");
+ if (aid && aid !== invoice.aid) throw new Error("cross-account");
} catch (e) {
if (t.toLowerCase().startsWith("lno")) {
const { offer_amount_msat: a } = await get(`/decode/${t}`);