From f54c0acc238441ed9033ada29bc1badac579bd46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Sim=C3=A3o?= Date: Fri, 24 Mar 2023 15:04:24 +0000 Subject: [PATCH] chore: clean up workflows and package.json --- .github/workflows/chromatic.yml | 2 +- package.json | 17 ++--- src/containers/DarkModeToggle/index.tsx | 18 ----- src/lib/form-validation/amm/index.ts | 10 --- src/lib/form-validation/amm/pool.ts | 44 ------------ src/lib/form-validation/common/balance.ts | 43 ----------- src/lib/form-validation/common/field.ts | 87 ----------------------- src/lib/form-validation/common/types.ts | 17 ----- src/lib/form-validation/index.ts | 19 ----- src/lib/form-validation/loans/borrow.ts | 83 --------------------- src/lib/form-validation/loans/index.ts | 13 ---- src/lib/form-validation/loans/lend.ts | 83 --------------------- src/lib/form-validation/types.ts | 18 ----- src/lib/form-validation/vaults/create.ts | 40 ----------- src/lib/form-validation/vaults/index.ts | 8 --- 15 files changed, 6 insertions(+), 496 deletions(-) delete mode 100644 src/containers/DarkModeToggle/index.tsx delete mode 100644 src/lib/form-validation/amm/index.ts delete mode 100644 src/lib/form-validation/amm/pool.ts delete mode 100644 src/lib/form-validation/common/balance.ts delete mode 100644 src/lib/form-validation/common/field.ts delete mode 100644 src/lib/form-validation/common/types.ts delete mode 100644 src/lib/form-validation/index.ts delete mode 100644 src/lib/form-validation/loans/borrow.ts delete mode 100644 src/lib/form-validation/loans/index.ts delete mode 100644 src/lib/form-validation/loans/lend.ts delete mode 100644 src/lib/form-validation/types.ts delete mode 100644 src/lib/form-validation/vaults/create.ts delete mode 100644 src/lib/form-validation/vaults/index.ts diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.yml index 5cc72d8f88..a2d95d9998 100644 --- a/.github/workflows/chromatic.yml +++ b/.github/workflows/chromatic.yml @@ -18,7 +18,7 @@ jobs: steps: # 👇 Version 2 of the action - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 # 👈 Required to retrieve git history - uses: actions/setup-node@v2 diff --git a/package.json b/package.json index 717e14d3ec..d71cd42cab 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,8 @@ "@craco/craco": "^6.1.1", "@headlessui/react": "^1.1.1", "@heroicons/react": "^2.0.0", - "@hookform/resolvers": "^2.9.7", "@interlay/bridge": "^0.2.3", "@interlay/interbtc-api": "2.0.2", - "@material-icons/svg": "^1.0.28", "@polkadot/api": "9.11.1", "@polkadot/extension-dapp": "0.44.1", "@polkadot/ui-keyring": "^2.9.7", @@ -41,9 +39,6 @@ "@react-stately/tooltip": "^3.2.3", "@react-stately/tree": "^3.4.1", "@tailwindcss/forms": "^0.3.2", - "@testing-library/jest-dom": "^5.11.4", - "@testing-library/react": "12.1.5", - "@testing-library/user-event": "^12.1.10", "big.js": "^6.1.1", "chart.js": "^2.9.4", "clsx": "^1.1.1", @@ -72,13 +67,10 @@ "react-transition-group": "^4.4.5", "react-use": "^17.2.3", "redux": "^4.0.5", - "redux-logger": "^3.0.6", "styled-components": "^5.3.5", "typescript": "4.3.2", - "use-dark-mode": "^2.3.1", "web-vitals": "^1.0.1", - "yup": "^0.32.11", - "zod": "^3.18.0" + "yup": "^0.32.11" }, "devDependencies": { "@babel/plugin-proposal-class-properties": "^7.16.7", @@ -123,11 +115,13 @@ "prettier": "2.2.1", "release-it": "^15.5.0", "storybook-addon-themes": "^6.1.0", - "tailwind-config-viewer": "^1.5.1", "tailwindcss": "npm:@tailwindcss/postcss7-compat", "tailwindcss-pseudo-elements": "^1.5.1", "ts-node": "^8.6.2", - "webpack-bundle-analyzer": "^4.4.0" + "webpack-bundle-analyzer": "^4.4.0", + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "12.1.5", + "@testing-library/user-event": "^12.1.10" }, "resolutions": { "babel-loader": "8.1.0", @@ -158,7 +152,6 @@ "setup": "yarn generate:defs && yarn generate:meta", "build": "REACT_APP_VERSION=$npm_package_version craco build", "build-with-webpack-bundle-analysis": "yarn build --stats && webpack-bundle-analyzer build/bundle-stats.json -m static -r build/bundle-stats.html -O", - "tailwind-config-viewer": "cd src && tailwind-config-viewer -o", "lint-and-type-check": "yarn lint && yarn type-check", "eject": "react-scripts eject", "compose:regtest": "docker-compose --env-file .env.development.local up", diff --git a/src/containers/DarkModeToggle/index.tsx b/src/containers/DarkModeToggle/index.tsx deleted file mode 100644 index a363e78950..0000000000 --- a/src/containers/DarkModeToggle/index.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import useDarkMode from 'use-dark-mode'; - -import Toggle from '@/legacy-components/Toggle'; -import { KUSAMA } from '@/utils/constants/relay-chain-names'; -import { CLASS_NAMES } from '@/utils/constants/styles'; - -// TODO: not used for now -const DarkModeToggle = (): JSX.Element => { - const darkMode = useDarkMode(process.env.REACT_APP_RELAY_CHAIN_NAME === KUSAMA, { - classNameDark: CLASS_NAMES.DARK, - classNameLight: CLASS_NAMES.LIGHT, - element: document.documentElement - }); - - return ; -}; - -export default DarkModeToggle; diff --git a/src/lib/form-validation/amm/index.ts b/src/lib/form-validation/amm/index.ts deleted file mode 100644 index 77c598be47..0000000000 --- a/src/lib/form-validation/amm/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { withdraw } from './pool'; - -const amm = { - pool: { - withdraw - } -}; - -export default amm; -export type { PoolWithdrawSchemaParams } from './pool'; diff --git a/src/lib/form-validation/amm/pool.ts b/src/lib/form-validation/amm/pool.ts deleted file mode 100644 index 79749a907c..0000000000 --- a/src/lib/form-validation/amm/pool.ts +++ /dev/null @@ -1,44 +0,0 @@ -import Big from 'big.js'; -import { TFunction } from 'i18next'; -import * as z from 'zod'; - -import balance from '../common/balance'; -import field from '../common/field'; -import { CommonSchemaParams, MaxAmountSchemaParams } from '../types'; - -type PoolWithdrawSchemaParams = CommonSchemaParams & MaxAmountSchemaParams; - -const withdraw = (t: TFunction, params: PoolWithdrawSchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { governanceBalance, transactionFee, minAmount, maxAmount } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('withdraw').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = new Big(value); - - if (!field.min.validate({ inputAmount, minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('withdraw').toLowerCase(), - amount: minAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!field.max.validate({ inputAmount, maxAmount: maxAmount.toBig() })) { - const issueArg = field.max.issue(t, { - action: t('withdraw').toLowerCase(), - amount: maxAmount.toString() - }); - return ctx.addIssue(issueArg); - } - }); - -export { withdraw }; -export type { PoolWithdrawSchemaParams }; diff --git a/src/lib/form-validation/common/balance.ts b/src/lib/form-validation/common/balance.ts deleted file mode 100644 index 230faaa059..0000000000 --- a/src/lib/form-validation/common/balance.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CurrencyExt } from '@interlay/interbtc-api'; -import { MonetaryAmount } from '@interlay/monetary-js'; -import * as z from 'zod'; - -import { GOVERNANCE_TOKEN_SYMBOL } from '@/config/relay-chains'; - -import { Validation } from './types'; - -type TransactionFeeBalanceValidationParams = { - availableBalance: MonetaryAmount; - transactionFee: MonetaryAmount; -}; - -const transactionFee: Validation = { - validate: ({ availableBalance, transactionFee }) => availableBalance.gte(transactionFee), - issue: (t) => ({ - code: z.ZodIssueCode.custom, - message: t('insufficient_funds_governance_token', { - governanceTokenSymbol: GOVERNANCE_TOKEN_SYMBOL - }) - }) -}; - -type CurrencyBalanceValidationParams = { - inputAmount: MonetaryAmount; - availableBalance: MonetaryAmount; -}; - -const currency: Validation = { - validate: ({ availableBalance, inputAmount }) => inputAmount.lte(availableBalance), - issue: (t) => ({ - code: z.ZodIssueCode.custom, - message: t('forms.please_enter_no_higher_available_balance') - }) -}; - -const balance = { - transactionFee, - currency -}; - -export default balance; -export type { CurrencyBalanceValidationParams, TransactionFeeBalanceValidationParams }; diff --git a/src/lib/form-validation/common/field.ts b/src/lib/form-validation/common/field.ts deleted file mode 100644 index 90242b0fa0..0000000000 --- a/src/lib/form-validation/common/field.ts +++ /dev/null @@ -1,87 +0,0 @@ -import Big from 'big.js'; -import * as z from 'zod'; - -import { Validation } from './types'; - -type RequiredFieldValidationParams = { - value: string; -}; - -type RequiredFieldIssueParams = { - fieldName: string; - fieldType?: 'text' | 'number'; -}; - -const required: Validation = { - validate: ({ value }): boolean => !!value, - issue: (t, params) => { - const translationField = - params?.fieldType === 'number' ? 'forms.please_enter_the_amount_to' : 'forms.please_enter_your_field'; - - return { - code: z.ZodIssueCode.too_small, - minimum: 1, - inclusive: true, - type: 'string', - message: t(translationField, { field: params?.fieldName }) - }; - } -}; - -type MinFieldValidationParams = { - minAmount: Big; - inputAmount: Big; -}; - -type MinFieldIssueParams = { - action: string; - amount: number | string; -}; - -const min: Validation = { - validate: ({ inputAmount, minAmount }): boolean => inputAmount.gte(minAmount), - issue: (t, params) => ({ - code: z.ZodIssueCode.too_small, - minimum: 1, - inclusive: true, - type: 'string', - message: t('forms.amount_must_be_at_least', { action: params?.action, amount: params?.amount }) - }) -}; - -type MaxFieldValidationParams = { - maxAmount: Big; - inputAmount: Big; -}; - -type MaxFieldIssueParams = { - action: string; - amount: number | string; -}; - -const max: Validation = { - validate: ({ inputAmount, maxAmount }): boolean => inputAmount.lte(maxAmount), - issue: (t, params) => ({ - code: z.ZodIssueCode.too_small, - minimum: 1, - inclusive: true, - type: 'string', - message: t('forms.amount_must_be_at_most', { action: params?.action, amount: params?.amount }) - }) -}; - -const field = { - required, - min, - max -}; - -export default field; -export type { - MaxFieldIssueParams, - MaxFieldValidationParams, - MinFieldIssueParams, - MinFieldValidationParams, - RequiredFieldIssueParams, - RequiredFieldValidationParams -}; diff --git a/src/lib/form-validation/common/types.ts b/src/lib/form-validation/common/types.ts deleted file mode 100644 index 1f6ef428ef..0000000000 --- a/src/lib/form-validation/common/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { TFunction } from 'i18next'; -import * as z from 'zod'; - -/** - * This type contains the structure of a validation - * @function validate contains one or multiple conditions - * that should return true if `params` respect condition restrictions - * @function issue should return the necessary meta data for zod `addIssue` - * and it's here also where error `message` is declared - * @note This kind of validation should only be used in reusable validations - */ -type Validation = { - validate: (params: V) => boolean; - issue: (t: TFunction, params?: I) => z.IssueData; -}; - -export type { Validation }; diff --git a/src/lib/form-validation/index.ts b/src/lib/form-validation/index.ts deleted file mode 100644 index 0911cf5389..0000000000 --- a/src/lib/form-validation/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import amm from './amm'; -import loans from './loans'; -import vaults from './vaults'; - -const validation = { - vaults, - loans, - amm -}; - -export type { PoolWithdrawSchemaParams } from './amm'; -export type { - LoanBorrowSchemaParams, - LoanLendSchemaParams, - LoanRepaySchemaParams, - LoanWithdrawSchemaParams -} from './loans'; -export type { VaultDepositSchemaParams } from './vaults'; -export default validation; diff --git a/src/lib/form-validation/loans/borrow.ts b/src/lib/form-validation/loans/borrow.ts deleted file mode 100644 index 011632f74d..0000000000 --- a/src/lib/form-validation/loans/borrow.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { newMonetaryAmount } from '@interlay/interbtc-api'; -import Big from 'big.js'; -import { TFunction } from 'i18next'; -import * as z from 'zod'; - -import balance from '../common/balance'; -import field from '../common/field'; -import { AvailableBalanceSchemaParams, CommonSchemaParams, MaxAmountSchemaParams } from '../types'; - -type LoanBorrowSchemaParams = CommonSchemaParams & MaxAmountSchemaParams; - -const borrow = (t: TFunction, params: LoanBorrowSchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { governanceBalance, transactionFee, minAmount, maxAmount } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('loans.borrow').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = new Big(value); - - if (!field.min.validate({ inputAmount, minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('loans.borrow').toLowerCase(), - amount: minAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!field.max.validate({ inputAmount, maxAmount: maxAmount.toBig() })) { - const issueArg = field.max.issue(t, { - action: t('loans.borrow').toLowerCase(), - amount: maxAmount.toString() - }); - return ctx.addIssue(issueArg); - } - }); - -type LoanRepaySchemaParams = CommonSchemaParams & MaxAmountSchemaParams & AvailableBalanceSchemaParams; - -const repay = (t: TFunction, params: LoanRepaySchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { governanceBalance, transactionFee, availableBalance, minAmount, maxAmount } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('loans.repay').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = newMonetaryAmount(value, availableBalance.currency, true); - - if (!field.min.validate({ inputAmount: inputAmount.toBig(), minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('loans.repay').toLowerCase(), - amount: minAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!field.max.validate({ inputAmount: inputAmount.toBig(), maxAmount: maxAmount.toBig() })) { - const issueArg = field.max.issue(t, { - action: t('loans.repay').toLowerCase(), - amount: maxAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!balance.currency.validate({ availableBalance, inputAmount })) { - return ctx.addIssue(balance.currency.issue(t)); - } - }); - -export { borrow, repay }; -export type { LoanBorrowSchemaParams, LoanRepaySchemaParams }; diff --git a/src/lib/form-validation/loans/index.ts b/src/lib/form-validation/loans/index.ts deleted file mode 100644 index 51773a02db..0000000000 --- a/src/lib/form-validation/loans/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { borrow, repay } from './borrow'; -import { lend, withdraw } from './lend'; - -const loans = { - borrow, - repay, - lend, - withdraw -}; - -export default loans; -export type { LoanBorrowSchemaParams, LoanRepaySchemaParams } from './borrow'; -export type { LoanLendSchemaParams, LoanWithdrawSchemaParams } from './lend'; diff --git a/src/lib/form-validation/loans/lend.ts b/src/lib/form-validation/loans/lend.ts deleted file mode 100644 index b6234cffd2..0000000000 --- a/src/lib/form-validation/loans/lend.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { newMonetaryAmount } from '@interlay/interbtc-api'; -import Big from 'big.js'; -import { TFunction } from 'i18next'; -import * as z from 'zod'; - -import balance from '../common/balance'; -import field from '../common/field'; -import { AvailableBalanceSchemaParams, CommonSchemaParams, MaxAmountSchemaParams } from '../types'; - -type LoanLendSchemaParams = CommonSchemaParams & AvailableBalanceSchemaParams & MaxAmountSchemaParams; - -const lend = (t: TFunction, params: LoanLendSchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { governanceBalance, transactionFee, availableBalance, minAmount, maxAmount } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('loans.lend').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = newMonetaryAmount(value, availableBalance.currency, true); - - if (!field.min.validate({ inputAmount: inputAmount.toBig(), minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('loans.lend').toLowerCase(), - amount: minAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!balance.currency.validate({ availableBalance: availableBalance, inputAmount })) { - return ctx.addIssue(balance.currency.issue(t)); - } - - if (!field.max.validate({ inputAmount: inputAmount.toBig(), maxAmount: maxAmount.toBig() })) { - const issueArg = field.max.issue(t, { - action: t('loans.lend').toLowerCase(), - amount: maxAmount.toString() - }); - return ctx.addIssue(issueArg); - } - }); - -type LoanWithdrawSchemaParams = CommonSchemaParams & MaxAmountSchemaParams; - -const withdraw = (t: TFunction, params: LoanWithdrawSchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { governanceBalance, transactionFee, minAmount, maxAmount } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('loans.withdraw').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = new Big(value); - - if (!field.min.validate({ inputAmount, minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('loans.withdraw').toLowerCase(), - amount: minAmount.toString() - }); - return ctx.addIssue(issueArg); - } - - if (!field.max.validate({ inputAmount, maxAmount: maxAmount.toBig() })) { - const issueArg = field.max.issue(t, { - action: t('loans.withdraw').toLowerCase(), - amount: maxAmount.toString() - }); - return ctx.addIssue(issueArg); - } - }); - -export { lend, withdraw }; -export type { LoanLendSchemaParams, LoanWithdrawSchemaParams }; diff --git a/src/lib/form-validation/types.ts b/src/lib/form-validation/types.ts deleted file mode 100644 index 414ce4e1e7..0000000000 --- a/src/lib/form-validation/types.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { CurrencyExt } from '@interlay/interbtc-api'; -import { MonetaryAmount } from '@interlay/monetary-js'; - -type CommonSchemaParams = { - governanceBalance: MonetaryAmount; - transactionFee: MonetaryAmount; - minAmount: MonetaryAmount; -}; - -type AvailableBalanceSchemaParams = { - availableBalance: MonetaryAmount; -}; - -type MaxAmountSchemaParams = { - maxAmount: MonetaryAmount; -}; - -export type { AvailableBalanceSchemaParams, CommonSchemaParams, MaxAmountSchemaParams }; diff --git a/src/lib/form-validation/vaults/create.ts b/src/lib/form-validation/vaults/create.ts deleted file mode 100644 index 44701225fd..0000000000 --- a/src/lib/form-validation/vaults/create.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { newMonetaryAmount } from '@interlay/interbtc-api'; -import { TFunction } from 'i18next'; -import * as z from 'zod'; - -import balance from '../common/balance'; -import field from '../common/field'; -import { AvailableBalanceSchemaParams, CommonSchemaParams } from '../types'; - -type VaultDepositSchemaParams = CommonSchemaParams & AvailableBalanceSchemaParams; - -const deposit = (t: TFunction, params: VaultDepositSchemaParams): z.ZodEffects => - z.string().superRefine((value, ctx) => { - const { availableBalance, governanceBalance, minAmount, transactionFee } = params; - - if (!field.required.validate({ value })) { - const issueArg = field.required.issue(t, { fieldName: t('vault.deposit').toLowerCase(), fieldType: 'number' }); - return ctx.addIssue(issueArg); - } - - if (!balance.transactionFee.validate({ availableBalance: governanceBalance, transactionFee })) { - return ctx.addIssue(balance.transactionFee.issue(t)); - } - - const inputAmount = newMonetaryAmount(value, availableBalance.currency, true); - - if (!field.min.validate({ inputAmount: inputAmount.toBig(), minAmount: minAmount.toBig() })) { - const issueArg = field.min.issue(t, { - action: t('vault.deposit').toLowerCase(), - amount: minAmount.toBig().toString() - }); - return ctx.addIssue(issueArg); - } - - if (!balance.currency.validate({ availableBalance, inputAmount })) { - return ctx.addIssue(balance.currency.issue(t)); - } - }); - -export { deposit }; -export type { VaultDepositSchemaParams }; diff --git a/src/lib/form-validation/vaults/index.ts b/src/lib/form-validation/vaults/index.ts deleted file mode 100644 index b3fec9b4b8..0000000000 --- a/src/lib/form-validation/vaults/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { deposit } from './create'; - -const vaults = { - deposit -}; - -export default vaults; -export type { VaultDepositSchemaParams } from './create';