Skip to content

Commit

Permalink
Merge pull request #211 from stabilitydao/4-vault
Browse files Browse the repository at this point in the history
invest form fix
  • Loading branch information
a17 authored Sep 5, 2024
2 parents 7e5b756 + 466ed17 commit 0b6ef50
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 665 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stability-ui",
"type": "module",
"version": "0.9.5-alpha",
"version": "0.9.6-alpha",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
Expand Down
14 changes: 7 additions & 7 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ const CHAINS = [
explorer: "https://polygonscan.com/address/",
active: true, // main page active networks
},
// {
// name: "Base",
// id: "8453",
// logoURI: "https://www.base.org/document/favicon-32x32.png",
// explorer: "https://basescan.org/address/",
// active: true, // main page active networks
// },
{
name: "Base",
id: "8453",
logoURI: "https://www.base.org/document/favicon-32x32.png",
explorer: "https://basescan.org/address/",
active: true, // main page active networks
},
];

const YEARN_PROTOCOLS = ["aave", "stargate", "stmatic", "compound"];
Expand Down
1 change: 1 addition & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ const { title } = Astro.props as IProps;
box-sizing:border-box;
box-shadow:0 1px 8px rgba(0,0,0,0.5);
display:none;
pointer-events: none;
}
.toLeft {
top:230px !important;
Expand Down
530 changes: 252 additions & 278 deletions src/modules/Vault/components/InvestForm/index.tsx

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions src/modules/Vault/functions/handleInputKeyDown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const handleInputKeyDown = (
evt: React.KeyboardEvent<HTMLInputElement>,
currentValue: string
): void => {
if (
!/[\d.]/.test(evt.key) &&
evt.key !== "Backspace" &&
evt.key !== "ArrowLeft" &&
evt.key !== "ArrowRight"
) {
evt.preventDefault();
}

if (evt.key === "0" && currentValue === "0") {
evt.preventDefault();
}

if (/^\d/.test(evt.key) && currentValue === "0" && evt.key !== ".") {
evt.preventDefault();
}

if (evt.key === "." && currentValue && currentValue.includes(".")) {
evt.preventDefault();
}
};

export { handleInputKeyDown };
8 changes: 7 additions & 1 deletion src/modules/Vault/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getAssetAllowance } from "./getAssetAllowance";
import { getPlatformBalance } from "./getPlatformBalance";
import { getAssetsBalances } from "./getAssetsBalances";
import { handleInputKeyDown } from "./handleInputKeyDown";

export { getAssetAllowance, getPlatformBalance, getAssetsBalances };
export {
getAssetAllowance,
getPlatformBalance,
getAssetsBalances,
handleInputKeyDown,
};
79 changes: 79 additions & 0 deletions src/modules/Vault/tests/handleInputKeyDown.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { describe, it, expect, vi } from "vitest";
import { handleInputKeyDown } from "../functions";

describe("handleInputKeyDown", () => {
it("should allow digits to be entered", () => {
const preventDefault = vi.fn();
const event = {
key: "1",
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "");

expect(preventDefault).not.toHaveBeenCalled();
});

it("should prevent multiple leading zeroes", () => {
const preventDefault = vi.fn();
const event = {
key: "0",
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "0");

expect(preventDefault).toHaveBeenCalled();
});

it("should allow a single decimal point", () => {
const preventDefault = vi.fn();
const event = {
key: ".",
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "123");

expect(preventDefault).not.toHaveBeenCalled();
});

it("should prevent multiple decimal points", () => {
const preventDefault = vi.fn();
const event = {
key: ".",
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "123.");

expect(preventDefault).toHaveBeenCalled();
});

it("should allow backspace and arrow keys", () => {
const preventDefault = vi.fn();

["Backspace", "ArrowLeft", "ArrowRight"].forEach((key) => {
const event = {
key,
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "123");

expect(preventDefault).not.toHaveBeenCalled();
});
});

it("should prevent invalid characters", () => {
const preventDefault = vi.fn();
const event = {
key: "a",
preventDefault,
} as unknown as React.KeyboardEvent<HTMLInputElement>;

handleInputKeyDown(event, "123");

expect(preventDefault).toHaveBeenCalled();
});
});
9 changes: 7 additions & 2 deletions src/utils/functions/get1InchRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ export const get1InchRoutes = async (
try {
const response = await axios.get(url);

setError(false);
if (!response?.data[0]?.amountOut) {
throw new Error(
`1inch status: ${response?.data?.[0]?.aggApiReply.status}`
);
}

setError(false);
return {
symbol: symbol as string,
address: address,
Expand All @@ -71,7 +76,7 @@ export const get1InchRoutes = async (
console.log(`Retrying (${currentRetry}/${maxRetries})...`, url);
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
console.error("1INCH API ERROR:", error);
console.error("1inch api error:", error);
setError(true);

return {
Expand Down
Loading

0 comments on commit 0b6ef50

Please sign in to comment.