-
Notifications
You must be signed in to change notification settings - Fork 49
Feat/kleros app #1756
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
Merged
Merged
Feat/kleros app #1756
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
32fbbfb
feat: kleros-app
tractorss f964a03
chore: update-prettier-eslint
tractorss a1484da
chore(kleros-app): migrate-to-vite
tractorss ecd7719
chore(kleros-app): remove-exports-field
tractorss e75a46b
fix: specify-temp-build-command-in-toml
tractorss 4027336
fix: build-command
tractorss 7c9a8ce
fix: polyfills
tractorss a90dd72
fix: externalize-wagmi
tractorss 5fcf106
fix: update-wagmi
tractorss 0071290
chore: eslint and other version bumps
jaybuidl 944de42
chore(web-devtools): upgraded Next to 15, React to 19, removed unused…
jaybuidl f054afb
chore: update-dependencies
tractorss fda1f81
fix(web-devtools): field-type
tractorss 88c1537
Merge pull request #1757 from kleros/chore/eslint-and-more-version-bump
tractorss 8c15591
refactor: update-kleros-app-readme-and-package-json
tractorss bb2a083
chore: dedupe-dependencies
tractorss f9d5d28
fix(web-devtools): eslint-errors
tractorss 819530a
feat(kleros-app): readme
tractorss df00e56
refactor(web-devtools): remove-ignore-comment
tractorss c3b5ca4
chore(web-devtools): netlify.toml
jaybuidl f2efd34
fix(web-devtools): downgrade-next-to-v14
tractorss 2e88299
chore: package.json cleanup, preparing for release of kleros-app
jaybuidl 1e6cd2c
chore(kleros-app): release @kleros/[email protected]
jaybuidl ae80adb
docs(kleros-app): readme typo
jaybuidl 86a88bc
chore(kleros-app): release @kleros/[email protected]
jaybuidl 42eb3ed
Merge branch 'dev' into feat/kleros-app
kemuru a8e6746
fix: downgrade-styled-components
tractorss ee802df
chore: update-graphql-codegen-client-preset
tractorss 2f3a8d8
Merge branch 'dev' into feat/kleros-app
alcercu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,112 @@ | ||
# Kelros App | ||
|
||
Library for Kleros DApps with reusable abstractions and components. | ||
|
||
# Usage | ||
|
||
```node | ||
yarn install @kleros/kleros-app | ||
``` | ||
|
||
## 1. Atlas Interaction | ||
|
||
- This library exports utilities to interact with Atlas (Kleros' backend) with minimal code. | ||
|
||
- AtlasProvider : Provides functions to interact with Atlas. | ||
|
||
> AtlasProvider needs to be wrapped with [<WagmiProvider/>](https://wagmi.sh/react/api/WagmiProvider) and [<QueryClientProvider/>](https://tanstack.com/query/latest/docs/framework/react/reference/QueryClientProvider#queryclientprovider) to work properly. | ||
|
||
#### Usage | ||
|
||
1. At the root of your app, setup AtlasProvider. | ||
**uri** : Atlas backend uri | ||
**product** : The product / Kleros DApp interacting with Atlas (CourtV2, Curate, etc.) | ||
|
||
```typescript | ||
import { WagmiProvider } from 'wagmi' | ||
import { config } from './config' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { AtlasProvider, Products } from "@kleros/kleros-app"; | ||
|
||
const queryClient = new QueryClient() | ||
|
||
function App() { | ||
return | ||
<WagmiProvider config={config}> | ||
<QueryClientProvider client={queryClient}> | ||
<AtlasProvider config={{ uri: import.meta.env.REACT_APP_ATLAS_URI, product: Products.CourtV2 }}> | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
... | ||
</AtlasProvider> | ||
</QueryClientProvider> | ||
</WagmiProvider> | ||
} | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
2. Once Provider is set up, use the functions provided. | ||
|
||
```typescript | ||
import React, { useCallback } from "react"; | ||
|
||
import { useAccount } from "wagmi"; | ||
import { useAtlasProvider } from "@kleros/kleros-app"; | ||
import { Button } from "@kleros/ui-components-library"; | ||
|
||
|
||
interface IEnsureAuth { | ||
children: React.ReactElement; | ||
className?: string; | ||
} | ||
|
||
const EnsureAuth: React.FC<IEnsureAuth> = ({ children, className }) => { | ||
const { address } = useAccount(); | ||
const { isVerified, isSigningIn, authoriseUser } = useAtlasProvider(); | ||
|
||
const handleClick = useCallback(() => { | ||
// authorise a user | ||
authoriseUser() | ||
.then((res) => { console.log(res)}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}, [authoriseUser]); | ||
tractorss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return isVerified ? ( | ||
children | ||
) : ( | ||
<Button | ||
text="Sign In" | ||
onClick={handleClick} | ||
disabled={isSigningIn || !address} | ||
isLoading={isSigningIn} | ||
{...{ className }} | ||
/> | ||
); | ||
}; | ||
|
||
export default EnsureAuth; | ||
|
||
``` | ||
|
||
3. [IAtlasProvider](https://github.com/kleros/kleros-v2/blob/feat/kleros-app/kleros-app/src/lib/atlas/providers/AtlasProvider.tsx) | ||
|
||
```typescript | ||
interface IAtlasProvider { | ||
isVerified: boolean; | ||
isSigningIn: boolean; | ||
isAddingUser: boolean; | ||
isFetchingUser: boolean; | ||
isUpdatingUser: boolean; | ||
isUploadingFile: boolean; | ||
user: User | undefined; | ||
userExists: boolean; | ||
authoriseUser: () => Promise<void>; | ||
addUser: (userSettings: AddUserData) => Promise<boolean>; | ||
updateEmail: (userSettings: UpdateEmailData) => Promise<boolean>; | ||
uploadFile: (file: File, role: Roles) => Promise<string | null>; | ||
confirmEmail: (userSettings: ConfirmEmailData) => Promise< | ||
ConfirmEmailResponse & { | ||
isError: boolean; | ||
} | ||
>; | ||
} | ||
``` |
This file contains hidden or 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,120 @@ | ||
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat"; | ||
import react from "eslint-plugin-react"; | ||
import reactHooks from "eslint-plugin-react-hooks"; | ||
import security from "eslint-plugin-security"; | ||
import _import from "eslint-plugin-import"; | ||
import globals from "globals"; | ||
import tsParser from "@typescript-eslint/parser"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import js from "@eslint/js"; | ||
import { FlatCompat } from "@eslint/eslintrc"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const compat = new FlatCompat({ | ||
baseDirectory: __dirname, | ||
recommendedConfig: js.configs.recommended, | ||
allConfig: js.configs.all, | ||
}); | ||
|
||
export default [ | ||
{ | ||
ignores: ["src/assets"], | ||
}, | ||
...fixupConfigRules( | ||
compat.extends( | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended", | ||
"plugin:import/recommended", | ||
"plugin:import/react", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended", | ||
"prettier" | ||
) | ||
), | ||
{ | ||
plugins: { | ||
react: fixupPluginRules(react), | ||
"react-hooks": fixupPluginRules(reactHooks), | ||
security: fixupPluginRules(security), | ||
import: fixupPluginRules(_import), | ||
}, | ||
|
||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
Atomics: "readonly", | ||
SharedArrayBuffer: "readonly", | ||
}, | ||
|
||
parser: tsParser, | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
|
||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
}, | ||
|
||
settings: { | ||
react: { | ||
version: "^18.3.1", | ||
}, | ||
|
||
"import/resolver": { | ||
typescript: { | ||
project: "./tsconfig.json", | ||
}, | ||
}, | ||
}, | ||
|
||
rules: { | ||
"max-len": [ | ||
"warn", | ||
{ | ||
code: 120, | ||
}, | ||
], | ||
|
||
"react/prop-types": 0, | ||
"no-unused-vars": "off", | ||
|
||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
varsIgnorePattern: "(^_+[0-9]*$)|([iI]gnored$)|(^ignored)", | ||
argsIgnorePattern: "(^_+[0-9]*$)|([iI]gnored$)|(^ignored)", | ||
}, | ||
], | ||
|
||
"no-console": [ | ||
"error", | ||
{ | ||
allow: ["warn", "error", "info", "debug"], | ||
}, | ||
], | ||
|
||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"security/detect-object-injection": "off", | ||
"security/detect-non-literal-fs-filename": "off", | ||
|
||
"import/extensions": [ | ||
"error", | ||
"ignorePackages", | ||
{ | ||
js: "never", | ||
jsx: "never", | ||
ts: "never", | ||
tsx: "never", | ||
}, | ||
], | ||
|
||
"import/no-unresolved": "off", | ||
}, | ||
}, | ||
]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.