Skip to content

Commit dcf3c40

Browse files
committed
fix: inability to remove network
1 parent cbf3616 commit dcf3c40

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

src/app/pages/select-network/components/network-list-item.layout.tsx

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Box, BoxProps, Flex, Stack, color } from '@stacks/ui';
1+
import { FiTrash2 } from 'react-icons/fi';
2+
3+
import { Box, BoxProps, Button, Flex, Stack, color } from '@stacks/ui';
24
import { SettingsSelectors } from '@tests-legacy/integration/settings.selectors';
35

46
import { NetworkConfiguration } from '@shared/constants';
@@ -12,11 +14,22 @@ interface NetworkListItemLayoutProps extends BoxProps {
1214
networkId: string;
1315
isOnline: boolean;
1416
isActive: boolean;
17+
isCustom: boolean;
1518
network: NetworkConfiguration;
1619
onSelectNetwork(): void;
20+
onRemoveNetwork(id: string): void;
1721
}
1822
export function NetworkListItemLayout(props: NetworkListItemLayoutProps) {
19-
const { networkId, isOnline, isActive, network, onSelectNetwork, ...rest } = props;
23+
const {
24+
networkId,
25+
isOnline,
26+
isActive,
27+
network,
28+
isCustom,
29+
onRemoveNetwork,
30+
onSelectNetwork,
31+
...rest
32+
} = props;
2033

2134
return (
2235
<Box
@@ -45,7 +58,7 @@ export function NetworkListItemLayout(props: NetworkListItemLayoutProps) {
4558
disabled={!isOnline}
4659
data-testid={network.id}
4760
>
48-
<Stack alignItems="flex-start">
61+
<Stack alignItems="flex-start" flex={1}>
4962
<Title
5063
fontWeight={400}
5164
lineHeight="1rem"
@@ -58,6 +71,19 @@ export function NetworkListItemLayout(props: NetworkListItemLayoutProps) {
5871
<Caption>{getUrlHostname(network.chain.stacks.url)}</Caption>
5972
</Stack>
6073
<NetworkStatusIndicator isActive={isActive} isOnline={isOnline} />
74+
{isCustom && (
75+
<Button
76+
type="button"
77+
mode="tertiary"
78+
ml="base"
79+
onClick={e => {
80+
e.stopPropagation();
81+
onRemoveNetwork(network.id);
82+
}}
83+
>
84+
<FiTrash2 size="14px" />
85+
</Button>
86+
)}
6187
</Flex>
6288
</Box>
6389
);

src/app/pages/select-network/network-list-item.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ import { NetworkListItemLayout } from './components/network-list-item.layout';
77

88
interface NetworkListItemProps {
99
networkId: string;
10+
isCustom: boolean;
1011
onNetworkSelected(networkId: string): void;
12+
onRemoveNetwork(networkId: string): void;
1113
}
12-
export function NetworkListItem({ networkId, onNetworkSelected }: NetworkListItemProps) {
14+
export function NetworkListItem({
15+
networkId,
16+
onNetworkSelected,
17+
onRemoveNetwork,
18+
isCustom,
19+
}: NetworkListItemProps) {
1320
const currentNetworkId = useCurrentNetworkId();
1421
const networks = useNetworks();
1522

@@ -22,7 +29,9 @@ export function NetworkListItem({ networkId, onNetworkSelected }: NetworkListIte
2229
isOnline={isOnline}
2330
network={network}
2431
networkId={networkId}
32+
isCustom={isCustom}
2533
onSelectNetwork={() => onNetworkSelected(networkId)}
34+
onRemoveNetwork={onRemoveNetwork}
2635
/>
2736
);
2837
}

src/app/pages/select-network/select-network.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
import { useNavigate } from 'react-router-dom';
22

3+
import { WalletDefaultNetworkConfigurationIds } from '@shared/constants';
34
import { RouteUrls } from '@shared/route-urls';
45

56
import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
67
import { BaseDrawer } from '@app/components/drawer/base-drawer';
78
import { NetworkListLayout } from '@app/pages/select-network/components/network-list.layout';
89
import { NetworkListItem } from '@app/pages/select-network/network-list-item';
9-
import { useNetworksActions } from '@app/store/networks/networks.hooks';
10+
import { useCurrentNetworkState, useNetworksActions } from '@app/store/networks/networks.hooks';
1011
import { useNetworks } from '@app/store/networks/networks.selectors';
1112

1213
import { AddNetworkButton } from './components/add-network-button';
1314

15+
const defaultNetworkIds = Object.values(WalletDefaultNetworkConfigurationIds) as string[];
16+
1417
export function SelectNetwork() {
1518
const navigate = useNavigate();
1619
const networks = useNetworks();
1720
const analytics = useAnalytics();
1821
const networksActions = useNetworksActions();
22+
const currentNetwork = useCurrentNetworkState();
1923

2024
function addNetwork() {
2125
void analytics.track('add_network');
2226
navigate(RouteUrls.AddNetwork);
2327
}
2428

29+
function removeNetwork(id: string) {
30+
void analytics.track('remove_network');
31+
networksActions.removeNetwork(id);
32+
}
33+
2534
function selectNetwork(id: string) {
2635
void analytics.track('change_network', { id });
2736
networksActions.changeNetwork(id);
@@ -36,7 +45,16 @@ export function SelectNetwork() {
3645
<BaseDrawer title="Select Network" isShowing onClose={closeNetworkModal}>
3746
<NetworkListLayout>
3847
{Object.keys(networks).map(id => (
39-
<NetworkListItem key={id} networkId={id} onNetworkSelected={id => selectNetwork(id)} />
48+
<NetworkListItem
49+
key={id}
50+
networkId={id}
51+
onNetworkSelected={id => selectNetwork(id)}
52+
isCustom={!defaultNetworkIds.includes(id)}
53+
onRemoveNetwork={id => {
54+
if (id === currentNetwork.id) networksActions.changeNetwork('mainnet');
55+
removeNetwork(id);
56+
}}
57+
/>
4058
))}
4159
</NetworkListLayout>
4260
<AddNetworkButton onAddNetwork={addNetwork} />

tests-legacy/utils/transation-test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function generateContractCallToken({
5353
functionArgs: [],
5454
functionName: 'print',
5555
postConditionMode: PostConditionMode.Allow,
56-
network,
56+
network: network as any,
5757
postConditions: [
5858
makeStandardFungiblePostCondition(
5959
address,

0 commit comments

Comments
 (0)