Skip to content

Commit

Permalink
Use SDK config with custom RPCs
Browse files Browse the repository at this point in the history
The first one (polygon's own) is the most solid. Others are flimsy and tend to break, hit timeouts, etc.

Matthew asked if we can go with the "default" main one. Here it is.
  • Loading branch information
mondoreale committed Oct 28, 2024
1 parent 6ea374b commit 7cb47df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@ethersproject/hdnode": "^5.7.0",
"@ethersproject/providers": "^5.5.3",
"@ibm/plex": "^5.1.3",
"@streamr/config": "^5.4.0",
"@streamr/sdk": "^101.1.2",
"@streamr/utils": "^101.1.2",
"@tanstack/react-query": "^5.28.4",
Expand Down
7 changes: 5 additions & 2 deletions src/components/StreamrClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react'
import React, { useState } from 'react'
import Provider from 'streamr-client-react'
import { getStreamrClientConfig } from '../utils/streams'

interface Props {
children: React.ReactNode
}

const StreamrClientProvider = ({ children }: Props) => {
return <Provider>{children}</Provider>
const [config] = useState(getStreamrClientConfig())

return <Provider {...config}>{children}</Provider>
}

export default StreamrClientProvider
17 changes: 15 additions & 2 deletions src/utils/streams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResendOptions, StreamDefinition, StreamMessage } from '@streamr/sdk'
import { ResendOptions, StreamDefinition, StreamMessage, StreamrClientConfig } from '@streamr/sdk'
import { keyToArrayIndex } from '@streamr/utils'
import { useQuery } from '@tanstack/react-query'
import { useEffect, useMemo, useRef, useState } from 'react'
Expand All @@ -13,6 +13,7 @@ import {
GetStreamsQueryVariables,
} from '../generated/gql/indexer'
import { getIndexerClient } from './queries'
import { config } from '@streamr/config'

function getLimitedStreamsQueryKey(phrase: string, limit: number) {
return ['useLimitedStreamsQuery', phrase, limit]
Expand Down Expand Up @@ -191,10 +192,22 @@ export function useRecentOperatorNodeMetricEntry(nodeId: string) {
return recent
}

export function getStreamrClientConfig(): StreamrClientConfig {
return {
metrics: false,
contracts: {
ethereumNetwork: {
chainId: config.polygon.id,
},
rpcs: config.polygon.rpcEndpoints.slice(0, 1)
},
}
}

async function getStreamrClientInstance() {
const StreamrClient = (await import('@streamr/sdk')).default

return new StreamrClient()
return new StreamrClient(getStreamrClientConfig())
}

export function useStreamFromClient(streamId: string) {
Expand Down

0 comments on commit 7cb47df

Please sign in to comment.