Skip to content

Commit

Permalink
fixes & tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTeaLeaf committed Jul 27, 2024
1 parent a1c0f00 commit 9130326
Show file tree
Hide file tree
Showing 71 changed files with 1,658 additions and 503 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/1_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
lint:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -21,4 +22,3 @@ jobs:
run: |
export NODE_OPTIONS=--max-old-space-size=8192
yarn lint
timeout-minutes: 60
1 change: 1 addition & 0 deletions .github/workflows/2_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
timeout-minutes: 60
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/3_e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
timeout-minutes: 60
Expand Down
67 changes: 46 additions & 21 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import typescriptPlugin from "@typescript-eslint/eslint-plugin";
import prettierPlugin from "eslint-plugin-prettier";
import eslintPluginAstro from "eslint-plugin-astro";
import astroParser from "astro-eslint-parser";
import reactPlugin from "eslint-plugin-react";

export default [
{
Expand All @@ -13,41 +14,65 @@ export default [
"public/**",
"test-results/**",
"tests/**",
".cache-synpress/**",
],
},
{
files: ["**/*.astro"],
languageOptions: {
parser: astroParser,
parserOptions: {
extraFileExtensions: [".astro"],
project: "./tsconfig.json",
},
},
plugins: {
astro: eslintPluginAstro,
prettier: prettierPlugin,
},
rules: {
...eslintPluginAstro.configs.recommended.rules,
"prettier/prettier": "error",
},
},
// {
// files: ["**/*.astro"],
// languageOptions: {
// parser: astroParser,
// parserOptions: {
// extraFileExtensions: [".astro"],
// project: "./tsconfig.json",
// },
// },
// plugins: {
// astro: eslintPluginAstro,
// prettier: prettierPlugin,
// },
// rules: {
// ...eslintPluginAstro.configs.recommended.rules,
// "prettier/prettier": "error",
// },
// },
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: typescriptParser,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: "./tsconfig.json",
},
},
plugins: {
"@typescript-eslint": typescriptPlugin,
prettier: prettierPlugin,
react: reactPlugin,
},
rules: {
"@typescript-eslint/no-unused-vars": "warn",
"prettier/prettier": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
"@typescript-eslint/explicit-module-boundary-types": "warn",
"@typescript-eslint/no-explicit-any": "warn",
// "@typescript-eslint/ban-ts-comment": "warn",
"react/no-unescaped-entities": "off",
"react/jsx-no-undef": "error",
"react/jsx-fragments": ["error", "syntax"],

// "@typescript-eslint/consistent-type-imports": "error",
// "@typescript-eslint/naming-convention": [
// "error",
// {
// selector: "variable",
// format: ["camelCase", "UPPER_CASE"],
// },
// {
// selector: "typeLike",
// format: ["PascalCase"],
// },
// ],
},
},
];
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
"lint": "eslint . --max-warnings 0",
"lint": "eslint .",
"test:unit": "vitest",
"test:e2e": "playwright test"
},
Expand All @@ -18,7 +18,9 @@
"@astrojs/tailwind": "^5.0.2",
"@astrojs/vercel": "^5.1.0",
"@nanostores/react": "^0.7.1",
"@stabilitydao/stability": "=0.9.1",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@safe-global/safe-apps-web3modal": "^23.0.0",
"@stabilitydao/stability": "^0.10.0",
"@tanstack/query-sync-storage-persister": "^5.22.2",
"@tanstack/react-query": "^5.22.2",
"@tanstack/react-query-persist-client": "^5.22.2",
Expand All @@ -35,11 +37,12 @@
"proxy-middleware": "^0.15.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"recharts": "^2.10.4",
"recharts": "^2.13.0-alpha.4",
"tailwindcss": "^3.3.5",
"vercel": "^32.5.0",
"viem": "^2.13.1",
"wagmi": "^2.5.7"
"wagmi": "^2.5.7",
"web3modal": "^1.9.12"
},
"devDependencies": {
"@currents/playwright": "1.4.5",
Expand All @@ -50,8 +53,12 @@
"@vitest/ui": "^2.0.2",
"astro-eslint-parser": "^1.0.2",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"prettier": "^3.3.3",
"typescript": "^5.5.3",
"vitest": "^2.0.2"
}
}
73 changes: 44 additions & 29 deletions src/components/CreateVaultComponent/BuildForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {

import { Loader } from "@components";

import { FactoryABI, ERC20ABI } from "@web3";
import { FactoryABI, ERC20ABI, wagmiConfig } from "@web3";

import { getTokenData } from "@utils";

import {
account,
platformsData,
Expand All @@ -22,9 +25,6 @@ import {
} from "@store";

import type { TInitParams, TAddress, TInputItem } from "@types";
import { getTokenData } from "@utils";

import { wagmiConfig } from "@web3";

import tokenlist from "@stabilitydao/stability/out/stability.tokenlist.json";

Expand All @@ -39,6 +39,16 @@ interface IProps {
nftData: { freeVaults: number; nextUpdate: string } | undefined;
}

type TTokenData = {
address: string;
allowance: string;
balance: string;
decimals: number;
price: string | undefined;
sum: number;
symbol: string | undefined;
};

const BuildForm = ({
vaultType,
strategyId,
Expand All @@ -48,24 +58,25 @@ const BuildForm = ({
defaultBoostTokens,
minInitialBoostPerDay,
nftData,
}: IProps) => {
}: IProps): JSX.Element => {
const $account = useStore(account);
const $platformsData = useStore(platformsData);
const $balance = useStore(userBalance);
const $assetsBalances: any = useStore(assetsBalances);
const $assetsPrices: any = useStore(assetsPrices);
const $assetsBalances = useStore(assetsBalances);
const $assetsPrices = useStore(assetsPrices);
const $currentChainID = useStore(currentChainID);
// todo implement using
const canUsePermitToken = false;

const needCheckAllowance = !canUsePermitToken;

const BRT = [
...new Set([initParams.initVaultAddresses[0], ...defaultBoostTokens]),
].map((addr) => ({
symbol: tokenlist.tokens.find((token) => token.address === addr)?.symbol,
address: addr,
balance: formatUnits(
$assetsBalances[addr] || "0",
$assetsBalances?.[addr] || 0n,
tokenlist.tokens.find((token) => token.address === addr)?.decimals ?? 18
),
price: $assetsPrices[$currentChainID][addr]?.price,
Expand All @@ -81,8 +92,10 @@ const BuildForm = ({
const [inputValues, setInputValues] = useState<Array<TInputItem>>(
Array(defaultBoostTokens.length).fill({ inputValue: "", valuePerDay: "" })
);
const [rewardingVaultApprove, setRewardingVaultApprove]: any =
useState(false);
const [rewardingVaultApprove, setRewardingVaultApprove] = useState<
TTokenData[]
>([]);

const [rewardingVaultDeploy, setRewardingVaultDeploy] = useState(false);
const refArray = Array.from({ length: boostRewardsTokens.length }).map(() =>
useRef<HTMLInputElement | null>(null)
Expand Down Expand Up @@ -117,33 +130,34 @@ const BuildForm = ({
setInputValues(newInputValues);
};
const handleDeploy = () => {
let tokensToAllowance: any = [];
const tokensData: TTokenData[] = [];

inputValues.forEach((value, index) => {
if (!value.inputValue) return;
if (
Number(boostRewardsTokens[index].balance) >= Number(value.inputValue) &&
Number(value.valuePerDay) >= Number(minInitialBoostPerDay)
) {
tokensToAllowance.push({
tokensData.push({
...boostRewardsTokens[index],
sum: value.inputValue,
sum: Number(value.inputValue),
});
}
});

if (tokensToAllowance?.length) {
getTokensAllowance(tokensToAllowance);
if (tokensData?.length) {
getTokensAllowance(tokensData);
} else {
setRewardingVaultDeploy(false);
setRewardingVaultApprove(false);
setRewardingVaultApprove([]);
}
};

const getTokensAllowance = async (tokens: any) => {
const getTokensAllowance = async (tokens: TTokenData[]) => {
if ($platformsData[$currentChainID]) {
const allowances: any[] = await Promise.all(
tokens.map(async (token: any) => {
const response: any = await readContract(wagmiConfig, {
const allowances: bigint[] = await Promise.all(
tokens.map(async (token: TTokenData) => {
const response = await readContract(wagmiConfig, {
address: token.address as TAddress,
abi: ERC20ABI,
functionName: "allowance",
Expand All @@ -152,18 +166,19 @@ const BuildForm = ({
$platformsData[$currentChainID]?.factory,
],
});

return response;
})
);
tokens = tokens.map((item: any, i: any) => ({
...item,
allowance: formatUnits(allowances[i], item.decimals),
tokens = tokens.map((token: TTokenData, index: number) => ({
...token,
allowance: formatUnits(allowances[index], token.decimals),
}));

// todo for multiple tokens
if (tokens[0].allowance >= tokens[0].sum) {
if (Number(tokens[0].allowance) >= tokens[0].sum) {
setRewardingVaultDeploy(true);
setRewardingVaultApprove(false);
setRewardingVaultApprove([]);
} else {
setRewardingVaultDeploy(false);
setRewardingVaultApprove(tokens);
Expand All @@ -173,9 +188,9 @@ const BuildForm = ({
const approveRewardingVaultTokens = async () => {
if ($platformsData[$currentChainID] && rewardingVaultApprove?.length) {
try {
rewardingVaultApprove.map(async (token: any) => {
rewardingVaultApprove.map(async (token: TTokenData) => {
const approve = await writeContract(wagmiConfig, {
address: token.address,
address: token.address as TAddress,
abi: ERC20ABI,
functionName: "approve",
args: [$platformsData[$currentChainID]?.factory, maxUint256],
Expand All @@ -189,7 +204,7 @@ const BuildForm = ({
setLoader(false);
// it will be work only with one approve
// todo fix approve state
setRewardingVaultApprove(false);
setRewardingVaultApprove([]);
setRewardingVaultDeploy(true);
}
});
Expand Down Expand Up @@ -489,7 +504,7 @@ const BuildForm = ({
) : (
buildResult === undefined &&
vaultType === "Rewarding" &&
(rewardingVaultApprove || rewardingVaultDeploy) && (
(rewardingVaultApprove?.length || rewardingVaultDeploy) && (
<div className="mt-10 flex justify-center">
{rewardingVaultApprove && (
<button
Expand Down
Loading

0 comments on commit 9130326

Please sign in to comment.