@@ -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