2.70.2 • Published 8 months ago

@futureverse/asset-register-react v2.70.2

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

Futureverse Asset Register SDK

Installation

NPM:

    npm install @futureverse/asset-register-react --save

Yarn:

    yarn add @futureverse/asset-register-react

Usage

import { useCreateSchema } from '@futureverse/asset-register-react'
import { NamespaceUrl } from '@futureverse/asset-register/types'
import { useState, useMemo } from 'react'
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'

const ASSET_REGISTER_ENDPOINT =
  'https://saybx2ywpd.execute-api.us-west-2.amazonaws.com/graphql'
const APP_DOMAIN = 'com.fv.app'
const WALLET_PRIVATE_KEY = ''
const APP_ORIGIN = 'http://com.fv.app/login'

const wallet = privateKeyToAccount(generatePrivateKey())
const walletAddress = wallet.address

function App() {
  const auth = useMemo(
    () => ({
      domain: APP_DOMAIN,
      origin: APP_ORIGIN,
      chainId: 1,
      sign: async (message) => {
        return await wallet.signMessage({ message })
      },
      walletAddress,
    }),
    [],
  )
  return (
    // Provide the client to your App
    <AssetRegisterClientProvider url={ASSET_REGISTER_ENDPOINT} auth={auth}>
      <SchemaCreator />
    </AssetRegisterClientProvider>
  )
}

export const SchemaCreator = () => {
  const [version, setVersion] = useState(1)
  const [schema, setSchema] = useState('{}')
  const [name, setName] = useState('schemaName')
  const [namespace, setNamespace] = useState<NamespaceUrl>(
    'http://schema.futureverse.dev/fv' as NamespaceUrl,
  )
  const { createAsync: createSchemaAsync, schema: createdSchema } =
    useCreateSchema()

  const handleCreateMutate = async () => {
    try {
      await createSchemaAsync({
        schema,
        version,
        namespace,
        name,
      })
      setVersion(version + 1)
    } catch (e) {
      alert(e)
    }
  }

  return (
    <div>
      <div>
        <label>version: </label>
        <input
          value={version}
          type="number"
          onChange={(e) => setVersion(parseInt(e.target.value))}
        />
      </div>
      <div>
        <label>namespace: </label>
        <input
          value={namespace}
          size={80}
          onChange={(e) => setNamespace(e.target.value as NamespaceUrl)}
        />
      </div>
      <div>
        <label>name: </label>
        <input
          value={name}
          size={80}
          onChange={(e) => setName(e.target.value as NamespaceUrl)}
        />
      </div>
      <div>
        <label>schema: </label>
        <textarea
          rows={10}
          cols={80}
          value={schema}
          onChange={(e) => setSchema(e.target.value)}
        />
      </div>
      <br />
      <button onClick={handleCreateMutate}>create schema</button>

      {createdSchema && <div>{`Schema Name: ${createdSchema.name}`}</div>}
    </div>
  )
}

render(<App />, document.getElementById('root'))

Troubleshoots

  1. ERR_UNSUPPORTED_DIR_IMPORT error on the nextjs project

    In case you encounter the ERR_UNSUPPORTED_DIR_IMPORT error while utilizing this SDK in your Next.js project, simply include the following configuration to the next.config.js file. For more details, please refer to here

//...
experimental: {
  esmExternals: false,
},
//...

Migration guide from @futureverse/asset-registry-react package

The new package name for this library is now @futureverse/asset-register-react. Hence, there are some files and codes that have been renamed in the new version. Here are the migration guides:

  • The package dependency @futureverse/asset-registry has been changed to refer to @futureverse/asset-register
  • Renamed files:
    • ./src/hooks/AssetRegistryClientProvider.tsx file is now ./src/hooks/AssetRegisterClientProvider.tsx
    • ./src/hooks/useAssetRegistryClientContext.ts file is now ./src/hooks/useAssetRegisterClientContext.ts
  • AssetRegistryClientProvider provider class is now AssetRegisterClientProvider
  • useAssetRegistryClientContext React hook is now useAssetRegisterClientContext
