@@ -33,6 +33,9 @@ import {
3333 BALANCE_LIST_FETCH_SUCCESS ,
3434 BALANCE_LIST_FETCH_ERROR ,
3535 SHIELDED_BALANCE_PROGRESS_SET ,
36+ FETCH_SHIELDED_REWARDS_IN_PROGRESS ,
37+ FETCH_SHIELDED_REWARDS_SUCCESS ,
38+ FETCH_SHIELDED_REWARDS_ERROR ,
3639} from '../../constants/accounts' ;
3740import Axios from 'axios' ;
3841import { urlFetchRevealedPubkey , urlFetchRewards , urlFetchUnBondingDelegations , urlFetchVestingBalance , urlFetchBlockHeight , urlFetchTokensList , urlFetchBalanceList } from '../../constants/url' ;
@@ -45,6 +48,7 @@ import { config } from '../../config';
4548import { getSdk } from '@namada/sdk/web' ;
4649import init from '@namada/sdk/web-init' ;
4750import { workerShieldedSync } from 'workers/balanceServices' ;
51+ import { fetchShieldedRewards } from 'workers/services' ;
4852// import { Tokens } from '@namada/types';
4953
5054export const setAccountAddress = ( value , shieldedAddress , shieldedDetails ) => {
@@ -661,3 +665,43 @@ export const reSyncBalance = (viewingKey, timestamp, tnam, znam, chainId = confi
661665 }
662666 }
663667} ;
668+
669+ const shieldedRewardsFetchInProgress = ( ) => ( {
670+ type : FETCH_SHIELDED_REWARDS_IN_PROGRESS ,
671+ } ) ;
672+
673+ const shieldedRewardsFetchSuccess = ( value ) => ( {
674+ type : FETCH_SHIELDED_REWARDS_SUCCESS ,
675+ value,
676+ } ) ;
677+
678+ const shieldedRewardsFetchError = ( error ) => ( {
679+ type : FETCH_SHIELDED_REWARDS_ERROR ,
680+ message : error || 'Failed to fetch shielded Rewards' ,
681+ } ) ;
682+
683+
684+ export const getShieldedRewards = ( viewingKey , chainId = config . CHAIN_ID , cb ) => async ( dispatch ) => {
685+ dispatch ( shieldedRewardsFetchInProgress ( ) ) ;
686+ try {
687+ const rewards = await fetchShieldedRewards (
688+ viewingKey ,
689+ chainId ,
690+ config . RPC_URL ,
691+ ) ;
692+ dispatch ( shieldedRewardsFetchSuccess ( rewards ) ) ;
693+ if ( cb ) {
694+ cb ( rewards ) ;
695+ }
696+ } catch ( error ) {
697+ console . error ( '❌ Shielded rewards error:' , {
698+ message : error . message || 'Unknown error' ,
699+ error,
700+ chainId,
701+ } ) ;
702+ dispatch ( shieldedRewardsFetchError ( error . message || 'Unknown error' ) ) ;
703+ if ( cb ) {
704+ cb ( null ) ;
705+ }
706+ }
707+ } ;
0 commit comments