storing filtered activities list in redux

This commit is contained in:
Nouman Tahir 2022-02-21 17:06:49 +05:00
parent ac5c336216
commit d303cdd56d
4 changed files with 21 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import { SET_SELECTED_COINS, SET_PRICE_HISTORY, SET_COINS_DATA } from '../constants/constants';
import { CoinBase, CoinData } from '../reducers/walletReducer';
import { SET_SELECTED_COINS, SET_PRICE_HISTORY, SET_COINS_DATA, SET_COIN_ACTIVITIES } from '../constants/constants';
import { CoinActivity, CoinBase, CoinData } from '../reducers/walletReducer';
export const setSelectedCoins = (coins: CoinBase[]) => ({
payload: coins,
@ -20,3 +20,11 @@ export const setPriceHistory = (coinId:string, vsCurrency:string, data:number[])
type: SET_PRICE_HISTORY
})
export const setCoinActivities = (coinId:string, data:CoinActivity[]) => ({
payload: {
id:coinId,
data,
},
type: SET_COIN_ACTIVITIES
})

View File

@ -115,3 +115,4 @@ export const REGISTER_TOOLTIP = 'REGISTER_TOOLTIP';
export const SET_SELECTED_COINS = 'SET_SELECTED_COINS';
export const SET_COINS_DATA = 'SET_COIN_DATA';
export const SET_PRICE_HISTORY = 'SET_PRICE_HISTORY';
export const SET_COIN_ACTIVITIES = 'SET_COIN_ACTIVITIES';

View File

@ -1,5 +1,5 @@
import DEFAULT_COINS from "../../constants/defaultCoins";
import { SET_PRICE_HISTORY, SET_SELECTED_COINS, SET_COINS_DATA } from "../constants/constants";
import { SET_PRICE_HISTORY, SET_SELECTED_COINS, SET_COINS_DATA, SET_COIN_ACTIVITIES } from "../constants/constants";
export interface DataPair {
value:string|number;
@ -87,6 +87,12 @@ export default function (state = initialState, action) {
...state
}
}
case SET_COIN_ACTIVITIES:{
state.coinsActivities[payload.id] = payload.data
return {
...state
}
}
default:
return state;
}

View File

@ -8,6 +8,7 @@ import { withNavigation } from 'react-navigation'
import { useAppDispatch, useAppSelector } from '../../../hooks'
import { CoinActivity, CoinData } from '../../../redux/reducers/walletReducer';
import { fetchCoinActivities } from '../../../utils/wallet';
import { setCoinActivities } from '../../../redux/actions/walletActions';
export interface CoinDetailsScreenParams {
coinId:string;
@ -34,8 +35,6 @@ const CoinDetailsScreen = ({navigation}:CoinDetailsScreenProps) => {
const {symbol, id } = selectedCoins.find((item)=>item.id===coinId)
const [activities, setActivities] = useState([])
useEffect(()=>{
_fetchCoinActivities();
@ -43,9 +42,7 @@ const CoinDetailsScreen = ({navigation}:CoinDetailsScreenProps) => {
const _fetchCoinActivities = async () => {
const _activites = await fetchCoinActivities(currentAccount.name, symbol, globalProps);
setActivities(_activites)
// dispatch();
dispatch(setCoinActivities(coinId, _activites));
}
@ -75,8 +72,7 @@ const CoinDetailsScreen = ({navigation}:CoinDetailsScreenProps) => {
<BasicHeader title="Coin Details" />
<ActivitiesList
header={_renderHeaderComponent}
activities={activities || []}
activities={coinActivities || []}
/>
</View>
)