Skip to content

Commit

Permalink
Merge branch 'main' into feat_LM_link-button-style
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuntaner authored Jan 23, 2024
2 parents 74f46c0 + 2a24820 commit 21e4ebf
Show file tree
Hide file tree
Showing 37 changed files with 56 additions and 13 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions e2e/input.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from "@playwright/test";

const testUrl = "/components/input";

test("should trim zero", async ({ page }) => {
await page.goto(testUrl);

const input = page.getByTestId("amount-decimals");
await input.fill("0.");

const output = page.getByTestId("amount-decimals-output");
await expect(output).toHaveText("0", { timeout: 500 });
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts/download-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ FILE="$DIR/qrcode.y4m"
if test -f "$FILE"; then
echo "$FILE exists"
else
wget --load-cookies /tmp/cookies.txt "https://drive.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://drive.google.com/uc?export=download&id=1wpsNoXTX3_y6Wrh7NE0SVwIZufK0-xeu' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1wpsNoXTX3_y6Wrh7NE0SVwIZufK0-xeu" -O $FILE && rm -rf /tmp/cookies.txt
curl -sSL https://dfinity-download-public.s3.eu-central-1.amazonaws.com/static/gix-qrcode.y4m -o "$FILE"
fi
15 changes: 8 additions & 7 deletions src/lib/components/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
let selectionStart: number | null = 0;
let selectionEnd: number | null = 0;
const toStringWrapDecimals = (value: string): string =>
Number(value).toLocaleString("en", {
useGrouping: false,
maximumFractionDigits: wrapDecimals,
});
// replace exponent format (1e-4) w/ plain (0.0001)
const exponentToPlainNumberString = (value: string): string =>
// number to toLocaleString doesn't support decimals for values >= ~1e16
value.includes("e")
? Number(value).toLocaleString("en", {
useGrouping: false,
maximumFractionDigits: wrapDecimals,
})
: value;
value.includes("e") ? toStringWrapDecimals(value) : value;
// To show undefined as "" (because of the type="text")
const fixUndefinedValue = (value: string | number | undefined): string =>
isNullish(value) ? "" : `${value}`;
Expand Down Expand Up @@ -134,7 +135,7 @@
value =
inputType === "icp"
? +currentValue
: (+currentValue).toFixed(wrapDecimals);
: toStringWrapDecimals(currentValue);
}
} else {
internalValueChange = true;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/styles/global/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--cp-light-500: #32449e;
--cp-light-600: #3d4d99; // never actually used
--cp-light-900: #151a33;
--cp-light-opaque: rgb(from var(--cp-light-50) r g b / 40%);
--cp-light-opaque: #ffffff40; // --cp-light-50 with 40% opacity
--cp-light-gradient-1: #d4e7fa;
--cp-light-gradient-2: #f2dae2;

Expand All @@ -35,13 +35,13 @@
--cp-dark-600: #170c36;
--cp-dark-650: #150c31;
--cp-dark-900: #130a2c;
--cp-dark-opaque: rgb(from #000 r g b / 20%);
--cp-dark-opaque: #00000020;
--cp-dark-gradient-1: #0f0f4d;
--cp-dark-gradient-2: #4d1259;

// Accessory
--fade: rgba(36, 20, 61, 0.6); // #24143d 60%
--fade-dark: rgba(36, 20, 61, 0.8); // #24143d 80%
--fade: #24143d60;
--fade-dark: #24143d80;
--orchid-tint: #b871d9;
--orchid: #af63db;
--indigo: #553b75;
Expand Down
7 changes: 6 additions & 1 deletion src/routes/(split)/components/input/+page.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import Input from "$lib/components/Input.svelte";
import IconQRCodeScanner from "$lib/icons/IconQRCodeScanner.svelte";

let amountWithDecimals: number | undefined = undefined;
</script>

# Input
Expand Down Expand Up @@ -55,7 +57,10 @@ Both slots are displayed `flex` with `space-between`.

<Input placeholder="Enter ICP" inputType="icp" value="" />

<Input placeholder="Enter ETH" inputType="currency" value="" decimals={18} />
<div>
<Input testId="amount-decimals" placeholder="Enter ETH" inputType="currency" decimals={18} bind:value={amountWithDecimals} />
<p>Amount: <output data-tid="amount-decimals-output">{amountWithDecimals ?? ""}</output></p>
</div>

<Input placeholder="Disabled" disabled value="This is a disabled value" inputType="text" />

Expand Down
24 changes: 24 additions & 0 deletions src/tests/lib/components/Input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,5 +488,29 @@ describe("Input", () => {
fireEvent.input(input, { target: { value: "0.0000000112312321219" } });
expect(input.value).toBe("0.000000011231232121");
});

it("should not round custom decimals with JS imprecision", () =>
new Promise<void>((done) => {
const { container, component } = render(InputValueTest, {
props: {
...props,
value: "0.12",
inputType: "currency",
decimals: 18,
},
});

const input: HTMLInputElement | null = container.querySelector("input");
assertNonNullish(input);

fireEvent.input(input, { target: { value: "0.122" } });

component.$on("testAmount", ({ detail }) => {
// Example if the input would be rounded with Number(value).toFixed(18)
expect(detail.amount).not.toBe("0.121999999999999997");
expect(detail.amount).toBe("0.122");
done();
});
}));
});
});

0 comments on commit 21e4ebf

Please sign in to comment.