Skip to content

Commit

Permalink
feat(suite): Enable amount unit switching only in debug mode
Browse files Browse the repository at this point in the history
(cherry picked from commit f2ba759)
  • Loading branch information
dahaca authored and matejkriz committed Aug 9, 2022
1 parent 2a83da7 commit 4ddcf5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Send form for bitcoin', () => {
cy.getTestElement('@wallet/send/outputs-and-options').matchImageSnapshot('bitcoin-send');
});

it('switch display units to satoshis, fill a form in satoshis and send', () => {
it.skip('switch display units to satoshis, fill a form in satoshis and send', () => {
cy.getTestElement('amount-unit-switch/regtest').click();

// test adding and removing outputs
Expand All @@ -66,7 +66,7 @@ describe('Send form for bitcoin', () => {
cy.getTestElement('@wallet/send/outputs-and-options').matchImageSnapshot(
'bitcoin-send-sats',
);
});
}); // TEMPORARY SOLUTION!
});

// todo: send tx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Tooltip, variables } from '@trezor/components';
import { useBitcoinAmountUnit } from '@wallet-hooks/useBitcoinAmountUnit';
import { NetworkSymbol } from '@wallet-types';
import { Translation } from './Translation';
import { useSelector } from '@suite-hooks/useSelector';

const Container = styled.div`
position: relative;
Expand All @@ -29,10 +30,15 @@ interface AmountUnitSwitchWrapperProps {
}

export const AmountUnitSwitchWrapper = ({ symbol, children }: AmountUnitSwitchWrapperProps) => {
const { isInDebugMode } = useSelector(state => ({
isInDebugMode: state.suite.settings.debug.showDebugMenu,
}));

const { areSatsDisplayed, toggleBitcoinAmountUnits, areUnitsSupportedByNetwork } =
useBitcoinAmountUnit(symbol);

if (!areUnitsSupportedByNetwork) {
// TEMPORARY SOLUTION!
if (!areUnitsSupportedByNetwork || !isInDebugMode) {
return <>{children}</>;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/suite/src/views/settings/general/SettingsGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ import { BitcoinAmountUnit } from './BitcoinAmountUnit';
import { NETWORKS } from '@wallet-config';

export const SettingsGeneral = () => {
const { desktopUpdate, isTorEnabled, enabledNetworks } = useSelector(state => ({
const { desktopUpdate, isTorEnabled, enabledNetworks, isInDebugMode } = useSelector(state => ({
desktopUpdate: state.desktopUpdate,
isTorEnabled: getIsTorEnabled(state.suite.torStatus),
enabledNetworks: state.wallet.settings.enabledNetworks,
isInDebugMode: state.suite.settings.debug.showDebugMenu,
}));

const hasBitcoinNetworks = NETWORKS.some(
({ symbol, features }) =>
enabledNetworks.includes(symbol) && features?.includes('amount-unit'),
);

// TEMPORARY SOLUTION!
const isUnitSectionShown = hasBitcoinNetworks && isInDebugMode;

return (
<SettingsLayout data-test="@settings/index">
<SettingsSection title={<Translation id="TR_LOCALIZATION" />} icon="FLAG">
<Language />
<Fiat />
{hasBitcoinNetworks && <BitcoinAmountUnit />}
{isUnitSectionShown && <BitcoinAmountUnit />}
</SettingsSection>

<SettingsSection title={<Translation id="TR_LABELING" />} icon="TAG_MINIMAL">
Expand Down

0 comments on commit 4ddcf5c

Please sign in to comment.