Skip to content

Commit

Permalink
console: Fix reset denonces
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaplots committed Oct 30, 2023
1 parent 64af2c7 commit 6c5b94e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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,7 +14,7 @@

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

import Link from '@ttn-lw/components/link'
import ModalButton from '@ttn-lw/components/button/modal-button'
Expand Down Expand Up @@ -49,8 +49,6 @@ import {
generate16BytesKey,
} from '@console/lib/device-utils'

import { selectSelectedApplicationId } from '@console/store/selectors/applications'

import messages from '../messages'
import {
isDeviceABP,
Expand Down Expand Up @@ -235,10 +233,11 @@ const NetworkServerForm = React.memo(props => {
)

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

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

0 comments on commit 6c5b94e

Please sign in to comment.