Repository: BoltzExchange/boltz-web-app
Pull request #885: fix: urlParam `receiveAsset` not working
Author: login: kiocos
Created: 2025-04-05T21:20:33Z | Merged: 2025-04-06T11:58:43Z

Closes #884

The problem occurred when`setDestination` returned `destinationAsset` as `null`, but the `if` checked if `destinationAsset` was `undefined`.
https://github.com/BoltzExchange/boltz-web-app/blob/cb62f517c97cf35e798922b79feaa8900cd88f16/src/context/Create.tsx#L88-L100

Fixed by returning `destinationAsset` as `undefined` (instead of redefining it as `null`) and added unit tests covering this scenario.

Linked issue #884: URL Params: setting `receiveAsset` doesn't work anymore
`receiveAsset` is ignored, test e.g. with https://boltz.exchange/?sendAsset=BTC&receiveAsset=RBTC . Likely that https://github.com/BoltzExchange/boltz-web-app/blob/main/src%2Fcontext%2FCreate.tsx#L100-L101 bricked it. Let's fix it and add tests for all URL params.
Linked issue comments: user: login: kilrau
created_at: 2025-04-05T09:15:53Z
body: @kiocosta 
author_association: MEMBER
user: login: kiocos
created_at: 2025-04-05T13:54:59Z
body: Working on it!
author_association: MEMBER

Diff:
diff --git a/src/context/Create.tsx b/src/context/Create.tsx
index 25bdc3db2..b4514345c 100644
--- a/src/context/Create.tsx
+++ b/src/context/Create.tsx
@@ -23,7 +23,7 @@ const setDestination = (
     setAssetReceive: Setter<string>,
     setInvoice: Setter<string>,
     setOnchainAddress: Setter<string>,
-): { destinationAsset: string | null; destination: string | null } => {
+): { destinationAsset?: string; destination?: string } => {
     const isValidForAsset = (
         asset: typeof BTC | typeof LBTC,
         address: string,
@@ -58,7 +58,7 @@ const setDestination = (
         }
     }
 
-    return { destinationAsset: null, destination: null };
+    return { destinationAsset: undefined, destination: undefined };
 };
 
 const isValidAsset = (asset: string) =>
diff --git a/tests/context/Create.spec.tsx b/tests/context/Create.spec.tsx
index aa59ee28d..82f3879a2 100644
--- a/tests/context/Create.spec.tsx
+++ b/tests/context/Create.spec.tsx
@@ -1,6 +1,6 @@
 import { render } from "@solidjs/testing-library";
 
-import { BTC, LBTC, LN } from "../../src/consts/Assets";
+import { BTC, LBTC, LN, RBTC } from "../../src/consts/Assets";
 import { SwapType } from "../../src/consts/Enums";
 import { TestComponent, contextWrapper, signals } from "../helper";
 
@@ -39,4 +39,56 @@ describe("signals", () => {
             expect(signals.valid()).toEqual(valid);
         },
     );
+
+    test.each`
+        sendAsset | receiveAsset | amount
+        ${BTC}    | ${LBTC}      | ${1000000}
+        ${BTC}    | ${RBTC}      | ${0}
+        ${LN}     | ${RBTC}      | ${1000000}
+        ${LN}     | ${BTC}       | ${0}
+        ${LBTC}   | ${LN}        | ${1000000}
+        ${LBTC}   | ${BTC}       | ${0}
+        ${RBTC}   | ${BTC}       | ${1000000}
+        ${RBTC}   | ${LN}        | ${0}
+    `(
+        "should set assets $sendAsset > $receiveAsset based on urlParams",
+        ({ sendAsset, receiveAsset, amount }) => {
+            vi.spyOn(URLSearchParams.prototype, "get").mockImplementation(
+                (key) => {
+                    if (key === "sendAsset") return sendAsset as string;
+                    if (key === "receiveAsset") return receiveAsset as string;
+                    if (key === "sendAmount") return amount as string;
+                    return null;
+                },
+            );
+
+            render(() => <TestComponent />, { wrapper: contextWrapper });
+
+            expect(signals.assetSend()).toEqual(sendAsset);
+            expect(signals.assetReceive()).toEqual(receiveAsset);
+            expect(Number(signals.sendAmount())).toEqual(amount);
+        },
+    );
+
+    test.each`
+        receiveAsset | destination                                                                                                | expectedReceiveAsset
+        ${BTC}       | ${"test@lnurl.com"}                                                                                        | ${LN}
+        ${LBTC}      | ${"bcrt1qgzzhsnvstqjd5nyr0u6fz706up6ap0jy4ajs3x"}                                                          | ${BTC}
+        ${BTC}       | ${"el1qqd60krw3zqwdg97gs4skuqjf05lgf6jht3w8fsg0hyhtyv203yqnjuhnd96t0an6nz8e35n0ndqh0rvmaq5g7dj999pl26nwr"} | ${LBTC}
+    `(
+        "should have destination taking precedence over receiveAsset",
+        ({ receiveAsset, destination, expectedReceiveAsset }) => {
+            vi.spyOn(URLSearchParams.prototype, "get").mockImplementation(
+                (key) => {
+                    if (key === "receiveAsset") return receiveAsset as string;
+                    if (key === "destination") return destination as string;
+                    return null;
+                },
+            );
+
+            render(() => <TestComponent />, { wrapper: contextWrapper });
+
+            expect(signals.assetReceive()).toEqual(expectedReceiveAsset);
+        },
+    );
 });


