diff --git a/src/pages/PairDevice/ConnectViaIP/AddressAndPortInputs.tsx b/src/pages/PairDevice/ConnectViaIP/AddressAndPortInputs.tsx index 6f317eeb..f849a373 100644 --- a/src/pages/PairDevice/ConnectViaIP/AddressAndPortInputs.tsx +++ b/src/pages/PairDevice/ConnectViaIP/AddressAndPortInputs.tsx @@ -38,21 +38,11 @@ const AddressAndPortInputs = ({ return } - if (portType === 'Beacon') { - dispatch({ type: 'pairDevice/setBeaconPort', payload: value }) - } else { - dispatch({ type: 'pairDevice/setVcPort', payload: value }) - } + dispatch({ type: 'pairDevice/setPort', payload: { value, portType } }) } const onAddressChange = (value: string) => { - if (addressType === 'Beacon') { - dispatch({ type: 'pairDevice/setBeaconAddress', payload: value }) - } else if (addressType === 'Validator Client') { - dispatch({ type: 'pairDevice/setVcAddress', payload: value }) - } else { - dispatch({ type: 'pairDevice/setNodeAddress', payload: value }) - } + dispatch({ type: 'pairDevice/setAddress', payload: { value, addressType } }) } return ( diff --git a/src/redux/PairDevice/slice.ts b/src/redux/PairDevice/slice.ts index 967dd1f7..fbee2281 100644 --- a/src/redux/PairDevice/slice.ts +++ b/src/redux/PairDevice/slice.ts @@ -1,4 +1,4 @@ -import { createSlice, PayloadAction } from '@reduxjs/toolkit' +import { createSlice } from '@reduxjs/toolkit' type PairDeviceStateType = { beaconPort: string @@ -20,20 +20,21 @@ const pairDeviceSlice = createSlice({ name: 'pairDevice', initialState, reducers: { - setBeaconPort: (state, action: PayloadAction) => { - state.beaconPort = action.payload + setPort: (state, action) => { + if (action.payload.portType === 'Beacon') { + state.beaconPort = action.payload.value + } else { + state.vcPort = action.payload.value + } }, - setVcPort: (state, action: PayloadAction) => { - state.vcPort = action.payload - }, - setBeaconAddress: (state, action: PayloadAction) => { - state.beaconAddress = action.payload - }, - setVcAddress: (state, action: PayloadAction) => { - state.vcAddress = action.payload - }, - setNodeAddress: (state, action: PayloadAction) => { - state.nodeAddress = action.payload + setAddress: (state, action) => { + if (action.payload.addressType === 'Beacon') { + state.beaconAddress = action.payload.value + } else if (action.payload.addressType === 'Validator Client') { + state.vcAddress = action.payload.value + } else { + state.nodeAddress = action.payload.value + } }, }, })