Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1544 Networks management #1202

Merged
merged 53 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
130b27a
TW-1555 Update some design and fix some bugs
keshan3262 Sep 13, 2024
b2dad24
TW-1555 Make some modals close after their backdrop is clicked
keshan3262 Sep 13, 2024
1414857
TW-1542 Resolve merge conflicts
keshan3262 Sep 13, 2024
6b250f3
TW-1542 Revert harmful changes
keshan3262 Sep 13, 2024
6dbdca1
TW-1542 Remove unused components
keshan3262 Sep 13, 2024
982e447
TW-1542 Implement new Settings menu design
keshan3262 Sep 13, 2024
4fb9a56
TW-1542 Remove some unused translations
keshan3262 Sep 13, 2024
6fcb3d7
TW-1542 Fix find-deadcode errors
keshan3262 Sep 13, 2024
f18b05d
TW-1542 Add changes from comments
keshan3262 Sep 16, 2024
f97bee1
TW-1543 Redesign 'General' settings section
keshan3262 Sep 16, 2024
3bbbc88
TW-1543 Refactoring
keshan3262 Sep 17, 2024
25b2037
TW-1542 Move localStorage clearing to frontend
keshan3262 Sep 17, 2024
03342d6
TW-1542 Update a label
keshan3262 Sep 17, 2024
9cdeb5c
TW-1555 Some more bugfixes
keshan3262 Sep 17, 2024
de837fa
Merge branch 'TW-1555-final-epic-testing' of https://github.com/madfi…
keshan3262 Sep 17, 2024
cf85bbd
Merge branch 'TW-1542-apply-design-for-settings-page' of https://gith…
keshan3262 Sep 17, 2024
74041ca
TW-1543 Change error output
keshan3262 Sep 17, 2024
93bd61d
TW-1543 Apply design updates
keshan3262 Sep 17, 2024
06f82f7
TW-1555 Remove some commented out code
keshan3262 Sep 17, 2024
ba0dc8a
TW-1543 Remove excessive locales loading checks
keshan3262 Sep 17, 2024
4dee114
TW-1555 Refactor setting classes
keshan3262 Sep 18, 2024
1feeace
TW-1555 Fix prettier problem
keshan3262 Sep 18, 2024
b3df9cc
TW-1555 Agree styles for app content wrapper and action modals
keshan3262 Sep 18, 2024
375d0c9
TW-1543 Bugfixes according to the comment from Figma
keshan3262 Sep 18, 2024
c885837
Merge branch 'TW-1555-final-epic-testing' of https://github.com/madfi…
keshan3262 Sep 18, 2024
f448902
TW-1542 Change a label
keshan3262 Sep 18, 2024
6aa1703
TW-1542 Fix font size for page header
keshan3262 Sep 18, 2024
9fcfbb8
Merge branch 'TW-1542-apply-design-for-settings-page' of https://gith…
keshan3262 Sep 18, 2024
438ab67
TW-1543 Remove an unused import
keshan3262 Sep 18, 2024
58f3ece
TW-1544 Implement RPCs and block explorers management (raw version)
keshan3262 Sep 20, 2024
3b02db6
TW-1544 Fix some bugs
keshan3262 Sep 23, 2024
9bb455e
TW-1542: Apply design for settings menu (#1199)
keshan3262 Sep 24, 2024
b1a95a9
TW-1543: 'General' section update (#1200)
keshan3262 Sep 24, 2024
625167f
TW-1544 Implement whole networks management
keshan3262 Sep 25, 2024
ce71784
TW-1544 Resolve merge conflicts
keshan3262 Sep 25, 2024
9a1ffa7
TW-1544 Some bugfixes
keshan3262 Sep 25, 2024
ff03850
TW-1544 Some bugfixes
keshan3262 Sep 26, 2024
48b25c5
TW-1544 Additional refactoring
keshan3262 Sep 26, 2024
c3d4c3b
TW-1544 Major refactoring
keshan3262 Sep 30, 2024
db0eb51
TW-1544 Refactoring according to comments
keshan3262 Oct 1, 2024
3172936
TW-1544 Fix a linting error
keshan3262 Oct 1, 2024
0b0585a
TW-1544 Additional refactoring according to comments
keshan3262 Oct 1, 2024
1e6bf34
TW-1548: Redesign 'Advanced Features' section (#1205)
keshan3262 Oct 7, 2024
e5db334
Merge branch 'TW-1541-epic-evm-settings' of https://github.com/madfis…
keshan3262 Oct 9, 2024
ce6d43e
Fix some bugs from comments in Jira
keshan3262 Oct 10, 2024
8e00f6c
TW-1544 Fix rest of bugs from comments in Jira
keshan3262 Oct 11, 2024
7ddbba2
TW-1544 Implmenent reserving space for an error below FormField
keshan3262 Oct 11, 2024
3239ec4
TW-1544 Resolve merge conflicts
keshan3262 Oct 11, 2024
1b145b7
TW-1544 Remove an unused import
keshan3262 Oct 14, 2024
7e1ef85
Merge branch 'development-2' of https://github.com/madfish-solutions/…
keshan3262 Oct 24, 2024
5ebde31
TW-1544 Prevent disabling main Tezos and EVM networks
keshan3262 Oct 24, 2024
71849a3
TW-1544 Minor refactoring
keshan3262 Oct 25, 2024
3c68cd2
TW-1544 Resolve merge conflicts
keshan3262 Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TW-1544 Prevent disabling main Tezos and EVM networks
  • Loading branch information
keshan3262 committed Oct 24, 2024
commit 5ebde31623f5e42f126c7bbffee21ac83898762f
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
"react-dev-utils/fork-ts-checker-webpack-plugin": "^9",
"tslib": "^2.4.0",
"@types/react": "18.0.15",
"@types/react-dev-utils/@types/webpack-dev-server": "^4",
"@taquito/taquito": "20.0.0",
"@taquito/utils": "20.0.0",
"@taquito/beacon-wallet": "20.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useAccountTokensForListing = (
: enabledChainsSlugs;

return enabledChainsSlugsFiltered.sort(tokensSortPredicate);
}, [tezTokens, evmTokens, isNonZeroBalance, tokensSortPredicate, gasChainsSlugs, filterZeroBalances]);
}, [gasChainsSlugs, tezTokens, evmTokens, filterZeroBalances, isNonZeroBalance, tokensSortPredicate]);

