Skip to content

Commit

Permalink
Merge pull request #6660 from TheThingsNetwork/fix/reset-mac-state
Browse files Browse the repository at this point in the history
Fix reset session and mac state
  • Loading branch information
kschiffer authored Oct 31, 2023
2 parents 29e889b + 6c5b94e commit b4aa590
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import React from 'react'
import { useDispatch } from 'react-redux'

import SubmitButton from '@ttn-lw/components/submit-button'
import SubmitBar from '@ttn-lw/components/submit-bar'
Expand All @@ -29,6 +30,7 @@ import tooltipIds from '@ttn-lw/lib/constants/tooltip-ids'
import diff from '@ttn-lw/lib/diff'
import PropTypes from '@ttn-lw/lib/prop-types'
import sharedMessages from '@ttn-lw/lib/shared-messages'
import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'

import { parseLorawanMacVersion, generate16BytesKey } from '@console/lib/device-utils'

Expand Down Expand Up @@ -79,9 +81,12 @@ const JoinServerForm = React.memo(props => {
[device, validationContext],
)

const dispatch = useDispatch()
const appId = device.ids.application_ids.application_id
const devId = device.ids.device_id
const handleUsedDevNoncesReset = React.useCallback(async () => {
try {
await onUsedDevNoncesReset()
await dispatch(attachPromise(onUsedDevNoncesReset(appId, devId)))
toast({
message: messages.resetSuccess,
type: toast.types.SUCCESS,
Expand All @@ -92,7 +97,7 @@ const JoinServerForm = React.memo(props => {
type: toast.types.ERROR,
})
}
}, [onUsedDevNoncesReset])
}, [onUsedDevNoncesReset, appId, devId, dispatch])

// Setup and memoize callbacks for changes to `resets_join_nonces` for displaying the field warning.
const handleResetsJoinNoncesChange = React.useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import React from 'react'
import { defineMessages } from 'react-intl'
import { useDispatch } from 'react-redux'

import Link from '@ttn-lw/components/link'
import ModalButton from '@ttn-lw/components/button/modal-button'
Expand All @@ -40,6 +41,7 @@ import { isBackend, getBackendErrorName } from '@ttn-lw/lib/errors/utils'
import diff from '@ttn-lw/lib/diff'
import sharedMessages from '@ttn-lw/lib/shared-messages'
import PropTypes from '@ttn-lw/lib/prop-types'
import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'

import {
parseLorawanMacVersion,
Expand Down Expand Up @@ -229,9 +231,13 @@ const NetworkServerForm = React.memo(props => {
),
[device, initialActivationMode, isClassB, isClassC, macSettings, validationContext],
)

const dispatch = useDispatch()
const appId = device.ids.application_ids.application_id
const devId = device.ids.device_id
const handleMacReset = React.useCallback(async () => {
try {
await onMacReset()
await dispatch(attachPromise(onMacReset(appId, devId)))
toast({
message: m.resetSuccess,
type: toast.types.SUCCESS,
Expand All @@ -242,7 +248,7 @@ const NetworkServerForm = React.memo(props => {
type: toast.types.ERROR,
})
}
}, [onMacReset])
}, [onMacReset, dispatch, devId, appId])

const handleSubmit = React.useCallback(
async (values, { resetForm, setSubmitting }) => {
Expand Down

0 comments on commit b4aa590

Please sign in to comment.