@flexar/sdk
v0.0.3
Published
Flexar subscriptions platform SDK
Downloads
79
Readme
flexar-sdk
Flexar React SDK
Subscriptions SDK
Basic usage
Install:
$ npm i @flexar/sdk
In your client component:
import { useSSP } from "@flexar/sdk"
import { useWallet } from "@solana/wallet-adapter-react"
export default function MyComponent() {
// @solana/wallet-adapter-react wallet component
const wallet = useWallet();
// Flexar SSP hook
const { isLoading, passes, refreshPasses, subscribe } = useSSP({ wallet, apiKey: "Your SSP API KEY" });
// ...
}
The hook will auto-load available passes for the API provided and update them once a wallet is connected.
Alternatively you can supply and API key via NEXT_PUBLIC_SSP_APIKEY
environment variable.
Types
Pass
type SSPPass = {
id: string;
name: string;
description: string;
symbol: string;
imageUrl: string;
/** Total number of passes */
minted: number;
/** Number of available passes */
available: number;
/** If the connected wallet is already subscribed to this pass */
isSubscribed?: boolean;
/** If the connected wallet is already subscribed to this pass, when the subscription ends */
subscribedEndDate?: number;
/** If the connected wallet can extend the subscription to this pass */
canExtend?: boolean;
tiers: SSPTier[];
};
Tier
type SSPTier = {
id: string;
description: string;
/** duration as ISO 8601 format, eg. "P1Y2M3DT4H5M6S". @see https://www.digi.com/resources/documentation/digidocs/90001488-13/reference/r_iso_8601_duration_format.htm */
duration: string;
/** Price in token (lamports for SOL) */
price: number;
/** SOL only at the moment */
token: string;
/** If the connected wallet can subscribe to this tier */
canSubscribe?: boolean;
};
Hook params
type UseSSPProps = {
/** Solana Wallet Adapter Wallet */
wallet?: WalletContextState;
/** FLEXAR SSP API key */
apiKey?: string;
/** FLEXAR SSP endpoint override */
apiEndpoint?: string;
};
Hook return
type UseSSPContext = {
/** Loading passes */
isLoading: boolean;
/**
* Available subscription passes.
* Undefined: Passes were never loaded
* Null: Loading error
*/
passes?: SSPPass[] | null;
/** Use to manually refresh passes */
refreshPasses: () => Promise<void>;
/** Subscribe to a tier */
subscribe: (tierId: string, statusCallback?: SSPStatusCallback) => Promise<boolean>;
};