An easy way to build Rarity games with React

Overview

rarity-react

An easy way to build Rarity games with React.

NPM JavaScript Style Guide

It started with a simple app... I wanted to see my summoners and the prizes they'd won while on a new adventure. There's lots of great example code out there, eg RarityExtended. But I didn't see much in the way of libraries or tools. And so it was...

I started with these goals

  • Make it easy to start building a new Rarity app with React
  • Apps can configure which expansions they use
  • Apps can write their own expansions or integrate 3rd party expansions
  • Typescript-first

Please give this 1st draft a try - ๐Ÿ‘น ๐Ÿ™

Features

  • Wrap your app with
  • Get summoners with useSummoners()
  • Builtin wallet support with useWeb3()
  • Builtin support for "core" expansions (eg, attributes, skills, gold, etc)
  • Support for custom\3rd party expansions via "sideExpansions"

What's Next

  • TypeChain integration
  • Support for writes (only does contract reads currently)
  • Builtin support for crafting and feats
  • Support for names, land, and monsters as 3rd party expansions
  • npx create-rarity-react-app
  • Api documentation

Install

yarn add rarity-react

Usage

  • Get an api key from ftmscan

  • Add a configuration file for rarity-react to your src path. You can call it almost anything, but here assume the name of the file is config.json. Open config.json and spec out your ftmscan settings and expansions. Here's an example config.example.json

  • Add some wallet code like this

import { useWeb3 } from 'rarity-react'
export default function() {
  const { initialized, active, connect } = useWeb3()
  return <>
    {!(initialized && active) && <button onClick={connect}>connect wallet</button>}
  </>
}
  • Get summoners like this
})} } ">
import { RarityApp, useSummoners } from 'rarity-react'
import config from './config.json'
export default function() {
  const { summoners } = useSummoners()
  return <RarityApp config={config}>
    {summoners.map(s => {
      return <div>{s.expansions["core"].tokenId}</div>
    })}
  </RarityApp>
}
  • Make a custom expansion like this
})} } ">
import { Call, Contract } from 'ethcall';
import { RarityApp, RarityExpansionConfig, RarityExpansion, useSummoners } from 'rarity-react'
import config from './config.json'

export default function() {
  const customConfig = {
    id: 'custom-expansion-id',
    contract: '0x123... contract address ...456',
    abi: [... contract abi ...]
  } as RarityExpansionConfig

  const customExpansion = {
    id: 'custom-expansion-id',
    getSummonerCalls: (contract: Contract, summonerId: string) => {
      return[
        contract.customContractCall(summonerId)
      ] as Call[];
    },
    getSummonerExpansion: (callResults: any[]) => {
      const [ customProperty ] = callResults
      return { customProperty }
    }
  }

  const sideExpansions = [] as RarityExpansion[]
  sideExpansions.push(...configureExpansions([customConfig], [customExpansion]))

  const { summoners } = useSummoners()

  return <RarityApp config={config} sideExpansions={sideExpansions}>
    {summoners.map(s => {
      return <div>{s.expansions["custom-expansion-id"].customProperty}</div>
    })}
  </RarityApp>
}

License

GPL-3.0-or-later ยฉ murderteeth

You might also like...
Github-profile-readme-maker - Best Profile Generator, Create your perfect GitHub Profile ReadMe in the best possible way
Github-profile-readme-maker - Best Profile Generator, Create your perfect GitHub Profile ReadMe in the best possible way

GPRM : GitHub Profile ReadMe Maker Features We got everything that you need ! Cr

๐Ÿ•น GBA emulator on your React project - easy and powerful to use!
๐Ÿ•น GBA emulator on your React project - easy and powerful to use!

