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

refactor: migrating to typescript #521

Merged
merged 52 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
2c164e2
init typescript settings
hanwencheng Jan 9, 2020
6a3ca1a
change let to const
hanwencheng Jan 9, 2020
73b4eff
use typescript strict
hanwencheng Jan 9, 2020
0e93399
update lint config for typescript
hanwencheng Jan 31, 2020
0679306
update lint config for typescript
hanwencheng Jan 31, 2020
44b1e8f
upgrade to react-navigation v4 and use typed navigator
hanwencheng Jan 31, 2020
78392b9
add required dependency for react navigation
hanwencheng Feb 2, 2020
6a99892
update with eslint and App.tsx
hanwencheng Feb 3, 2020
0edb0cb
merge master branch
hanwencheng Feb 6, 2020
bcb1900
following merging
hanwencheng Feb 6, 2020
f0a7929
refactor buttons
hanwencheng Feb 6, 2020
a4f49a0
refactor
hanwencheng Feb 7, 2020
13f8803
Merge branch 'master' into hanwen-typescript
hanwencheng Feb 7, 2020
1161fe4
stash
hanwencheng Feb 7, 2020
0e72d9e
add types for networks specs
hanwencheng Feb 10, 2020
ce9f300
fix add legacy account error
hanwencheng Feb 10, 2020
6946e94
update typescript configs
hanwencheng Feb 11, 2020
c756dc0
refactor identity and account stores
hanwencheng Feb 11, 2020
b875f7f
Merge branch 'master' into hanwen-typescript
hanwencheng Feb 11, 2020
38b2028
hoc.js to typescript
hanwencheng Feb 11, 2020
be443a1
refactor main landing page
hanwencheng Feb 12, 2020
44a369f
complete identity utils and account store
hanwencheng Feb 13, 2020
356ab39
renaming files
hanwencheng Feb 13, 2020
6c7daec
refactor components and payloads component
hanwencheng Feb 13, 2020
090a3ba
refactor all the components and scanner store
hanwencheng Feb 16, 2020
ff52b55
fix typescript compiler errors
hanwencheng Feb 17, 2020
9f23678
rename alls screens
hanwencheng Feb 17, 2020
2bd342b
refactor screens
hanwencheng Feb 17, 2020
eaab2d4
refactor all the screens
hanwencheng Feb 18, 2020
a25e7fe
fix typescript compiler errors
hanwencheng Feb 18, 2020
863e5c0
fixed compiler and lint error
hanwencheng Feb 18, 2020
735cc44
reorder files and use path alias
hanwencheng Feb 19, 2020
6415444
reoder imports
hanwencheng Feb 19, 2020
39b5fe0
ignore jest caches
hanwencheng Feb 19, 2020
06ff166
integrate typescript with jest
hanwencheng Feb 19, 2020
689fa4f
integrate e2e test
hanwencheng Feb 20, 2020
ad51f83
update travis config and readme
hanwencheng Feb 20, 2020
240fd54
remove logs and comments
hanwencheng Feb 20, 2020
974ac90
delete redundant line
hanwencheng Feb 20, 2020
788df04
fix scanner name
hanwencheng Feb 20, 2020
5508a2b
multi signing fix
hanwencheng Feb 20, 2020
cc44c2e
add default catch
hanwencheng Feb 20, 2020
a939cb8
use await to avoid async problem and remove one warning with source.uri
hanwencheng Feb 21, 2020
9d0df06
use path alias of e2e and utils
hanwencheng Feb 21, 2020
b2e1760
imporve sign button display in small screen
hanwencheng Feb 21, 2020
5a04c78
hide path derivation option for ethereum account
hanwencheng Feb 22, 2020
5bf29b9
fix path display error
hanwencheng Feb 22, 2020
92677a4
fix ethereum delete problem
hanwencheng Mar 2, 2020
be4408a
imporve navigation
hanwencheng Mar 2, 2020
2a35ff9
upgrade react navigation to resolve bug
hanwencheng Mar 2, 2020
0ebb3e8
add react hooks lint
hanwencheng Mar 2, 2020
3fed3ce
fix missing icon bug
hanwencheng Mar 2, 2020
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
78 changes: 66 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
const commonRules = {
"no-bitwise": "off",
"comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "single", { "avoidEscape": true }],
"no-unused-vars": ["error", { "args": "none" }],
"react-native/no-inline-styles": "off",
"sort-keys": ["error", "asc", {"caseSensitive": true, "natural": false, "minKeys": 2}],
"import/order": ["error", {
"newlines-between": "always"
}]
};

