Skip to content

Commit

Permalink
Merge pull request #7 from vechainfoundation/pre-commit-hooks
Browse files Browse the repository at this point in the history
Pre commit hooks
  • Loading branch information
davidecarpini authored Oct 24, 2023
2 parents c397d7e + 8ab1b40 commit af0a4c3
Show file tree
Hide file tree
Showing 20 changed files with 873 additions and 205 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["custom/library"],
};
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install lint-staged
4 changes: 2 additions & 2 deletions apps/sample-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-app-rewired eject",
"lint": "eslint src/**/*",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"clean": "rm -rf build node_modules .turbo"
},
"dependencies": {
Expand Down Expand Up @@ -74,4 +74,4 @@
"last 1 safari version"
]
}
}
}
2 changes: 1 addition & 1 deletion apps/sample-react-app/src/Components/AddressIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import type { HTMLChakraProps} from "@chakra-ui/react";
import type { HTMLChakraProps } from "@chakra-ui/react";
import { Img } from "@chakra-ui/react";
import { getPicassoImgSrc } from "../Utils/AccountUtils";

Expand Down
3 changes: 1 addition & 2 deletions apps/sample-react-app/src/Components/shared/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
HTMLChakraProps} from "@chakra-ui/react";
import type { HTMLChakraProps } from "@chakra-ui/react";
import {
Modal,
ModalBody,
Expand Down
9 changes: 2 additions & 7 deletions apps/sample-react-app/src/Components/shared/StyledCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import type {
HTMLChakraProps} from "@chakra-ui/react";
import {
Card,
CardBody,
useColorModeValue,
} from "@chakra-ui/react";
import type { HTMLChakraProps } from "@chakra-ui/react";
import { Card, CardBody, useColorModeValue } from "@chakra-ui/react";
import React from "react";

interface StyledCardProps extends HTMLChakraProps<"div"> {
Expand Down
2 changes: 1 addition & 1 deletion apps/sample-react-app/src/Logos/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HTMLChakraProps} from "@chakra-ui/react";
import type { HTMLChakraProps } from "@chakra-ui/react";
import { Image, useColorModeValue } from "@chakra-ui/react";
import React from "react";

Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,34 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"lint": "turbo run lint",
"build": "turbo run build",
"test": "turbo run test"
"test": "turbo run test",
"prepare": "husky install"
},
"devDependencies": {
"@commitlint/config-conventional": "^18.0.0",
"commitlint": "^18.0.0",
"eslint": "^8.4.1",
"eslint-config-custom": "workspace:*",
"eslint-plugin-prefer-arrow": "1.2.3",
"husky": "^8.0.0",
"lint-staged": "^15.0.2",
"prettier": "^2.5.1",
"tsconfig": "workspace:*",
"turbo": "latest"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,md}": [
"prettier --write",
"git add"
],
"*.{js,jsx,ts,tsx}": [
"eslint"
]
},
"packageManager": "[email protected]"
}
}
134 changes: 0 additions & 134 deletions packages/react-vendor/README.md
Original file line number Diff line number Diff line change
@@ -1,135 +1 @@
# React Vendor

## Usage

- Wrap a `ConnexVendorProvider` around your application:

```typescript jsx
export const SampleApp: React.FC = () => {

// So that we can use the genesis ID
const thor = new Connex.Thor({
node: "https://mainnet.vechain.org/",
network: "main",
});

return (
<ConnexVendorProvider
defaultWallet={{ source: "sync2" }}
genesisId={thor.genesis.id}
>
<Account />
</ConnexVendorProvider>
);
};

```

- Selecting a wallet source

```typescript jsx
// https://docs.walletconnect.com/cloud/explorer#setting-up-a-new-project

const walletConnectProjectId = "yourProjectId";
const walletConnectMetadata = "yourMetadata";

const mobileWalletOptions: MobileWalletOptions = {
projectId: "yourProjectId",
metadata: {
name: "My dApp",
description: "My dApp description",
url: window.location.origin,
icons: [`${window.location.origin}/images/logo/my-dapp.png`],
},
};

const SelectWallet: React.FC = (): JSX.Element => {
const { setWallet, wallet } = useConnexVendor();

const handleOptionChange = (event: ChangeEvent<HTMLInputElement>) => {
const { value } = event.target;

switch (value) {
case "sync2":
case "sync": {
setWallet({ source: value });
break;
}
case "veworld-extension": {
// validate the extension is installed
if (!window.vechain) return;
setWallet({ source: value });
break;
}
case "veworld-mobile": {
// pass in the options for VeWorld Mobile
setWallet({ source: value, options: mobileWalletOptions });
break;
}
}
};

/**
* TODO: Create a component to select the wallet
* - you should disable veworld extension option if `window.vechain` is not defined
*/

return (
<div>
<h2>Select a Wallet</h2>
<form>
{/*TODO: Create a component to select the wallet*/}
</form>

<p>Selected Wallet: {wallet.source}</p>
</div>
)
;
}
;
```

- Vendor Usage:

```typescript jsx
const IdentifyUser: React.FC = (): JSX.Element => {
const { vendor } = useConnexVendor();

const [account, setAccount] = useState<string>();

const requestSignCertificate = useCallback(
async (msg: Connex.Vendor.CertMessage): Promise<string> => {
const response = await vendor.sign("cert", msg).request();

//TODO: Validate signature / signer

return response.annex.signer;
},
[vendor]
);

const identifyUser = useCallback((): void => {
requestSignCertificate({
purpose: "identification",
payload: {
type: "text",
content: "Hello, VeChain!",
},
})
.then(setAccount)
.catch((err) => {
throw err;
});
}, [requestSignCertificate]);

return (
<>
<button onClick={identifyUser} type="button">
Identify
</button>

{account ? <p>Account: {account}</p> : null}
</>
);
};
```
4 changes: 2 additions & 2 deletions packages/react-vendor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "tsup src/index.tsx --format cjs --dts --external react",
"clean": "rm -rf dist node_modules .turbo",
"dev": "tsup src/index.tsx --format cjs --watch --dts --external react",
"lint": "eslint src/**/*"
"lint": "eslint src --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@vechain/connex": "2.1.0",
Expand All @@ -28,4 +28,4 @@
"tsup": "^5.10.1",
"typescript": "4.9.5"
}
}
}
6 changes: 2 additions & 4 deletions packages/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@
"skipLibCheck": true,
"strict": true
},
"exclude": [
"node_modules"
]
}
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/tsconfig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"publishConfig": {
"access": "public"
}
}
}
6 changes: 1 addition & 5 deletions packages/tsconfig/react-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
"declarationMap": false,
"incremental": true,
"jsx": "preserve",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"noEmit": true,
"resolveJsonModule": true,
Expand Down
5 changes: 1 addition & 4 deletions packages/tsconfig/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
"extends": "./base.json",
"compilerOptions": {
"jsx": "react-jsx",
"lib": [
"ES2020",
"dom"
],
"lib": ["ES2020", "dom"],
"sourceMap": false,
"module": "ESNext",
"target": "ES6"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet-connect/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `wallet-connect`
# `wallet-connect`
4 changes: 2 additions & 2 deletions packages/wallet-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "tsup src/index.ts --format cjs --dts",
"clean": "rm -rf dist node_modules .turbo",
"dev": "tsup src/index.ts --format cjs --watch --dts",
"lint": "eslint src/**/*"
"lint": "eslint src --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@walletconnect/modal": "2.6.2",
Expand All @@ -25,4 +25,4 @@
"tsup": "^5.10.1",
"typescript": "4.9.5"
}
}
}
Loading

0 comments on commit af0a4c3

Please sign in to comment.