react-gbajs GBA emulator on your React project - easy and powerful to use! Just three steps to set it up โœจ 1 - Apply GbaProvider import { GbaProvider

A library that makes using pdfjs in react projects easy.

A library that makes using pdfjs in react projects easy.

Very quick and easy integration of the Potree Viewer in React

Very quick and easy integration of the Potree Viewer in React

Just a small collection of hooks that make it easy to integrate React Query into a REST API

react-query-restful is just a small collection of hooks that make it easy to integrate React Query into a REST API.

Easy to use editor for crontab schedules.

Cron Expression Generator Easy to use editor for crontab schedules. Development Setup Prerequisites Node.js (recommended version: 16+) Package Manager

Remove unnecessary React propTypes from the production build. :balloon:

babel-plugin-transform-react-remove-prop-types Remove unnecessary React propTypes from the production build. Installation npm install --save-dev babel

Build blazing fast, modern apps and websites with React

Gatsby v2 โš›๏ธ ๐Ÿ“„ ๐Ÿš€ Fast in every way that matters Gatsby is a free and open source framework based on React that helps developers build blazing fast w

This is the FARM Stack course, where you are going to learn how to build an application from scratch using FASTAPI, React and mongoDB

This is the FARM Stack course, where you are going to learn how to build an application from scratch using FASTAPI, React and mongoDB

Comments
  • Support wallets with 100+ Summoners

    Support wallets with 100+ Summoners

    RE: https://github.com/andrecronje/rarity/issues/87#issuecomment-940669053

    useSummoners() currently gets all of a wallet's summoners, then tries to get all of their metadata in a single MultiCall. If the sdk is pulling a lot of summoner expansion fields, this fails to scale as the summoner count gets towards 100.

    Redesign useSummoner to support paging. Consider the design of useQuery and fetchMore from apollo client's react library: https://www.apollographql.com/docs/react/data/queries/

    opened by murderteeth 0
Releases(v1.0.0)
Owner
murderteeth
Chaotic Neutral Half Orc Fighter Barbarian
murderteeth
A simple way to write re-usable features with React + EffectorA simple way to write re-usable features with React + Effector

Effector Factorio The simplest way to write re-usable features with React + Effector Install npm install effector-factorio Why this? People became to

Anton Kosykh 39 Dec 25, 2022
null 1 Apr 28, 2022
:speech_balloon: Easy way to create conversation chats

React Simple Chatbot A simple chatbot component to create conversation chats Getting Start npm install react-simple-chatbot --save Usage There are sev

Lucas Bassetti 1.5k Dec 27, 2022
Jed Saylor minting dapp is a quick and easy way to connect your smart contract and start minting NFTs.

Welcome to Jed Saylor ?? All the code in these repos was created and explained by Jed Saylor on his course. To find help please visit: ?? Instagram Je

null 1 Nov 26, 2021
A javascript framework to share url to social media sites like facebook, twitter, reddit, whastapp in an easy and simple way.

simple-sharer [by BUILDBROTHERS.COM] A javascript framework to share url to social media sites like facebook, twitter, reddit, whastapp in an easy and

null 5 May 29, 2022
A simple React component to reproduce the way iOS deletes an item in a list

react-swipe-to-delete-ios A simple React component to reproduce the way iOS deletes an item in a list. Demo Installation yarn add react-swipe-to-delet

Arnaud Ambroselli 32 Oct 1, 2022
The easiest way to move your React application to Server-Side Rendering. Handles Side Effects and synchronizes State.

The easiest way to move your React application to Server-Side Rendering. Handles Side Effects and synchronizes State. Table of Contents Articles Featu

Sergey 94 Dec 4, 2022
Simplest way to add twitter widgets to your react project.

React Twitter Embed Component React Twitter Embed Component Simplest way to add Twitter Widgets to your react project. Demo and Examples https://saura

Saurabh Nemade 306 Dec 30, 2022
A guide to building your own React stack, explaining options and tradeoffs along the way

Custom React Stack React has a very rich ecosystem. For anything you want to do, there is probably a library or a framework available for it. That's g

Naresh Bhatia 13 Nov 23, 2022
Node.js library for building systematic trading strategies in reactive way.

Node.js library for building systematic trading strategies in reactive way. Use the power of TypeScript and Reactive Programming to research, develop

null 2 Dec 22, 2021