module.exports = {
extends: ["@react-native-community", "plugin:prettier/recommended", "plugin:import/errors", "plugin:import/warnings"],
extends: [
"@react-native-community",
"plugin:prettier/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
globals: { inTest: "writable" },
overrides: [
{
"files": ["e2e/*.spec.js", "e2e/init.js", "e2e/e2eUtils.js"],
"rules": {
files: ["e2e/*.spec.js", "e2e/init.js", "e2e/e2eUtils.js"],
rules: {
"no-undef": "off"
}
},
{
files: ["**/*.ts", "**/*.tsx"],
env: { "browser": true, "es6": true, "node": true },
extends: [
"@react-native-community",
"plugin:prettier/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: { "jsx": true },
ecmaVersion: 2018,
sourceType: "module",
project: "./tsconfig.json"
},
plugins: ["@typescript-eslint", "react-hooks"],
rules: {
...commonRules,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/semi": ["error"],
"@typescript-eslint/no-use-before-define": ["error", { "variables": false }], // enable defining variables after react component;
"@typescript-eslint/no-non-null-assertion": 0,
'@typescript-eslint/camelcase': 0,
"no-void": "off",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"semi": "off"
}
}
],
parserOptions: {
Expand All @@ -16,18 +69,19 @@ module.exports = {
},
},
settings: {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
},
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<roo/>@types` directory even it doesn't contain any source code, like `@types/unist`
},
},
"import/ignore": "react-navigation",
react: {
"pragma": "React", // Pragma to use, default to "React"
"version": "16.9.0", // React version, default to the latest React stable release
},
},
rules: {
"no-bitwise": "off",
"comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"quotes": ["error", "single", { "avoidEscape": true }],
"no-unused-vars": ["error", { "args": "none" }],
"react-native/no-inline-styles": "off",
"sort-keys": ["error", "asc", {"caseSensitive": true, "natural": false, "minKeys": 2}]
}
rules: commonRules
};
81 changes: 0 additions & 81 deletions .flowconfig

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
yarn-error.log
package-lock.json

# typescript output directory
dist/

# jest cache
.jest/cache

# NDK
NDK/
rust/.cargo
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"printWidth": 80,
"parser": "flow",
"parser": "typescript",
"singleQuote": true,
"useTabs": true,
"tabWidth": 2
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
language: node_js
node_js: 8
node_js: 10

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Parity Signer was built to be used offline. The mobile device used to run the ap
## Build it
### Requirements

- `node.js` (tested on `v8.4.0`)
- `node.js` ( `>=10`)
- `yarn` (tested on `1.6.0`)
- `rustup` (tested on `rustup 1.16.0`)
- `rustc` (tested on `rustc 1.32.0 (9fda7c223 2019-01-16)`)
Expand Down
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ android {
}

dependencies {
implementation project(':react-native-safe-area-context')
implementation project(':react-native-camera')
implementation project(':react-native-secure-storage')
implementation project(':react-native-gesture-handler')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Application;

import com.facebook.react.ReactApplication;
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
import com.reactlibrary.RNSecureStoragePackage;
import org.reactnative.camera.RNCameraPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
Expand Down Expand Up @@ -30,6 +31,7 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SafeAreaContextPackage(),
new RNSecureStoragePackage(),
new RNCameraPackage(),
new SvgPackage(),
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
rootProject.name = 'Parity Signer'
include ':react-native-safe-area-context'
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
include ':react-native-secure-storage'
project(':react-native-secure-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-secure-storage/android')
include ':react-native-gesture-handler'
Expand Down
17 changes: 17 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ module.exports = {
vm: 'vm-browserify'
}
}
],
[
'module-resolver',
{
alias: {
components: './src/components',
constants: './src/constants',
e2e: './e2e',
res: './res',
screens: './src/screens',
stores: './src/stores',
styles: './src/styles',
types: './src/types',
utils: './src/utils'
},
root: ['.']
}
]
],
presets: ['module:metro-react-native-babel-preset']
Expand Down
2 changes: 1 addition & 1 deletion e2e/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"setupFilesAfterEnv": ["./init.js"],
"setupFilesAfterEnv": ["./init.ts"],
"testEnvironment": "node",
"reporters": ["detox/runners/jest/streamlineReporter"],
"verbose": true
Expand Down
32 changes: 21 additions & 11 deletions e2e/e2eUtils.js → e2e/e2eUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,43 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

'use strict';
import { expect, element, by } from 'detox';

import testIDs from './testIDs';
const { IdentityPin } = testIDs;

export const testTap = async buttonId => await element(by.id(buttonId)).tap();
export const testTap = async (buttonId: string): Promise<Detox.Actions<any>> =>
await element(by.id(buttonId)).tap();

export const testVisible = async componentId =>
export const testVisible = async (componentId: string): Promise<void> =>
await expect(element(by.id(componentId))).toBeVisible();

export const testExist = async componentId =>
export const testExist = async (componentId: string): Promise<void> =>
await expect(element(by.id(componentId))).toExist();

export const testNotExist = async componentId =>
export const testNotExist = async (componentId: string): Promise<void> =>
await expect(element(by.id(componentId))).toNotExist();

export const testNotVisible = async componentId =>
export const testNotVisible = async (componentId: string): Promise<void> =>
await expect(element(by.id(componentId))).toBeNotVisible();

export const tapBack = async () =>
export const tapBack = async (): Promise<Detox.Actions<any>> =>
await element(by.id(testIDs.Header.headerBackButton))
.atIndex(0)
.tap();

export const testInput = async (inputId, inputText) => {
export const testInput = async (
inputId: string,
inputText: string
): Promise<void> => {
await element(by.id(inputId)).typeText(inputText);
await element(by.id(inputId)).tapReturnKey();
};

export const testInputWithDone = async (inputId, inputText) => {
export const testInputWithDone = async (
inputId: string,
inputText: string
): Promise<void> => {
await element(by.id(inputId)).typeText(inputText);
if (device.getPlatform() === 'ios') {
await element(by.label('Done'))
Expand All @@ -54,14 +61,17 @@ export const testInputWithDone = async (inputId, inputText) => {
}
};

export const testScrollAndTap = async (buttonId, screenId) => {
export const testScrollAndTap = async (
buttonId: string,
screenId: string
): Promise<void> => {
await waitFor(element(by.id(buttonId)))
.toBeVisible()
.whileElement(by.id(screenId))
.scroll(100, 'down');
await testTap(buttonId);
};

export const testUnlockPin = async pinCode => {
export const testUnlockPin = async (pinCode: string): Promise<void> => {
await testInputWithDone(IdentityPin.unlockPinInput, pinCode);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

'use strict';
import { by, device, element } from 'detox';

import testIDs from './testIDs';
import {
Expand Down Expand Up @@ -54,7 +54,7 @@ const defaultPath = '//default',
const mockSeedPhrase =
'split cradle example drum veteran swear cruel pizza guilt surface mansion film grant benefit educate marble cargo ignore bind include advance grunt exile grow';

const testSetUpDefaultPath = async () => {
const testSetUpDefaultPath = async (): Promise<void> => {
await testInput(IdentityPin.setPin, pinCode);
await testInputWithDone(IdentityPin.confirmPin, pinCode);
await testVisible(AccountNetworkChooser.chooserScreen);
Expand Down
Loading