@soroban-react/events
TypeScript icon, indicating that this package has built-in type declarations

9.1.3 • Public • Published

@soroban-react/events

See the official gitbook: https://soroban-react.gitbook.io/index/


import { useSorobanEvents, EventSubscription } from '@soroban-react/events'

const crowdfundPledgedEventSubscription: EventSubscription = {
      contractId: Constants.CrowdfundId, 
      topics: ['pledged_amount_changed'], 
      cb: (event: SorobanClient.SorobanRpc.EventResponse): void => {
        let eventTokenBalance = xdr.ScVal.fromXDR(event.value.xdr, 'base64')
        setTokenBalance(convert.scvalToBigNumber(eventTokenBalance))
      }, 
      id: Math.random()}

  const crowdfundTargetReachedSubscription: EventSubscription = {
      contractId: Constants.CrowdfundId, 
      topics: ['target_reached'], 
      cb: (event: SorobanClient.SorobanRpc.EventResponse): void => {
        setTargetReached(true)
      }, 
      id: Math.random()}

  const sorobanEventsContext = useSorobanEvents()
  React.useEffect(() => {
    const pledgedSubId = sorobanEventsContext.subscribe(crowdfundPledgedEventSubscription)
    const reachedSubId = sorobanEventsContext.subscribe(crowdfundTargetReachedSubscription)

    return () => {
      sorobanEventsContext.unsubscribe(pledgedSubId);
      sorobanEventsContext.unsubscribe(reachedSubId);
    }
  }, [sorobanEventsContext]);

Package Sidebar

Install

npm i @soroban-react/events

Weekly Downloads

132

Version

9.1.3

License

Apache-2.0

Unpacked Size

19.9 kB

Total Files

11

Last publish

Collaborators

  • devmonsterblock
  • abstract829
  • benjaminsalon
  • coderipper
  • paulbellamy
  • esteblock