-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from BoltzExchange/feat-url-params-3
feat: improve embedding of swapbox
- Loading branch information
Showing
11 changed files
with
323 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
description: >- | ||
To prefill certain inputs of the the site, URL query parameters can be used. | ||
Those parameters are documented here. | ||
--- | ||
|
||
# URL query parameters | ||
|
||
## Embedding | ||
|
||
When `embed` is set to `1`, only the swap box will be shown. | ||
|
||
## Destination | ||
|
||
`destination` prefills either the onchain address or invoice input field. The | ||
inferred asset takes precedence over `receiveAsset` and in case a lightning | ||
invoice is set, its amount takes precedence over all other inputs to set the | ||
amount. | ||
|
||
## Assets | ||
|
||
`sendAsset` and `receiveAsset` can be used to set the assets. Possible values | ||
are: | ||
|
||
- `LN` | ||
- `BTC` | ||
- `L-BTC` | ||
- `RBTC` | ||
|
||
## Amounts | ||
|
||
`sendAmount` or `receiveAmount` set the respective amounts. Value is denominated | ||
in satoshis and `sendAmount` takes precedence. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import BigNumber from "bignumber.js"; | ||
|
||
import { Denomination } from "../src/consts/Enums"; | ||
import { formatAmount } from "../src/utils/denomination"; | ||
import { | ||
generateInvoiceLnd, | ||
getBitcoinAddress, | ||
getLiquidAddress, | ||
} from "./utils"; | ||
|
||
test.describe("URL params", () => { | ||
test("BTC address destination", async ({ page }) => { | ||
const address = await getBitcoinAddress(); | ||
|
||
await page.goto(`/?destination=${address}`); | ||
const receiveAsset = page.locator(".asset-BTC"); | ||
expect(receiveAsset).toBeDefined(); | ||
|
||
const onchainAddress = page.getByTestId("onchainAddress"); | ||
await expect(onchainAddress).toHaveValue(address); | ||
}); | ||
|
||
test("L-BTC address destination", async ({ page }) => { | ||
const address = await getLiquidAddress(); | ||
|
||
await page.goto(`/?destination=${address}`); | ||
const receiveAsset = page.locator(".asset-L-BTC"); | ||
expect(receiveAsset).toBeDefined(); | ||
|
||
const onchainAddress = page.getByTestId("onchainAddress"); | ||
await expect(onchainAddress).toHaveValue(address); | ||
}); | ||
|
||
test("Lightning invoice destination", async ({ page }) => { | ||
const amount = 100_000; | ||
const invoice = await generateInvoiceLnd(amount); | ||
|
||
await page.goto(`/?destination=${invoice}`); | ||
const receiveAsset = page.locator(".asset-LN"); | ||
expect(receiveAsset).toBeDefined(); | ||
|
||
const invoiceInput = page.getByTestId("invoice"); | ||
await expect(invoiceInput).toHaveValue(invoice); | ||
|
||
const receiveAmount = page.getByTestId("receiveAmount"); | ||
await expect(receiveAmount).toHaveValue( | ||
formatAmount(BigNumber(amount), Denomination.Sat, "."), | ||
); | ||
}); | ||
|
||
test("should set send amount", async ({ page }) => { | ||
const amount = 210_000; | ||
await page.goto(`/?sendAmount=${amount}`); | ||
|
||
const sendAmount = page.getByTestId("sendAmount"); | ||
await expect(sendAmount).toHaveValue( | ||
formatAmount(BigNumber(amount), Denomination.Sat, "."), | ||
); | ||
}); | ||
|
||
test("should set receive amount", async ({ page }) => { | ||
const amount = 210_000; | ||
await page.goto(`/?receiveAmount=${amount}`); | ||
|
||
const receiveAmount = page.getByTestId("receiveAmount"); | ||
await expect(receiveAmount).toHaveValue( | ||
formatAmount(BigNumber(amount), Denomination.Sat, "."), | ||
); | ||
}); | ||
|
||
test("should not set receive amount when send amount is set", async ({ | ||
page, | ||
}) => { | ||
const sendAmount = 100_000; | ||
const receiveAmount = 210_000; | ||
await page.goto( | ||
`/?sendAmount=${sendAmount}&receiveAmount=${receiveAmount}`, | ||
); | ||
|
||
const sendAmountInput = page.getByTestId("sendAmount"); | ||
await expect(sendAmountInput).toHaveValue( | ||
formatAmount(BigNumber(sendAmount), Denomination.Sat, "."), | ||
); | ||
}); | ||
|
||
test("should not set amount when lightning invoice is set", async ({ | ||
page, | ||
}) => { | ||
const invoiceAmount = 200_000; | ||
const invoice = await generateInvoiceLnd(invoiceAmount); | ||
|
||
const sendAmount = 100_000; | ||
|
||
await page.goto(`/?sendAmount=${sendAmount}&destination=${invoice}`); | ||
|
||
const receiveAmount = page.getByTestId("receiveAmount"); | ||
await expect(receiveAmount).toHaveValue( | ||
formatAmount(BigNumber(invoiceAmount), Denomination.Sat, "."), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.