Skip to content

Commit

Permalink
fix(suite): order of network filter
Browse files Browse the repository at this point in the history
  • Loading branch information
izmy authored and tomasklim committed Nov 13, 2024
1 parent 928d504 commit 76f75ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default [
initialState: { enabledNetworks: [] },
action: () => walletSettingsActions.changeNetworks(['ltc', 'eth']),
result: {
enabledNetworks: ['ltc', 'eth'],
enabledNetworks: ['eth', 'ltc'],
},
},
{
Expand Down
12 changes: 8 additions & 4 deletions packages/suite/src/reducers/wallet/settingsReducer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import produce from 'immer';

import { WalletSettings } from '@suite-common/wallet-types';
import type { WalletSettings } from '@suite-common/wallet-types';
import { PROTO } from '@trezor/connect';
import { networkSymbolCollection } from '@suite-common/wallet-config';

import { STORAGE } from 'src/actions/suite/constants';
import { WALLET_SETTINGS } from 'src/actions/settings/constants';
import * as walletSettingsActions from 'src/actions/settings/walletSettingsActions';
import { Action, AppState } from 'src/types/suite';
import { STORAGE } from 'src/actions/suite/constants';
import type { Action, AppState } from 'src/types/suite';

export type State = WalletSettings;

Expand Down Expand Up @@ -36,7 +37,10 @@ const settingsReducer = (state: State = initialState, action: Action): State =>

case walletSettingsActions.changeNetworks.type: {
if (walletSettingsActions.changeNetworks.match(action)) {
draft.enabledNetworks = action.payload;
draft.enabledNetworks = [...action.payload].sort(
(a, b) =>
networkSymbolCollection.indexOf(a) - networkSymbolCollection.indexOf(b),
);
}
break;
}
Expand Down
5 changes: 5 additions & 0 deletions suite-common/wallet-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export const NORMAL_ACCOUNT_TYPE = 'normal' satisfies AccountType;
*/
export const networksCollection: Network[] = Object.values(networks);

/**
* array of network symbols
*/
export const networkSymbolCollection = networksCollection.map(n => n.symbol);

export const getMainnets = (debug = false) =>
networksCollection.filter(n => !n.testnet && (!n.isDebugOnlyNetwork || debug));

Expand Down

0 comments on commit 76f75ed

Please sign in to comment.