1.1.17 • Published 9 months ago

@kazunetakeda25/widget-react v1.1.17

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Papaya Subscription React Widget SDK

The Papaya Widget React SDK provides an easy way to integrate Papaya subscription payments into your react app.


Features

  • Subscription Management: Simplified and secure subscription payment flows.
  • Automatic Providers: No need to configure wallet or query providers in your app—handled by the SDK.
  • Multi-Network Support: Supports Ethereum, BSC, Polygon, Avalanche, Arbitrum, Base, and more.
  • Customization: Easily configure metadata, themes, and supported networks.
  • Works in Both Next.js and React Apps: Supports both SSR (Next.js) and CSR (React).

Installation

Install the SDK using npm:

npm install @papaya-finance/widget-react  

Or using yarn:

yarn add @papaya-finance/widget-react  

Prerequisites

  1. Project ID
    Obtain your projectId from the Reown Cloud Dashboard. Ensure your app's URL is whitelisted in the dashboard to allow usage of the SDK.

  2. Peer Dependencies
    The SDK requires the following dependencies in your project:

    npm install react react-dom @reown/appkit @reown/appkit-adapter-wagmi @reown/appkit-wallet-button wagmi @tanstack/react-query viem  

    Or using yarn:

    yarn add react react-dom @reown/appkit @reown/appkit-adapter-wagmi @reown/appkit-wallet-button wagmi @tanstack/react-query viem  

Usage in Create React App (CRA)

Step 1: Create config.js

Create a new file src/config.js and add:

import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
import {
  mainnet,
  bsc,
  polygon,
  avalanche,
  arbitrum,
  base,
} from "@reown/appkit/networks";
import { cookieStorage, createStorage } from "@wagmi/core";

export const metadata = {
  name: "My App",
  description: "A subscription demo app using Papaya Widget React SDK",
  url: "http://your-react-app.com", // Whitelist this in Reown Cloud
  icons: [],
};

export const projectId = "your_project_id"; // Obtain from Reown Cloud

export const networks = [mainnet, bsc, polygon, avalanche, arbitrum, base];

export const wagmiAdapter = new WagmiAdapter({
  storage: createStorage({ storage: cookieStorage }),
  ssr: false,
  projectId,
  networks,
});

Step 2: Wrap Your App with SubscriptionProvider

Modify src/index.js:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { SubscriptionProvider } from "@papaya-finance/widget-react";
import { QueryClient } from "@tanstack/react-query";
import { wagmiAdapter, metadata, projectId, networks } from "./config";

const queryClient = new QueryClient();

const RootApp = () => (
  <SubscriptionProvider
    wagmiAdapter={wagmiAdapter}
    queryClient={queryClient}
    metadata={metadata}
    themeMode="light"
    projectId={projectId}
    networks={networks}
  >
    <App />
  </SubscriptionProvider>
);

ReactDOM.render(
  <React.StrictMode>
    <RootApp />
  </React.StrictMode>,
  document.getElementById("root")
);

Step 3: Use Subscription Modal in Your Components

Modify App.js to include the subscription modal:

import React, { useState } from "react";
import { SubscriptionModal, SubscriptionPayCycle } from "@papaya-finance/widget-react";

function App() {
  const [isModalOpen, setIsModalOpen] = useState(false);

  return (
    <div style={{ textAlign: "center", marginTop: "50px" }}>
      <h1>Subscription Demo</h1>
      <button onClick={() => setIsModalOpen(true)}>Subscribe Now</button>

      <SubscriptionModal
        open={isModalOpen}
        onClose={() => setIsModalOpen(false)}
        subscriptionDetails={{
          toAddress: "YOUR_SUBSCRIBE_TO_ADDRESS", // Replace it
          cost: "0.99", // Replace it
          token: "usdt", // Available options are: usdt, usdc, and pyusd
          payCycle: SubscriptionPayCycle.Monthly, // Available options are: Daily, Weekly, Monthly, and Yearly
        }}
      />
    </div>
  );
}

export default App;

🌍 Usage in Next.js

In Next.js, you need to mark the provider as a client component:

Step 1: Create providers.js inside src/

"use client"; // Required for Next.js 

import React from "react";
import { SubscriptionProvider } from "@papaya-finance/widget-react";
import { QueryClient } from "@tanstack/react-query";
import { wagmiAdapter, metadata, projectId, networks } from "./config";

const queryClient = new QueryClient();

