Hooks

Custom hooks for wallet, subscriptions, and payments

useWallet

Manage wallet connection state

Returns

addressstring | null

Connected wallet address

isConnectedboolean

Whether wallet is connected

connect() => void

Connect wallet function

disconnect() => void

Disconnect wallet function

Example

1import { useWallet } from 'pyhard-vendor-sdk';
2
3function MyComponent() {
4  const { address, isConnected, connect, disconnect } = useWallet();
5
6  return (
7    <div>
8      {isConnected ? (
9        <div>
10          <p>Connected: {address}</p>
11          <button onClick={disconnect}>Disconnect</button>
12        </div>
13      ) : (
14        <button onClick={connect}>Connect Wallet</button>
15      )}
16    </div>
17  );
18}

useSubscriptions

Fetch and manage subscriptions

Parameters

vendorAddressstring

Vendor wallet address

Returns

subscriptionsSubscription[]

Array of subscriptions

loadingboolean

Loading state

errorstring | null

Error message if any

executePayment(subscription: Subscription) => Promise<string>

Execute payment for subscription

Example

1import { useSubscriptions } from 'pyhard-vendor-sdk';
2
3function VendorDashboard() {
4  const { 
5    subscriptions, 
6    loading, 
7    error, 
8    executePayment 
9  } = useSubscriptions('0x...');
10
11  if (loading) return <div>Loading...</div>;
12  if (error) return <div>Error: {error}</div>;
13
14  return (
15    <div>
16      {subscriptions.map(sub => (
17        <div key={sub.id}>
18          <p>Subscription: {sub.amount} PYUSD</p>
19          <button onClick={() => executePayment(sub)}>
20            Execute Payment
21          </button>
22        </div>
23      ))}
24    </div>
25  );
26}

usePaymentHistory

Fetch payment history for a subscription

Parameters

subscriptionIdstring

Subscription ID

smartWalletAddressstring

Smart wallet address

Returns

paymentsPayment[]

Array of payments

loadingboolean

Loading state

errorstring | null

Error message if any

Example

1import { usePaymentHistory } from 'pyhard-vendor-sdk';
2
3function PaymentHistory({ subscriptionId, smartWalletAddress }) {
4  const { payments, loading, error } = usePaymentHistory(
5    subscriptionId, 
6    smartWalletAddress
7  );
8
9  if (loading) return <div>Loading payments...</div>;
10  if (error) return <div>Error: {error}</div>;
11
12  return (
13    <div>
14      {payments.map(payment => (
15        <div key={payment.id}>
16          <p>Amount: {payment.amount} PYUSD</p>
17          <p>Date: {payment.date}</p>
18        </div>
19      ))}
20    </div>
21  );
22}

usePaymentDetection

Detect new payments in real-time

Parameters

subscriptionIdstring

Subscription ID to monitor

Returns

newPaymentsPayment[]

New payments detected

isPollingboolean

Whether currently polling

Example

1import { usePaymentDetection } from 'pyhard-vendor-sdk';
2
3function PaymentMonitor({ subscriptionId }) {
4  const { newPayments, isPolling } = usePaymentDetection(subscriptionId);
5
6  return (
7    <div>
8      <p>Polling: {isPolling ? 'Yes' : 'No'}</p>
9      <p>New payments: {newPayments.length}</p>
10    </div>
11  );
12}