mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-21 12:21:31 +03:00
support for caching quotes, action to reset wallet
This commit is contained in:
parent
82f2cd90ed
commit
744935d8db
@ -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 },
|
||||
}),
|
||||
);
|
||||
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user