const Providers = ({ children }) => {
  return (
    <SubscriptionProvider
      wagmiAdapter={wagmiAdapter}
      queryClient={queryClient}
      metadata={metadata}
      themeMode="light" // Your theme dark or light
      projectId={projectId}
      networks={networks}
    >
      {children}
    </SubscriptionProvider>
  );
};

export default Providers;

Step 2: Update _app.js (For Pages Router)

import Providers from "../providers";

function MyApp({ Component, pageProps }) {
  return (
    <Providers>
      <Component {...pageProps} />
    </Providers>
  );
}

export default MyApp;

Step 2: Update layout.js (For App Router)

import Providers from "../providers";

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

Step 3: Use the Modal in a Next.js Page

"use client";

import React, { useState } from "react";
import { SubscriptionModal, SubscriptionPayCycle } from "@papaya-finance/widget-react";

const Page = () => {
  const [isModalOpen, setIsModalOpen] = useState(false);

  return (
    <div>
      <h1>Subscription Demo</h1>
      <button onClick={() => setIsModalOpen(true)}>Subscribe Now</button>

      <SubscriptionModal
        open={isModalOpen}
        onClose={() => setIsModalOpen(false)}
        subscriptionDetails={{
          toAddress: "YOUR_SUBSCRIBE_TO_ADDRESS", // Replace it
          cost: "0.99", // Replace it
          token: "usdt", // Available options are: usdt, usdc, and pyusd
          payCycle: SubscriptionPayCycle.Monthly, // Available options are: Daily, Weekly, Monthly, and Yearly
        }}
      />
    </div>
  );
};

export default Page;

Props Overview

SubscriptionProvider

PropTypeDescription
wagmiAdapterWagmiAdapterAdapter for wallet management.
queryClientQueryClientQuery client for React Query.
metadataobjectMetadata for your application (name, url, etc).
projectIdstringYour unique project ID.
networksAppKitNetwork[]List of supported networks.

SubscriptionModal

PropTypeDescription
openbooleanControls the modal visibility.
onClose() => voidFunction called when the modal is closed.
subscriptionDetails{ toAddress, cost, token, payCycle }Details about the subscription.

Notes

  • Ensure the app's URL is whitelisted in the Reown Cloud Dashboard for the project ID.
  • The SDK internally handles the wallet provider and React Query provider when wagmiAdapter and queryClient are passed.

Example App

Check out the demo app to see the SDK in action.


License

This SDK is licensed under the Appache License.

1.1.17

9 months ago

1.1.16

9 months ago

1.1.15

9 months ago

1.1.14

9 months ago

1.1.13

9 months ago

1.1.12

9 months ago

1.1.11

9 months ago

1.1.10

9 months ago

1.1.9

9 months ago

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.99

9 months ago

1.0.98

9 months ago

1.0.97

9 months ago

1.0.96

9 months ago

1.0.95

9 months ago

1.0.94

9 months ago

1.0.93

9 months ago

1.0.92

9 months ago

1.0.91

9 months ago

1.0.90

9 months ago

1.0.89

9 months ago

1.0.88

9 months ago

1.0.87

9 months ago

1.0.86

9 months ago

1.0.85

9 months ago

1.0.84

9 months ago

1.0.83

9 months ago

1.0.82

9 months ago

1.0.81

9 months ago

1.0.80

9 months ago

1.0.79

9 months ago

1.0.78

9 months ago

1.0.77

9 months ago

1.0.76

9 months ago

1.0.75

9 months ago

1.0.74

9 months ago

1.0.73

9 months ago

1.0.72

9 months ago

1.0.71

9 months ago

1.0.70

9 months ago

1.0.69

9 months ago

1.0.68

9 months ago

1.0.67

9 months ago

1.0.66

9 months ago

1.0.65

9 months ago

1.0.64

9 months ago

1.0.63

9 months ago

1.0.62

9 months ago

1.0.61

9 months ago

1.0.60

9 months ago

1.0.59

9 months ago

1.0.58

9 months ago

1.0.57

9 months ago

1.0.56

9 months ago

1.0.55

9 months ago

1.0.54

9 months ago

1.0.53

9 months ago

1.0.52

9 months ago

1.0.51

9 months ago

1.0.50

9 months ago

1.0.49

9 months ago

1.0.48

9 months ago

1.0.47

9 months ago

1.0.46

9 months ago

1.0.45

9 months ago

1.0.44

9 months ago

1.0.43

9 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

9 months ago

1.0.33

9 months ago

1.0.32

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.27

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago