Skip to content

Commit

Permalink
feat(suite-native): move coin enabling to settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Aug 6, 2024
1 parent fc30734 commit becfe2b
Show file tree
Hide file tree
Showing 26 changed files with 246 additions and 78 deletions.
3 changes: 3 additions & 0 deletions suite-common/icons/assets/icons/coins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions suite-common/icons/src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const icons = {
clockClockwise: require('../assets/icons/clockClockwise.svg'),
close: require('../assets/icons/close.svg'),
closeCircle: require('../assets/icons/closeCircle.svg'),
coins: require('../assets/icons/coins.svg'),
confirmation: require('../assets/icons/confirmation.svg'),
copy: require('../assets/icons/copy.svg'),
database: require('../assets/icons/database.svg'),
Expand Down
1 change: 1 addition & 0 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@suite-native/analytics": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/biometrics": "workspace:*",
"@suite-native/coin-enabling": "workspace:*",
"@suite-native/config": "workspace:*",
"@suite-native/device": "workspace:*",
"@suite-native/device-authorization": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions suite-native/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{ "path": "../analytics" },
{ "path": "../atoms" },
{ "path": "../biometrics" },
{ "path": "../coin-enabling" },
{ "path": "../config" },
{ "path": "../device" },
{ "path": "../device-authorization" },
Expand Down
24 changes: 24 additions & 0 deletions suite-native/coin-enabling/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@suite-native/coin-enabling",
"version": "1.0.0",
"private": true,
"license": "See LICENSE.md in repo root",
"sideEffects": false,
"main": "src/index",
"scripts": {
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'",
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build"
},
"dependencies": {
"@reduxjs/toolkit": "1.9.5",
"@suite-common/wallet-config": "workspace:*",
"@suite-common/wallet-core": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/discovery": "workspace:*",
"@suite-native/feature-flags": "workspace:*",
"react": "18.2.0",
"react-native": "0.74.1",
"react-redux": "8.0.7"
}
}
7 changes: 7 additions & 0 deletions suite-native/coin-enabling/redux.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AsyncThunkAction } from '@reduxjs/toolkit';

declare module 'redux' {
export interface Dispatch {
<TThunk extends AsyncThunkAction<any, any, any>>(thunk: TThunk): ReturnType<TThunk>;
}
}
36 changes: 36 additions & 0 deletions suite-native/coin-enabling/src/components/DiscoveryCoinsFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useDispatch } from 'react-redux';

import { VStack, Text, HStack, Switch, Card } from '@suite-native/atoms';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { toggleEnabledDiscoveryNetworkSymbol } from '@suite-native/discovery';

import { useCoinEnabling } from '../hooks/useCoinEnabling';

export const DiscoveryCoinsFilter = () => {
const dispatch = useDispatch();

const { enabledNetworkSymbols, availableNetworks } = useCoinEnabling();

const uniqueNetworkSymbols = [...new Set(availableNetworks.map(n => n.symbol))];

return (
<Card>
<VStack spacing="small">
<Text variant="titleSmall">Enable discovery of networks</Text>
<VStack>
{uniqueNetworkSymbols.map((networkSymbol: NetworkSymbol) => (
<HStack justifyContent="space-between" key={networkSymbol}>
<Text>{networkSymbol.toUpperCase()}</Text>
<Switch
onChange={() =>
dispatch(toggleEnabledDiscoveryNetworkSymbol(networkSymbol))
}
isChecked={enabledNetworkSymbols.includes(networkSymbol)}
/>
</HStack>
))}
</VStack>
</VStack>
</Card>
);
};
33 changes: 33 additions & 0 deletions suite-native/coin-enabling/src/hooks/useCoinEnabling.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useSelector } from 'react-redux';

import { FeatureFlag, FeatureFlagsRootState, useFeatureFlag } from '@suite-native/feature-flags';
import {
selectAreTestnetsEnabled,
selectEnabledDiscoveryNetworkSymbols,
selectDiscoverySupportedNetworks,
DiscoveryConfigSliceRootState,
} from '@suite-native/discovery';
import { DeviceRootState } from '@suite-common/wallet-core';

export const useCoinEnabling = () => {
const [isCoinEnablingActive] = useFeatureFlag(FeatureFlag.IsCoinEnablingActive);
const areTestnetsEnabled = useSelector(selectAreTestnetsEnabled);
const availableNetworks = useSelector((state: DeviceRootState) =>
selectDiscoverySupportedNetworks(state, areTestnetsEnabled),
);
const enabledNetworkSymbols = useSelector(
(state: DiscoveryConfigSliceRootState & DeviceRootState & FeatureFlagsRootState) =>
selectEnabledDiscoveryNetworkSymbols(state, areTestnetsEnabled),
);

const applyDiscoveryChanges = () => {
// TODO: remove disabled network accounts and run discovery check
};

return {
isCoinEnablingActive,
enabledNetworkSymbols,
availableNetworks,
applyDiscoveryChanges,
};
};
2 changes: 2 additions & 0 deletions suite-native/coin-enabling/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './components/DiscoveryCoinsFilter';
export * from './hooks/useCoinEnabling';
15 changes: 15 additions & 0 deletions suite-native/coin-enabling/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "outDir": "libDev" },
"references": [
{
"path": "../../suite-common/wallet-config"
},
{
"path": "../../suite-common/wallet-core"
},
{ "path": "../atoms" },
{ "path": "../discovery" },
{ "path": "../feature-flags" }
]
}
7 changes: 2 additions & 5 deletions suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ export const discoveryConfigSlice = createSlice({
setDiscoveryInfo: (state, { payload }: PayloadAction<DiscoveryInfo | null>) => {
state.discoveryInfo = payload;
},
toggleEnabledDiscoveryNetworkSymbols: (
state,
{ payload }: PayloadAction<NetworkSymbol>,
) => {
toggleEnabledDiscoveryNetworkSymbol: (state, { payload }: PayloadAction<NetworkSymbol>) => {
const networkSymbol = payload;
const index = state.enabledDiscoveryNetworkSymbols.indexOf(networkSymbol);

Expand Down Expand Up @@ -115,6 +112,6 @@ export const selectEnabledDiscoveryNetworkSymbols = memoizeWithArgs(
},
);

export const { toggleAreTestnetsEnabled, setDiscoveryInfo, toggleEnabledDiscoveryNetworkSymbols } =
export const { toggleAreTestnetsEnabled, setDiscoveryInfo, toggleEnabledDiscoveryNetworkSymbol } =
discoveryConfigSlice.actions;
export const discoveryConfigReducer = discoveryConfigSlice.reducer;
36 changes: 36 additions & 0 deletions suite-native/intl/src/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,35 @@ export const en = {
},
},
moduleSettings: {
items: {
application: {
title: 'Application',
devUtils: {
title: 'DEV utils',
subtitle: 'Only for devs and internal testers.',
},
localization: {
title: 'Localization',
subtitle: 'Currency, Bitcoin units',
},
customization: {
title: 'Customization',
subtitle: 'Color scheme',
},
privacyAndSecurity: {
title: 'Privacy & Security',
subtitle: 'Analytics, Discreet mode, Biometrics',
},
viewOnly: {
title: 'View-only',
subtitle: 'Check balances without your Trezor',
},
coinEnabling: {
title: 'Enabled coins',
subtitle: 'Manage coins that you use',
},
},
},
faq: {
title: 'Get help',
supportCard: {
Expand Down Expand Up @@ -466,6 +495,13 @@ export const en = {
privacyAndSecurity: {
title: 'Privacy & Security',
},
coinEnabling: {
settings: {
title: 'Enabled coins',
subtitle:
'Only choosing coins that you use will shorten loading times when connecting your Trezor.',
},
},
viewOnly: {
title: 'View-only',
emptyTitle: 'Connect your device to enable view-only',
Expand Down
1 change: 0 additions & 1 deletion suite-native/module-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"@react-navigation/native-stack": "6.9.26",
"@sentry/react-native": "5.22.3",
"@suite-common/icons": "workspace:*",
"@suite-common/wallet-config": "workspace:*",
"@suite-common/wallet-core": "workspace:*",
"@suite-common/wallet-types": "workspace:*",
"@suite-native/atoms": "workspace:*",
Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions suite-native/module-dev-utils/src/screens/DevUtilsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ import {
} from '@suite-native/navigation';
import { clearStorage } from '@suite-native/storage';
import { getCommitHash, getSuiteVersion } from '@trezor/env-utils';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';

import { RenderingUtils } from '../components/RenderingUtils';
import { FeatureFlags } from '../components/FeatureFlags';
import { TestnetsToggle } from '../components/TestnetsToggle';
import { DiscoveryCoinsFilter } from '../components/DiscoveryCoinsFilter';
import { DevicePassphraseSwitch } from '../components/DevicePassphraseSwitch';

export const DevUtilsScreen = ({
navigation,
}: StackProps<DevUtilsStackParamList, DevUtilsStackRoutes.DevUtils>) => {
const [isCoinEnablingActive] = useFeatureFlag(FeatureFlag.IsCoinEnablingActive);

return (
<Screen screenHeader={<ScreenSubHeader content="DEV utils" />}>
<VStack>
Expand All @@ -49,7 +45,7 @@ export const DevUtilsScreen = ({
<DevicePassphraseSwitch />
</>
)}
{isCoinEnablingActive && <DiscoveryCoinsFilter />}

<Button
onPress={() => {
const errorMessage = `Sentry test error - ${Date.now()}`;
Expand Down
3 changes: 0 additions & 3 deletions suite-native/module-dev-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"compilerOptions": { "outDir": "libDev" },
"references": [
{ "path": "../../suite-common/icons" },
{
"path": "../../suite-common/wallet-config"
},
{
"path": "../../suite-common/wallet-core"
},
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@suite-native/analytics": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/biometrics": "workspace:*",
"@suite-native/coin-enabling": "workspace:*",
"@suite-native/config": "workspace:*",
"@suite-native/device-manager": "workspace:*",
"@suite-native/feature-flags": "workspace:*",
Expand Down
Loading

0 comments on commit becfe2b

Please sign in to comment.