From 951aae189289d7e3fae6d28a9d5b9e03436c7d17 Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Mon, 16 Dec 2024 09:36:25 +0100 Subject: [PATCH] Refactor: extract CGW types into a package (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: make prettier config global * feature: extract store gateway to separate package I’ve moved the autogenerated gateway API code to a separate package. This will allow us to reuse it in the web application. In the process I created 2 more configuration packages: - config/tsconfig - config/jest-presets The goal of those is to offer base tsconfig and jest presets for reuse across packages. * fix: improve yarn installation instructions * fix: tsx & linting issues --- .github/workflows/mobile-lint.yml | 2 + .lintstagedrc.json | 5 +- .../mobile/.prettierignore => .prettierignore | 2 + apps/mobile/.prettierrc => .prettierrc | 0 README.md | 35 ++-- apps/mobile/app/_layout.tsx | 2 +- apps/mobile/jest.config.js | 3 + apps/mobile/package.json | 3 +- .../components/SafeListItem/SafeListItem.tsx | 2 +- apps/mobile/src/components/TxInfo/TxInfo.tsx | 4 +- .../Card/TxBatchCard/TxBatchCard.stories.tsx | 2 +- .../Card/TxBatchCard/TxBatchCard.test.tsx | 2 +- .../Card/TxBatchCard/TxBatchCard.tsx | 4 +- .../TxConflictingCard/TxConflictingCard.tsx | 2 +- .../TxContractInteractionCard.stories.tsx | 4 +- .../TxContractInteractionCard.test.tsx | 4 +- .../TxContractInteractionCard.tsx | 4 +- .../TxCreationCard/TxCreationCard.stories.tsx | 4 +- .../TxCreationCard/TxCreationCard.test.tsx | 4 +- .../Card/TxCreationCard/TxCreationCard.tsx | 2 +- .../TxGroupedCard/TxGroupedCard.stories.tsx | 4 +- .../Card/TxGroupedCard/TxGroupedCard.test.tsx | 4 +- .../Card/TxGroupedCard/TxGroupedCard.tsx | 4 +- .../TxRejectionCard.stories.tsx | 2 +- .../TxRejectionCard/TxRejectionCard.test.tsx | 2 +- .../Card/TxRejectionCard/TxRejectionCard.tsx | 4 +- .../TxSafeAppCard/TxSafeAppCard.stories.tsx | 2 +- .../Card/TxSafeAppCard/TxSafeAppCard.test.tsx | 2 +- .../Card/TxSafeAppCard/TxSafeAppCard.tsx | 4 +- .../TxSettingsCard/TxSettingCard.stories.tsx | 4 +- .../TxSettingsCard/TxSettingCard.test.tsx | 4 +- .../Card/TxSettingsCard/TxSettingsCard.tsx | 4 +- .../Card/TxSwapCard/TxSwapCard.stories.tsx | 2 +- .../Card/TxSwapCard/TxSwapCard.test.tsx | 2 +- .../Card/TxSwapCard/TxSwapCard.tsx | 4 +- .../Card/TxTokenCard/TxTokenCard.stories.tsx | 4 +- .../Card/TxTokenCard/TxTokenCard.tsx | 4 +- .../components/Balance/Balance.container.tsx | 7 +- .../Assets/components/Balance/Balance.tsx | 4 +- .../Assets/components/Balance/ChainItems.tsx | 2 +- .../Assets/components/NFTs/NFTItem.tsx | 2 +- .../Assets/components/NFTs/NFTs.container.tsx | 2 +- .../components/Tokens/Tokens.container.tsx | 8 +- .../PendingTxList/PendingTxList.container.tsx | 4 +- apps/mobile/src/features/PendingTx/utils.tsx | 4 +- .../features/Settings/Settings.container.tsx | 4 +- .../mobile/src/features/Settings/Settings.tsx | 2 +- .../TxHistory/TxHistory.container.tsx | 4 +- .../TxHistoryList/TxHistoryList.tsx | 4 +- apps/mobile/src/features/TxHistory/utils.tsx | 4 +- apps/mobile/src/hooks/usePendingTxs/index.ts | 4 +- .../src/hooks/useTransactionType/index.tsx | 6 +- .../useTransactionType.test.tsx | 2 +- apps/mobile/src/store/activeChainSlice.ts | 2 +- apps/mobile/src/store/chains/index.ts | 15 ++ apps/mobile/src/store/gateway/cgwClient.ts | 7 - apps/mobile/src/store/gateway/utils.ts | 9 - .../mobile/src/store/hooks/storeHooks.test.ts | 2 +- apps/mobile/src/store/index.ts | 5 +- apps/mobile/src/store/txHistorySlice.ts | 2 +- apps/mobile/src/tests/mocks.ts | 4 +- apps/mobile/src/utils/gateway.ts | 2 +- .../src/utils/transaction-guards.test.ts | 2 +- apps/mobile/src/utils/transaction-guards.ts | 6 +- apps/mobile/src/utils/transactions.tsx | 2 +- apps/mobile/tsconfig.json | 3 +- config/jest-presets/package.json | 12 ++ config/jest-presets/presets/jest-preset.js | 24 +++ config/tsconfig/confs/base.json | 41 +++++ config/tsconfig/package.json | 8 + package.json | 9 +- packages/store/README.md | 39 +++++ packages/store/jest.config.js | 5 + packages/store/package.json | 13 ++ .../store/scripts}/api-schema/schema.json | 0 packages/store/scripts/openapi-config.ts | 73 ++++++++ .../src}/gateway/AUTO_GENERATED/about.ts | 0 .../src}/gateway/AUTO_GENERATED/accounts.ts | 0 .../store/src}/gateway/AUTO_GENERATED/auth.ts | 0 .../src}/gateway/AUTO_GENERATED/balances.ts | 0 .../src}/gateway/AUTO_GENERATED/chains.ts | 0 .../gateway/AUTO_GENERATED/collectibles.ts | 0 .../src}/gateway/AUTO_GENERATED/community.ts | 0 .../src}/gateway/AUTO_GENERATED/contracts.ts | 0 .../gateway/AUTO_GENERATED/data-decoded.ts | 0 .../src}/gateway/AUTO_GENERATED/delegates.ts | 0 .../gateway/AUTO_GENERATED/estimations.ts | 0 .../src}/gateway/AUTO_GENERATED/messages.ts | 0 .../gateway/AUTO_GENERATED/notifications.ts | 0 .../src}/gateway/AUTO_GENERATED/owners.ts | 0 .../src}/gateway/AUTO_GENERATED/relay.ts | 0 .../src}/gateway/AUTO_GENERATED/safe-apps.ts | 0 .../src}/gateway/AUTO_GENERATED/safes.ts | 0 .../AUTO_GENERATED/targeted-messages.ts | 0 .../gateway/AUTO_GENERATED/transactions.ts | 0 packages/store/src/gateway/cgwClient.test.ts | 67 ++++++++ packages/store/src/gateway/cgwClient.ts | 37 ++++ .../store/src}/gateway/chains/index.ts | 24 +-- .../store/src}/gateway/index.ts | 0 .../store/src}/gateway/types.ts | 2 +- packages/store/src/index.ts | 3 + packages/store/tsconfig.json | 7 + yarn.lock | 160 ++++++++++++++++-- 103 files changed, 632 insertions(+), 162 deletions(-) rename apps/mobile/.prettierignore => .prettierignore (78%) rename apps/mobile/.prettierrc => .prettierrc (100%) create mode 100644 apps/mobile/src/store/chains/index.ts delete mode 100644 apps/mobile/src/store/gateway/cgwClient.ts delete mode 100644 apps/mobile/src/store/gateway/utils.ts create mode 100644 config/jest-presets/package.json create mode 100644 config/jest-presets/presets/jest-preset.js create mode 100644 config/tsconfig/confs/base.json create mode 100644 config/tsconfig/package.json create mode 100644 packages/store/README.md create mode 100644 packages/store/jest.config.js create mode 100644 packages/store/package.json rename {apps/mobile/src/store/gateway => packages/store/scripts}/api-schema/schema.json (100%) create mode 100644 packages/store/scripts/openapi-config.ts rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/about.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/accounts.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/auth.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/balances.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/chains.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/collectibles.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/community.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/contracts.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/data-decoded.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/delegates.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/estimations.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/messages.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/notifications.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/owners.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/relay.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/safe-apps.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/safes.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/targeted-messages.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/AUTO_GENERATED/transactions.ts (100%) create mode 100644 packages/store/src/gateway/cgwClient.test.ts create mode 100644 packages/store/src/gateway/cgwClient.ts rename {apps/mobile/src/store => packages/store/src}/gateway/chains/index.ts (56%) rename {apps/mobile/src/store => packages/store/src}/gateway/index.ts (100%) rename {apps/mobile/src/store => packages/store/src}/gateway/types.ts (97%) create mode 100644 packages/store/src/index.ts create mode 100644 packages/store/tsconfig.json diff --git a/.github/workflows/mobile-lint.yml b/.github/workflows/mobile-lint.yml index 0d485c2496..b8be43d5a1 100644 --- a/.github/workflows/mobile-lint.yml +++ b/.github/workflows/mobile-lint.yml @@ -6,9 +6,11 @@ on: - main paths: - apps/mobile/** + - packages/store/** pull_request: paths: - apps/mobile/** + - packages/store/** jobs: lint: diff --git a/.lintstagedrc.json b/.lintstagedrc.json index c9e38faadb..021c37f754 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,5 +1,8 @@ { "*.ts": ["yarn prettier:fix", "yarn eslint"], "*.tsx": ["yarn prettier:fix", "yarn eslint"], - "apps/mobile/assets/fonts/safe-icons/selection.json": ["node ./apps/mobile/scripts/generateIconTypes.js", "git add ./apps/mobile/src/types/iconTypes.ts"] + "apps/mobile/assets/fonts/safe-icons/selection.json": [ + "node ./apps/mobile/scripts/generateIconTypes.js", + "git add ./apps/mobile/src/types/iconTypes.ts" + ] } diff --git a/apps/mobile/.prettierignore b/.prettierignore similarity index 78% rename from apps/mobile/.prettierignore rename to .prettierignore index 6482fc9c60..bd82d1908e 100644 --- a/apps/mobile/.prettierignore +++ b/.prettierignore @@ -6,3 +6,5 @@ html ios android /assets + +apps/mobile/assets diff --git a/apps/mobile/.prettierrc b/.prettierrc similarity index 100% rename from apps/mobile/.prettierrc rename to .prettierrc diff --git a/README.md b/README.md index 22fff027f4..bb0f170cf3 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,27 @@ To get started, ensure you have the required tools installed and follow these st ### Prerequisites - **Node.js**: Install the latest stable version from [Node.js](https://nodejs.org/). -- **Yarn**: Use Yarn version 4.5.3 or later. You can install it globally: +- **Yarn**: Use Yarn version 4.5.3 or later + +to install it with the latest node version you can simply do + +```bash +corepack enable +``` + +and then just run ```bash -npm install -g yarn +yarn ``` +This will install the required version of yarn and resolve all dependencies. + +> [!INFO] +> +> Corepack is a tool to help with managing versions of your package managers. It exposes binary proxies for each supported package manager that, when called, will identify whatever package manager is +> configured for the current project, download it if needed, and finally run it. + ### Initial Setup 1. Clone the repository: @@ -52,7 +67,7 @@ yarn workspace