2.53.0-beta.0

1 year ago

2.69.0

10 months ago

2.69.1

10 months ago

2.57.0

1 year ago

2.57.1

1 year ago

2.57.2

1 year ago

2.64.0

1 year ago

2.64.1

1 year ago

2.60.0

1 year ago

2.60.1

1 year ago

2.60.2

1 year ago

2.68.0

11 months ago

2.68.1

11 months ago

2.56.0

1 year ago

2.63.1

1 year ago

2.63.2

1 year ago

2.67.0

11 months ago

2.63.0

1 year ago

2.70.2

8 months ago

2.55.0

1 year ago

2.70.1

9 months ago

2.54.0-beta.1

1 year ago

2.54.0-beta.0

1 year ago

2.70.0

10 months ago

2.54.0-beta.2

8 months ago

2.52.0-beta.0

1 year ago

2.59.0

1 year ago

2.59.1

1 year ago

2.66.0

12 months ago

2.62.0

1 year ago

2.54.7

1 year ago

2.58.0

1 year ago

2.54.6

1 year ago

2.65.0

12 months ago

2.61.0

1 year ago

2.61.1

1 year ago

2.54.3

1 year ago

2.54.4

1 year ago

2.54.5

1 year ago

2.54.2

1 year ago

2.53.0

1 year ago

2.53.1

1 year ago

2.53.2

1 year ago

2.51.5

1 year ago

2.54.0

1 year ago

2.54.1

1 year ago

2.52.0

1 year ago

2.51.2

1 year ago

2.51.3

1 year ago

2.51.4

1 year ago

2.51.1

1 year ago

2.51.2-beta.0

1 year ago

2.51.0

1 year ago

2.48.0-rc.3

1 year ago

2.46.0

1 year ago

2.44.1-rc.2

2 years ago

2.32.0

2 years ago

2.46.1-rc.1

1 year ago

2.44.1-rc.1

2 years ago

2.34.0

2 years ago

2.48.0-rc.1

1 year ago

2.45.0-rc.5

1 year ago

2.45.0-rc.4

1 year ago

2.48.0-rc.2

1 year ago

2.45.0-rc.3

2 years ago

2.47.0-rc.1

1 year ago

2.46.0-rc.2

1 year ago

2.45.0-rc.2

2 years ago

2.47.0-rc.2

1 year ago

2.46.0-rc.3

1 year ago

2.45.0-rc.1

2 years ago

2.47.0-rc.3

1 year ago

2.47.0-rc.4

1 year ago

2.46.0-rc.1

1 year ago

2.44.0-rc.1

2 years ago

2.36.0

2 years ago

2.38.0

2 years ago

2.43.0

2 years ago

2.45.0

1 year ago

2.41.0

2 years ago

2.47.0

1 year ago

2.45.1

1 year ago

2.45.1-rc.1

1 year ago

2.33.0

2 years ago

2.43.1-rc.1

2 years ago

2.39.1

2 years ago

2.39.0

2 years ago

2.35.0

2 years ago

2.37.1

2 years ago

2.37.0

2 years ago

2.42.0

2 years ago

2.44.0

2 years ago

2.40.0

2 years ago

2.31.0

2 years ago

2.30.0

2 years ago

2.29.0

2 years ago

2.28.0

2 years ago

2.27.0

2 years ago

2.25.0

2 years ago

2.26.0

2 years ago

2.24.0

2 years ago

2.23.0

2 years ago

2.22.1

2 years ago

2.22.0

2 years ago

2.21.0

2 years ago

2.20.0

2 years ago

2.19.0

2 years ago

2.18.0

2 years ago

2.17.0

2 years ago

2.16.1

2 years ago

2.16.2

2 years ago

2.16.0

2 years ago

2.15.0

2 years ago

2.14.0

2 years ago

2.13.1

2 years ago

2.13.0

2 years ago

2.12.0

2 years ago

2.11.0

2 years ago