Skip to content

Commit

Permalink
feat: useCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Oct 11, 2023
1 parent 2314f1e commit b68309d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/context/WalletProvider/Ledger/components/Connect.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebUSBLedgerAdapter } from '@shapeshiftoss/hdwallet-ledger-webusb'
import React, { useState } from 'react'
import React, { useCallback, useState } from 'react'
import type { RouteComponentProps } from 'react-router-dom'
import type { ActionTypes } from 'context/WalletProvider/actions'
import { WalletActions } from 'context/WalletProvider/actions'
Expand All @@ -23,10 +23,12 @@ export const LedgerConnect = ({ history }: LedgerSetupProps) => {
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)

// eslint-disable-next-line no-sequences
const setErrorLoading = (e: string | null) => (setError(e), setLoading(false))
const setErrorLoading = useCallback((e: string | null) => {
setError(e)
setLoading(false)
}, [])

const pairDevice = async () => {
const pairDevice = useCallback(async () => {
setError(null)
setLoading(true)
if (state.adapters) {
Expand Down Expand Up @@ -68,7 +70,7 @@ export const LedgerConnect = ({ history }: LedgerSetupProps) => {
}
}
setLoading(false)
}
}, [history, setErrorLoading, state.adapters, state.keyring, walletDispatch])

return (
<ConnectModal
Expand All @@ -78,6 +80,6 @@ export const LedgerConnect = ({ history }: LedgerSetupProps) => {
onPairDeviceClick={pairDevice}
loading={loading}
error={error}
></ConnectModal>
/>
)
}

0 comments on commit b68309d

Please sign in to comment.