0.19.20 • Published 1 year ago

@abstract-money/abstract.js-react v0.19.20

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Abstract React

Getting Started

  1. Install Abstract.js-react and React Query
pnpm install @abstract-money/abstract.js-react
  1. Add the AbstractProvider to the root providers in your app.
const App = () => (
  <ChakraProvider theme={theme}>
+   <AbstractProvider>
      <Router>
        <Layout>
          <Routings />
        </Layout>
      </Router>
+   </AbstractProvider>
  </ChakraProvider>
);

Querying Abstract API

  1. Install the necessary packages (see https://github.com/AbstractSDK/frontend/)

  2. Create a query hook and connect your component to it:

import {
  AbstractAccountId,
  useApiQuery,
} from "@abstract-money/abstract.js-react";

import { gql } from "../__generated__/gql";

const accountInfoQuery = gql(/* GraphQL */ `
  query AccountsByIds($ids: [AccountIdWithChain!]!) {
    accountsByIds(ids: $ids) {
      info {
        name
        chainId
        governance {
          governanceType
          owner
        }
        description
        link
      }
    }
  }
`);

const useAccountInfoQuery = ({ accountId }: { accountId: string }) => {
  const accountIdDecoded = AbstractAccountId.fromStringId(accountId);

  return useApiQuery(
    {
      select: (data) => data.accountsByIds[0].info,
      queryKey: ["api", "accountInfo", accountIdDecoded],
    },

    accountInfoQuery,
    { ids: [accountIdDecoded.toApi()] }
  );
};

export const DashboardPage = () => {
  const { data, error, isError, isLoading } = useAccountInfoQuery({
    accountId: "kujiratestnet-20",
  });

  return data === undefined ? (
    <>
      {isLoading ? <div>Loading...</div> : null}
      {isError ? <div>{error.message}</div> : null}
    </>
  ) : (
    <div>
      <h1>{data.name}</h1>
      <p>{data.chainId}</p>
      <span>{data.governance.owner}</span>
      <p>{data.description}</p>
    </div>
  );
};

Integrating Wallets

  1. Install cosmos-kit
pnpm install @cosmos-kit/react @cosmos-kit/keplr chain-registry

See the cosmos-kit getting started guide for further details:

Notes

  1. We'd also recommend installing react-query for state management:
pnpm install @tanstack/react-query@v4 @tanstack/react-query-devtools

Using Vite

If you're using Vite, you'll have to polyfill the common modules.

pnpm install rollup-plugin-node-polyfills @esbuild-plugins/node-globals-polyfill
// vite.config.ts
import rollupNodePolyFill from "rollup-plugin-node-polyfills";

export default defineConfig({
  build: {
    rollupOptions: {
      plugins: [
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        rollupNodePolyFill(),
      ],
    },
  },
  optimizeDeps: {
    esbuildOptions: {
      // Node.js global to browser globalThis
      define: {
        global: "globalThis",
      },
      plugins: [
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        NodeGlobalsPolyfillPlugin({
          process: true,
          buffer: true,
        }),
      ],
    },
  },
});
0.19.20

1 year ago

0.19.15

2 years ago

0.19.16

2 years ago

0.19.17

2 years ago

0.19.18

2 years ago

0.19.19

2 years ago

0.19.11

2 years ago

0.19.12

2 years ago

0.19.13

2 years ago

0.19.10

2 years ago

0.19.9

2 years ago

0.19.0

2 years ago

0.19.1

2 years ago

0.17.3

2 years ago

0.17.4

2 years ago

0.17.5

2 years ago

0.17.6

2 years ago

0.17.7

2 years ago

0.19.6

2 years ago

0.17.8

2 years ago

0.19.7

2 years ago

0.17.9

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.15.4

2 years ago

0.15.5

2 years ago

0.15.6

2 years ago

0.15.2

2 years ago

0.15.3

2 years ago

0.15.0

2 years ago

0.14.2

2 years ago

0.14.1

2 years ago