Skip to content

Commit

Permalink
Refactor: extract CGW types into a package (#57)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
compojoom committed Dec 20, 2024
1 parent 3a12ca0 commit 951aae1
Show file tree
Hide file tree
Showing 103 changed files with 632 additions and 162 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/mobile-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ on:
- main
paths:
- apps/mobile/**
- packages/store/**
pull_request:
paths:
- apps/mobile/**
- packages/store/**

jobs:
lint:
Expand Down
5 changes: 4 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
2 changes: 2 additions & 0 deletions apps/mobile/.prettierignore → .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ html
ios
android
/assets

apps/mobile/assets
File renamed without changes.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -52,7 +67,7 @@ yarn workspace <workspace-name> <script>
```

Example:

```bash
yarn workspace @safe-global/mobile start
```
Expand All @@ -64,20 +79,21 @@ yarn workspace <workspace-name> add <package-name>
```

- **Remove a dependency from a specific workspace:**

```bash
yarn workspace <workspace-name> remove <package-name>
```

> [!Note]
>
> Yarn treats commands that contain a semicolon as global commands. For example if you have a
>
> Yarn treats commands that contain a semicolon as global commands. For example if you have a
> command in a workspace that has a semicolon and there isn't another workspace that has the same command,
>you can run the command without specifying the workspace name. For example:
>
> you can run the command without specifying the workspace name. For example:
>
> ```bash
> yarn start:ios
> ```
>
>
> is equivalent to:
>
> ```bash
Expand Down Expand Up @@ -137,4 +153,3 @@ yarn install

If you have any questions or run into issues, feel free to open a discussion or contact the maintainers. Happy coding!
🚀

2 changes: 1 addition & 1 deletion apps/mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Provider } from 'react-redux'
import { persistor, store } from '@/src/store'
import { PersistGate } from 'redux-persist/integration/react'
import { isStorybookEnv } from '@/src/config/constants'
import { apiSliceWithChainsConfig } from '@/src/store/gateway/chains/index'
import { apiSliceWithChainsConfig } from '@safe-global/store/gateway/chains'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
import { HeaderBackButton } from '@react-navigation/elements'
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet'
Expand Down
3 changes: 3 additions & 0 deletions apps/mobile/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const preset = require('../../config/jest-presets/presets/jest-preset')

module.exports = {
...preset,
preset: 'jest-expo',
collectCoverage: true,
collectCoverageFrom: [
Expand Down
3 changes: 1 addition & 2 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"storybook-generate": "sb-rn-get-stories",
"generate:icons": "node ./scripts/generateIconTypes.js",
"prepare": "husky",
"api-generate": " npx @rtk-query/codegen-openapi openapi-config.ts",
"build-storybook": "STORYBOOK_WEB='true' storybook build",
"e2e:metro-ios": "EXPO_PUBLIC_ENV=e2e NODE_ENV=test RN_SRC_EXT=e2e.ts,e2e.tsx expo run:ios",
"e2e:metro-android": "EXPO_PUBLIC_ENV=e2e NODE_ENV=test RN_SRC_EXT=e2e.ts,e2e.tsx expo run:android",
Expand All @@ -48,6 +47,7 @@
"@react-navigation/material-top-tabs": "^7.0.1",
"@react-navigation/native": "^7.0.0",
"@reduxjs/toolkit": "^2.4.0",
"@safe-global/store": "workspace:^",
"@storybook/addon-react-native-web": "^0.0.26",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@tamagui/animations-moti": "^1.117.1",
Expand Down Expand Up @@ -128,7 +128,6 @@
"globals": "^15.11.0",
"jest": "^29.7.0",
"jest-expo": "~52.0.2",
"prettier": "3.3.3",
"react-native-svg": "15.8.0",
"redux-devtools-expo-dev-plugin": "^1.0.0",
"storybook": "^8.4.6",
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/components/SafeListItem/SafeListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Text, Theme, ThemeName, View } from 'tamagui'
import { IconProps, SafeFontIcon } from '../SafeFontIcon/SafeFontIcon'
import { ellipsis } from '@/src/utils/formatters'
import { isMultisigExecutionInfo } from '@/src/utils/transaction-guards'
import { Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { Badge } from '../Badge'

interface SafeListItemProps {
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/components/TxInfo/TxInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { type Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'
import { type Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { useTransactionType } from '@/src/hooks/useTransactionType'
import { TxTokenCard } from '@/src/components/transactions-list/Card/TxTokenCard'
import { TxSettingsCard } from '@/src/components/transactions-list/Card/TxSettingsCard'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxBatchCard } from '@/src/components/transactions-list/Card/TxBatchCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { MultiSend, TransactionInfoType } from '@/src/store/gateway/types'
import { MultiSend, TransactionInfoType } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxBatchCard> = {
title: 'TransactionsList/TxBatchCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@/src/tests/test-utils'
import { TxBatchCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { MultiSend, TransactionInfoType } from '@/src/store/gateway/types'
import { MultiSend, TransactionInfoType } from '@safe-global/store/gateway/types'

describe('TxBatchCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import { Avatar, View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import type { MultiSend } from '@/src/store/gateway/types'
import type { Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import type { MultiSend } from '@safe-global/store/gateway/types'
import type { Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxBatchCardProps {
txInfo: MultiSend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { Theme, View } from 'tamagui'
import { TxInfo } from '@/src/components/TxInfo'
import { Alert } from '@/src/components/Alert'
import { TransactionQueuedItem } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionQueuedItem } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxConflictingCard {
transactions: TransactionQueuedItem[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxContractInteractionCard } from '@/src/components/transactions-list/Card/TxContractInteractionCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { CustomTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { CustomTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxContractInteractionCard> = {
title: 'TransactionsList/TxContractInteractionCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from '@/src/tests/test-utils'
import { TxContractInteractionCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { CustomTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'
import { CustomTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

describe('TxContractInteractionCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import { Avatar, Text, Theme, View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import { MultiSend } from '@/src/store/gateway/types'
import { Transaction, CustomTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { MultiSend } from '@safe-global/store/gateway/types'
import { Transaction, CustomTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxContractInteractionCardProps {
bordered?: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxCreationCard } from '@/src/components/transactions-list/Card/TxCreationCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { type CreationTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { type CreationTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxCreationCard> = {
title: 'TransactionsList/TxCreationCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from '@/src/tests/test-utils'
import { TxCreationCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { CreationTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'
import { CreationTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

describe('TxCreationCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Theme, View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import { shortenAddress } from '@/src/utils/formatters'
import type { Transaction, CreationTransactionInfo } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import type { Transaction, CreationTransactionInfo } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxCreationCardProps {
txInfo: CreationTransactionInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { mockERC20Transfer, mockListItemByType, mockNFTTransfer } from '@/src/tests/mocks'
import { TransactionItem } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionListItemType, TransactionStatus } from '@/src/store/gateway/types'
import { TransactionItem } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { TransactionListItemType, TransactionStatus } from '@safe-global/store/gateway/types'
import { TxGroupedCard } from '.'

const meta: Meta<typeof TxGroupedCard> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from '@/src/tests/test-utils'
import { TxGroupedCard } from '.'
import { mockERC20Transfer, mockListItemByType, mockNFTTransfer, mockSwapTransfer } from '@/src/tests/mocks'
import { TransactionListItemType, TransactionStatus } from '@/src/store/gateway/types'
import { TransactionItem } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionListItemType, TransactionStatus } from '@safe-global/store/gateway/types'
import { TransactionItem } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

describe('TxGroupedCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import { TxInfo } from '@/src/components/TxInfo'
import { getOrderClass } from '@/src/hooks/useTransactionType'
import { isSwapTransferOrderTxInfo } from '@/src/utils/transaction-guards'
import { OrderTransactionInfo } from '@/src/store/gateway/types'
import { TransactionQueuedItem, TransactionItem } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { OrderTransactionInfo } from '@safe-global/store/gateway/types'
import { TransactionQueuedItem, TransactionItem } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxGroupedCard {
transactions: (TransactionItem | TransactionQueuedItem)[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxRejectionCard } from '@/src/components/transactions-list/Card/TxRejectionCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { Cancellation } from '@/src/store/gateway/types'
import { Cancellation } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxRejectionCard> = {
title: 'TransactionsList/TxRejectionCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@/src/tests/test-utils'
import { TxRejectionCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { Cancellation } from '@/src/store/gateway/types'
import { Cancellation } from '@safe-global/store/gateway/types'

describe('TxRejectionCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import { View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import type { Cancellation } from '@/src/store/gateway/types'
import type { Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import type { Cancellation } from '@safe-global/store/gateway/types'
import type { Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxRejectionCardProps {
bordered?: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxSafeAppCard } from '@/src/components/transactions-list/Card/TxSafeAppCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { MultiSend } from '@/src/store/gateway/types'
import { MultiSend } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxSafeAppCard> = {
title: 'TransactionsList/TxSafeAppCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render } from '@/src/tests/test-utils'
import { TxSafeAppCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { MultiSend } from '@/src/store/gateway/types'
import { MultiSend } from '@safe-global/store/gateway/types'

describe('TxSafeAppCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import { Avatar, Text, View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import type { MultiSend } from '@/src/store/gateway/types'
import type { SafeAppInfo, Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import type { MultiSend } from '@safe-global/store/gateway/types'
import type { SafeAppInfo, Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxSafeAppCardProps {
safeAppInfo: SafeAppInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxSettingsCard } from '@/src/components/transactions-list/Card/TxSettingsCard'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { SettingsChangeTransaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { SettingsChangeTransaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxSettingsCard> = {
title: 'TransactionsList/TxSettingsCard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from '@/src/tests/test-utils'
import { TxSettingsCard } from '.'
import { mockTransferWithInfo } from '@/src/tests/mocks'
import { TransactionInfoType } from '@/src/store/gateway/types'
import { SettingsChangeTransaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { TransactionInfoType } from '@safe-global/store/gateway/types'
import { SettingsChangeTransaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

describe('TxSettingCard', () => {
it('should render the default markup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import { Theme, View } from 'tamagui'
import { SafeListItem } from '@/src/components/SafeListItem'
import { SafeFontIcon } from '@/src/components/SafeFontIcon/SafeFontIcon'
import { SettingsInfoType } from '@/src/store/gateway/types'
import { SettingsChangeTransaction, Transaction } from '@/src/store/gateway/AUTO_GENERATED/transactions'
import { SettingsInfoType } from '@safe-global/store/gateway/types'
import { SettingsChangeTransaction, Transaction } from '@safe-global/store/gateway/AUTO_GENERATED/transactions'

interface TxSettingsCardProps {
txInfo: SettingsChangeTransaction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react'
import { TxSwapCard } from '@/src/components/transactions-list/Card/TxSwapCard'
import { mockSwapTransfer } from '@/src/tests/mocks'
import { OrderTransactionInfo } from '@/src/store/gateway/types'
import { OrderTransactionInfo } from '@safe-global/store/gateway/types'

const meta: Meta<typeof TxSwapCard> = {
title: 'TransactionsList/TxSwapCard',
Expand Down
Loading

0 comments on commit 951aae1

Please sign in to comment.