@kleros/kleros-app
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Kleros App

Library for Kleros DApps with reusable abstractions and components.

Usage

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 and 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.)
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 }}>
            ...
            </AtlasProvider>
        </QueryClientProvider>
    </WagmiProvider>
}
  1. Once Provider is set up, use the functions provided.
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]);

  return isVerified ? (
    children
  ) : (
    <Button
      text="Sign In"
      onClick={handleClick}
      disabled={isSigningIn || !address}
      isLoading={isSigningIn}
      {...{ className }}
    />
  );
};

export default EnsureAuth;
  1. IAtlasProvider
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;
    }
  >;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @kleros/kleros-app

Weekly Downloads

1,206

Version

2.0.1

License

MIT

Unpacked Size

309 kB

Total Files

21

Last publish

Collaborators

  • clesaege
  • ferittuncer
  • danild
  • alcercu
  • jaybuidl