-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Us 1169 - Added transactions as a slice to redux (#364)
* US-1169 Initial commit * US-1169 - Finished implementation * Fixed RIFSockets.test.tsx after rebase * useOnSocketChangeEmitted.ts -> changed to switch types.ts -> fixed any * Added reset function * Added init socket event to redux * Added appStateSlice.ts Modified reset to use redux socketReset * Added events to the transactions slice. I added it so that we'll be able to store the events, and consume them if necessary, but this is not being used anywhere apart from the EventsScreen which is not being used. * Homescreen will now consume isSetup from appState from redux * Moved actions to shared/actions dir for better redability * Removed RIFSockets.tsx Modified Core.tsx to use new hook without a provider * Cleaning up tpyes.ts useRifSockets.ts will receive wallet and mnemonic as props * Removed unused files Modified useOnSocketChangeEmitted.ts to inline dispatch actions * RifWalletServicesSocket.ts - should not return null. Should at least return the originTransaction * Reorganized useOnSocketChangeEmitted.ts Fixed types and eslint and typescript errors * Fixed SendScreen.tsx * Fixed Core.tsx non null assertion * Fixed eslint issues with the new redux implementation
- Loading branch information
1 parent
0350054
commit e383570
Showing
32 changed files
with
385 additions
and
506 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
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,3 @@ | ||
import { createAction } from '@reduxjs/toolkit' | ||
|
||
export const resetSocketState = createAction('RESET_SOCKET_STATE') |
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,24 @@ | ||
import { AppState } from 'store/slices/appStateSlice/types' | ||
import { createSlice } from '@reduxjs/toolkit' | ||
import { resetSocketState } from 'store/shared/actions/resetSocketState' | ||
|
||
const initialState: AppState = { | ||
isSetup: false, | ||
} | ||
|
||
const appStateSlice = createSlice({ | ||
name: 'appState', | ||
initialState, | ||
reducers: { | ||
setIsSetup: (state, { payload }: { payload: boolean }) => { | ||
state.isSetup = payload | ||
return state | ||
}, | ||
}, | ||
extraReducers: builder => { | ||
builder.addCase(resetSocketState, () => initialState) | ||
}, | ||
}) | ||
|
||
export const { setIsSetup } = appStateSlice.actions | ||
export const appStateReducer = appStateSlice.reducer |
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,3 @@ | ||
import { RootState } from 'src/redux' | ||
|
||
export const selectAppState = (state: RootState) => state.appState |
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,3 @@ | ||
export type AppState = { | ||
isSetup: boolean | ||
} |
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
Empty file.
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,3 @@ | ||
import { RootState } from 'src/redux' | ||
|
||
export const selectTransactions = (state: RootState) => state.transactions |
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,61 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
import { ITransactionsState } from 'store/slices/transactionsSlice/types' | ||
import { | ||
filterEnhancedTransactions, | ||
sortEnhancedTransactions, | ||
} from 'src/subscriptions/utils' | ||
import { | ||
IActivityTransaction, | ||
IEvent, | ||
TransactionsServerResponseWithActivityTransactions, | ||
} from 'src/subscriptions/types' | ||
import { resetSocketState } from 'store/shared/actions/resetSocketState' | ||
|
||
const initialState: ITransactionsState = { | ||
next: '', | ||
prev: '', | ||
transactions: [], | ||
events: [], | ||
} | ||
|
||
const deserializeTransactions = (transactions: IActivityTransaction[]) => | ||
transactions.sort(sortEnhancedTransactions).filter(filterEnhancedTransactions) | ||
|
||
const transactionsSlice = createSlice({ | ||
name: 'transactions', | ||
initialState, | ||
reducers: { | ||
addNewTransactions: ( | ||
state, | ||
{ | ||
payload, | ||
}: PayloadAction<TransactionsServerResponseWithActivityTransactions>, | ||
) => { | ||
state.transactions = deserializeTransactions( | ||
state.transactions.concat(payload.activityTransactions || []), | ||
) | ||
state.next = payload.next || null | ||
state.prev = payload.prev || null | ||
return state | ||
}, | ||
addNewTransaction: ( | ||
state, | ||
{ payload }: PayloadAction<IActivityTransaction>, | ||
) => { | ||
state.transactions.push(payload) | ||
state.transactions = deserializeTransactions(state.transactions || []) | ||
return state | ||
}, | ||
addNewEvent: (state, { payload }: PayloadAction<IEvent>) => { | ||
state.events.push(payload) | ||
return state | ||
}, | ||
}, | ||
extraReducers: builder => { | ||
builder.addCase(resetSocketState, () => initialState) | ||
}, | ||
}) | ||
|
||
export const { addNewTransactions, addNewTransaction, addNewEvent } = | ||
transactionsSlice.actions | ||
export const transactionsReducer = transactionsSlice.reducer |
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,8 @@ | ||
import { IActivityTransaction, IEvent } from 'src/subscriptions/types' | ||
|
||
export interface ITransactionsState { | ||
prev: string | null | ||
next: string | null | ||
transactions: IActivityTransaction[] | ||
events: IEvent[] | ||
} |
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
Oops, something went wrong.