Skip to content

Commit

Permalink
Chore/workspace settings (#153)
Browse files Browse the repository at this point in the history
* chore: added recommended vscode extensions file and default formatter for background package.

* chore: added specific recommended extensions per package.

* chore: use prettier to lint and fix the lint with yarn commands

* chore: allow multiple lint running in the pipeline

* chore: fix CI

* chore: improve messages

* fix: prettier only with tsx

* fix: prettier only with tsx

* fix: pipeline and lint some files

* fix: lint

* fix: exclude only json in provider and background

* fix: vars

* chore: applied lint fix in UI package.

* chore: linting fixes on background package.

* fix: typo

* chore: added prettier config to eslint.

* fix: exit code in lint

* fix: var

* fix: use if

* fix: operator

* fix: operator again

* chore: removed comments from json files.

Co-authored-by: Julian Ariel Martinez <[email protected]>
  • Loading branch information
sreblock and julianariel authored Oct 10, 2022
1 parent 935d509 commit c7e74ab
Show file tree
Hide file tree
Showing 48 changed files with 426 additions and 431 deletions.
69 changes: 47 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ jobs:
- name: Dependency UI cache
uses: actions/cache@v3
with:
path: "packages/ui/node_modules"
path: 'packages/ui/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/ui/yarn.lock') }}

- name: Dependency Background cache
uses: actions/cache@v3
with:
path: "packages/background/node_modules"
path: 'packages/background/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/background/yarn.lock') }}

- name: Dependency Provider cache
uses: actions/cache@v3
with:
path: "packages/provider/node_modules"
path: 'packages/provider/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/provider/yarn.lock') }}

- name: Install packages dependencies
Expand All @@ -51,20 +51,45 @@ jobs:
GITHUB_TOKEN: ${{ secrets.PAT }}
NODE_AUTH_TOKEN: ${{secrets.REGISTRY_AUTH_TOKEN}}

- name: Check lint in un
- name: Check lint in all the packages
run: |
echo "::group::UI"
cd packages/ui/
yarn lint
- name: Check lint in background
run: |
cd packages/background/
yarn lint
- name: Check lint in provider
run: |
cd packages/provider/
yarn lint
if yarn lint; then
echo "::notice:: UI lint OK"
lint_ui=0
else
echo '::error:: UI lint failed. Run "yarn lint:fix" in the folder "packages/ui/" to fix it and commit your changes.'
lint_ui=1
fi
echo "::endgroup::"
echo "::group::Background"
cd ..
cd background/
if yarn lint; then
echo "::notice:: Background lint OK"
lint_background=0
else
echo '::error:: Background lint failed. Run "yarn lint:fix" in the folder "packages/background/" to fix it and commit your changes.'
lint_background=1
fi
echo "::endgroup::"
echo "::group::Provider"
cd ..
cd provider/
if yarn lint; then
echo "::notice:: Provider lint OK"
lint_provider=0
else
echo '::error:: Provider lint failed. Run "yarn lint:fix" in the folder "packages/provider/" to fix it and commit your changes.'
lint_provider=1
fi
echo "::endgroup::"
if [[ "$lint_ui" -ne "0" || "$lint_background" -ne "0" || "$lint_provider" -ne "0" ]]; then
exit 1
fi
test:
runs-on: ubuntu-latest
Expand All @@ -85,19 +110,19 @@ jobs:
- name: Dependency UI cache
uses: actions/cache@v3
with:
path: "packages/ui/node_modules"
path: 'packages/ui/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/ui/yarn.lock') }}

- name: Dependency Background cache
uses: actions/cache@v3
with:
path: "packages/background/node_modules"
path: 'packages/background/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/background/yarn.lock') }}

- name: Dependency Provider cache
uses: actions/cache@v3
with:
path: "packages/provider/node_modules"
path: 'packages/provider/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/provider/yarn.lock') }}

- name: Install packages dependencies
Expand Down Expand Up @@ -152,19 +177,19 @@ jobs:
- name: Dependency UI cache
uses: actions/cache@v3
with:
path: "packages/ui/node_modules"
path: 'packages/ui/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/ui/yarn.lock') }}

- name: Dependency Background cache
uses: actions/cache@v3
with:
path: "packages/background/node_modules"
path: 'packages/background/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/background/yarn.lock') }}

