Skip to content

Commit fd0a73e

Browse files
authored
Merge pull request #230 from golemfactory/update-react-sdk-to-3.0
Document the changes in @golem-sdk/react version 3.0
2 parents e1d2cd5 + 9f27911 commit fd0a73e

File tree

6 files changed

+41
-205
lines changed

6 files changed

+41
-205
lines changed

src/pages/docs/creators/javascript/react/api-reference-overview.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ type: React Reference
88

99
This section contains short descriptions of all the components and hooks available in the React SDK. Click on the name of the component or hook to see the full documentation.
1010

11-
| Component or hook | Description |
12-
| --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
13-
| [YagnaProvider](/docs/creators/javascript/react/yagna-provider) | This component provides context for the Golem React SDK. It's required to wrap your app with this component if you want to use the SDK. |
14-
| [useYagna](/docs/creators/javascript/react/use-yagna) | This hook provides information about the Yagna connection status. |
15-
| [useExecutor](/docs/creators/javascript/react/use-executor) | This hook allows you to initialize and manage a task executor. |
16-
| [useTask](/docs/creators/javascript/react/use-task) | This hook allows you to run a single task on the Golem Network |
17-
| [useInvoices](/docs/creators/javascript/react/use-invoices) | This hook allows you to fetch all invoices known to your Yagna node. |
18-
| [useHandleInvoice](/docs/creators/javascript/react/use-handle-invoice) | This hook allows you to handle invoices (currently only paying them is supported). |
19-
| [useDebitNotes](/docs/creators/javascript/react/use-debit-notes) | This hook allows you to fetch all debit notes known to your Yagna node. |
20-
| [useHandleDebitNote](/docs/creators/javascript/react/use-handle-debit-note) | This hook allows you to handle debit notes (currently only paying them is supported). |
11+
| Component or hook | Description |
12+
| ---------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
13+
| [YagnaProvider](/docs/creators/javascript/react/yagna-provider) | This component provides context for the Golem React SDK. It's required to wrap your app with this component if you want to use the SDK. |
14+
| [useYagna](/docs/creators/javascript/react/use-yagna) | This hook provides information about the Yagna connection status. |
15+
| [useExecutor](/docs/creators/javascript/react/use-executor) | This hook allows you to initialize and manage a task executor. |
16+
| [useTask](/docs/creators/javascript/react/use-task) | This hook allows you to run a single task on the Golem Network |
17+
| [useInvoices](/docs/creators/javascript/react/use-invoices) | This hook allows you to search through all invoices known to your Yagna node. |
18+
| [useHandleInvoice](/docs/creators/javascript/react/use-handle-invoice) | This hook allows you to handle invoices (currently only paying them is supported). |

src/pages/docs/creators/javascript/react/getting-started.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bun add @golem-sdk/react
5858
Then make sure to wrap your app with the `YagnaProvider` component:
5959

6060
```jsx
61-
<YagnaProvider config={{ yagnaAppKey: 'my-app-key' }}>
61+
<YagnaProvider>
6262
<App />
6363
</YagnaProvider>
6464
```
@@ -79,23 +79,26 @@ Now that you have the SDK installed and configured, you can start using it in yo
7979

8080
```jsx
8181
function YagnaStatus() {
82-
const { isConnected, reconnect, isLoading, error } = useYagna()
83-
if (isLoading) {
84-
return <div>Loading...</div>
82+
const { isConnected, setYagnaOptions } = useYagna()
83+
const inputRef = useRef(null)
84+
if (isConnected) {
85+
return <span>Connected to Yagna!</span>
8586
}
8687
return (
8788
<div>
88-
<div>Yagna is {isConnected ? 'connected' : 'disconnected'}</div>
89-
<button onClick={reconnect} disabled={isConnected}>
90-
Reconnect
89+
<div>Enter your app key to connect to Yagna</div>
90+
<input ref={inputRef} />
91+
<button
92+
onClick={() => setYagnaOptions({ apiKey: inputRef.current.value })}
93+
>
94+
Set app key
9195
</button>
92-
{error && <div>Error: {error.toString()}</div>}
9396
</div>
9497
)
9598
}
9699
```
97100

98-
Add this component to your application and refresh the page. If you have set up everything correctly you should see "Yagna is connected"
101+
Add this component to your application and refresh the page. Enter your app-key and if you have set up everything correctly you should see "Connected to Yagna!".
99102

100103
{% docnavigation title="Next steps" %}
101104

src/pages/docs/creators/javascript/react/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ The Golem React SDK provides a set of React hooks and components that make it ea
1919
- Connecting to Yagna - use the [useYagna](/docs/creators/javascript/react/use-yagna) hook to connect display the connection status and reconnect to Yagna if the connection is lost.
2020
- Running tasks on the network - use the [useExecutor](/docs/creators/javascript/react/use-executor) hook to initialize and terminate executors and the [useTask](/docs/creators/javascript/react/use-task) hook to run tasks on the network.
2121
- Listing and handling invoices - use the [useInvoices](/docs/creators/javascript/react/use-invoices) hook to list invoices and the [useHandleInvoice](/docs/creators/javascript/react/use-handle-invoice) hook to handle invoices.
22-
- Listing and handling debit notes - use the [useDebitNotes](/docs/creators/javascript/react/use-debit-notes) hook to list debit notes and the [useHandleDebitNote](/docs/creators/javascript/react/use-handle-debit-note) hook to handle debit notes.
2322