return {
enabledChainsSlugsSorted,
Expand Down
26 changes: 4 additions & 22 deletions src/app/pages/ChainSettings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
import React, { memo, useCallback, useEffect, useState } from 'react';

import { ToggleSwitch } from 'app/atoms';
import { ActionModalBodyContainer, ActionModalButton, ActionModalButtonsContainer } from 'app/atoms/action-modal';
Expand All @@ -7,18 +7,12 @@ import { SettingsCell } from 'app/atoms/SettingsCell';
import { SettingsCellGroup } from 'app/atoms/SettingsCellGroup';
import { StyledButton } from 'app/atoms/StyledButton';
import PageLayout from 'app/layouts/PageLayout';
import { MAIN_CHAINS_IDS } from 'lib/constants';
import { T, t } from 'lib/i18n';
import { useBooleanState } from 'lib/ui/hooks';
import { HistoryAction, navigate } from 'lib/woozie';
import {
OneOfChains,
useAllEvmChains,
useAllTezosChains,
useEnabledEvmChains,
useEnabledTezosChains
} from 'temple/front';
import { OneOfChains, useAllEvmChains, useAllTezosChains } from 'temple/front';
import { BlockExplorer } from 'temple/front/block-explorers';
import { isPossibleTestnetChain } from 'temple/front/chains';
import { StoredEvmNetwork, StoredTezosNetwork } from 'temple/networks';
import { TempleChainKind } from 'temple/types';

Expand All @@ -42,8 +36,6 @@ const explorerUrlFn = (item: { url: string }) => item.url;

const ChainExistentSettings = memo<ChainExistentSettingsProps>(({ chain, bottomEdgeIsVisible }) => {
const [removeChainModalIsOpen, openRemoveChainModal, closeRemoveChainModal] = useBooleanState(false);
const enabledEvmChains = useEnabledEvmChains();
const enabledTezChains = useEnabledTezosChains();
const { kind: chainKind, chainId } = chain;
const {
setChainEnabled,
Expand All @@ -55,17 +47,7 @@ const ChainExistentSettings = memo<ChainExistentSettingsProps>(({ chain, bottomE
removeBlockExplorer,
removeChain
} = useChainOperations(chainKind, chainId);
const allEnabledChains = useMemo(
() => (enabledEvmChains as OneOfChains[]).concat(enabledTezChains),
[enabledEvmChains, enabledTezChains]
);
const enabledMainnetChains = useMemo(
() => allEnabledChains.filter(chain => !isPossibleTestnetChain(chain)),
[allEnabledChains]
);
const enabledTestnetChains = useMemo(() => allEnabledChains.filter(isPossibleTestnetChain), [allEnabledChains]);
const shouldPreventDisablingChain =
(isPossibleTestnetChain(chain) ? enabledTestnetChains : enabledMainnetChains).length === 1;
const shouldPreventDisablingChain = MAIN_CHAINS_IDS.includes(chainId);

keshan3262 marked this conversation as resolved.
Show resolved Hide resolved
const handleConfirmRemoveClick = useCallback(() => {
closeRemoveChainModal();
Expand Down
8 changes: 6 additions & 2 deletions src/app/templates/AddressBook/AddressBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const SUBMIT_ERROR_TYPE = 'submit-error';
const AddNewContactForm: React.FC<{ className?: string }> = ({ className }) => {
const { addContact } = useContactsActions();

const chainSelectController = useChainSelectController();
const chainSelectController = useChainSelectController(false);
const network = chainSelectController.value;

const {
Expand Down Expand Up @@ -171,7 +171,11 @@ const AddNewContactForm: React.FC<{ className?: string }> = ({ className }) => {

return (
<form className={className} onSubmit={handleSubmit(onAddContactSubmit)}>
<ChainSelectSection controller={chainSelectController} onlyForAddressResolution />
<ChainSelectSection
controller={chainSelectController}
onlyForAddressResolution
shouldFilterByCurrentAccount={false}
/>

<FormField
ref={register({ validate: validateAddressField })}
Expand Down
112 changes: 65 additions & 47 deletions src/app/templates/ChainSelect/ChainsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { useShortcutAccountSelectModalIsOpened } from 'app/hooks/use-account-sel
import { ReactComponent as SignalAltIcon } from 'app/icons/monochrome/signal-alt.svg';
import { T } from 'lib/i18n';
import { PopperRenderProps } from 'lib/ui/Popper';
import { TezosChain, EvmChain, useEnabledTezosChains, useEnabledEvmChains } from 'temple/front';
import {
TezosChain,
EvmChain,
useEnabledTezosChains,
useEnabledEvmChains,
useAccountAddressForTezos,
useAccountAddressForEvm
} from 'temple/front';
import { TempleChainTitle } from 'temple/types';

import { ChainButton } from './ChainButton';
Expand All @@ -16,13 +23,16 @@ import styles from './style.module.css';

interface Props extends PopperRenderProps {
controller: ChainSelectController;
shouldFilterByCurrentAccount: boolean;
keshan3262 marked this conversation as resolved.
Show resolved Hide resolved
}

export const ChainsDropdown = memo<Props>(({ opened, setOpened, controller }) => {
export const ChainsDropdown = memo<Props>(({ opened, setOpened, controller, shouldFilterByCurrentAccount }) => {
const selectedChain = controller.value;

const tezosChains = useEnabledTezosChains();
const evmChains = useEnabledEvmChains();
const accountTezAddress = useAccountAddressForTezos();
const accountEvmAddress = useAccountAddressForEvm();

useShortcutAccountSelectModalIsOpened(() => setOpened(false));

Expand Down Expand Up @@ -53,51 +63,59 @@ export const ChainsDropdown = memo<Props>(({ opened, setOpened, controller }) =>
return (
<DropdownWrapper opened={opened} design="dark" className="origin-top-right mt-1 p-2">
<div className={styles.scroll}>
<h2 className={h2ClassName}>
<SignalAltIcon className="w-auto h-4 mr-1 stroke-current" />
{TempleChainTitle.tezos} <T id="networks" />
</h2>

{tezosChains.map(chain => {
const { chainId } = chain;
const selected = chainId === selectedChain.chainId && selectedChain.kind === 'tezos';

return (
<ChainButton
key={chainId}
chain={chain}
selected={selected}
onClick={() => {
setOpened(false);

if (!selected) handleTezosNetworkSelect(chain);
}}
/>
);
})}

<h2 className={clsx(h2ClassName, 'mt-2')}>
<SignalAltIcon className="w-auto h-4 mr-1 stroke-current" />
{TempleChainTitle.evm} <T id="networks" />
</h2>

{evmChains.map(chain => {
const { chainId } = chain;
const selected = chainId === selectedChain.chainId && selectedChain.kind === 'evm';

return (
<ChainButton
key={chainId}
chain={chain}
selected={selected}
onClick={() => {
setOpened(false);

if (!selected) handleEvmNetworkSelect(chain);
}}
/>
);
})}
{(!shouldFilterByCurrentAccount || accountTezAddress) && (
<>
<h2 className={h2ClassName}>
<SignalAltIcon className="w-auto h-4 mr-1 stroke-current" />
{TempleChainTitle.tezos} <T id="networks" />
</h2>

{tezosChains.map(chain => {
const { chainId } = chain;
const selected = chainId === selectedChain?.chainId && selectedChain.kind === 'tezos';

return (
<ChainButton
key={chainId}
chain={chain}
selected={selected}
onClick={() => {
setOpened(false);

if (!selected) handleTezosNetworkSelect(chain);
}}
/>
);
})}
</>
)}

{(!shouldFilterByCurrentAccount || accountEvmAddress) && (
<>
<h2 className={clsx(h2ClassName, 'mt-2')}>
<SignalAltIcon className="w-auto h-4 mr-1 stroke-current" />
{TempleChainTitle.evm} <T id="networks" />
</h2>

{evmChains.map(chain => {
const { chainId } = chain;
const selected = chainId === selectedChain?.chainId && selectedChain.kind === 'evm';

return (
<ChainButton
key={chainId}
chain={chain}
selected={selected}
onClick={() => {
setOpened(false);

if (!selected) handleEvmNetworkSelect(chain);
}}
/>
);
})}
</>
)}
</div>
</DropdownWrapper>
);
Expand Down
6 changes: 4 additions & 2 deletions src/app/templates/ChainSelect/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export interface ChainSelectController {
setValue: SyncFn<OneOfChains>;
}

export const useChainSelectController = (): ChainSelectController => {
export const useChainSelectController = (shouldFilterByCurrentAccount = true): ChainSelectController => {
const tezosMainnetChain = useTezosMainnetChain();
const evmMainnet = useEthereumMainnetChain();
const accountTezAddress = useAccountAddressForTezos();

const [value, setValue] = useState<OneOfChains>(() => (accountTezAddress ? tezosMainnetChain : evmMainnet));
const [value, setValue] = useState<OneOfChains>(() =>
accountTezAddress || !shouldFilterByCurrentAccount ? tezosMainnetChain : evmMainnet
);

return useMemo(() => ({ value, setValue }), [value]);
};
11 changes: 9 additions & 2 deletions src/app/templates/ChainSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@ export { useChainSelectController } from './controller';

interface Props {
controller: ChainSelectController;
shouldFilterByCurrentAccount?: boolean;
}

const ChainSelect = memo<Props>(({ controller }) => {
const ChainSelect = memo<Props>(({ controller, shouldFilterByCurrentAccount = true }) => {
const selectedChain = controller.value;

return (
<Popper
placement="bottom-end"
strategy="fixed"
popup={props => <ChainsDropdown controller={controller} {...props} />}
popup={props => (
<ChainsDropdown
shouldFilterByCurrentAccount={shouldFilterByCurrentAccount}
controller={controller}
{...props}
/>
)}
>
{({ ref, opened, toggleOpened }) => (
<Button
Expand Down
7 changes: 6 additions & 1 deletion src/app/templates/NetworksSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';

import { EmptyState } from 'app/atoms/EmptyState';
import { useSearchParamsBoolean } from 'app/hooks/use-search-params-boolean';
import { MAIN_CHAINS_IDS } from 'lib/constants';
import { t } from 'lib/i18n';
import { filterNetworksByName } from 'lib/ui/filter-networks-by-name';
import { useBooleanState } from 'lib/ui/hooks';
Expand All @@ -28,7 +29,11 @@ export const NetworksSettings = memo<SettingsTabProps>(({ setHeaderChildren }) =
const [searchValue, setSearchValue] = useState('');

const allChains = useMemo(
() => [...Object.values(tezosChainsRecord), ...Object.values(evmChainsRecord)],
() =>
[...Object.values(tezosChainsRecord), ...Object.values(evmChainsRecord)].sort(
({ chainId: aChainId }, { chainId: bChainId }) =>
MAIN_CHAINS_IDS.indexOf(bChainId) - MAIN_CHAINS_IDS.indexOf(aChainId)
),
[evmChainsRecord, tezosChainsRecord]
);
const matchingChains = useMemo(() => filterNetworksByName(allChains, searchValue), [allChains, searchValue]);
Expand Down
14 changes: 14 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
ETHEREUM_MAINNET_CHAIN_ID,
ETH_SEPOLIA_CHAIN_ID,
TEZOS_MAINNET_CHAIN_ID,
TempleTezosChainId
} from './temple/types';

export enum ContentScriptType {
ExternalLinksActivity = 'ExternalLinksActivity',
ExternalAdsActivity = 'ExternalAdsActivity',
Expand Down Expand Up @@ -82,3 +89,10 @@ export const SHOULD_BACKUP_MNEMONIC_STORAGE_KEY = 'SHOULD_BACKUP_MNEMONIC';
export const DEFAULT_SEED_PHRASE_WORDS_AMOUNT = 12;

export const DEFAULT_PASSWORD_INPUT_PLACEHOLDER = '••••••••••';

export const MAIN_CHAINS_IDS = [
TEZOS_MAINNET_CHAIN_ID,
ETHEREUM_MAINNET_CHAIN_ID,
TempleTezosChainId.Ghostnet,
ETH_SEPOLIA_CHAIN_ID
];
1 change: 1 addition & 0 deletions src/lib/temple/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface TempleState {

export const TEZOS_MAINNET_CHAIN_ID = 'NetXdQprcVkpaWU';
export const ETHEREUM_MAINNET_CHAIN_ID = 1;
export const ETH_SEPOLIA_CHAIN_ID = 11155111;

export enum TempleTezosChainId {
Mainnet = TEZOS_MAINNET_CHAIN_ID,
Expand Down
4 changes: 2 additions & 2 deletions src/temple/front/chains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TID } from 'lib/i18n';
import { EvmNativeTokenMetadata } from 'lib/metadata/types';
import { TEZOS_MAINNET_CHAIN_ID } from 'lib/temple/types';
import { ETHEREUM_MAINNET_CHAIN_ID, TEZOS_MAINNET_CHAIN_ID } from 'lib/temple/types';
import type { StoredTezosNetwork, StoredEvmNetwork } from 'temple/networks';
import type { TempleChainKind } from 'temple/types';

Expand Down Expand Up @@ -51,4 +51,4 @@ export const useEvmChainByChainId = (evmChainId: number): EvmChain | undefined =
return allEvmChains[evmChainId];
};

export const useEthereumMainnetChain = () => useEvmChainByChainId(1)!;
export const useEthereumMainnetChain = () => useEvmChainByChainId(ETHEREUM_MAINNET_CHAIN_ID)!;
Loading
Loading