Skip to content

Commit

Permalink
chore(suite): update network symbol naming 10
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and tomasklim committed Dec 8, 2024
1 parent 6715904 commit c9c15b4
Show file tree
Hide file tree
Showing 52 changed files with 260 additions and 278 deletions.
4 changes: 2 additions & 2 deletions packages/suite/src/components/suite/CoinGroup/CoinGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';

import styled from 'styled-components';

import { Network, NetworkSymbol } from '@suite-common/wallet-config';
import type { Network, NetworkSymbol } from '@suite-common/wallet-config';

import { useDispatch } from 'src/hooks/suite';
import { changeCoinVisibility } from 'src/actions/settings/walletSettingsActions';
Expand Down Expand Up @@ -35,7 +35,7 @@ export const CoinGroup = ({ networks, enabledNetworks }: CoinGroupProps) => {
dispatch(
openModal({
type: 'advanced-coin-settings',
coin: symbol,
symbol,
}),
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const NavBackends = ({ customBackends, children }: NavBackendsProps) => {
dispatch(
openModal({
type: 'advanced-coin-settings',
coin: backend.coin,
symbol: backend.coin,
}),
),
})),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';

import { variables } from '@trezor/components';
import { networks, NetworkSymbol } from '@suite-common/wallet-config';
import { getNetwork, type NetworkSymbol } from '@suite-common/wallet-config';
import { CoinLogo } from '@trezor/product-components';

import { Modal, Translation } from 'src/components/suite';
Expand Down Expand Up @@ -37,15 +37,15 @@ const Subheader = styled.span`
`;

interface AdvancedCoinSettingsModalProps {
coin: NetworkSymbol;
symbol: NetworkSymbol;
onCancel: () => void;
}

