Skip to content

Commit

Permalink
feat(suite-native): revert for only passphrase remembered add also st…
Browse files Browse the repository at this point in the history
…andard wallet

This reverts commit 9e4882a.
  • Loading branch information
vytick committed Nov 8, 2024
1 parent f2e0b66 commit d8fcbfe
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 66 deletions.
16 changes: 0 additions & 16 deletions suite-common/wallet-core/src/accounts/accountsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,6 @@ export const selectVisibleNonEmptyDeviceAccountsByNetworkSymbol = (
export const selectNonEmptyDeviceAccounts = (state: AccountsRootState & DeviceRootState) =>
selectDeviceAccounts(state).filter(account => !account.empty);

export const selectDeviceHasAccountsByDeviceState = memoizeWithArgs(
(
state: AccountsRootState & DeviceRootState,
deviceState: StaticSessionId | DeviceState | undefined,
) => {
if (!deviceState) {
return false;
}

return selectAccountsByDeviceState(state, deviceState).length > 0;
},
{
size: 10,
},
);

export const selectAccountsByNetworkAndDeviceState = memoizeWithArgs(
(state: AccountsRootState, deviceState: StaticSessionId, networkSymbol: NetworkSymbol) => {
const accounts = selectAccounts(state);
Expand Down
1 change: 0 additions & 1 deletion suite-native/device-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@suite-native/intl": "workspace:*",
"@suite-native/link": "workspace:*",
"@suite-native/navigation": "workspace:*",
"@suite-native/settings": "workspace:*",
"@trezor/styles": "workspace:*",
"@trezor/theme": "workspace:*",
"jotai": "1.9.1",
Expand Down
32 changes: 9 additions & 23 deletions suite-native/device-manager/src/components/WalletItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ import { Translation } from '@suite-native/intl';
import { Icon } from '@suite-native/icons';
import { TrezorDevice } from '@suite-common/suite-types';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import {
AccountsRootState,
DeviceRootState,
FiatRatesRootState,
selectDevice,
selectDeviceByState,
selectDeviceHasAccountsByDeviceState,
} from '@suite-common/wallet-core';
import { selectDevice, selectDeviceByState } from '@suite-common/wallet-core';
import { FiatAmountFormatter } from '@suite-native/formatters';
import { selectDeviceTotalFiatBalanceNative } from '@suite-native/device';
import { SettingsSliceRootState } from '@suite-native/settings';

type WalletItemProps = {
deviceState: NonNullable<TrezorDevice['state']>;
Expand Down Expand Up @@ -61,14 +53,10 @@ const labelStyle = prepareNativeStyle(() => ({

export const WalletItem = ({ deviceState, onPress, isSelectable = true }: WalletItemProps) => {
const { applyStyle } = useNativeStyles();
const device = useSelector((state: DeviceRootState) => selectDeviceByState(state, deviceState));
const hasAccounts = useSelector((state: AccountsRootState & DeviceRootState) =>
selectDeviceHasAccountsByDeviceState(state, device?.state),
);
const device = useSelector((state: any) => selectDeviceByState(state, deviceState));
const selectedDevice = useSelector(selectDevice);
const fiatBalance = useSelector(
(state: AccountsRootState & FiatRatesRootState & SettingsSliceRootState) =>
selectDeviceTotalFiatBalanceNative(state, deviceState.staticSessionId!),
const fiatBalance = useSelector((state: any) =>
selectDeviceTotalFiatBalanceNative(state, deviceState.staticSessionId!),
);

if (!device) {
Expand Down Expand Up @@ -105,13 +93,11 @@ export const WalletItem = ({ deviceState, onPress, isSelectable = true }: Wallet
</Text>
</HStack>
<HStack alignItems="center" spacing="sp12">
{hasAccounts && (
<FiatAmountFormatter
value={String(fiatBalance)}
variant="hint"
color="textSubdued"
/>
)}
<FiatAmountFormatter
value={String(fiatBalance)}
variant="hint"
color="textSubdued"
/>
{isSelectable && <Radio value="" onPress={onPress} isChecked={isSelected} />}
</HStack>
</HStack>
Expand Down
1 change: 0 additions & 1 deletion suite-native/device-manager/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
{ "path": "../intl" },
{ "path": "../link" },
{ "path": "../navigation" },
{ "path": "../settings" },
{ "path": "../../packages/styles" },
{ "path": "../../packages/theme" }
]
Expand Down
26 changes: 2 additions & 24 deletions suite-native/device/src/middlewares/deviceMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AnyAction, isAnyOf } from '@reduxjs/toolkit';
import { A } from '@mobily/ts-belt';

import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils';
import { DEVICE } from '@trezor/connect';
Expand All @@ -14,8 +13,6 @@ import {
selectAccountsByDeviceState,
createDeviceInstanceThunk,
createImportedDeviceThunk,
selectDevice,
selectDeviceInstances,
} from '@suite-common/wallet-core';
import { FeatureFlag, selectIsFeatureFlagEnabled } from '@suite-native/feature-flags';
import { clearAndUnlockDeviceAccessQueue } from '@suite-native/device-mutex';
Expand All @@ -41,7 +38,7 @@ const isActionDeviceRelated = (action: AnyAction): boolean => {
};

export const prepareDeviceMiddleware = createMiddlewareWithExtraDeps(
async (action, { dispatch, next, getState }) => {
(action, { dispatch, next, getState }) => {
if (action.type === DEVICE.DISCONNECT) {
dispatch(forgetDisconnectedDevices(action.payload));
}
Expand Down Expand Up @@ -78,26 +75,7 @@ export const prepareDeviceMiddleware = createMiddlewareWithExtraDeps(
case DEVICE.CONNECT:
case DEVICE.CONNECT_UNACQUIRED:
if (isUsbDeviceConnectFeatureEnabled) {
await dispatch(selectDeviceThunk(action.payload));

const deviceInstances = selectDeviceInstances(getState());
const selectedDevice = selectDevice(getState());

// If there is selected device, but no useEmptyPassphrase device for connected trezor,
// add normal wallet but keep the original one selected.
// This happens after connecting device with only remembered passphrases wallet.
if (
selectedDevice &&
A.isEmpty(deviceInstances.filter(d => d.useEmptyPassphrase))
) {
await dispatch(
createDeviceInstanceThunk({
device: selectedDevice,
useEmptyPassphrase: true,
}),
);
dispatch(selectDeviceThunk({ device: selectedDevice }));
}
dispatch(selectDeviceThunk(action.payload));
}
break;
case DEVICE.DISCONNECT:
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9636,7 +9636,6 @@ __metadata:
"@suite-native/intl": "workspace:*"
"@suite-native/link": "workspace:*"
"@suite-native/navigation": "workspace:*"
"@suite-native/settings": "workspace:*"
"@trezor/styles": "workspace:*"
"@trezor/theme": "workspace:*"
jotai: "npm:1.9.1"
Expand Down

0 comments on commit d8fcbfe

Please sign in to comment.