Skip to content

Commit 867c8ab

Browse files
shielded rewards updates. (#232)
1 parent 5aea37e commit 867c8ab

File tree

13 files changed

+175
-23
lines changed

13 files changed

+175
-23
lines changed

src/Router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const routes = [{
3333
path: '/tokens',
3434
component: Tokens,
3535
}, {
36-
path: '/tokensShielded',
36+
path: '/shieldedTokens',
3737
component: Tokens,
3838
// }, {
3939
// path: '/externalTransfer/withdraw',

src/actions/accounts/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
3740
import Axios from 'axios';
3841
import { urlFetchRevealedPubkey, urlFetchRewards, urlFetchUnBondingDelegations, urlFetchVestingBalance, urlFetchBlockHeight, urlFetchTokensList, urlFetchBalanceList } from '../../constants/url';
@@ -45,6 +48,7 @@ import { config } from '../../config';
4548
import { getSdk } from '@namada/sdk/web';
4649
import init from '@namada/sdk/web-init';
4750
import { workerShieldedSync } from 'workers/balanceServices';
51+
import { fetchShieldedRewards } from 'workers/services';
4852
// import { Tokens } from '@namada/types';
4953

5054
export 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+
};

src/constants/accounts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export const FETCH_SHIELDED_BALANCE_SUCCESS = 'FETCH_SHIELDED_BALANCE_SUCCESS';
4545
export const SHIELDED_BALANCE_PROGRESS_SET = 'SHIELDED_BALANCE_PROGRESS_SET';
4646
export const FETCH_SHIELDED_BALANCE_ERROR = 'FETCH_SHIELDED_BALANCE_ERROR';
4747

48+
export const FETCH_SHIELDED_REWARDS_IN_PROGRESS = 'FETCH_SHIELDED_REWARDS_IN_PROGRESS';
49+
export const FETCH_SHIELDED_REWARDS_SUCCESS = 'FETCH_SHIELDED_REWARDS_SUCCESS';
50+
export const FETCH_SHIELDED_REWARDS_ERROR = 'FETCH_SHIELDED_REWARDS_ERROR';
51+
4852
// export const FETCH_SHIELDED_SYNC_IN_PROGRESS = 'FETCH_SHIELDED_SYNC_IN_PROGRESS';
4953
// export const FETCH_SHIELDED_SYNC_SUCCESS = 'FETCH_SHIELDED_SYNC_SUCCESS';
5054
// export const FETCH_SHIELDED_SYNC_ERROR = 'FETCH_SHIELDED_SYNC_ERROR';

src/containers/Home/TokenDetails/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ const TokenDetails = (props) => {
8282
}, 0);
8383
rewards = rewards ? rewards / 10 ** config.COIN_DECIMALS : 0;
8484

85+
const shieldedRewards = props.shieldedRewards && props.shieldedRewards / 10 ** config.COIN_DECIMALS;
86+
8587
const handleTransfer = () => {
8688
const value = {
8789
name: 'Transparent Namada',
@@ -167,6 +169,21 @@ const TokenDetails = (props) => {
167169
{/* /!* <Compound disable={tokens <= 0}/> *!/ */}
168170
</div>
169171
</div>
172+
{/* <div className="chip_info">Add commentMore actions
173+
<p>{variables[props.lang].shielded_rewards}</p>
174+
{props.shieldedRewardsInProgress ? (
175+
<ChipSkeleton/>
176+
) : (
177+
<div className="chip">
178+
<img alt="total tokens" src={rewardsIcon}/>
179+
<p>{shieldedRewards > 0 ? shieldedRewards.toFixed(4) : 0}</p>
180+
</div>
181+
)}
182+
183+
<div className="buttons_div">
184+
<ClaimButton disable={rewards <= 0}/>
185+
</div>
186+
</div> */}
170187
{/* <div className="chip_info"> */}
171188
{/* <p>{variables[props.lang]['un_staked_tokens']}</p> */}
172189
{/* <div className="chip"> */}
@@ -194,6 +211,8 @@ TokenDetails.propTypes = {
194211
setIBCTransferType: PropTypes.func.isRequired,
195212
fetchGasEstimation: PropTypes.func.isRequired,
196213
showTransparentTokensTransferDialog: PropTypes.func.isRequired,
214+
shieldedRewards: PropTypes.object.isRequired,
215+
shieldedRewardsInProgress: PropTypes.bool.isRequired,
197216
shieldedBalance: PropTypes.array,
198217
shieldedBalanceInProgress: PropTypes.bool,
199218
unBondingDelegations: PropTypes.arrayOf(
@@ -222,6 +241,8 @@ const stateToProps = (state) => {
222241
unBondingDelegationsInProgress: state.accounts.unBondingDelegations.inProgress,
223242
rewards: state.accounts.rewards.result,
224243
rewardsInProgress: state.accounts.rewards.inProgress,
244+
shieldedRewards: state.accounts.shieldedRewards.result,
245+
shieldedRewardsInProgress: state.accounts.shieldedRewards.inProgress,
225246
lang: state.language,
226247
revealPublicKey: state.accounts.revealPublicKey.result,
227248
};

src/containers/NavBar/ConnectDialog/NamadaConnectButton.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
fetchBalanceList,
1616
shieldedBalanceFetchSuccess,
1717
reSyncBalance,
18+
getShieldedRewards,
1819
} from '../../../actions/accounts';
1920
import { connect } from 'react-redux';
2021
import { showMessage } from '../../../actions/snackbar';
@@ -60,6 +61,7 @@ const KeplrConnectButton = (props) => {
6061
// const address2 = `${shieldedAddress?.[1]?.address ?? ""}`;
6162
if (shieldedAddress && shieldedAddress.length && shieldedAddress[1]) {
6263
props.getShieldedBalance(shieldedAddress[1]?.viewingKey, shieldedAddress[1]?.timestamp, addressList?.address, shieldedAddress[1]?.address);
64+
// props.getShieldedRewards(shieldedAddress[1]?.viewingKey);
6365
}
6466
// props.fetchVestingBalance(addressList && addressList.address);
6567
// if (!props.proposalTab) {
@@ -99,6 +101,7 @@ KeplrConnectButton.propTypes = {
99101
getDelegatedValidatorsDetails: PropTypes.func.isRequired,
100102
getDelegations: PropTypes.func.isRequired,
101103
getShieldedBalance: PropTypes.func.isRequired,
104+
getShieldedRewards: PropTypes.func.isRequired,
102105
getUnBondingDelegations: PropTypes.func.isRequired,
103106
hideConnectDialog: PropTypes.func.isRequired,
104107
lang: PropTypes.string.isRequired,
@@ -127,6 +130,7 @@ const actionsToProps = {
127130
hideConnectDialog,
128131
getBalance,
129132
getShieldedBalance,
133+
getShieldedRewards,
130134
getUnBondingDelegations,
131135
fetchRewards,
132136
setAccountDetails,

src/containers/NavBar/Tabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Tabs extends Component {
4242
if (this.props.router.location.pathname.split('/')[2] && this.props.router.location.pathname.split('/')[2] === 'withdraw') {
4343
this.props.setExternalTransferSubTabs('namada_to_ibc_chain_transparent_transfer');
4444
}
45-
} else if (this.state.value !== route && (route === 'tokensShielded')) {
45+
} else if (this.state.value !== route && (route === 'shieldedTokens')) {
4646
this.props.setAssetsTabs('shielded');
4747
this.setState({
4848
value: 'tokens',
@@ -74,7 +74,7 @@ class Tabs extends Component {
7474
if (this.props.router.location.pathname.split('/')[2] && this.props.router.location.pathname.split('/')[2] === 'withdraw') {
7575
this.props.setExternalTransferSubTabs('namada_to_ibc_chain_transparent_transfer');
7676
}
77-
} else if (value !== this.state.value && (value === 'tokensShielded')) {
77+
} else if (value !== this.state.value && (value === 'shieldedTokens')) {
7878
this.props.setAssetsTabs('shielded');
7979
this.setState({
8080
value: 'tokens',

src/containers/NavBar/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
getBalance,
2323
getDelegations,
2424
getShieldedBalance,
25+
getShieldedRewards,
2526
getUnBondingDelegations,
2627
reSyncBalance,
2728
setAccountAddress,
@@ -369,6 +370,7 @@ class NavBar extends Component {
369370
const index = shieldedAddress.findIndex((val) => val.address === address);
370371
if (shieldedAddress[index + 1]) {
371372
this.props.getShieldedBalance(shieldedAddress[index + 1]?.viewingKey, shieldedAddress[index + 1]?.timestamp, address, shieldedAddress[index + 1]?.address);
373+
// this.props.getShieldedRewards(shieldedAddress[index + 1]?.viewingKey);
372374
}
373375
}
374376
this.props.fetchTokensList();
@@ -622,6 +624,7 @@ NavBar.propTypes = {
622624
getUnBondingDelegations: PropTypes.func.isRequired,
623625
getValidators: PropTypes.func.isRequired,
624626
getShieldedBalance: PropTypes.func.isRequired,
627+
getShieldedRewards: PropTypes.func.isRequired,
625628
fetchUnBondingValidators: PropTypes.func.isRequired,
626629
shieldedBalanceFetchSuccess: PropTypes.func.isRequired,
627630
handleClose: PropTypes.func.isRequired,
@@ -748,6 +751,7 @@ const actionToProps = {
748751
fetchTokensList,
749752
fetchBalanceList,
750753
getShieldedBalance,
754+
getShieldedRewards,
751755
fetchUnBondingValidators,
752756
shieldedBalanceFetchSuccess,
753757
fetchGasPrice,

src/containers/Stake/DelegateDialog/SuccessDialog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const SuccessDialog = (props) => {
105105
: props.router && props.router.location && (props.router.location.pathname === '/externalTransfer' ||
106106
props.router.location.pathname === '/internalTransfer' || props.router.location.pathname === '/externalTransfer/withdraw' ||
107107
props.router.location.pathname === '/externalShielding' || props.router.location.pathname === '/internalShielding' ||
108-
props.router.location.pathname === '/tokens' || props.router.location.pathname === '/tokensShielded')
108+
props.router.location.pathname === '/tokens' || props.router.location.pathname === '/shieldedTokens')
109109
? <h1>{variables[props.lang].tokens_trans_success}</h1>
110110
: props.router && props.router.params && props.router.params.proposalID
111111
? <h1>{variables[props.lang].vote_success}</h1>
@@ -127,7 +127,7 @@ const SuccessDialog = (props) => {
127127
: props.router && props.router.location && (props.router.location.pathname === '/externalTransfer' ||
128128
props.router.location.pathname === '/internalTransfer' || props.router.location.pathname === '/externalTransfer/withdraw' ||
129129
props.router.location.pathname === '/externalShielding' || props.router.location.pathname === '/internalShielding' ||
130-
props.router.location.pathname === '/tokens' || props.router.location.pathname === '/tokensShielded')
130+
props.router.location.pathname === '/tokens' || props.router.location.pathname === '/shieldedTokens')
131131
? <>
132132
<div className="row">
133133
<p>{variables[props.lang]['transaction_hash']}</p>

src/containers/Tokens/Tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const AssetTabs = (props) => {
2323
const handleChange = (newValue) => {
2424
props.onChange(newValue);
2525
if (newValue === 'shielded') {
26-
props.router.navigate('/tokensShielded');
26+
props.router.navigate('/shieldedTokens');
2727
} else {
2828
props.router.navigate('/tokens');
2929
}

src/reducers/accounts/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ import {
3434
BALANCE_LIST_FETCH_SUCCESS,
3535
BALANCE_LIST_FETCH_ERROR,
3636
SHIELDED_BALANCE_PROGRESS_SET,
37+
FETCH_SHIELDED_REWARDS_IN_PROGRESS,
38+
FETCH_SHIELDED_REWARDS_SUCCESS,
39+
FETCH_SHIELDED_REWARDS_ERROR,
3740
} from '../../constants/accounts';
3841

3942
const address = (state = {
@@ -389,6 +392,37 @@ const revealPublicKey = (state = {
389392
}
390393
};
391394

395+
const shieldedRewards = (state = {
396+
result: 0,
397+
inProgress: false,
398+
}, action) => {
399+
switch (action.type) {
400+
case FETCH_SHIELDED_REWARDS_IN_PROGRESS:
401+
return {
402+
...state,
403+
inProgress: true,
404+
};
405+
case FETCH_SHIELDED_REWARDS_SUCCESS:
406+
return {
407+
...state,
408+
inProgress: false,
409+
result: action.value,
410+
};
411+
case FETCH_SHIELDED_REWARDS_ERROR:
412+
return {
413+
...state,
414+
inProgress: false,
415+
};
416+
case DISCONNECT_SET:
417+
return {
418+
...state,
419+
result: {},
420+
};
421+
default:
422+
return state;
423+
}
424+
};
425+
392426
export default combineReducers({
393427
address,
394428
delegations,
@@ -402,4 +436,5 @@ export default combineReducers({
402436
rewards,
403437
revealPublicKey,
404438
shieldedBalance,
439+
shieldedRewards,
405440
});

0 commit comments

Comments
 (0)