Browse Source

cache coin data into store array

all-modes
pbca26 8 years ago
parent
commit
d8c3257c62
  1. 9
      react/src/actions/actionCreators.js
  2. 79
      react/src/reducers/activeCoin.js

9
react/src/actions/actionCreators.js

@ -51,9 +51,16 @@ export const SYNC_ONLY_MODAL_TOGGLE = 'SYNC_ONLY_MODAL_TOGGLE';
export const SYNC_ONLY_DATA = 'SYNC_ONLY_DATA';
export const LOAD_APP_CONFIG = 'LOAD_APP_CONFIG';
export const SAVE_APP_CONFIG = 'SAVE_APP_CONFIG';
export const SERVICE_ERROR = 'SERVICE_ERROR';
var iguanaForks = {}; // forks in mem array
function updateErrosStack(method) {
return {
apiMethod: method,
}
}
export function toggleSyncOnlyModal(display) {
return {
type: SYNC_ONLY_MODAL_TOGGLE,
@ -607,6 +614,7 @@ export function iguanaActiveHandle(getMainAddress) {
})
.catch(function(error) {
console.log(error);
dispatch(updateErrosStack('activeHandle'));
dispatch(triggerToaster(true, translate('TOASTR.IGUANA_ARE_YOU_SURE'), translate('TOASTR.SERVICE_NOTIFICATION'), 'error'));
})
.then(response => response.json())
@ -923,6 +931,7 @@ export function getAddressesByAccount(coin, mode) {
})
.catch(function(error) {
console.log(error);
dispatch(updateErrosStack('activeHandle'));
dispatch(triggerToaster(true, 'getAddressesByAccount', 'Error', 'error'));
})
.then(response => response.json())

79
react/src/reducers/activeCoin.js

@ -17,9 +17,10 @@ import {
DASHBOARD_DISPLAY_NOTARIES_MODAL
} from '../actions/actionCreators';
// TODO: keep all coin data in array of objects instead of single object
// TODO: refactor
export function ActiveCoin(state = {
coins: {},
coin: null,
mode: null,
send: false,
@ -38,17 +39,71 @@ export function ActiveCoin(state = {
}, action) {
switch (action.type) {
case DASHBOARD_ACTIVE_COIN_CHANGE:
return Object.assign({}, state, {
coin: action.coin,
mode: action.mode,
balance: 0,
txhistory: [],
send: false,
receive: false,
showTransactionInfo: false,
showTransactionInfoTxIndex: null,
nativeActiveSection: 'default',
});
if (state.coins[action.coin]) {
const _coinData = state.coins[action.coin];
return Object.assign({}, state, {
coins: state.coins,
addresses: _coinData.addresses,
coin: _coinData.coin,
mode: _coinData.mode,
balance: _coinData.balance,
txhistory: _coinData.txhistory,
send: _coinData.send,
receive: _coinData.receive,
showTransactionInfo: _coinData.showTransactionInfo,
showTransactionInfoTxIndex: _coinData.showTransactionInfoTxIndex,
nativeActiveSection: _coinData.nativeActiveSection,
lastSendToResponse: _coinData.lastSendToResponse,
mainBasiliskAddress: _coinData.mainBasiliskAddress,
opids: _coinData.opids,
});
} else {
if (state.coin) {
const _coinData = {
addresses: state.addresses,
coin: state.coin,
mode: state.mode,
balance: state.balance,
txhistory: state.txhistory,
send: state.send,
receive: state.receive,
showTransactionInfo: state.showTransactionInfo,
showTransactionInfoTxIndex: state.showTransactionInfoTxIndex,
nativeActiveSection: state.nativeActiveSection,
lastSendToResponse: state.lastSendToResponse,
mainBasiliskAddress: state.mainBasiliskAddress,
opids: state.opids,
};
let _coins = state.coins;
_coins[state.coin] = _coinData;
return Object.assign({}, state, {
coins: _coins,
coin: action.coin,
mode: action.mode,
balance: 0,
txhistory: 'loading',
send: false,
receive: false,
showTransactionInfo: false,
showTransactionInfoTxIndex: null,
nativeActiveSection: 'default',
});
} else {
return Object.assign({}, state, {
coin: action.coin,
mode: action.mode,
balance: 0,
txhistory: 'loading',
send: false,
receive: false,
showTransactionInfo: false,
showTransactionInfoTxIndex: null,
nativeActiveSection: 'default',
});
}
}
case DASHBOARD_ACTIVE_COIN_BALANCE:
return Object.assign({}, state, {
balance: action.balance,

Loading…
Cancel
Save