- name: Dependency Provider cache
uses: actions/cache@v3
with:
path: "packages/provider/node_modules"
path: 'packages/provider/node_modules'
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/provider/yarn.lock') }}

- name: Install packages dependencies
Expand Down Expand Up @@ -241,7 +266,7 @@ jobs:
- name: Install yarn
run: |
npm install --global yarn
- name: Cache e2e dependencies
id: cache-cypress
uses: actions/cache@v3
Expand Down
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"eamodio.gitlens",
]
}
5 changes: 5 additions & 0 deletions packages/background/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"maty.vscode-mocha-sidebar"
],
}
3 changes: 2 additions & 1 deletion packages/background/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"mochaExplorer.env": {
"TS_NODE_PROJECT": "tsconfig.json",
"TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\" }"
}
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
17 changes: 9 additions & 8 deletions packages/background/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
"private": true,
"dependencies": {
"@block-wallet/chains-assets": "https://github.com/block-wallet/chains-assets#v0.0.14",
"@block-wallet/circomlib": "^0.0.21",
"@block-wallet/eth-ledger-bridge-keyring": "https://github.com/block-wallet/eth-ledger-bridge-keyring",
"@block-wallet/explorer-link": "https://github.com/block-wallet/explorer-link#v2.2.2",
"@block-wallet/fixed-merkle-tree": "^0.6.1",
"@block-wallet/snarkjs": "^0.1.20",
"@block-wallet/websnark": "^0.0.5",
"@ethereumjs/tx": "^3.2.1",
"@unstoppabledomains/resolution": "^7.1.4",
"async-mutex": "^0.3.2",
Expand All @@ -14,7 +18,6 @@
"bip39": "^3.0.3",
"blake3": "^2.1.4",
"browser-passworder": "^2.0.3",
"@block-wallet/circomlib": "^0.0.21",
"compare-versions": "^3.6.0",
"eth-ens-namehash": "^2.0.8",
"eth-keyring-controller": "^6.2.0",
Expand All @@ -23,15 +26,12 @@
"ethereumjs-util": "^7.0.7",
"ethereumjs-wallet": "^1.0.1",
"ethers": "^5.4.0",
"@block-wallet/fixed-merkle-tree": "^0.6.1",
"idb": "^6.0.0",
"lodash": "^4.17.21",
"loglevel": "^1.7.1",
"phishing-prevention": "git+https://github.com/block-wallet/phishing-prevention#4708461673825816104b8a6cf5260ecb29b75c61",
"schema-validator": "git+https://github.com/block-wallet/schema-validator.git",
"@block-wallet/snarkjs": "^0.1.20",
"uuid": "^8.3.2",
"@block-wallet/websnark": "^0.0.5"
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
Expand Down Expand Up @@ -64,7 +64,7 @@
"mock-require": "^3.0.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.4.1",
"prettier": "^2.7.1",
"semver": "^7.3.7",
"sinon": "^9.2.3",
"sinon-chrome": "^3.0.1",
Expand Down Expand Up @@ -93,6 +93,7 @@
"test": "make test/background",
"build": "make build/background",
"eslint-report": "eslint src --ext .ts -o eslint-report.html -f html",
"lint": "eslint src --ext .ts --quiet"
"lint": "prettier --check src/ '!**/*.json'",
"lint:fix": "prettier --write src/ '!**/*.json'"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,9 @@ export class TornadoNotesService extends NotesService {
let depositIndex = isReconstruct
? 0
: await this._blankDepositVault.getDerivedDepositIndex(
currencyAmountPair,
chainId
);
currencyAmountPair,
chainId
);

// Disabled rule as needed to iterate through all the deposits
// eslint-disable-next-line no-constant-condition
Expand Down
5 changes: 3 additions & 2 deletions packages/background/src/controllers/erc-20/TokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ for (const chainId in TOKENS_LIST) {
if ('l' in token) {
logo = 'https://' + token['l'];
} else {
logo = `https://raw.githubusercontent.com/block-wallet/assets/master/blockchains/${NETWORKS_NAMES[parseInt(chainId)]
}/assets/${address}/logo.png`;
logo = `https://raw.githubusercontent.com/block-wallet/assets/master/blockchains/${
NETWORKS_NAMES[parseInt(chainId)]
}/assets/${address}/logo.png`;
}

let type = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
};
},
// Migration version must match new bumped package.json version
version: '0.2.0',
version: "0.2.0",
};
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export default {
NetworkController: {
...persistedState.NetworkController,
availableNetworks: { ...updatedNetworks },

},
};
},
Expand Down
20 changes: 10 additions & 10 deletions packages/background/src/utils/releaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Options {

const defaultOptions: Options = {
stackNotes: true,
currentVersionOnly: false
currentVersionOnly: false,
};

const generateReleaseNotesNews = (
Expand All @@ -23,7 +23,9 @@ const generateReleaseNotesNews = (
...defaultOptions,
...options,
};
let sortedNotes = [...releasesNotes].sort((r1, r2) => compareVersions(r2.version, r1.version));
let sortedNotes = [...releasesNotes].sort((r1, r2) =>
compareVersions(r2.version, r1.version)
);

if (safeOptions.lastVersionSeen) {
sortedNotes = sortedNotes.filter(
Expand All @@ -32,15 +34,13 @@ const generateReleaseNotesNews = (
);
}

const filteredNotes = sortedNotes.filter(
({ version }) => {
const result = compareVersions(userCurrentVersion, version)
if (safeOptions.currentVersionOnly) {
return result === 0
}
return result > -1
const filteredNotes = sortedNotes.filter(({ version }) => {
const result = compareVersions(userCurrentVersion, version);
if (safeOptions.currentVersionOnly) {
return result === 0;
}
);
return result > -1;
});

//keep last version only
if (filteredNotes.length && !safeOptions.stackNotes) {
Expand Down
15 changes: 4 additions & 11 deletions packages/background/src/utils/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export const validateSignature = <TSignatureType extends SignatureMethods>(
if (typeof nParams.data === 'string') {
const typedData = JSON.parse(nParams.data);
nParams.data = sanitizeTypedData(typedData);


}
}

Expand Down Expand Up @@ -203,31 +201,26 @@ export const hexToString = (hex: string): string => {
return output;
};


const sanitizeTypedData = (typedData: TypedMessage<MessageSchema>): any => {

try {
// Check and remove null values from the typed data primary type.
const uint256Properties = typedData.types[typedData.primaryType].filter(t => t.type === 'uint256');
const uint256Properties = typedData.types[typedData.primaryType].filter(
(t) => t.type === 'uint256'
);

if (!uint256Properties) return typedData;


// Loop properties
for (const k in uint256Properties) {
const propertyName = uint256Properties[k].name;

// If an uint256 property has null value, we replace it with a 0 to prevent errors.
if (typedData.message[propertyName] === null)
typedData.message[propertyName] = 0;

}

return typedData;
} catch (error) {
return typedData;
}


}

};
4 changes: 1 addition & 3 deletions packages/background/src/utils/userPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ export const getReleaseNotes = async (): Promise<ReleaseNote[]> => {
}
};


export const generateOnDemandReleaseNotes = async (
version: string
): Promise<ReleaseNote[]> => {
const releaseNotesData = await getReleaseNotes();
const data = generateReleaseNotesNews(releaseNotesData, version, {
lastVersionSeen: undefined,
stackNotes: false,
currentVersionOnly: true
currentVersionOnly: true,
});
return data || [];
};


export const resolvePreferencesAfterWalletUpdate = async (
userPreferences: Partial<PreferencesControllerState>,
newManifestVersion: string
Expand Down
2 changes: 1 addition & 1 deletion packages/background/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6743,7 +6743,7 @@ prepend-http@^1.0.1:
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
integrity sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==

prettier@^2.4.1:
prettier@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==
Expand Down
5 changes: 3 additions & 2 deletions packages/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"jsdom-global": "^3.0.2",
"mocha": "^9.1.1",
"nyc": "^15.1.0",
"prettier": "^2.4.1",
"prettier": "^2.7.1",
"ts-loader": "^9.1.2",
"ts-node": "^10.2.1",
"tsconfig-paths": "^3.11.0",
Expand All @@ -39,6 +39,7 @@
"test": "make test/provider",
"build": "make build/provider",
"eslint-report": "eslint src --ext .ts -o eslint-report.html -f html",
"lint": "eslint src --ext .ts --quiet"
"lint": "prettier --check src/ '!**/*.json'",
"lint:fix": "prettier --write src/ '!**/*.json'"
}
}
Loading

0 comments on commit c7e74ab

Please sign in to comment.