Giter Site home page Giter Site logo

kirksgithub / cardinal-identity-ui Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 10.0 24.1 MB

Cardinal Identity UI is a library of react components for building identity tokens into dApps. It also maintains a deployment for for our Twitter linking flow https://twitter.cardinal.so

Home Page: https://cardinal-labs.github.io/cardinal-identity-ui/

JavaScript 5.54% TypeScript 94.30% CSS 0.17%

cardinal-identity-ui's Introduction

Cardinal Identity UI

This repository houses the UI and associated components for integrating identity tokens into dApps. It also maintains a deployment for our on-chain Twitter linking flow https://twitter.cardinal.so.

Use this repo to link identity tokens to your wallet, or drop the UI components into your app to implement global identity and enhance its UX.

For questions or technical help, join our Discord.

Package Description Version Docs
@cardinal/namespaces-components TypeScript SDK for namespaces-components npm Docs

Quick Links


Example UI

The main UI can be accessed at https://twitter.cardinal.so. Use this UI as a simple interface to link and unlink twitter profiles. Each profile is represented as an NFT generated by https://github.com/cardinal-labs/cardinal-generators.

For infomration on how to use the UI components, please see the Getting Started section.

Getting Started

Start by taking a look at the UI components documentation here https://cardinal-labs.github.io/cardinal-identity-ui/

This documentation offers a high level overview of how to incorporate cardinal-identity-ui into your dApp.

The UI has the following components

  • Fully featured account connector that includes wallet and setting identity
  • Modal for linking new identities and managing existing ones
  • Drop in components for replacing wallet addresses with names, images, and small profiles
  • Hooks to directly look up the mapping from wallet to name (and vice versa) and to use this data in your app. All hooks come with loading state for smooth build-ins

Install

yarn add @cardinal/namespaces \
         @solana/web3.js \
         react

Setup

import '@cardinal/namespaces-components/dist/esm/styles.css'
import { WalletProvider } from '@solana/wallet-adapter-react'
import { getWalletAdapters } from '@solana/wallet-adapter-wallets'
import { WalletModalProvider } from '@solana/wallet-adapter-react-ui'
import { WalletIdentityProvider } from '@cardinal/namespaces-components'

require('@solana/wallet-adapter-react-ui/styles.css')

const App = () => (
  <WalletProvider autoConnect wallets={getWalletAdapters()}>
    <WalletIdentityProvider>
      <WalletModalProvider>
        {/* Your app's components go here, nested within the context providers. */}
      </WalletModalProvider>
    </WalletIdentityProvider>
  </WalletProvider>
)

export default App

Usage of UI Components

import React from 'react'
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
import {
  AddressImage,
  DisplayAddress,
  ProfileSmall,
} from '@cardinal/namespaces-components'
import { Wallet } from '@saberhq/solana-contrib'

export const User: FC = () => {
  const { connection } = useConnection()
  const wallet = useWallet()
  return (
    <div>
      {/* Account linking and wallet connector */}
      <AccountConnect
        dark={true}
        connection={connection}
        handleDisconnect={() => wallet.disconnect()}
        wallet={wallet as Wallet}
      />
      {/* Replace address with image */}
      <AddressImage address={wallet.publicKey} connection={connection} />
      {/* Replace address with name */}
      <DisplayAddress address={wallet.publicKey} connection={connection} />
      {/* Profile from address */}
      <ProfileSmall address={wallet.publicKey} connection={connection} />
      {/* Button to connect twitter profile */}
      <ConnectTwitterButton connection={connection} wallet={wallet} />
    </div>
  )
}

Usage of Hooks

import React from 'react'
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
import {
  AddressImage,
  DisplayAddress,
  ProfileSmall,
} from '@cardinal/namespaces-components'
import { Wallet } from '@saberhq/solana-contrib'

export const User: FC = () => {
  const { connection } = useConnection()
  const wallet = useWallet()
  const { displayName, loadingName, refreshName } = useAddressName(
    connection,
    wallet.publicKey
  )
  const { addressImage, loadingImage } = useAddressImage(
    connection,
    wallet.publicKey
  )
  return (
    <div>
      <div>{displayName}</div>
      <img
        style={{
          height: '150px',
          width: '150px',
          borderRadius: '50%',
          border: '4px solid white',
        }}
        alt={`profile-${addressStr}`}
        src={addressImage}
      />
    </div>
  )
}

Development

To get started, clone the repo and run:

yarn install

Next, run the development server:

yarn run dev

Open http://localhost:3000 with your browser to see the staking interface running locally.

Set your Cluster

To access different clusters in the scaffold, set the cluster query parameter in the URL:

The default cluster set is mainnet. It's recommended to ensure you have ?cluster=devnet while testing out functionality.

Have questions?

Join our Discord to get technical support as you build on Cardinal.


cardinal-identity-ui's People

Contributors

jpbogle avatar srust32 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.