Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed Jan 12, 2025
1 parent 8dc2d52 commit a7ea8e3
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ export const ImportAccounts = ({ chainId, onClose }: ImportAccountsProps) => {
return
}

if (!walletDeviceId) {
console.error('Missing walletDeviceId')
return
}

setIsSubmitting(true)

// For every new account that is active, fetch the account and upsert it into the redux state
Expand Down
2 changes: 1 addition & 1 deletion src/components/MultiHopTrade/hooks/useReceiveAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useReceiveAddress = ({
? skipToken
: async () => {
// Already partially covered in isInitializing, but TypeScript lyfe mang.
if (!buyAsset || !wallet || !buyAccountId || !buyAccountMetadata) {
if (!buyAsset || !wallet || !buyAccountId || !buyAccountMetadata || !deviceId) {
return undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const KeepKeyPassphrase = () => {
state: { deviceId, keyring },
dispatch,
} = useWallet()
const wallet = keyring.get(deviceId)
const wallet = keyring.get(deviceId ?? '')
const walletId = useAppSelector(selectWalletId)
const appDispatch = useAppDispatch()

Expand Down
6 changes: 3 additions & 3 deletions src/context/WalletProvider/KeepKey/components/Pin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const KeepKeyPin = ({
},
dispatch,
} = useWallet()
const wallet = keyring.get(deviceId)
const wallet = keyring.get(deviceId ?? '')

const pinFieldRef = useRef<HTMLInputElement | null>(null)

Expand Down Expand Up @@ -138,10 +138,10 @@ export const KeepKeyPin = ({
}
}

keyring.on(['KeepKey', deviceId, String(MessageType.FAILURE)], handleError)
keyring.on(['KeepKey', deviceId ?? '', String(MessageType.FAILURE)], handleError)

return () => {
keyring.off(['KeepKey', deviceId, String(MessageType.FAILURE)], handleError)
keyring.off(['KeepKey', deviceId ?? '', String(MessageType.FAILURE)], handleError)
}
}, [deviceId, keyring])

Expand Down
9 changes: 5 additions & 4 deletions src/context/WalletProvider/Ledger/components/Chains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const LedgerChains = () => {

const handleConnectClick = useCallback(
async (chainId: ChainId) => {
if (!walletState?.wallet) {
const { wallet, deviceId } = walletState ?? {}
if (!wallet || !deviceId) {
console.error('No wallet found')
return
}
Expand All @@ -67,7 +68,7 @@ export const LedgerChains = () => {
]({
accountNumber: 0,
chainIds,
wallet: walletState.wallet,
wallet,
isSnapInstalled: false,
})

Expand Down Expand Up @@ -102,7 +103,7 @@ export const LedgerChains = () => {
const accountMetadata = accountMetadataByAccountId[accountId]
const payload = {
accountMetadataByAccountId: { [accountId]: accountMetadata },
walletId: walletState.deviceId,
walletId: deviceId,
}

dispatch(portfolio.actions.upsertAccountMetadata(payload))
Expand All @@ -120,7 +121,7 @@ export const LedgerChains = () => {
setLoadingChains(prevLoading => ({ ...prevLoading, [chainId]: false }))
}
},
[dispatch, walletState.deviceId, walletState.wallet],
[dispatch, walletState],
)

const chainsRows = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ export const EnterPassword = () => {

const [showPw, setShowPw] = useState<boolean>(false)

// TODO: this is always null
console.log('EnterPassword', deviceId)

const {
setError,
handleSubmit,
Expand All @@ -61,6 +58,7 @@ export const EnterPassword = () => {
const onSubmit = useCallback(
async (values: FieldValues) => {
try {
if (!deviceId) return
const wallet = keyring.get<NativeHDWallet>(deviceId)
const Vault = await import('@shapeshiftoss/hdwallet-native-vault').then(m => m.Vault)
const vault = await Vault.open(deviceId, values.password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ export const useNativeEventHandler = (state: InitialState, dispatch: Dispatch<Ac
break
}

console.log({
nativeWalletPendingDeviceId: state.nativeWalletPendingDeviceId,
deviceId: state.deviceId,
})

// If we're on the native mobile app we don't need to handle the MNEMONIC_REQUIRED event as we use the device's native authentication instead
// Reacting to this event will incorrectly open the native password modal after authentication completes when on the mobile app
if (isMobileApp) break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const useWalletConnectV2EventHandler = (
*/
state.wallet?.disconnect?.()
dispatch({ type: WalletActions.RESET_STATE })
localWallet.clearLocalWallet()
}, [dispatch, localWallet, state.wallet])
}, [dispatch, state.wallet])

useEffect(() => {
// This effect should never run for wallets other than WalletConnectV2 since we explicitly tap into @walletconnect/ethereum-provider provider
Expand Down
5 changes: 0 additions & 5 deletions src/context/WalletProvider/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => {
store.dispatch(portfolioSlice.actions.setWalletMeta(undefined))
}
const { deviceId, name, wallet, icon, meta, isDemoWallet, connectedType } = action.payload
console.log('SET_WALLET', deviceId)
// set wallet metadata in redux store
const walletMeta = {
walletId: deviceId,
Expand Down Expand Up @@ -220,7 +219,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => {
}
return newState
case WalletActions.NATIVE_PASSWORD_OPEN:
console.log('NATIVE_PASSWORD_OPEN', action.payload)
return {
...state,
modal: action.payload.modal,
Expand Down Expand Up @@ -328,8 +326,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => {
initialRoute: KeepKeyRoutes.Disconnect,
}
case WalletActions.SET_NATIVE_PENDING_DEVICE_ID:
console.log('SET_NATIVE_PENDING_DEVICE_ID')

store.dispatch(localWalletSlice.actions.clearLocalWallet())
store.dispatch(portfolioSlice.actions.setWalletMeta(undefined))
return {
Expand All @@ -340,7 +336,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => {
nativeWalletPendingDeviceId: action.payload,
}
case WalletActions.RESET_NATIVE_PENDING_DEVICE_ID:
console.log('RESET_NATIVE_PENDING_DEVICE_ID')
return {
...state,
nativeWalletPendingDeviceId: null,
Expand Down
5 changes: 0 additions & 5 deletions src/context/WalletProvider/WalletViewsSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { Route, Switch, useHistory, useLocation, useRouteMatch } from 'react-rou
import { SlideTransition } from 'components/SlideTransition'
import { WalletActions } from 'context/WalletProvider/actions'
import { useWallet } from 'hooks/useWallet/useWallet'
import { localWalletSlice } from 'state/slices/localWalletSlice/localWalletSlice'
import { store } from 'state/store'

import { SUPPORTED_WALLETS } from './config'
import { KeyManager } from './KeyManager'
Expand Down Expand Up @@ -63,14 +61,11 @@ export const WalletViewsSwitch = () => {
if (disposition === 'initializing' || disposition === 'recovering') {
await wallet?.cancel()
disconnect()
store.dispatch(localWalletSlice.actions.clearLocalWallet())
dispatch({ type: WalletActions.OPEN_KEEPKEY_DISCONNECT })
} else {
history.replace(INITIAL_WALLET_MODAL_ROUTE)
if (disconnectOnCloseModal) {
disconnect()
dispatch({ type: WalletActions.RESET_STATE })
store.dispatch(localWalletSlice.actions.clearLocalWallet())
} else {
dispatch({ type: WalletActions.SET_WALLET_MODAL, payload: false })
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/Accounts/AddAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const AddAccountModal = () => {
if (!wallet) return
if (!selectedChainId) return
if (!nextAccountNumber) return
if (!walletDeviceId) return
;(async () => {
const accountNumber = nextAccountNumber
const chainIds = [selectedChainId]
Expand Down

0 comments on commit a7ea8e3

Please sign in to comment.