Skip to content

Commit 55a6597

Browse files
committed
chore: very basic transfer over to TypeScript
1 parent 5bb46c6 commit 55a6597

33 files changed

+539
-304
lines changed

Diff for: babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
presets: [
3-
[
4-
'@babel/preset-env',
3+
'@babel/preset-typescript',
4+
['@babel/preset-env',
55
{
66
targets: {
77
node: 'current',

Diff for: packages/contract-artifacts/.eslintrc.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
"env": {
3+
"es6": true,
4+
"browser": true
5+
},
6+
"extends": [
7+
'eslint:recommended',
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
10+
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
11+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
12+
],
13+
// "ignorePatterns": [],
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"project": "./tsconfig.json",
17+
"tsconfigRootDir": __dirname,
18+
"sourceType": "module"
19+
},
20+
"plugins": [
21+
"@typescript-eslint",
22+
],
23+
"rules": {
24+
"import/extensions": [
25+
"error",
26+
"ignorePackages",
27+
{
28+
"js": "never",
29+
"ts": "never"
30+
}
31+
]
32+
},
33+
"settings": {
34+
'import/resolver': {
35+
node: {
36+
extensions: ['.js', '.ts']
37+
},
38+
},
39+
}
40+
};

Diff for: packages/contract-artifacts/lib/index.js

+10-16
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@ var _rinkeby = _interopRequireDefault(require("../addresses/rinkeby.json"));
1212
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1313

1414
// import mainnetAddresses from "./addresses/mainnet";
15-
const {
16-
isUndefined
17-
} = require('lodash');
18-
1915
const abis = {
2016
AztecStreamer: _AztecStreamer.default
2117
};
22-
exports.abis = abis;
23-
const networkToAddresses = {
24-
// '1': {
25-
// ...mainnetAddresses,
26-
// },
27-
4: { ..._rinkeby.default
28-
}
29-
};
3018
/**
3119
* Used to get addresses of contracts that have been deployed to either the
3220
* Ethereum mainnet or a supported testnet. Throws if there are no known
@@ -36,12 +24,18 @@ const networkToAddresses = {
3624
* given networkId.
3725
*/
3826

27+
exports.abis = abis;
28+
3929
const getContractAddressesForNetwork = networkId => {
40-
if (isUndefined(networkToAddresses[networkId])) {
41-
throw new Error(`Unknown network id (${networkId}). No known AZTEC contracts have been deployed on this network.`);
30+
switch (networkId) {
31+
// case 1:
32+
// return mainnetAddresses;
33+
case 4:
34+
return _rinkeby.default;
35+
36+
default:
37+
throw new Error(`Unknown network id (${networkId}). No known NoteStream contracts have been deployed on this network.`);
4238
}
43-
44-
return networkToAddresses[networkId];
4539
};
4640

4741
exports.getContractAddressesForNetwork = getContractAddressesForNetwork;

Diff for: packages/contract-artifacts/lib/src/index.d.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export declare type Address = string;
2+
export interface Deployment {
3+
ACE: Address;
4+
AztecStreamer: Address;
5+
}
6+
export declare const abis: object;
7+
/**
8+
* Used to get addresses of contracts that have been deployed to either the
9+
* Ethereum mainnet or a supported testnet. Throws if there are no known
10+
* contracts deployed on the corresponding network.
11+
* @param networkId The desired networkId.
12+
* @returns The set of addresses for contracts which have been deployed on the
13+
* given networkId.
14+
*/
15+
export declare const getContractAddressesForNetwork: (networkId: number) => Deployment;

Diff for: packages/contract-artifacts/package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
"bugs": {
77
"url": "https://github.com/TomAFrench/NoteStream/issues"
88
},
9-
"dependencies": {
10-
"lodash": "^4.17.11"
11-
},
9+
"dependencies": {},
1210
"devDependencies": {
1311
"@babel/cli": "^7.4.3",
1412
"@babel/core": "^7.4.0",
1513
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
16-
"@babel/preset-env": "^7.4.2",
14+
"@babel/preset-env": "^7.9.0",
15+
"@babel/preset-typescript": "^7.9.0",
1716
"eslint": "^5.15.3",
1817
"eslint-config-airbnb-base": "^13.1.0",
1918
"eslint-config-prettier": "^6.0.0",
@@ -44,11 +43,12 @@
4443
"url": "git+https://github.com/TomAFrench/NoteStream.git"
4544
},
4645
"scripts": {
47-
"build:dev": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
48-
"build": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
49-
"build:prod": "yarn build",
46+
"prepare": "yarn clean && yarn lint --fix",
47+
"build": "yarn prepare && yarn build:types && yarn build:js",
48+
"build:js": " babel src --out-dir lib --extensions '.ts,.tsx' --root-mode upward ./src",
49+
"build:types": "tsc --emitDeclarationOnly",
5050
"clean": "shx rm -rf ./lib",
51-
"lint": "eslint --ignore-path ../../.eslintignore .",
52-
"watch": "yarn build:dev --watch"
51+
"lint": "eslint --config .eslintrc.js --ext .js,.ts . ",
52+
"watch": "yarn build --watch"
5353
}
5454
}

Diff for: packages/contract-artifacts/src/index.js

-33
This file was deleted.

Diff for: packages/contract-artifacts/src/index.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import AztecStreamerABI from "../abis/AztecStreamer.json";
2+
// import mainnetAddresses from "./addresses/mainnet";
3+
import rinkebyAddresses from "../addresses/rinkeby.json";
4+
5+
export type Address = string;
6+
7+
export interface Deployment {
8+
ACE: Address;
9+
AztecStreamer: Address;
10+
}
11+
12+
export const abis: object = {
13+
AztecStreamer: AztecStreamerABI,
14+
};
15+
16+
/**
17+
* Used to get addresses of contracts that have been deployed to either the
18+
* Ethereum mainnet or a supported testnet. Throws if there are no known
19+
* contracts deployed on the corresponding network.
20+
* @param networkId The desired networkId.
21+
* @returns The set of addresses for contracts which have been deployed on the
22+
* given networkId.
23+
*/
24+
export const getContractAddressesForNetwork = (
25+
networkId: number
26+
): Deployment => {
27+
switch (networkId) {
28+
// case 1:
29+
// return mainnetAddresses;
30+
case 4:
31+
return rinkebyAddresses;
32+
default:
33+
throw new Error(
34+
`Unknown network id (${networkId}). No known NoteStream contracts have been deployed on this network.`
35+
);
36+
}
37+
};

Diff for: packages/contract-artifacts/tsconfig.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"lib": [
5+
"ES2015",
6+
"DOM"
7+
],
8+
"module": "ES2015",
9+
"outDir": "lib",
10+
"sourceMap": true,
11+
"target": "ES2015",
12+
"declaration": true,
13+
/* Strict Type-Checking Options */
14+
"noImplicitAny": true,
15+
"strict": true,
16+
/* Module Resolution Options */
17+
"esModuleInterop": true,
18+
"moduleResolution": "node",
19+
"resolveJsonModule": true,
20+
"skipLibCheck": false,
21+
/* Advanced Options */
22+
"forceConsistentCasingInFileNames": true,
23+
},
24+
"include": [
25+
"./src/**/*",
26+
"./lib/**/*"
27+
]
28+
}

Diff for: packages/react-app/.eslintrc.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
"env": {
3-
"es6": true
3+
"es6": true,
4+
"browser": true
45
},
56
"extends": [
67
'eslint:recommended',
@@ -20,9 +21,28 @@ module.exports = {
2021
"@typescript-eslint",
2122
// "@typescript-eslint/tslint"
2223
],
24+
"rules": {
25+
"spaced-comment": ["error", "always", { "markers": ["/"] }],
26+
"import/extensions": [
27+
"error",
28+
"ignorePackages",
29+
{
30+
"js": "never",
31+
"jsx": "never",
32+
"ts": "never",
33+
"tsx": "never"
34+
}
35+
]
36+
},
2337
"settings": {
2438
"react": {
2539
"version": "detect"
26-
}
40+
},
41+
'import/resolver': {
42+
node: {
43+
paths: ["src", "node_modules"],
44+
extensions: ['.js', '.jsx', '.ts', '.tsx']
45+
},
46+
},
2747
}
2848
};

