Skip to content

Commit

Permalink
chore(suite): update network symbol naming
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and tomasklim committed Dec 4, 2024
1 parent 7063601 commit b6003e8
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { spacings, spacingsPx } from '@trezor/theme';
import { AssetLogo, Badge, Column, Row, Text } from '@trezor/components';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { getContractAddressForNetwork } from '@suite-common/wallet-utils';
import { getContractAddressForNetworkSymbol } from '@suite-common/wallet-utils';

import { CoinLogo } from '../CoinLogo/CoinLogo';
import { AssetOptionBaseProps } from './SelectAssetModal';
Expand Down Expand Up @@ -63,7 +63,10 @@ export const AssetItem = ({
coingeckoId={coingeckoId}
contractAddress={
symbolExtended && contractAddress
? getContractAddressForNetwork(symbolExtended, contractAddress)
? getContractAddressForNetworkSymbol(
symbolExtended,
contractAddress,
)
: undefined
}
placeholder={ticker.toUpperCase()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled, { css } from 'styled-components';
import { AssetLogo, useElevation } from '@trezor/components';
import { getCoingeckoId, NetworkSymbol } from '@suite-common/wallet-config';
import { TokenInfo } from '@trezor/connect';
import { getContractAddressForNetwork } from '@suite-common/wallet-utils';
import { getContractAddressForNetworkSymbol } from '@suite-common/wallet-utils';
import { borders, Elevation, mapElevationToBackground, mapElevationToBorder } from '@trezor/theme';

export type TokenIconSetProps = {
Expand Down Expand Up @@ -57,7 +57,7 @@ export const TokenIconSet = ({ symbol, tokens }: TokenIconSetProps) => {
key={token.contract}
size={20}
coingeckoId={coingeckoId ?? ''}
contractAddress={getContractAddressForNetwork(symbol, token.contract)}
contractAddress={getContractAddressForNetworkSymbol(symbol, token.contract)}
placeholder={token.symbol?.toUpperCase() ?? ''}
placeholderWithTooltip={false}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const exportTransactionsThunk = createThunk(
// Prepare data in right format
const data = await formatData(
{
coin: account.symbol,
symbol: account.symbol,
accountName,
type,
transactions: filteredTransaction,
Expand Down
24 changes: 12 additions & 12 deletions packages/suite/src/utils/suite/__fixtures__/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,14 @@ export const getEthNetworkForWalletSdkFixture = [
{
description: 'should return "holesky" for "thol"',
args: {
symbol: 'thol',
symbol: 'thol' as const,
},
result: 'holesky',
},
{
description: 'should return "mainnet" for "eth"',
args: {
symbol: 'eth',
symbol: 'eth' as const,
},
result: 'mainnet',
},
Expand All @@ -697,7 +697,7 @@ export const getEthNetworkForWalletSdkFixture = [
{
description: 'should return "mainnet" for an unknown symbol',
args: {
symbol: 'unknown',
symbol: 'unknown' as const,
},
result: 'mainnet',
},
Expand All @@ -712,7 +712,7 @@ export const getInstantStakeTypeFixture = [
to: '0x19449f0f696703Aa3b1485DfA2d855F33659397a',
},
address: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: 'stake',
},
Expand All @@ -724,7 +724,7 @@ export const getInstantStakeTypeFixture = [
to: '0x66cb3AeD024740164EBcF04e292dB09b5B63A2e1',
},
address: 'address',
symbol: 'thol',
symbol: 'thol' as const,
},
result: 'stake',
},
Expand All @@ -736,7 +736,7 @@ export const getInstantStakeTypeFixture = [
to: 'address',
},
address: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: 'unstake',
},
Expand All @@ -748,7 +748,7 @@ export const getInstantStakeTypeFixture = [
to: 'address',
},
address: 'address',
symbol: 'thol',
symbol: 'thol' as const,
},
result: 'unstake',
},
Expand All @@ -760,7 +760,7 @@ export const getInstantStakeTypeFixture = [
to: 'address',
},
address: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: 'claim',
},
Expand All @@ -772,7 +772,7 @@ export const getInstantStakeTypeFixture = [
to: 'address',
},
address: 'address',
symbol: 'thol',
symbol: 'thol' as const,
},
result: 'claim',
},
Expand All @@ -784,7 +784,7 @@ export const getInstantStakeTypeFixture = [
to: 'unknown',
},
address: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: null,
},
Expand Down Expand Up @@ -813,7 +813,7 @@ export const getChangedInternalTxFixture = [
{ type: 'sent', txid: '4', internalTransfers: [] },
],
selectedAccountAddress: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: null,
},
Expand All @@ -840,7 +840,7 @@ export const getChangedInternalTxFixture = [
{ type: 'sent', txid: '2', internalTransfers: [] },
],
selectedAccountAddress: 'address',
symbol: 'eth',
symbol: 'eth' as const,
},
result: {
from: '0xD523794C879D9eC028960a231F866758e405bE34',
Expand Down
7 changes: 3 additions & 4 deletions packages/suite/src/utils/suite/__tests__/stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '@trezor/connect/src/types/api/blockchainEstimateFee';
import { WalletAccountTransaction } from '@suite-common/wallet-types';
import { ValidatorsQueue } from '@suite-common/wallet-core';
import { NetworkSymbol } from '@suite-common/wallet-config';

import {
transformTx,
Expand Down Expand Up @@ -226,7 +225,7 @@ describe('getAdjustedGasLimitConsumption', () => {
describe('getEthNetworkForWalletSdk', () => {
getEthNetworkForWalletSdkFixture.forEach(test => {
it(test.description, async () => {
const result = await getEthNetworkForWalletSdk(test.args.symbol as NetworkSymbol);
const result = await getEthNetworkForWalletSdk(test.args.symbol);
expect(result).toEqual(test.result);
});
});
Expand All @@ -238,7 +237,7 @@ describe('getInstantStakeType', () => {
const result = await getInstantStakeType(
test.args.internalTransfer as InternalTransfer,
test.args.address,
test.args.symbol as NetworkSymbol,
test.args.symbol,
);
expect(result).toEqual(test.result);
});
Expand All @@ -252,7 +251,7 @@ describe('getChangedInternalTx', () => {
test.args.prevTxs as WalletAccountTransaction[],
test.args.currentTxs as WalletAccountTransaction[],
test.args.selectedAccountAddress,
test.args.symbol as NetworkSymbol,
test.args.symbol,
);
expect(result).toEqual(test.result);
});
Expand Down
7 changes: 5 additions & 2 deletions packages/suite/src/utils/suite/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ const secondsToDays = (seconds: number) => Math.round(seconds / 60 / 60 / 24);

type EthNetwork = 'holesky' | 'mainnet';

export const getEthNetworkForWalletSdk = (symbol: NetworkSymbol): EthNetwork => {
export const getEthNetworkForWalletSdk = (
symbol: NetworkSymbol | 'unknown' | undefined,
): EthNetwork => {
const ethNetworks: PartialRecord<NetworkSymbol, EthNetwork> = {
thol: 'holesky',
eth: 'mainnet',
};
const network = symbol && symbol !== 'unknown' ? ethNetworks[symbol] : ethNetworks.eth;

return ethNetworks[symbol] || ethNetworks.eth!;
return network!;
};

export const getAdjustedGasLimitConsumption = (estimatedFee: Success<BlockchainEstimatedFee>) =>
Expand Down
11 changes: 5 additions & 6 deletions packages/suite/src/utils/wallet/__fixtures__/tokenUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EnhancedTokenInfo, TokenDefinition } from '@suite-common/token-definitions';
import { NetworkSymbol } from '@suite-common/wallet-config';

export const getTokensFixtures = [
{
Expand All @@ -8,7 +7,7 @@ export const getTokensFixtures = [
{ contract: '0x1', balance: '100' } as EnhancedTokenInfo,
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo,
],
symbol: 'eth' as NetworkSymbol,
symbol: 'eth' as const,
coinDefinitions: {
error: false,
isLoading: false,
Expand Down Expand Up @@ -36,7 +35,7 @@ export const getTokensFixtures = [
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo,
{ contract: '0x3', balance: '0' } as EnhancedTokenInfo,
],
symbol: 'eth' as NetworkSymbol,
symbol: 'eth' as const,
coinDefinitions: {
error: false,
isLoading: false,
Expand All @@ -61,7 +60,7 @@ export const getTokensFixtures = [
{ contract: '0x2', balance: '200' } as EnhancedTokenInfo,
{ contract: '0x3', balance: '0' } as EnhancedTokenInfo,
],
symbol: 'eth' as NetworkSymbol,
symbol: 'eth' as const,
coinDefinitions: {
error: false,
isLoading: false,
Expand All @@ -88,7 +87,7 @@ export const getTokensFixtures = [
{ contract: '0x4', balance: '0' } as EnhancedTokenInfo,
{ contract: '0x5', balance: '0' } as EnhancedTokenInfo,
],
symbol: 'eth' as NetworkSymbol,
symbol: 'eth' as const,
coinDefinitions: {
error: false,
isLoading: false,
Expand Down Expand Up @@ -119,7 +118,7 @@ export const getTokensFixtures = [
{ contract: '0x2', balance: '200', symbol: 'DEF' } as EnhancedTokenInfo,
{ contract: '0x3', balance: '0', symbol: 'GHI' } as EnhancedTokenInfo,
],
symbol: 'eth' as NetworkSymbol,
symbol: 'eth' as const,
coinDefinitions: {
error: false,
isLoading: false,
Expand Down
18 changes: 9 additions & 9 deletions packages/suite/src/utils/wallet/coinmarket/coinmarketUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import {
Network,
NetworkSymbol,
getCoingeckoId,
getNetwork,
getNetworkByCoingeckoId,
getNetworkByCoingeckoNativeId,
getNetworkFeatures,
getNetworkType,
networks,
} from '@suite-common/wallet-config';
import TrezorConnect from '@trezor/connect';
import { DefinitionType, isTokenDefinitionKnown } from '@suite-common/token-definitions';
import {
getContractAddressForNetwork,
getContractAddressForNetworkSymbol,
substituteBip43Path,
sortByCoin,
} from '@suite-common/wallet-utils';
Expand Down Expand Up @@ -75,7 +75,7 @@ export function testnetToProdCryptoId(cryptoId: CryptoId): CryptoId {
}

export const getNetworkName = (symbol: NetworkSymbol) => {
return networks[symbol].name;
return getNetwork(symbol).name;
};

interface CoinmarketGetDecimalsProps {
Expand Down Expand Up @@ -353,7 +353,7 @@ export const coinmarketBuildAccountOptions = ({
accountType,
} = account;

if (!networks[accountSymbol].coingeckoNativeId) {
if (!getNetwork(accountSymbol).coingeckoNativeId) {
return;
}

Expand All @@ -365,10 +365,10 @@ export const coinmarketBuildAccountOptions = ({
index,
});

const accountDecimals = networks[accountSymbol].decimals;
const accountDecimals = getNetwork(accountSymbol).decimals;
const options: CoinmarketAccountOptionsGroupOptionProps[] = [
{
value: networks[accountSymbol].coingeckoNativeId as CryptoId,
value: getNetwork(accountSymbol).coingeckoNativeId as CryptoId,
label: accountSymbol.toUpperCase(),
cryptoName: getNetworkName(accountSymbol),
descriptor,
Expand All @@ -391,7 +391,7 @@ export const coinmarketBuildAccountOptions = ({
return;
}

const contractAddress = getContractAddressForNetwork(accountSymbol, contract);
const contractAddress = getContractAddressForNetworkSymbol(accountSymbol, contract);

const tokenCryptoId = toTokenCryptoId(accountSymbol, contractAddress);
if (supportedCryptoIds && !supportedCryptoIds.has(tokenCryptoId)) {
Expand Down Expand Up @@ -510,8 +510,8 @@ export const getAddressAndTokenFromAccountOptionsGroupProps = (
return { address: '', token: null };
}

const networkSymbol = cryptoIdToSymbol(selected.value);
const networkType = networkSymbol ? getNetworkType(networkSymbol) : null;
const symbol = cryptoIdToSymbol(selected.value);
const networkType = symbol ? getNetworkType(symbol) : null;

// set token address for ERC20 transaction to estimate the fees more precisely
if (networkType === 'ethereum') {
Expand Down
Loading

0 comments on commit b6003e8

Please sign in to comment.