-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from valorem-labs-inc/init
init react-hooks
- Loading branch information
Showing
34 changed files
with
10,942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { resolve } = require('node:path'); | ||
|
||
const project = resolve(process.cwd(), 'tsconfig.json'); | ||
|
||
/** @type {import('eslint').Linter.Config} */ | ||
module.exports = { | ||
extends: [ | ||
'@vercel/style-guide/eslint/browser', | ||
'@vercel/style-guide/eslint/typescript', | ||
'@vercel/style-guide/eslint/react', | ||
].map(require.resolve), | ||
parserOptions: { | ||
project, | ||
}, | ||
globals: { | ||
JSX: true, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: { | ||
project, | ||
}, | ||
}, | ||
}, | ||
ignorePatterns: [ | ||
'node_modules/', | ||
'dist/', | ||
'*.config.*', | ||
'src/lib/codegen/', | ||
'src/lib/trade-interfaces/', | ||
'**/*.cjs', | ||
'docs', | ||
'coverage', | ||
'test', | ||
'*.test.ts*', | ||
], | ||
rules: { | ||
'unicorn/filename-case': 'off', | ||
'import/no-extraneous-dependencies': 'off', | ||
'@typescript-eslint/no-unsafe-member-access': 'off', | ||
'@typescript-eslint/no-unsafe-call': 'off', | ||
'@typescript-eslint/no-unsafe-return': 'off', | ||
'@typescript-eslint/no-unsafe-argument': 'off', | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [released] | ||
|
||
permissions: | ||
contents: write # for github pages | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: latest | ||
|
||
- name: Install packages, compile SDK, and build docs | ||
run: | | ||
pnpm i | ||
pnpm build | ||
pnpm gen-docs | ||
- name: Deploy Docs to Github Pages | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
folder: docs | ||
|
||
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies | ||
run: pnpm audit signatures | ||
|
||
# Setup .npmrc file to publish to npm | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: pnpm publish --access public --no-git-checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- 'v**' | ||
- 'releases/v**' | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- main | ||
- 'v**' | ||
- 'releases/v**' | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: latest | ||
|
||
- name: Install packages, build, lint, and test | ||
run: | | ||
pnpm i | ||
pnpm build | ||
pnpm lint | ||
pnpm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.log | ||
.DS_Store | ||
node_modules | ||
dist | ||
|
||
coverage | ||
|
||
src/lib/codegen | ||
src/lib/trade-interfaces | ||
|
||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "trade-interfaces"] | ||
path = src/lib/trade-interfaces | ||
url = https://github.com/valorem-labs-inc/trade-interfaces.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
This is a work in progress. The API is not yet stable, and is subject to change, including breaking changes. Contributions welcome. | ||
|
||
# Valorem React Hooks | ||
|
||
Valorem is a DeFi protocol enabling physically settled or cash settled, American, European, and Exotic options. | ||
The Valorem React Hooks package wraps Valorem's signature relay, Seaport and Clear contract interfaces into hooks consumable by any React frontend. | ||
|
||
## Documentation | ||
|
||
For documentation, visit [https://valorem-labs-inc.github.io/react-hooks/](https://valorem-labs-inc.github.io/react-hooks/) | ||
|
||
## Installation | ||
|
||
```bash | ||
npm i @valorem-labs-inc/react-hooks | ||
``` | ||
|
||
```bash | ||
pnpm i @valorem-labs-inc/react-hooks | ||
``` | ||
|
||
```bash | ||
yarn add @valorem-labs-inc/react-hooks | ||
``` | ||
|
||
## Getting Started | ||
|
||
Wrap your app in the `ValoremProvider`. This should be done inside of a `WagmiConfig` provider: | ||
|
||
```tsx | ||
import { ValoremProvider } from '@valorem-labs-inc/react-hooks'; | ||
import { WagmiConfig } from 'wagmi'; | ||
|
||
function App() { | ||
return ( | ||
<WagmiConfig config={/* see https://wagmi.sh/react/getting-started */}> | ||
<ValoremProvider>{children}</ValoremProvider> | ||
</WagmiConfig> | ||
); | ||
} | ||
``` | ||
|
||
Now you can use the hooks anywhere in your app: | ||
|
||
```tsx | ||
import { QuoteRequest, NULL_BYTES32 } from '@valorem-labs-inc/sdk'; | ||
import { useRFQ, useSeaportFulfillOrder } from '@valorem-labs-inc/react-hooks'; | ||
|
||
const quoteRequest = new QuoteRequest({ | ||
// your quote request parameters | ||
}); | ||
|
||
function Component() { | ||
const { quotes } = useRFQ({ quoteRequest }); | ||
|
||
const bestQuote = useMemo(() => { | ||
if (!quotes) return undefined; | ||
|
||
// add your own logic to filter through offers | ||
|
||
return quotes[0]; | ||
}, [quotes]); | ||
|
||
const { config } = usePrepareSeaportFulfillOrder({ | ||
args: | ||
bestQuote !== undefined | ||
? [ | ||
{ | ||
parameters: bestQuote.order.parameters, | ||
signature: bestQuote.order.signature, | ||
}, | ||
NULL_BYTES32, | ||
] | ||
: undefined, | ||
enabled: bestQuote !== undefined, | ||
}); | ||
|
||
const { write, isLoading } = useSeaportFulfillOrder({ | ||
...config, | ||
async onSuccess({ hash }) { | ||
const { status, transactionHash } = await waitForTransaction({ hash }); | ||
|
||
/* ... */ | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<button | ||
onClick={write} | ||
disabled={write === undefined || isLoading === true} | ||
> | ||
{bestQuote === undefined | ||
? 'Waiting for an RFQ response...' | ||
: 'Fulfill Order'} | ||
</button> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
## Development | ||
|
||
Install dependencies with `pnpm i`, run tests with `pnpm test`, and build with `pnpm build`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: v1 | ||
plugins: | ||
- plugin: es | ||
out: src/lib/codegen | ||
opt: | ||
- target=ts | ||
- name: connect-query | ||
out: src/lib/codegen | ||
opt: | ||
- target=ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version: v1 | ||
directories: | ||
- src/lib/trade-interfaces/proto/valorem/trade/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"name": "@valorem-labs-inc/react-hooks", | ||
"version": "0.0.1-alpha.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/valorem-labs-inc/react-hooks.git" | ||
}, | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"build": "pnpm clean && pnpm codegen && pnpm tsup", | ||
"clean": "rm -rf ./dist", | ||
"codegen": "rm -rf ./src/lib/codegen && wagmi generate && npx buf generate", | ||
"format": "prettier --write \"**/*.{ts,tsx,md,json}\"", | ||
"gen-docs": "typedoc", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"prepare": "git submodule update --init --recursive && pnpm codegen", | ||
"test": "NODE_TLS_REJECT_UNAUTHORIZED=0 vitest run --coverage" | ||
}, | ||
"prettier": "@vercel/style-guide/prettier", | ||
"dependencies": { | ||
"@bufbuild/protobuf": "^1.3.3", | ||
"@connectrpc/connect": "^1.1.2", | ||
"@connectrpc/connect-query": "^0.5.3", | ||
"@connectrpc/connect-web": "^1.1.2", | ||
"@tanstack/query-core": "^4.36.1", | ||
"@tanstack/react-query": "^4.36.1", | ||
"@valorem-labs-inc/sdk": "^0.0.1", | ||
"@wagmi/cli": "^1.5.2", | ||
"@wagmi/core": "^1.4.5", | ||
"abitype": "0.8.7", | ||
"connectkit": "^1.5.3", | ||
"siwe": "^2.1.4", | ||
"viem": "^1.16.6", | ||
"wagmi": "^1.4.5" | ||
}, | ||
"devDependencies": { | ||
"@bufbuild/buf": "^1.27.1", | ||
"@bufbuild/protoc-gen-es": "^1.3.3", | ||
"@connectrpc/protoc-gen-connect-query": "^0.5.3", | ||
"@testing-library/react": "^14.0.0", | ||
"@testing-library/react-hooks": "^8.0.1", | ||
"@types/node": "^20.8.7", | ||
"@types/react": "^18.2.31", | ||
"@types/react-dom": "^18.2.14", | ||
"@vercel/style-guide": "^5.0.1", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"eslint": "^8.52.0", | ||
"happy-dom": "^12.9.1", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jsdom": "^22.1.0", | ||
"prettier": "^3.0.3", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"semantic-release": "^22.0.5", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^7.2.0", | ||
"typedoc": "^0.25.2", | ||
"typedoc-plugin-missing-exports": "^2.1.0", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.6", | ||
"zod": "^3.22.4" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=17.0.0", | ||
"typescript": ">=5.0.4", | ||
"viem": ">=0.3.35" | ||
}, | ||
"peerDependenciesMeta": { | ||
"typescript": { | ||
"optional": true | ||
} | ||
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
} |
Oops, something went wrong.