Widget Install

Install

If you're using pnpm

pnpm add @ic-pay/icpay-widget @ic-pay/icpay-sdk

If you're using npm

npm install @ic-pay/icpay-widget @ic-pay/icpay-sdk

If you're using yarn

yarn add @ic-pay/icpay-widget @ic-pay/icpay-sdk

Examples

Usage examples

'use client'
import { useEffect, useRef } from 'react'
import '@ic-pay/icpay-widget'

export default function Page() {
  const ref = useRef<any>(null)
  useEffect(() => {
    if (!ref.current) return
    ref.current.config = {
      publishableKey: process.env.NEXT_PUBLIC_ICPAY_PK,
      amountsUsd: [1,5,10],
      defaultAmountUsd: 5,
    }
    const onDone = (e: any) => console.log('Tip completed', e.detail)
    window.addEventListener('icpay-sdk-transaction-completed', onDone)
    return () => window.removeEventListener('icpay-sdk-transaction-completed', onDone)
  }, [])
  return <icpay-tip-jar ref={ref as any} />
}

Was this page helpful?