Skip to content

Commit 96bbabf

Browse files
SgtPookiCopilot
andauthored
feat: use synapse 0.35.x (#86)
* fix: get filecoin-pin-website working with latest synapse + filecoin-pin * feat: update to latest synapse-sdk and filecoin-pin * fix: address synapse-sdk telemetry issues * fix: synapse-sdk patch * fix: synapse-sdk has latest changes needed for browser telemetry * chore: remove patched @filoz/synapse-sdk * chore: improve use-ipni-check hook * chore: remove unused code * chore: remove sentry debug option * fix: providerId and dataSetId query params override storage context * fix: useIpniCheck dedupes inflight requests * fix: remove unnecessary dataSetId check * deps: use latest filecoin-pin * Update src/lib/filecoin-pin/synapse.ts Co-authored-by: Copilot <[email protected]> * Update src/hooks/use-ipni-check.ts Co-authored-by: Copilot <[email protected]> * fix: don't disable sentry on synapse init * chore: fix hasOverrides * fix: ensure ipni-check can receive updated validateAdvertisementOptions * chore: fix linter errors * fix: use v1.0.0 known good providers * chore: jsdoc comment clarifications add comment about providerId=2 being the only provider that results in successful ipni advertisements * chore: temporarily hardcode provider=2 --------- Co-authored-by: Copilot <[email protected]>
1 parent 5e3b2e7 commit 96bbabf

File tree

16 files changed

+3344
-1572
lines changed

16 files changed

+3344
-1572
lines changed

.github/workflows/filecoin-pin-upload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
# This PROVIDER_ID set here will be used by the upload action below to override provider selection.
4040
- name: Select random known good provider
4141
run: |
42-
known_good_provider_ids=(2 8 16)
42+
known_good_provider_ids=(2)
4343
selected_provider_id=${known_good_provider_ids[$RANDOM % ${#known_good_provider_ids[@]}]}
4444
echo "PROVIDER_ID=$selected_provider_id" >> $GITHUB_ENV
4545
echo "Selected known good provider ID: $selected_provider_id"

package-lock.json

Lines changed: 3093 additions & 1210 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@tailwindcss/vite": "^4.1.14",
1818
"class-variance-authority": "^0.7.1",
1919
"clsx": "^2.1.1",
20-
"filecoin-pin": "^0.9.0",
20+
"filecoin-pin": "^0.11.1",
2121
"lucide-react": "^0.545.0",
2222
"pino": "^10.0.0",
2323
"pretty-bytes": "^7.1.0",

src/components/layout/content.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ export default function Content() {
4040
// Active upload accordion expansion (separate from history expansion)
4141
const [activeUploadExpanded, setActiveUploadExpanded] = useState(true)
4242

43-
// Wallet/synapse status for loading states
44-
const { wallet, synapse } = useFilecoinPinContext()
43+
// Wallet/synapse/dataset status for loading states
44+
const { wallet, synapse, dataSet, storageContext } = useFilecoinPinContext()
4545

4646
// Determine if we're still initializing (wallet, synapse, provider)
4747
// Note: We don't block on isLoadingPieces - users can upload while history loads
4848
const isInitializing = wallet.status === 'loading' || wallet.status === 'idle'
4949

50+
// Check if we've confirmed there's no dataset (wallet/synapse ready, but no dataset found)
51+
// In this case, we shouldn't show loading because there won't be any pieces/history to load
52+
const hasConfirmedNoDataset =
53+
wallet.status === 'ready' && synapse !== null && dataSet.status === 'idle' && !storageContext && !isInitializing
54+
5055
// Get loading message based on current state
5156
const getLoadingMessage = () => {
5257
if (wallet.status === 'loading' || wallet.status === 'idle') {
@@ -55,7 +60,7 @@ export default function Content() {
5560
if (!synapse) {
5661
return 'Initializing storage service...'
5762
}
58-
return 'Preparing upload interface...'
63+
return 'Loading previous uploads...'
5964
}
6065

6166
// If wallet failed to load, show error instead of spinner
@@ -105,10 +110,10 @@ export default function Content() {
105110
</div>
106111
)}
107112

108-
{/* Show loading state while initializing */}
109-
{(!hasLoadedHistory || isLoadingPieces || isInitializing) && uploadHistory.length === 0 && (
110-
<LoadingState message={getLoadingMessage()} />
111-
)}
113+
{/* Show loading state while initializing, but not if we've confirmed there's no dataset */}
114+
{!hasConfirmedNoDataset &&
115+
(!hasLoadedHistory || isLoadingPieces || isInitializing) &&
116+
uploadHistory.length === 0 && <LoadingState message={getLoadingMessage()} />}
112117

113118
{/* Always show upload history when available */}
114119
{uploadHistory.length > 0 && (

src/components/upload/upload-completed.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react'
1+
import { useMemo, useState } from 'react'
22
import { INPI_ERROR_MESSAGE } from '@/hooks/use-filecoin-upload.ts'
33
import {
44
getDatasetExplorerLink,
@@ -29,6 +29,7 @@ function UploadCompleted({ cid, fileName, pieceCid, datasetId }: UploadCompleted
2929
// Get provider info from context via hook
3030
const providerInfo = useProviderInfo()
3131
const [hasIpniFailure, setHasIpniFailure] = useState(false)
32+
const validateIpniOptions = useMemo(() => ({ maxAttempts: 1 }), [])
3233

3334
/**
3435
* Get the status of the IPNI check to change how we render the completed state.
@@ -37,11 +38,10 @@ function UploadCompleted({ cid, fileName, pieceCid, datasetId }: UploadCompleted
3738
cid: cid || null,
3839
isActive: true,
3940
onSuccess: () => setHasIpniFailure(false),
40-
maxAttempts: 1,
41-
onError: (error) => {
42-
console.error('[UploadCompleted] IPNI check failed:', error)
41+
onError: () => {
4342
setHasIpniFailure(true)
4443
},
44+
validateIpniAdvertisementOptions: validateIpniOptions,
4545
})
4646
// TODO: fix types, datasetId should never be undefined here...
4747
const datasetIdOrDefault = datasetId || providerInfo?.datasetId || ''

src/context/filecoin-pin-provider.tsx

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface FilecoinPinContextValue {
2020
refreshWallet: () => Promise<void>
2121
synapse: SynapseService['synapse'] | null
2222
dataSet: DataSetState
23-
ensureDataSet: () => Promise<number | null>
23+
checkIfDatasetExists: () => Promise<number | null>
2424
/**
2525
* Storage context for the current data set.
2626
* Only available when dataSet.status === 'ready'.
@@ -43,26 +43,13 @@ export const FilecoinPinProvider = ({ children }: { children: ReactNode }) => {
4343
const debugParams = useMemo(() => getDebugParams(), [])
4444

4545
// Use the data set manager hook
46-
const { dataSet, ensureDataSet, storageContext, providerInfo } = useDataSetManager({
46+
const { dataSet, checkIfDatasetExists, storageContext, providerInfo } = useDataSetManager({
4747
synapse: synapseRef.current,
4848
walletAddress: wallet.status === 'ready' ? wallet.data.address : null,
4949
debugParams,
5050
})
5151

5252
const refreshWallet = useCallback(async () => {
53-
const hasStandardAuth = config.privateKey != null
54-
const hasSessionKeyAuth = config.walletAddress != null && config.sessionKey != null
55-
56-
if (!hasStandardAuth && !hasSessionKeyAuth) {
57-
setWallet((prev) => ({
58-
status: 'error',
59-
error:
60-
'Missing authentication: provide either VITE_FILECOIN_PRIVATE_KEY or (VITE_WALLET_ADDRESS + VITE_SESSION_KEY)',
61-
data: prev.data,
62-
}))
63-
return
64-
}
65-
6653
setWallet((prev) => ({
6754
status: 'loading',
6855
data: prev.status === 'ready' ? prev.data : undefined,
@@ -96,35 +83,30 @@ export const FilecoinPinProvider = ({ children }: { children: ReactNode }) => {
9683
}, [])
9784

9885
/**
99-
* Proactively ensure data set when wallet and synapse are ready
100-
* This creates a better UX by having the data set ready before users attempt to upload, preventing long looking upload times.
101-
*
102-
* Trade-off: This may create data sets for users who just visit the site but never upload.
103-
* This means some USDFC will be used and locked up for Data Sets that may never be used, but this ensures a smooth upload experience for our demo.
104-
* Also, dataset creation fee is being removed in next release, so this won't really be a concern at that point.
105-
* @see https://github.com/filecoin-project/filecoin-pin-website/issues/11
86+
* Proactively check if data set exists when wallet and synapse are ready
87+
* We need to check for an existing data set in order to load previously uploaded pieces.
10688
*
10789
* Keep in mind that in the regular filecoin-pin flow, there is a single user with a single wallet, and synapse/filecoin-pin will select a dataset for you automatically.
108-
* Users usually don't need to worry about this, but for our demo, we want to ensure a smooth upload experience for users who visit the site but never upload.
90+
* Users usually don't need to worry about this, but for our demo, we want to check for existing data sets proactively.
10991
*/
11092
useEffect(() => {
11193
if (wallet.status === 'ready' && synapseRef.current && dataSet.status === 'idle') {
112-
console.debug('[DataSet] Wallet and Synapse ready, proactively ensuring data set')
113-
void ensureDataSet()
94+
console.debug('[DataSet] Wallet and Synapse ready, proactively checking if data set exists')
95+
void checkIfDatasetExists()
11496
}
115-
}, [wallet.status, ensureDataSet, dataSet.status])
97+
}, [wallet.status, checkIfDatasetExists, dataSet.status])
11698

11799
const value = useMemo<FilecoinPinContextValue>(
118100
() => ({
119101
wallet,
120102
refreshWallet,
121103
synapse: synapseRef.current,
122104
dataSet,
123-
ensureDataSet,
105+
checkIfDatasetExists,
124106
storageContext,
125107
providerInfo,
126108
}),
127-
[wallet, refreshWallet, dataSet, ensureDataSet, storageContext, providerInfo]
109+
[wallet, refreshWallet, dataSet, checkIfDatasetExists, storageContext, providerInfo]
128110
)
129111

130112
return <FilecoinPinContext.Provider value={value}>{children}</FilecoinPinContext.Provider>

0 commit comments

Comments
 (0)