diff --git a/src/redux/actions/walletActions.ts b/src/redux/actions/walletActions.ts index 326cd4172..6ca193aaf 100644 --- a/src/redux/actions/walletActions.ts +++ b/src/redux/actions/walletActions.ts @@ -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 +}) + diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index 7c6b7a1e5..af67678cc 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -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'; diff --git a/src/redux/reducers/walletReducer.ts b/src/redux/reducers/walletReducer.ts index 76471bdfd..6ca7b6d22 100644 --- a/src/redux/reducers/walletReducer.ts +++ b/src/redux/reducers/walletReducer.ts @@ -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; } diff --git a/src/screens/coinDetails/screen/coinDetailsScreen.tsx b/src/screens/coinDetails/screen/coinDetailsScreen.tsx index 9b52cc4ea..ff0b8b844 100644 --- a/src/screens/coinDetails/screen/coinDetailsScreen.tsx +++ b/src/screens/coinDetails/screen/coinDetailsScreen.tsx @@ -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) => { )