Skip to content

Commit

Permalink
fix(suite-native): ensure that devices with BTC-only firmware have BT…
Browse files Browse the repository at this point in the history
…C enabled
  • Loading branch information
yanascz committed Jan 7, 2025
1 parent d91a389 commit 30b62f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion suite-native/app/src/hooks/useCoinEnablingInitialCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useCoinEnablingInitialCheck = () => {
let timeoutId: TimerId;
//if btc only device, just run discovery for btc and do not show the UI
if (hasBitcoinOnlyFirmware) {
dispatch(setEnabledDiscoveryNetworkSymbols(['btc']));
// discoveryMiddleware ensures that BTC is enabled for devices with BTC-only firmware
dispatch(setIsCoinEnablingInitFinished(true));
dispatch(applyDiscoveryChangesThunk());
} else {
Expand Down
6 changes: 6 additions & 0 deletions suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export const discoveryConfigSlice = createSlice({
setDiscoveryInfo: (state, { payload }: PayloadAction<DiscoveryInfo | null>) => {
state.discoveryInfo = payload;
},
addEnabledDiscoveryNetworkSymbol: (state, { payload }: PayloadAction<NetworkSymbol>) => {
if (!state.enabledDiscoveryNetworkSymbols.includes(payload)) {
state.enabledDiscoveryNetworkSymbols.push(payload);
}
},
toggleEnabledDiscoveryNetworkSymbol: (state, { payload }: PayloadAction<NetworkSymbol>) => {
const symbol = payload;
const index = state.enabledDiscoveryNetworkSymbols.indexOf(symbol);
Expand Down Expand Up @@ -208,6 +213,7 @@ export const selectTokenDefinitionsEnabledNetworks = createMemoizedSelector(
export const {
toggleAreTestnetsEnabled,
setDiscoveryInfo,
addEnabledDiscoveryNetworkSymbol,
toggleEnabledDiscoveryNetworkSymbol,
setEnabledDiscoveryNetworkSymbols,
setIsCoinEnablingInitFinished,
Expand Down
11 changes: 11 additions & 0 deletions suite-native/discovery/src/discoveryMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
accountsActions,
} from '@suite-common/wallet-core';
import { isFirmwareVersionSupported } from '@suite-native/device';
import { hasBitcoinOnlyFirmware } from '@trezor/device-utils';

import { startDescriptorPreloadedDiscoveryThunk, discoveryCheckThunk } from './discoveryThunks';
import {
Expand All @@ -17,6 +18,7 @@ import {
toggleAreTestnetsEnabled,
setEnabledDiscoveryNetworkSymbols,
toggleEnabledDiscoveryNetworkSymbol,
addEnabledDiscoveryNetworkSymbol,
} from './discoveryConfigSlice';

export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps(
Expand Down Expand Up @@ -69,6 +71,15 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps(
);
}

// ensure that BTC is enabled when device with BTC-only firmware is connected
// (it could have been disabled via some other device with universal firmware)
if (deviceActions.selectDevice.match(action)) {
const device = action.payload;
if (device?.connected && hasBitcoinOnlyFirmware(device)) {
dispatch(addEnabledDiscoveryNetworkSymbol('btc'));
}
}

// for further continual discovery check for various other reasons
if (
deviceActions.selectDevice.match(action) || // user switched device
Expand Down

0 comments on commit 30b62f5

Please sign in to comment.