Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not enable debug features on npm start #549

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This creates and funds a wallet `Satoshi` with password `test`.
Start the UI on port 3000:

```sh
npm start
npm run dev:start
```

Make your changes and be sure to manually test them before submitting them to us.
Expand Down Expand Up @@ -100,7 +100,7 @@ This creates and funds a wallet `Satoshi` with password `test`.
Start the UI on port 3000:

```sh
npm start
npm run dev:start
```

Enjoy the test drive!
Expand Down
4 changes: 2 additions & 2 deletions docker/regtest/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ npm run regtest:init
npm run regtest:mine

# start jam in development mode
npm start
npm run dev:start

[...]

Expand All @@ -49,7 +49,7 @@ npm run regtest:init
Once the regtest environment is up and running you can start Jam with:

```sh
npm start
npm run dev:start
```

### Stop
Expand Down
4 changes: 2 additions & 2 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For a complete development environment you need a local JoinMarket instance that
## Linting

We use Create React App's [default ESLint integration](https://create-react-app.dev/docs/setting-up-your-editor/#displaying-lint-output-in-the-editor).
You'll see linting issues in the console when running the app with `npm start`.
You'll see linting issues in the console when running the app with `npm run dev:start`.
Pull request builds will fail if ESLint is not happy with the code.

## Code Formatting
Expand Down Expand Up @@ -118,5 +118,5 @@ In short:
```bash
git clone https://github.com/joinmarket-webui/jam.git
cd jam/
npm install && npm start
npm install && npm run dev:start
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
"serve": "14.0.1"
},
"scripts": {
"dev:start": "REACT_APP_JAM_DEV_MODE=true npm start",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple, I like it 👍

"dev:start:secondary": "PORT=3001 JAM_BACKEND=jam-standalone JAM_API_PORT=29080 npm run dev:start",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"postinstall": "husky install",
"lint": "prettier --check --no-error-on-unmatched-pattern 'src/**/*.{js,jsx,ts,tsx,json,css,md}'",
"format": "prettier --write --no-error-on-unmatched-pattern 'src/**/*.{js,jsx,ts,tsx,json,css,md}'",
"start:regtest:secondary": "PORT=3001 JAM_BACKEND=jam-standalone JAM_API_PORT=29080 npm start",
"version": "node scripts/changelog.mjs && git checkout -b \"prepare-v${npm_package_version}-$(date +%s)\" && git add --all && git commit --message \"chore(release): v${npm_package_version}\" && git push --set-upstream origin $(git branch --show-current)",
"postversion": "which gh && gh pr create --title \"chore(release): v${npm_package_version}\" --body \"Prepares the v${npm_package_version} release.\" --assignee @me --label release --repo joinmarket-webui/jam --draft",
"regtest:build": "npm run regtest:clear && docker-compose --env-file docker/regtest/.env.example --file docker/regtest/docker-compose.yml build --pull",
Expand Down
4 changes: 2 additions & 2 deletions src/components/CreateWallet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { walletDisplayName } from '../utils'
import { useServiceInfo } from '../context/ServiceInfoContext'
import * as Api from '../libs/JmWalletApi'
import { routes } from '../constants/routes'
import { isFeatureEnabled } from '../constants/features'
import { isDebugFeatureEnabled } from '../constants/debugFeatures'
import styles from './CreateWallet.module.css'

const PreventLeavingPageByMistake = () => {
Expand Down Expand Up @@ -192,7 +192,7 @@ const BackupConfirmation = ({ createdWallet, walletConfirmed, parentStepSetter }
const { t } = useTranslation()
const [seedBackup, setSeedBackup] = useState(false)
const [seedWordConfirmations, setSeedWordConfirmations] = useState(new Array(seedphrase.length).fill(false))
const [showSkipButton] = useState(isFeatureEnabled('skipWalletBackupConfirmation'))
const [showSkipButton] = useState(isDebugFeatureEnabled('skipWalletBackupConfirmation'))

useEffect(() => {
setSeedBackup(seedWordConfirmations.every((wordConfirmed) => wordConfirmed))
Expand Down
4 changes: 2 additions & 2 deletions src/components/CreateWallet.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BrowserRouter } from 'react-router-dom'
import user from '@testing-library/user-event'
import { render, screen, waitFor } from '../testUtils'
import { act } from 'react-dom/test-utils'
import { __testSetFeatureEnabled } from '../constants/features'
import { __testSetDebugFeatureEnabled } from '../constants/debugFeatures'

import * as apiMock from '../libs/JmWalletApi'

Expand Down Expand Up @@ -159,7 +159,7 @@ describe('<CreateWallet />', () => {
})

it('should verify that "skip" button IS visible when feature is enabled', async () => {
__testSetFeatureEnabled('skipWalletBackupConfirmation', true)
__testSetDebugFeatureEnabled('skipWalletBackupConfirmation', true)

apiMock.postWalletCreate.mockResolvedValueOnce({
ok: true,
Expand Down
12 changes: 5 additions & 7 deletions src/constants/debugFeatures.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
interface DebugFeatures {
insecureScheduleTesting: boolean
allowCreatingExpiredFidelityBond: boolean
skipWalletBackupConfirmation: boolean
}

const devMode = process.env.NODE_ENV === 'development'
const devMode = process.env.NODE_ENV === 'development' && process.env.REACT_APP_JAM_DEV_MODE === 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const debugFeatures: DebugFeatures = {
insecureScheduleTesting: true,
allowCreatingExpiredFidelityBond: true,
allowCreatingExpiredFidelityBond: devMode,
insecureScheduleTesting: devMode,
skipWalletBackupConfirmation: devMode,
}

type DebugFeature = keyof DebugFeatures

export const isDebugFeatureEnabled = (name: DebugFeature): boolean => {
if (!devMode) {
return false
}

return debugFeatures[name] || false
}

Expand Down
20 changes: 0 additions & 20 deletions src/constants/features.ts

This file was deleted.