From 744935d8db2a74274065c03a74f114ba9e0bb5cd Mon Sep 17 00:00:00 2001 From: noumantahir Date: Fri, 25 Feb 2022 00:14:36 +0500 Subject: [PATCH] support for caching quotes, action to reset wallet --- src/redux/actions/walletActions.ts | 17 +++++++++++++++-- src/redux/constants/constants.js | 2 ++ src/redux/reducers/walletReducer.ts | 19 +++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/redux/actions/walletActions.ts b/src/redux/actions/walletActions.ts index 6ca193aaf..461b210d2 100644 --- a/src/redux/actions/walletActions.ts +++ b/src/redux/actions/walletActions.ts @@ -1,5 +1,6 @@ -import { SET_SELECTED_COINS, SET_PRICE_HISTORY, SET_COINS_DATA, SET_COIN_ACTIVITIES } from '../constants/constants'; -import { CoinActivity, CoinBase, CoinData } from '../reducers/walletReducer'; +import { getLatestQuotes } from '../../providers/ecency/ecency'; +import { SET_SELECTED_COINS, SET_PRICE_HISTORY, SET_COINS_DATA, SET_COIN_ACTIVITIES, SET_COIN_QUOTES, RESET, RESET_WALLET_DATA } from '../constants/constants'; +import { CoinActivity, CoinBase, CoinData, QuoteItem } from '../reducers/walletReducer'; export const setSelectedCoins = (coins: CoinBase[]) => ({ payload: coins, @@ -28,3 +29,15 @@ export const setCoinActivities = (coinId:string, data:CoinActivity[]) => ({ type: SET_COIN_ACTIVITIES }) +export const resetWalletData = () => ({ + type: RESET_WALLET_DATA +}) + + +export const fetchCoinQuotes = () => (dispatch) => + getLatestQuotes().then((quotes) => + dispatch({ + type: SET_COIN_QUOTES, + payload: { ...quotes }, + }), + ); diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index 6bcf17f0d..935ea0d72 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -118,3 +118,5 @@ 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'; +export const SET_COIN_QUOTES = 'SET_COIN_QUOTES'; +export const RESET_WALLET_DATA = 'RESET_WALLET_DATA'; diff --git a/src/redux/reducers/walletReducer.ts b/src/redux/reducers/walletReducer.ts index b9aae36ac..32d8e2c2c 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, SET_COIN_ACTIVITIES } from "../constants/constants"; +import { SET_PRICE_HISTORY, SET_SELECTED_COINS, SET_COINS_DATA, SET_COIN_ACTIVITIES, SET_COIN_QUOTES, RESET_WALLET_DATA } from "../constants/constants"; export interface DataPair { value:string|number; @@ -22,7 +22,6 @@ export interface CoinData { vsCurrency:string; actions:string[]; extraDataPairs?:DataPair[]; - } export interface PriceHistory { @@ -59,6 +58,9 @@ interface State { coinsActivities:{ [key: string]: CoinActivity[]; }, + quotes:{ + [key: string]: QuoteItem; + } updateTimestamp:number; } @@ -67,12 +69,19 @@ const initialState:State = { coinsData:{}, priceHistories:{}, coinsActivities:{}, + quotes: {}, updateTimestamp:0 }; export default function (state = initialState, action) { const {type, payload} = action; switch (type) { + case RESET_WALLET_DATA:{ + return { + ...initialState, + selectedCoins:state.selectedCoins + } + } case SET_SELECTED_COINS:{ return { ...state, @@ -102,6 +111,12 @@ export default function (state = initialState, action) { ...state } } + case SET_COIN_QUOTES:{ + return { + ...state, + quotes:payload, + } + } default: return state; }