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

@neoswap/packs-widget

v0.0.14

Published

Packs Widget for Solana

Downloads

65

Readme

Neoswap Packs Widget

This package allows you to easily integrate Neoswap packs into your web application. It can be used directly in an HTML file or within a React application.

Installation

First, install the package via npm:

npm install @neoswap/packs-widget

Usage

Method 1: Directly in an HTML File

You can include the widget directly in an HTML file using a script tag. Here's an example:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Packs Widget Example</title>
    <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
  </head>
  <body>
    <div id="packs-widget-container"></div>
    <script src="https://unpkg.com/@neoswap/[email protected]/dist/packs-widget.js"></script>
    <script>
      PacksWidget.default.renderPacksWidget('packs-widget-container', 'YOUR_PARTNER_TOKEN')
    </script>
  </body>
</html>

Replace 'YOUR_PARTNER_TOKEN' with your actual partner token.

Method 2: Using in a React Application

You can also use the widget in a React application. Below is an example of how to integrate it into a React component.

Using renderPacksWidget

Create a React component to render the widget:

import React, { useEffect, useRef } from 'react';

import { renderPacksWidget } from '@neoswap/packs-widget';



const PacksWidgetContainer: React.FC = () => {

const widgetContainerRef = useRef<HTMLDivElement  |  null>(null);

const partnerToken = process.env.YOUR_PARTNER_TOKEN!;



useEffect(() => {

if (widgetContainerRef.current) {

renderPacksWidget(widgetContainerRef.current.id, partnerToken);

}

}, [partnerToken]);



return <div  id="packs-widget-container"  ref={widgetContainerRef}></div>;

};



export default PacksWidgetContainer;

Add this component to your application's routing or render it directly in your main application component.

Using usePackData

Here's how you can use the usePackData hook to fetch and display pack data:

import React, { useEffect } from 'react';
import packsWidget from '@neoswap/packs-widget';

const PacksPage: React.FC = () => {

const partnerToken = process.env.YOUR_PARTNER_TOKEN!;

const {
  packGroups,
  packDetails,
  transactions,
  balances,
  fetchBalances,
  fetchPackDetails,
  fetchPackDetailsPost,
  fetchTransactions,
  fetchPackGroups,
  isLoadingPackGroups,
  errorPackGroups
} = packsWidget.usePackData(partnerToken);

useEffect(() => {
  fetchPackGroups();
}, [fetchBalances, fetchPackGroups, fetchTransactions]);



if (isLoadingPackGroups) {
  return <div>Loading...</div>;
}



if (errorPackGroups) {
  return <div>Error loading data</div>;
}



return (
<div>
<h1>Packs Information</h1>
<h2>Pack Groups</h2>
<button  onClick={fetchPackGroups}>Refresh Pack Groups</button>
<ul>
{packGroups.map(group => (
<li  key={group.id}>{group.name}</li>
))}
</ul>
</div>
);
};

export default PacksPage;

Environment Variables

For the React example, ensure you have a .env file with the following content:

YOUR_PARTNER_TOKEN=your_partner_token

Replace 'your_partner_token' with your actual partner token.