-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): add trading slice to mobile
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './navigation/TradingStackNavigator'; | ||
export * from './tradingSlice'; |
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,60 @@ | ||
import { PayloadAction } from '@reduxjs/toolkit'; | ||
|
||
import { createSliceWithExtraDeps, createWeakMapSelector } from '@suite-common/redux-utils'; | ||
import { | ||
TradingBuyState as CommonTradingBuyState, | ||
TradingState as CommonTradingState, | ||
initialState as commonInitialState, | ||
prepareTradingReducer, | ||
} from '@suite-common/trading'; | ||
|
||
import { ReceiveAccount } from './types'; | ||
|
||
export interface TradingBuyState extends CommonTradingBuyState { | ||
selectedReceiveAccount: ReceiveAccount | undefined; | ||
} | ||
|
||
interface TradingState extends CommonTradingState { | ||
buy: TradingBuyState; | ||
} | ||
|
||
export type TradeRootState = { | ||
wallet: { | ||
trading: TradingState; | ||
}; | ||
}; | ||
|
||
export const initialState: TradingState = { | ||
...commonInitialState, | ||
buy: { ...commonInitialState.buy, selectedReceiveAccount: undefined }, | ||
}; | ||
|
||
export const tradingSlice = createSliceWithExtraDeps({ | ||
name: 'trading', | ||
initialState, | ||
reducers: { | ||
setBuySelectedReceiveAccount: ( | ||
state, | ||
{ payload }: PayloadAction<{ selectedReceiveAccount: ReceiveAccount }>, | ||
) => { | ||
state.buy.selectedReceiveAccount = payload.selectedReceiveAccount; | ||
}, | ||
}, | ||
extraReducers: (builder, extra) => { | ||
const commonTradingFormReducer = prepareTradingReducer(extra); | ||
builder | ||
// In case that this reducer does not match the action, try to handle it by suite-common tradingReducer. | ||
.addDefaultCase((state, action) => { | ||
commonTradingFormReducer(state, action); | ||
}); | ||
}, | ||
}); | ||
|
||
export const { setBuySelectedReceiveAccount } = tradingSlice.actions; | ||
|
||
export const createMemoizedSelector = createWeakMapSelector.withTypes<TradeRootState>(); | ||
|
||
export const selectTradingBuy = (state: TradeRootState) => state.wallet.trading.buy; | ||
|
||
export const selectBuySelectedReceiveAccount = (state: TradeRootState) => | ||
selectTradingBuy(state).selectedReceiveAccount; |
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