Reviews:
user: login: kilrau
body: tACK
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-06T09:08:15Z
user: login: michael1011
body: Works but needs the correct return type
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-06T09:09:06Z
user: login: kiocos
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-06T11:30:00Z
user: login: michael1011
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-06T11:58:03Z

Review comments:
diff_hunk: @@ -23,7 +23,7 @@ const setDestination = (
     setAssetReceive: Setter<string>,
     setInvoice: Setter<string>,
     setOnchainAddress: Setter<string>,
-): { destinationAsset: string | null; destination: string | null } => {
+): { destinationAsset: string; destination: string } => {
path: src/context/Create.tsx
user: login: michael1011
body: ```suggestion
): { destinationAsset?: string; destination?: string } => {
```
created_at: 2025-04-06T09:08:41Z
author_association: MEMBER
diff_hunk: @@ -23,7 +23,7 @@ const setDestination = (
     setAssetReceive: Setter<string>,
     setInvoice: Setter<string>,
     setOnchainAddress: Setter<string>,
-): { destinationAsset: string | null; destination: string | null } => {
+): { destinationAsset: string; destination: string } => {
path: src/context/Create.tsx
user: login: kiocos
body: @michael1011 fixed :)
created_at: 2025-04-06T11:30:00Z
author_association: MEMBER

PR comments:
user: login: vercel[bot]
created_at: 2025-04-05T21:20:36Z
body: @kiocosta is attempting to deploy a commit to the **boltz** Team on [Vercel](https://vercel.com).

A member of the Team first needs to [authorize it](https://vercel.com/git/authorize?team=boltz&type=github&job=%7B%22headInfo%22%3A%7B%22sha%22%3A%22cb62f517c97cf35e798922b79feaa8900cd88f16%22%7D%2C%22id%22%3A%22QmRg1uiGbBazhAFKfDZjvaMwDJ2tQzNxsXEohB1DFrCB8S%22%2C%22org%22%3A%22BoltzExchange%22%2C%22prId%22%3A885%2C%22repo%22%3A%22boltz-web-app%22%7D).


author_association: NONE
user: login: vercel[bot]
created_at: 2025-04-06T09:05:26Z
body: [vc]: #o1uNjiuXluyP4mcYfpr1Dtk7UtZ39j6nSLa3G1k45Os=:eyJpc01vbm9yZXBvIjp0cnVlLCJ0eXBlIjoiZ2l0aHViIiwicHJvamVjdHMiOlt7Im5hbWUiOiJ3ZWJhcHAiLCJyb290RGlyZWN0b3J5IjpudWxsLCJpbnNwZWN0b3JVcmwiOiJodHRwczovL3ZlcmNlbC5jb20vYm9sdHovd2ViYXBwL0VwZkdmRUdUcVFkS25VUXB1Vm5rUHRTdlJudjIiLCJwcmV2aWV3VXJsIjoid2ViYXBwLWdpdC1mb3JrLWtpb2Nvc3RhLWZpeC1yZWNlaXZlLWFzc2V0LWJvbHR6LnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifSx7Im5hbWUiOiJ3ZWJhcHAtbWFpbm5ldCIsInJvb3REaXJlY3RvcnkiOm51bGwsImluc3BlY3RvclVybCI6Imh0dHBzOi8vdmVyY2VsLmNvbS9ib2x0ei93ZWJhcHAtbWFpbm5ldC81bXFjSnBUR01mb0RTRTZXMW93V003Z01lRGZkIiwicHJldmlld1VybCI6IndlYmFwcC1tYWlubmV0LWdpdC1mb3JrLWtpb2Nvc3RhLWZpeC1yZWNlaXZlLWFzc2V0LWJvbHR6LnZlcmNlbC5hcHAiLCJuZXh0Q29tbWl0U3RhdHVzIjoiREVQTE9ZRUQifV19
**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)

| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------ |
| **webapp** | ✅ Ready ([Inspect](https://vercel.com/boltz/webapp/EpfGfEGTqQdKnUQpuVnkPtSvRnv2)) | [Visit Preview](https://webapp-git-fork-kiocosta-fix-receive-asset-boltz.vercel.app) | Apr 6, 2025 11:57am |
| **webapp-mainnet** | ✅ Ready ([Inspect](https://vercel.com/boltz/webapp-mainnet/5mqcJpTGMfoDSE6W1owWM7gMeDfd)) | [Visit Preview](https://webapp-mainnet-git-fork-kiocosta-fix-receive-asset-boltz.vercel.app) | Apr 6, 2025 11:57am |



author_association: NONE