forked from ripple/explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: handling of token page throttling (ripple#1100)"
This reverts commit 8d503da.
- Loading branch information
Showing
11 changed files
with
371 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const START_LOADING_ACCOUNT_STATE = 'START_LOADING_ACCOUNT_STATE' | ||
export const FINISHED_LOADING_ACCOUNT_STATE = 'FINISHED_LOADING_ACCOUNT_STATE' | ||
export const ACCOUNT_STATE_LOAD_SUCCESS = 'ACCOUNT_STATE_LOAD_SUCCESS' | ||
export const ACCOUNT_STATE_LOAD_FAIL = 'ACCOUNT_STATE_LOAD_FAIL' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { isValidClassicAddress, isValidXAddress } from 'ripple-address-codec' | ||
import { getToken } from '../../../rippled' | ||
import { analytics } from '../../shared/analytics' | ||
import { BAD_REQUEST } from '../../shared/utils' | ||
import * as actionTypes from './actionTypes' | ||
|
||
export const loadTokenState = | ||
(currency, accountId, rippledSocket) => (dispatch) => { | ||
if (!isValidClassicAddress(accountId) && !isValidXAddress(accountId)) { | ||
dispatch({ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
status: BAD_REQUEST, | ||
error: '', | ||
}) | ||
return Promise.resolve() | ||
} | ||
|
||
dispatch({ | ||
type: actionTypes.START_LOADING_ACCOUNT_STATE, | ||
}) | ||
return getToken(currency, accountId, rippledSocket) | ||
.then((data) => { | ||
dispatch({ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE }) | ||
dispatch({ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_SUCCESS, | ||
data, | ||
}) | ||
}) | ||
.catch((error) => { | ||
const status = error.code | ||
analytics.trackException( | ||
`token ${currency}.${accountId} --- ${JSON.stringify(error)}`, | ||
) | ||
dispatch({ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE }) | ||
dispatch({ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
error: status === 500 ? 'get_account_state_failed' : '', | ||
status, | ||
}) | ||
}) | ||
} | ||
|
||
export default loadTokenState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as actionTypes from './actionTypes' | ||
|
||
export const initialState = { | ||
loading: false, | ||
data: {}, | ||
error: '', | ||
status: null, | ||
} | ||
|
||
// eslint-disable-next-line default-param-last | ||
const tokenReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case actionTypes.START_LOADING_ACCOUNT_STATE: | ||
return { ...state, loading: true } | ||
case actionTypes.FINISHED_LOADING_ACCOUNT_STATE: | ||
return { ...state, loading: false } | ||
case actionTypes.ACCOUNT_STATE_LOAD_SUCCESS: | ||
return { ...state, error: '', data: action.data } | ||
case actionTypes.ACCOUNT_STATE_LOAD_FAIL: | ||
return { | ||
...state, | ||
error: action.error, | ||
status: action.status, | ||
data: state.data.length ? state.data : {}, | ||
} | ||
case 'persist/REHYDRATE': | ||
return { ...initialState } | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default tokenReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import configureMockStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
import * as actions from '../actions' | ||
import * as actionTypes from '../actionTypes' | ||
import { initialState } from '../reducer' | ||
import { NOT_FOUND, BAD_REQUEST, SERVER_ERROR } from '../../../shared/utils' | ||
import rippledResponses from './rippledResponses.json' | ||
import actNotFound from './actNotFound.json' | ||
import MockWsClient from '../../../test/mockWsClient' | ||
|
||
const TEST_ADDRESS = 'rDsbeomae4FXwgQTJp9Rs64Qg9vDiTCdBv' | ||
const TEST_CURRENCY = 'abc' | ||
|
||
describe('TokenHeader Actions', () => { | ||
jest.setTimeout(10000) | ||
|
||
const middlewares = [thunk] | ||
const mockStore = configureMockStore(middlewares) | ||
let client | ||
beforeEach(() => { | ||
client = new MockWsClient() | ||
}) | ||
|
||
afterEach(() => { | ||
client.close() | ||
}) | ||
|
||
it('should dispatch correct actions on successful loadTokenState', () => { | ||
client.addResponses(rippledResponses) | ||
const expectedData = { | ||
name: undefined, | ||
obligations: '100', | ||
sequence: 2148991, | ||
reserve: 10, | ||
rate: undefined, | ||
domain: undefined, | ||
emailHash: undefined, | ||
flags: [], | ||
balance: '123456000', | ||
previousTxn: | ||
'6B6F2CA1633A22247058E988372BA9EFFFC5BF10212230B67341CA32DC9D4A82', | ||
previousLedger: 68990183, | ||
} | ||
const expectedActions = [ | ||
{ type: actionTypes.START_LOADING_ACCOUNT_STATE }, | ||
{ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE }, | ||
{ type: actionTypes.ACCOUNT_STATE_LOAD_SUCCESS, data: expectedData }, | ||
] | ||
const store = mockStore({ news: initialState }) | ||
return store | ||
.dispatch(actions.loadTokenState(TEST_CURRENCY, TEST_ADDRESS, client)) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions) | ||
}) | ||
}) | ||
|
||
it('should dispatch correct actions on server error', () => { | ||
client.setReturnError() | ||
const expectedActions = [ | ||
{ type: actionTypes.START_LOADING_ACCOUNT_STATE }, | ||
{ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE }, | ||
{ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
status: SERVER_ERROR, | ||
error: 'get_account_state_failed', | ||
}, | ||
] | ||
const store = mockStore({ news: initialState }) | ||
return store | ||
.dispatch(actions.loadTokenState(TEST_CURRENCY, TEST_ADDRESS, client)) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions) | ||
}) | ||
}) | ||
|
||
it('should dispatch correct actions on ripple address not found', () => { | ||
client.addResponse('account_info', { result: actNotFound }) | ||
const expectedActions = [ | ||
{ type: actionTypes.START_LOADING_ACCOUNT_STATE }, | ||
{ type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE }, | ||
{ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
status: NOT_FOUND, | ||
error: '', | ||
}, | ||
] | ||
const store = mockStore({ news: initialState }) | ||
return store | ||
.dispatch(actions.loadTokenState(TEST_CURRENCY, TEST_ADDRESS, client)) | ||
.then(() => { | ||
expect(store.getActions()).toEqual(expectedActions) | ||
}) | ||
}) | ||
|
||
it('should dispatch correct actions on invalid ripple address', () => { | ||
const expectedActions = [ | ||
{ | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
status: BAD_REQUEST, | ||
error: '', | ||
}, | ||
] | ||
const store = mockStore({ news: initialState }) | ||
store.dispatch(actions.loadTokenState('ZZZ', null, client)).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as actionTypes from '../actionTypes' | ||
import reducer, { initialState } from '../reducer' | ||
|
||
describe('AccountHeader reducers', () => { | ||
it('should return the initial state', () => { | ||
expect(reducer(undefined, {})).toEqual(initialState) | ||
}) | ||
|
||
it('should handle START_LOADING_ACCOUNT_STATE', () => { | ||
const nextState = { ...initialState, loading: true } | ||
expect( | ||
reducer(initialState, { type: actionTypes.START_LOADING_ACCOUNT_STATE }), | ||
).toEqual(nextState) | ||
}) | ||
|
||
it('should handle FINISHED_LOADING_ACCOUNT_STATE', () => { | ||
const nextState = { ...initialState, loading: false } | ||
expect( | ||
reducer(initialState, { | ||
type: actionTypes.FINISHED_LOADING_ACCOUNT_STATE, | ||
}), | ||
).toEqual(nextState) | ||
}) | ||
|
||
it('should handle ACCOUNT_STATE_LOAD_SUCCESS', () => { | ||
const data = [['XRP', 123.456]] | ||
const nextState = { ...initialState, data } | ||
expect( | ||
reducer(initialState, { | ||
data, | ||
type: actionTypes.ACCOUNT_STATE_LOAD_SUCCESS, | ||
}), | ||
).toEqual(nextState) | ||
}) | ||
|
||
it('should handle ACCOUNT_STATE_LOAD_FAIL', () => { | ||
const status = 500 | ||
const error = 'error' | ||
const nextState = { ...initialState, status, error } | ||
expect( | ||
reducer(initialState, { | ||
status, | ||
error, | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
}), | ||
).toEqual(nextState) | ||
}) | ||
|
||
it('will not clear previous data on ACCOUNT_STATE_LOAD_FAIL', () => { | ||
const data = [['XRP', 123.456]] | ||
const error = 'error' | ||
const status = 500 | ||
const stateWithData = { ...initialState, data } | ||
const nextState = { ...stateWithData, error, status } | ||
expect( | ||
reducer(stateWithData, { | ||
status, | ||
error, | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
}), | ||
).toEqual(nextState) | ||
}) | ||
|
||
it('should clear data on rehydration', () => { | ||
const error = 'error' | ||
const status = 500 | ||
const nextState = { ...initialState, error, status } | ||
expect( | ||
reducer(initialState, { | ||
type: actionTypes.ACCOUNT_STATE_LOAD_FAIL, | ||
error, | ||
status, | ||
}), | ||
).toEqual(nextState) | ||
expect(reducer(nextState, { type: 'persist/REHYDRATE' })).toEqual( | ||
initialState, | ||
) | ||
}) | ||
}) |
Oops, something went wrong.