2423
{% docnavigation title="API reference" %}
2524

@@ -31,6 +30,8 @@ If you want to learn more about each of the hooks and components provided by the
3130

3231
To help you get started we have created an example application that uses every hook and component provided by the SDK. You can find the source code for the example app on [GitHub](https://github.com/golemfactory/golem-sdk-react/tree/master/examples/react-with-vite). Feel free to clone the repository and play around with the code. Follow the instructions in the README to run the app locally.
3332

33+
To see the example app in action, you can also visit the [live demo](https://golem-react-showcase.vercel.app/).
34+
3435
## GitHub repository
3536

3637
The source code for the SDK along with an example app is available on [GitHub](https://github.com/golemfactory/golem-sdk-react) and we welcome contributions.

src/pages/docs/creators/javascript/react/use-debit-notes.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/pages/docs/creators/javascript/react/use-handle-debit-note.md

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/pages/docs/creators/javascript/react/use-invoices.md

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: useInvoices
3-
description: React hook for fetching all invoices
3+
description: React hook for searching invoices
44
type: React Reference
55
---
66

77
# useInvoices
88

9-
`useInvoices` is a hook that fetches all invoices known to the connected yagna instance. It paginates data by default. Under the hood it uses [SWR](https://swr.vercel.app/) so you get all the benefits of caching and revalidation. It's also possible to configure that behavior by passing the `swrConfig` parameter. It returns an object with the following properties:
9+
`useInvoices` is a hook that allows you to search through all invoices known to the connected yagna instance. Under the hood it uses [SWR](https://swr.vercel.app/) so you get all the benefits of caching and revalidation. It's also possible to configure that behavior by passing the `swrConfig` parameter. It returns an object with the following properties:
1010

1111
| Name | Description |
1212
| ------------ | ---------------------------------------------------------------------------------------------- |
@@ -37,46 +37,28 @@ type: React Reference
3737

3838
This hook accepts a single configuration object with the following properties:
3939

40-
| Name | Description |
41-
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
42-
| after (optional) | A string representing the timestamp to start fetching invoices from. If not provided, the hook will fetch invoices starting from the earliest invoice known to the connected yagna instance. |
43-
| limit (optional) | The maximum number of invoices to fetch. Defaults to 10. |
44-
| swrConfig (optional) | [SWR configuration object](https://swr.vercel.app/docs/api#options) |
45-
46-
To achieve pagination, pass the `timestamp` of the last invoice in the `after` parameter of the next call.
40+
| Name | Description |
41+
| --------------------------- | ---------------------------------------------------------------------------------------- |
42+
| after (optional) | Only return invoices with a timestamp greater than this value. |
43+
| limit (optional) | Maximum number of invoices to return. Default is 50. |
44+
| statuses (optional) | Array of statuses to filter by. |
45+
| providerIds (optional) | Array of provider IDs to filter by. |
46+
| minAmount (optional) | Only return invoices with an amount greater than or equal to this value. |
47+
| maxAmount (optional) | Only return invoices with an amount less than or equal to this value. |
48+
| providerWallets (optional) | Array of provider wallets to filter by. |
49+
| invoiceIds (optional) | Array of invoice IDs to filter by. If provided, all other search parameters are ignored. |
50+
| paymentPlatforms (optional) | Array of payment platforms to filter by. |
51+
| swrConfig (optional) | [SWR configuration object](https://swr.vercel.app/docs/api#options) |
4752

4853
## Example
4954

5055
```jsx
5156
function MyComponent() {
52-
const { invoices, isLoading, error, refetch } = useInvoices()
53-
if (isLoading) {
54-
return <div>Loading...</div>
55-
}
56-
if (error) {
57-
return <div>Error: {error.toString()}</div>
58-
}
59-
return (
60-
<div>
61-
<ul>
62-
{invoices.map((invoice) => (
63-
<li key={invoice.invoiceId}>
64-
{invoice.invoiceId} - {invoice.status}
65-
</li>
66-
))}
67-
</ul>
68-
<button onClick={refetch}> Refresh </button>
69-
</div>
70-
)
71-
}
72-
```
73-
74-
With pagination:
75-
76-
```jsx
77-
function MyComponent() {
78-
const [after, setAfter] = useState()
79-
const { invoices, isLoading, error, refetch } = useInvoices({ after })
57+
const { invoices, isLoading, error, refetch } = useInvoices({
58+
limit: 10,
59+
statuses: ['RECEIVED'],
60+
after: new Date('2021-01-01'),
61+
})
8062
if (isLoading) {
8163
return <div>Loading...</div>
8264
}
@@ -92,9 +74,6 @@ function MyComponent() {
9274
</li>
9375
))}
9476
</ul>
95-
<button onClick={() => setAfter(invoices[invoices.length - 1].timestamp)}>
96-
Next
97-
</button>
9877
<button onClick={refetch}> Refresh </button>
9978
</div>
10079
)

0 commit comments

Comments
 (0)