Diff for: packages/react-app/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
"@babel/core": "^7.8.4",
3535
"@babel/node": "^7.8.4",
3636
"@babel/preset-env": "^7.8.4",
37+
"@babel/preset-typescript": "^7.9.0",
3738
"@testing-library/jest-dom": "^4.2.4",
3839
"@testing-library/react": "^9.3.2",
3940
"@testing-library/user-event": "^7.1.2",
41+
"@types/react-copy-to-clipboard": "^4.3.0",
4042
"@typescript-eslint/eslint-plugin-tslint": "^2.27.0",
4143
"eslint": "^6.8.0",
4244
"eslint-config-airbnb-base": "^14.1.0",
@@ -45,13 +47,17 @@
4547
"eslint-plugin-prettier": "^3.1.2",
4648
"eslint-plugin-react": "^7.19.0",
4749
"prettier": "^2.0.4",
50+
"shx": "^0.3.2",
4851
"typescript": "^3.8.3"
4952
},
5053
"scripts": {
54+
"prepare": "yarn clean && yarn lint",
5155
"start": "react-scripts start",
52-
"build": "react-scripts build",
56+
"build": "yarn prepare",
57+
"build:js": "react-scripts build",
5358
"test": "react-scripts test",
5459
"eject": "react-scripts eject",
60+
"clean": "shx rm -rf ./build",
5561
"lint": "eslint --config .eslintrc.js ./src --ext .js,.jsx,.ts,.tsx"
5662
},
5763
"eslintConfig": {
@@ -69,4 +75,4 @@
6975
"last 1 safari version"
7076
]
7177
}
72-
}
78+
}

Diff for: packages/react-app/src/App.test.js

-9
This file was deleted.

0 commit comments

Comments
 (0)