npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@futureverse/swappable-viewer-react

v1.4.17

Published

Provides a wrapper around the Futureverse Asset Register. It exposes hooks to query what is currently equipped/linked to the parent collection along with token metadata and other information.

Downloads

108

Readme

Futureverse Swappable Viewer React

Provides a wrapper around the Futureverse Asset Register. It exposes hooks to query what is currently equipped/linked to the parent collection along with token metadata and other information.

Installation

npm:

npm install @futureverse/swappable-viewer-react --save

yarn:

yarn add @futureverse/swappable-viewer-react

pnpm:

pnpm add @futureverse/swappable-viewer-react

bun:

bun add @futureverse/swappable-viewer-react

Providers

SwappableEngineProvider

Provides hooks and utility for querying collections, metadata, and what is equipped to your swappable. This is not strictly required; if you are just looking to implement the 3D viewer, then the ViewerProvider is all that is required.

Queries use react-query. To use the provider, you must make sure it is a child of a QueryClientProvider.

Setup

environment

When using testnets such as Porcini, use development otherwise production.

<SwappableEngineProvider
  environment="production"
  config={swappableConfig}
>

Swappable Config Example

This config provides the SwappableProvider with context as to which on-chain collections you are interested in retrieving data for. Locations are on-chain destinations, and you are free to specify multiple locations.

type CollectionParts = 'Chasis' | 'Engines' | 'Wheels' | 'Exhausts' | 'Accessories';

const swappableConfig: SwappableCollectionConfig<CollectionParts> = {
  parent: {
    name: 'Chasis',
    locations: ['7672:root:<chasis_root_collection_id>'],
  },
  linked: [
    { name: 'Engines', locations: ['7672:root:<engines_root_collection_id>'] },
    { name: 'Wheels', locations: ['7672:root:<wheels_root_collection_id>'] },
    {
      name: 'Exhausts',
      locations: ['7672:root:<exhausts_root_collection_id>'],
    },
    {
      name: 'Accessories',
      locations: ['7672:root:<accessories_root_collection_id>'],
    },
  ],
};

Hooks

useQueryEquipped

Query what is equipped for FuturePass address and token.

import { useQueryEquipped } from '@futureverse/swappable-viewer-react';
const { data: equipped } = useQueryEquipped<CollectionParts>(['<FuturePassAddress>'], '<token_id>');

useQueryCollection

Query all parts owned by this address for "Engines".

import { useQueryCollection } from '@futureverse/swappable-viewer-react';

// You can pass multiples addresses
const addresses = ['metamask-eoa', 'futurepass', 'xaman-eoa', ...];
const { data: engines } = useQueryCollection<RaicersParts>('Engines', addresses);

ViewerProvider

Renders the Unity application in the client. It is recommended that you use this provider where you would like to view your 3D model/avatar/scene. The ViewerProvider provides utility hooks to command the viewer through event messages.

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnMount: false,
      refetchOnWindowFocus: false,
    },
  },
});


const swappableConfig: SwappableCollectionConfig = {
....
};

export default function Index() {
  return (
    <QueryClientProvider client={queryClient}>
      <SwappableEngineProvider
        environment="development"
        config={swappableConfig}
      >
        <ViewerProvider
          buildUrl="<your-unity-3d-viewer-build-url>"
          buildDir="viewer/WebGL"
          streamingAssetsDir="StreamingAssets"
          compression="br"
          style={{ width: '100%', height: '100vh' }}
        >
          ...
        </ViewerProvider>
      </SwappableEngineProvider>
    </QueryClientProvider>
  );
}

Hooks

Sending events through the event orchestration handler: The events largely depend on what is implemented in the Unity build. It is up to the developer to decide which events they wish to support. The code below is an example of updating a 3D model to display based on metadata.

import { useViewer } from '@futureverse/swappable-viewer-react';
const { data: equipped } = useQueryEquipped<CollectionParts>(
  ['<FuturePassAddress>'],
  '<token_id>'
);
const { sendEvent } = useViewer();

...

sendEvent('update_model', equipped.engine.attributes);