Skip to content

Commit 4338f7f

Browse files
- shielded balance fetch (#229)
- shieldedTokens route update - sub assets balance validation fixes - sub assets display fixes in shielded tokens.
1 parent 38e3449 commit 4338f7f

File tree

15 files changed

+180
-19
lines changed

15 files changed

+180
-19
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: 45 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,44 @@ export const reSyncBalance = (viewingKey, timestamp, tnam, znam, chainId = confi
661665
}
662666
}
663667
};
668+
669+
670+
const shieldedRewardsFetchInProgress = () => ({
671+
type: FETCH_SHIELDED_REWARDS_IN_PROGRESS,
672+
});
673+
674+
const shieldedRewardsFetchSuccess = (value) => ({
675+
type: FETCH_SHIELDED_REWARDS_SUCCESS,
676+
value,
677+
});
678+
679+
const shieldedRewardsFetchError = (error) => ({
680+
type: FETCH_SHIELDED_REWARDS_ERROR,
681+
message: error || 'Failed to fetch shielded Rewards',
682+
});
683+
684+
685+
export const getShieldedRewards = (viewingKey, chainId = config.CHAIN_ID, cb) => async (dispatch) => {
686+
dispatch(shieldedRewardsFetchInProgress());
687+
try {
688+
const rewards = await fetchShieldedRewards(
689+
viewingKey,
690+
chainId,
691+
config.RPC_URL,
692+
);
693+
dispatch(shieldedRewardsFetchSuccess(rewards));
694+
if (cb) {
695+
cb(rewards);
696+
}
697+
} catch (error) {
698+
console.error('❌ Shielded rewards error:', {
699+
message: error.message || 'Unknown error',
700+
error,
701+
chainId,
702+
});
703+
dispatch(shieldedRewardsFetchError(error.message || 'Unknown error'));
704+
if (cb) {
705+
cb(null);
706+
}
707+
}
708+
};

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">
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/IBCTransfer/AmountTextField.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const AmountTextField = (props) => {
1111
amount = props.fromNamadaSelectedAsset?.balance?.minDenomAmount && Number(props.fromNamadaSelectedAsset?.balance?.minDenomAmount) / 10 ** fromNamadaSelectedConfig.COIN_DECIMALS;
1212
} else if(props.from === 'namada_deposit') {
1313
props.ibcBalance && props.ibcBalance.length && props.ibcBalance.map((val) => {
14-
if (val) {
14+
if (val && val.denom === props.selectedChain?.config?.COIN_MINIMAL_DENOM) {
1515
amount = val && val.amount;
1616
}
1717

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/ShieldedTokensListTable.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,16 @@ class ShieldedTokensListTable extends React.Component {
123123
this.props.fetchIBCBalance(config.REST_URL, address[0].address);
124124
this.props.fetchIBCChannel(value.channel_link);
125125
const find = ibcList.find((item) => item.value === value.coingecko_id);
126-
this.props.setSelectedChain(find);
126+
if (find?.assets && find.assets.length > 1) {
127+
const index = find?.assets?.findIndex((val) => val.base === value.base);
128+
if (index > -1 && find.assets && find.assets.length > 1) {
129+
const [item] = find.assets.splice(index, 1); // remove item at index i
130+
find.assets.unshift(item);
131+
find.config.COIN_DENOM = item.symbol;
132+
find.config.COIN_MINIMAL_DENOM = item.base;
133+
}
134+
}
135+
this.props.setSelectedChain({...find});
127136
});
128137
}
129138

0 commit comments

Comments
 (0)