export const AdvancedCoinSettingsModal = ({ coin, onCancel }: AdvancedCoinSettingsModalProps) => {
export const AdvancedCoinSettingsModal = ({ symbol, onCancel }: AdvancedCoinSettingsModalProps) => {
const blockchain = useSelector(state => state.wallet.blockchain);
const network = networks[coin];
const network = getNetwork(symbol);

const { symbol, name, features, testnet: isTestnet } = network;
const { name, features, testnet: isTestnet } = network;
const hasCustomBackend = !!blockchain[symbol].backends.selected;
const label = getCoinLabel(features, isTestnet, hasCustomBackend);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from 'styled-components';

import { Paragraph } from '@trezor/components';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { type NetworkSymbol } from '@suite-common/wallet-config';

import { useSelector } from 'src/hooks/suite';
import { Translation } from 'src/components/suite/Translation';
Expand All @@ -14,13 +14,13 @@ const Wrapper = styled(Paragraph)`
`;

interface ConnectionInfoProps {
coin: NetworkSymbol;
symbol: NetworkSymbol;
}

const ConnectionInfo = ({ coin }: ConnectionInfoProps) => {
const ConnectionInfo = ({ symbol }: ConnectionInfoProps) => {
const blockchain = useSelector(state => state.wallet.blockchain);

const { connected, url, blockHash: hash, blockHeight: height, version } = blockchain[coin];
const { connected, url, blockHash: hash, blockHeight: height, version } = blockchain[symbol];

return (
<Wrapper typographyStyle="hint">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const CustomBackends = ({ network, onCancel }: CustomBackendsProps) => {
const dispatch = useDispatch();
const [torModalOpen, setTorModalOpen] = useState(false);

const { symbol: coin } = network;
const { symbol } = network;

const {
type,
Expand All @@ -59,7 +59,7 @@ export const CustomBackends = ({ network, onCancel }: CustomBackendsProps) => {
removeUrl,
save,
hasOnlyOnions,
} = useBackendsForm(coin);
} = useBackendsForm(symbol);

const onSaveClick = () => {
if (!isTorEnabled && hasOnlyOnions()) {
Expand Down Expand Up @@ -88,7 +88,7 @@ export const CustomBackends = ({ network, onCancel }: CustomBackendsProps) => {
}
};

const { defaultUrls, isLoading } = useDefaultUrls(coin);
const { defaultUrls, isLoading } = useDefaultUrls(symbol);
const { ref: inputRef, ...inputField } = register(name, { validate });
const isEditable = type !== 'default';
const isSubmitButtonDisabled = isEditable && !!error;
Expand Down Expand Up @@ -125,7 +125,7 @@ export const CustomBackends = ({ network, onCancel }: CustomBackendsProps) => {
<BackendInput
key={url}
url={url}
isActive={url === blockchain[coin]?.url}
isActive={url === blockchain[symbol]?.url}
isLoading={isLoading}
onRemove={isEditable ? () => removeUrl(url) : undefined}
/>
Expand Down Expand Up @@ -162,7 +162,7 @@ export const CustomBackends = ({ network, onCancel }: CustomBackendsProps) => {
heading={<Translation id="SETTINGS_ADV_COIN_CONN_INFO_TITLE" />}
margin={{ top: spacings.md }}
>
<ConnectionInfo coin={coin} />
<ConnectionInfo symbol={symbol} />
</CollapsibleBox>

<SaveButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button, H3, Paragraph, variables } from '@trezor/components';
import { getTitleForNetwork } from '@suite-common/wallet-utils';
import { UserContextPayload } from '@suite-common/suite-types';
import { blockchainActions } from '@suite-common/wallet-core';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { type NetworkSymbol } from '@suite-common/wallet-config';
import { CoinLogo } from '@trezor/product-components';

import { Modal, Translation } from 'src/components/suite';
Expand Down Expand Up @@ -52,17 +52,17 @@ const CoinUrls = styled.span`
`;

interface BackendRowProps {
coin: NetworkSymbol;
symbol: NetworkSymbol;
urls: string[];
onSettings: () => void;
}

const BackendRow = ({ coin, urls, onSettings }: BackendRowProps) => (
const BackendRow = ({ symbol, urls, onSettings }: BackendRowProps) => (
<BackendRowWrapper>
<CoinLogo symbol={coin} />
<CoinLogo symbol={symbol} />
<CoinDescription>
<CoinTitle>
<Translation id={getTitleForNetwork(coin)} />
<Translation id={getTitleForNetwork(symbol)} />
</CoinTitle>
<CoinUrls>{urls.join(', ')}</CoinUrls>
</CoinDescription>
Expand Down Expand Up @@ -90,7 +90,7 @@ type DisableTorModalProps = Omit<Extract<UserContextPayload, { type: 'disable-to

export const DisableTorModal = ({ onCancel, decision }: DisableTorModalProps) => {
const dispatch = useDispatch();
const [coin, setCoin] = useState<NetworkSymbol>();
const [symbol, setSymbol] = useState<NetworkSymbol>();
const onionBackends = useCustomBackends().filter(({ urls }) => urls.every(isOnionUrl));

const onDisableTor = () => {
Expand Down Expand Up @@ -145,9 +145,9 @@ export const DisableTorModal = ({ onCancel, decision }: DisableTorModalProps) =>
{onionBackends.map(({ coin, urls }) => (
<BackendRow
key={coin}
coin={coin}
symbol={coin}
urls={urls}
onSettings={() => setCoin(coin)}
onSettings={() => setSymbol(coin)}
/>
))}
</>
Expand All @@ -162,7 +162,9 @@ export const DisableTorModal = ({ onCancel, decision }: DisableTorModalProps) =>
</>
)}
</Modal>
{coin && <AdvancedCoinSettingsModal coin={coin} onCancel={() => setCoin(undefined)} />}
{symbol && (
<AdvancedCoinSettingsModal symbol={symbol} onCancel={() => setSymbol(undefined)} />
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const Row = styled.span`

const getIcon = (symbol?: NetworkSymbol) => symbol && <CoinLogo symbol={symbol} size={24} />;

const useActionAllowed = (path: string, network?: NetworkSymbol) => {
const useActionAllowed = (path: string, symbol?: NetworkSymbol) => {
const selectedAccount = useSelector(state => state.wallet.selectedAccount);
const pathMatch = useRouteMatch(`${process.env.ASSET_PREFIX || ''}${path}`);

return !!pathMatch && selectedAccount?.network?.symbol === network;
return !!pathMatch && selectedAccount?.network?.symbol === symbol;
};

export const CoinProtocolRenderer = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useState, useEffect } from 'react';

import { reconnectBlockchainThunk } from '@suite-common/wallet-core';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { type NetworkSymbol } from '@suite-common/wallet-config';

import { useDispatch } from 'src/hooks/suite';

export const useBackendReconnection = (
coin: NetworkSymbol,
symbol: NetworkSymbol,
identity?: string,
resolveTime?: number,
) => {
Expand All @@ -29,7 +29,7 @@ export const useBackendReconnection = (

const reconnect = async () => {
setProgress(true);
const r: any = await dispatch(reconnectBlockchainThunk({ coin, identity }));
const r: any = await dispatch(reconnectBlockchainThunk({ coin: symbol, identity }));
if (!r.success) {
setProgress(false);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/suite/src/hooks/wallet/sign-verify/useSignVerifyForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { yupResolver } from '@hookform/resolvers/yup';

import { yup } from '@suite-common/validators';
import { isAddressValid } from '@suite-common/wallet-utils';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { type NetworkSymbol } from '@suite-common/wallet-config';

import type { Account } from 'src/types/wallet';

Expand All @@ -14,7 +14,7 @@ export const MAX_LENGTH_SIGNATURE = 255;

type SignVerifyContext = {
isSignPage: boolean;
accountNetwork: NetworkSymbol;
symbol: NetworkSymbol;
};

const signVerifySchema = yup.object({
Expand All @@ -33,9 +33,7 @@ const signVerifySchema = yup.object({
'isAddressValid',
'TR_ADD_TOKEN_ADDRESS_NOT_VALID',
(value, { options }) =>
value &&
options.context?.accountNetwork &&
isAddressValid(value, options.context?.accountNetwork),
value && options.context?.symbol && isAddressValid(value, options.context?.symbol),
)
.required(),
path: yup.string().when('$isSignPage', {
Expand Down Expand Up @@ -78,7 +76,7 @@ export const useSignVerifyForm = (isSignPage: boolean, account: Account) => {
resolver: yupResolver(signVerifySchema),
context: {
isSignPage,
accountNetwork: account?.symbol,
symbol: account?.symbol,
},
defaultValues: DEFAULT_VALUES,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const CoinItem = ({ symbol }: CoinItemProps) => {
dispatch(
openModal({
type: 'advanced-coin-settings',
coin: symbol,
symbol,
}),
);
};
Expand Down
3 changes: 2 additions & 1 deletion suite-common/suite-types/src/modal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Deferred } from '@trezor/utils';
import { Account, AddressType, WalletAccountTransaction } from '@suite-common/wallet-types';
import { RequestEnableTorResponse } from '@suite-common/suite-config';
import { type NetworkSymbol } from '@suite-common/wallet-config';

import { TrezorDevice } from './device';

Expand Down Expand Up @@ -110,7 +111,7 @@ export type UserContextPayload =
}
| {
type: 'advanced-coin-settings';
coin: Account['symbol'];
symbol: NetworkSymbol;
}
| {
type: 'add-token';
Expand Down
16 changes: 8 additions & 8 deletions suite-common/token-definitions/src/__fixtures__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ export const isTokenDefinitionKnownFixtures = [
{
testName: 'Token definition known, case-insensitive network',
tokenDefinitions: ['0xa', '0xb'],
networkSymbol: 'eth' as const,
symbol: 'eth' as const,
contractAddress: '0xA',
result: true,
},
{
testName: 'Token definition unknown, case-sensitive network',
tokenDefinitions: ['0xa', '0xb'],
networkSymbol: 'sol' as const,
symbol: 'sol' as const,
contractAddress: '0xA',
result: false,
},
{
testName: 'Token definition known, case-sensitive network',
tokenDefinitions: ['0xA', '0xb'],
networkSymbol: 'sol' as const,
symbol: 'sol' as const,
contractAddress: '0xA',
result: true,
},
{
testName: 'Token definition not known',
tokenDefinitions: ['0xa', '0xb'],
networkSymbol: 'eth' as const,
symbol: 'eth' as const,
contractAddress: '0xC',
result: false,
},
{
testName: 'Token definitions are undefined',
tokenDefinitions: undefined,
networkSymbol: 'eth' as const,
symbol: 'eth' as const,
contractAddress: '0xA',
result: false,
},
Expand All @@ -41,20 +41,20 @@ export const isTokenDefinitionKnownFixtures = [
export const getSupportedDefinitionTypesFixtures = [
{
testName: 'Supports both token and NFT definitions',
networkSymbol: 'eth' as const,
symbol: 'eth' as const,
features: ['coin-definitions', 'nft-definitions'],
result: [DefinitionType.COIN, DefinitionType.NFT],
},
// Temporarily skipped while token definitions are disabled for Cardano.
// {
// testName: 'Supports only token definitions',
// networkSymbol: 'ada' as const,
// symbol: 'ada' as const,
// features: ['coin-definitions'],
// result: [DefinitionType.COIN],
// },
{
testName: 'Supports neither token nor NFT definitions',
networkSymbol: 'ltc' as const,
symbol: 'ltc' as const,
features: [],
result: [],
},
Expand Down
12 changes: 6 additions & 6 deletions suite-common/token-definitions/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import {

describe('isTokenDefinitionKnown', () => {
isTokenDefinitionKnownFixtures.forEach(
({ testName, tokenDefinitions, networkSymbol, contractAddress, result }) => {
({ testName, tokenDefinitions, symbol, contractAddress, result }) => {
test(testName, () => {
expect(
isTokenDefinitionKnown(tokenDefinitions, networkSymbol, contractAddress),
).toBe(result);
expect(isTokenDefinitionKnown(tokenDefinitions, symbol, contractAddress)).toBe(
result,
);
});
},
);
});

describe('getSupportedDefinitionTypes', () => {
getSupportedDefinitionTypesFixtures.forEach(({ testName, networkSymbol, result }) => {
getSupportedDefinitionTypesFixtures.forEach(({ testName, symbol, result }) => {
test(testName, () => {
expect(getSupportedDefinitionTypes(networkSymbol)).toEqual(result);
expect(getSupportedDefinitionTypes(symbol)).toEqual(result);
});
});
});
Expand Down
Loading

0 comments on commit c9c15b4

Please sign in to comment.