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 { SET_SELECTED_COINS, SET_PRICE_HISTORY, SET_COINS_DATA, SET_COIN_ACTIVITIES } from '../constants/constants';
import { CoinBase, CoinData } from '../reducers/walletReducer'; import { CoinActivity, CoinBase, CoinData } from '../reducers/walletReducer';
export const setSelectedCoins = (coins: CoinBase[]) => ({ export const setSelectedCoins = (coins: CoinBase[]) => ({
payload: coins, payload: coins,
@ -20,3 +20,11 @@ export const setPriceHistory = (coinId:string, vsCurrency:string, data:number[])
type: SET_PRICE_HISTORY 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_SELECTED_COINS = 'SET_SELECTED_COINS';
export const SET_COINS_DATA = 'SET_COIN_DATA'; export const SET_COINS_DATA = 'SET_COIN_DATA';
export const SET_PRICE_HISTORY = 'SET_PRICE_HISTORY'; 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 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 { export interface DataPair {
value:string|number; value:string|number;
@ -87,6 +87,12 @@ export default function (state = initialState, action) {
...state ...state
} }
} }
case SET_COIN_ACTIVITIES:{
state.coinsActivities[payload.id] = payload.data
return {
...state
}
}
default: default:
return state; return state;
} }

View File

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