Skip to content

Commit

Permalink
chore(suite): update network symbol naming 8
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive committed Dec 6, 2024
1 parent 0fc5924 commit 3a820b2
Show file tree
Hide file tree
Showing 46 changed files with 178 additions and 197 deletions.
12 changes: 6 additions & 6 deletions suite-common/formatters/src/utils/convert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { networks, NetworkSymbol } from '@suite-common/wallet-config';
import { getNetwork, type NetworkSymbol } from '@suite-common/wallet-config';
import {
amountToSmallestUnit,
formatNetworkAmount,
Expand All @@ -9,37 +9,37 @@ import { BigNumber } from '@trezor/utils/src/bigNumber';

type ConvertInput = {
amount: string | null;
networkSymbol: NetworkSymbol;
symbol: NetworkSymbol;
isAmountInSats?: boolean;
rate?: number;
};

export const convertCryptoToFiatAmount = ({
amount,
networkSymbol,
symbol,
isAmountInSats = true,
rate,
}: ConvertInput): string | null => {
if (!amount) {
return null;
}

const networkAmount = isAmountInSats ? formatNetworkAmount(amount, networkSymbol) : amount;
const networkAmount = isAmountInSats ? formatNetworkAmount(amount, symbol) : amount;

return toFiatCurrency(networkAmount, rate);
};

export const convertFiatToCryptoAmount = ({
amount,
networkSymbol,
symbol,
isAmountInSats = true,
rate,
}: ConvertInput): string | null => {
if (!amount) {
return null;
}

const { decimals } = networks[networkSymbol];
const { decimals } = getNetwork(symbol);
const cryptoAmount = fromFiatCurrency(amount, decimals, rate);

if (!cryptoAmount || !isAmountInSats) {
Expand Down
4 changes: 2 additions & 2 deletions suite-common/formatters/src/utils/tests/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('convertCryptoToFiatAmount', () => {
expect(
convertCryptoToFiatAmount({
amount,
networkSymbol: 'btc',
symbol: 'btc',
isAmountInSats,
rate: 22666,
}),
Expand All @@ -47,7 +47,7 @@ describe('convertFiatToCryptoAmount', () => {
expect(
convertFiatToCryptoAmount({
amount,
networkSymbol: 'btc',
symbol: 'btc',
isAmountInSats,
rate: 22666,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export const prepareTokenDefinitionsMiddleware = createMiddlewareWithExtraDeps(
next(action);

if (action.type === CHANGE_NETWORKS) {
action.payload.forEach((networkSymbol: NetworkSymbol) => {
const tokenDefinitions = selectNetworkTokenDefinitions(getState(), networkSymbol);
action.payload.forEach((symbol: NetworkSymbol) => {
const tokenDefinitions = selectNetworkTokenDefinitions(getState(), symbol);

if (!tokenDefinitions) {
const definitionTypes = getSupportedDefinitionTypes(networkSymbol);
const definitionTypes = getSupportedDefinitionTypes(symbol);

definitionTypes.forEach(type => {
dispatch(
getTokenDefinitionThunk({
networkSymbol,
symbol,
type,
}),
);
Expand Down
14 changes: 7 additions & 7 deletions suite-common/token-definitions/src/tokenDefinitionsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export const prepareTokenDefinitionsReducer = createReducerWithExtraDeps(
(builder, extra) => {
builder
.addCase(getTokenDefinitionThunk.pending, (state, action) => {
const { networkSymbol } = action.meta.arg;
const { symbol } = action.meta.arg;

if (!state[networkSymbol]) {
state[networkSymbol] = {
if (!state[symbol]) {
state[symbol] = {
coin: {
error: false,
data: undefined,
Expand All @@ -33,9 +33,9 @@ export const prepareTokenDefinitionsReducer = createReducerWithExtraDeps(
}
})
.addCase(getTokenDefinitionThunk.fulfilled, (state, action) => {
const { networkSymbol, type } = action.meta.arg;
const { symbol, type } = action.meta.arg;

const definitions = state[networkSymbol];
const definitions = state[symbol];

if (definitions) {
definitions[type] = {
Expand All @@ -48,9 +48,9 @@ export const prepareTokenDefinitionsReducer = createReducerWithExtraDeps(
}
})
.addCase(getTokenDefinitionThunk.rejected, (state, action) => {
const { networkSymbol, type } = action.meta.arg;
const { symbol, type } = action.meta.arg;

const definitions = state[networkSymbol];
const definitions = state[symbol];

if (definitions) {
definitions[type] = {
Expand Down
14 changes: 7 additions & 7 deletions suite-common/token-definitions/src/tokenDefinitionsThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export const getTokenDefinitionThunk = createThunk(
`${TOKEN_DEFINITIONS_MODULE}/getNftTokenDefinition`,
async (
params: {
networkSymbol: NetworkSymbol;
symbol: NetworkSymbol;
type: DefinitionType;
},
{ fulfillWithValue, rejectWithValue },
) => {
const { networkSymbol, type } = params;
const coingeckoId = getCoingeckoId(networkSymbol);
const { symbol, type } = params;
const coingeckoId = getCoingeckoId(symbol);

try {
if (!coingeckoId) {
Expand Down Expand Up @@ -86,10 +86,10 @@ export const initTokenDefinitionsThunk = createThunk(
const enabledNetworks = extra.selectors.selectTokenDefinitionsEnabledNetworks(getState());

const promises = enabledNetworks
.map((networkSymbol: NetworkSymbol) => {
let definitionTypes = getSupportedDefinitionTypes(networkSymbol);
.map(symbol => {
let definitionTypes = getSupportedDefinitionTypes(symbol);

const tokenDefinitions = selectNetworkTokenDefinitions(getState(), networkSymbol);
const tokenDefinitions = selectNetworkTokenDefinitions(getState(), symbol);

if (tokenDefinitions) {
// Filter out definition types that have data or are in a loading state
Expand All @@ -105,7 +105,7 @@ export const initTokenDefinitionsThunk = createThunk(
return definitionTypes.map(type =>
dispatch(
getTokenDefinitionThunk({
networkSymbol,
symbol,
type,
}),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const AccountsListItem = ({
showDivider={showDivider}
onPress={handleOnPress}
disabled={disabled}
icon={<RoundedIcon networkSymbol={account.symbol} />}
icon={<RoundedIcon symbol={account.symbol} />}
title={
shouldShowAccountLabel ? (
accountLabel
Expand All @@ -125,7 +125,7 @@ export const AccountsListItem = ({
value={fiatBalance}
/>
) : (
<CryptoToFiatAmountFormatter value={account.balance} network={account.symbol} />
<CryptoToFiatAmountFormatter value={account.balance} symbol={account.symbol} />
)
}
secondaryValue={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const AccountsListStakingItem = ({
mainValue={
<CryptoToFiatAmountFormatter
value={stakingCryptoBalance}
network={account.symbol}
symbol={account.symbol}
isBalance
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ export const AccountsListTokenItem = ({
isFirst={isFirst}
isLast={isLast}
onPress={onSelectAccount}
icon={<RoundedIcon networkSymbol={account.symbol} contractAddress={token.contract} />}
icon={<RoundedIcon symbol={account.symbol} contractAddress={token.contract} />}
title={getTokenName(token.name)}
mainValue={
<TokenToFiatAmountFormatter
networkSymbol={account.symbol}
symbol={account.symbol}
value={balance}
contract={token.contract}
/>
}
secondaryValue={
<TokenAmountFormatter
value={balance}
symbol={tokenSymbol}
tokenSymbol={tokenSymbol}
numberOfLines={1}
ellipsizeMode="tail"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const SelectableNetworkItem = ({ symbol, onPress, rightIcon }: Selectable
testID={`@onboarding/select-coin/${symbol}`}
>
<Box flexDirection="row" alignItems="center">
<RoundedIcon networkSymbol={symbol} />
<RoundedIcon symbol={symbol} />
<Box style={applyStyle(selectableAssetContentStyle)}>
<Box flex={1} justifyContent="space-between" alignItems="flex-start">
<Text variant="body">{networkName}</Text>
Expand Down
8 changes: 4 additions & 4 deletions suite-native/assets/src/components/AssetItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const CryptoAmount = React.memo(({ network }: { network: NetworkSymbol }) => {
);
});

const FiatAmount = React.memo(({ network }: { network: NetworkSymbol }) => {
const fiatValue = useSelector((state: AssetsRootState) => selectAssetFiatValue(state, network));
const FiatAmount = React.memo(({ symbol }: { symbol: NetworkSymbol }) => {
const fiatValue = useSelector((state: AssetsRootState) => selectAssetFiatValue(state, symbol));

return <FiatAmountFormatter network={network} value={fiatValue} />;
return <FiatAmountFormatter symbol={symbol} value={fiatValue} />;
});

const PercentageIcon = React.memo(({ network }: { network: NetworkSymbol }) => {
Expand Down Expand Up @@ -129,7 +129,7 @@ export const AssetItem = React.memo(({ cryptoCurrencySymbol, onPress }: AssetIte
)}
</>
}
mainValue={<FiatAmount network={cryptoCurrencySymbol} />}
mainValue={<FiatAmount symbol={cryptoCurrencySymbol} />}
secondaryValue={<CryptoAmount network={cryptoCurrencySymbol} />}
/>
);
Expand Down
8 changes: 3 additions & 5 deletions suite-native/atoms/src/RoundedIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Box, BoxProps } from './Box';

export type RoundedIconProps = {
name?: IconName;
networkSymbol?: NetworkSymbol;
symbol?: NetworkSymbol;
contractAddress?: TokenAddress;
color?: Color;
iconSize?: IconSize;
Expand Down Expand Up @@ -40,7 +40,7 @@ const iconContainerStyle = prepareNativeStyle<{ backgroundColor?: Color; contain

export const RoundedIcon = ({
name,
networkSymbol,
symbol,
contractAddress,
color,
iconSize,
Expand All @@ -59,9 +59,7 @@ export const RoundedIcon = ({
{name && name in icons ? (
<Icon name={name as IconName} color={color} size={iconSize} />
) : (
networkSymbol && (
<CryptoIcon symbol={networkSymbol} contractAddress={contractAddress} />
)
symbol && <CryptoIcon symbol={symbol} contractAddress={contractAddress} />
)}
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const CoinAmountFormatter = ({
<TokenAmountFormatter
decimals={decimals ?? tokenInfo.decimals}
value={value}
symbol={tokenSymbol}
tokenSymbol={tokenSymbol}
{...restProps}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export const CoinToFiatAmountFormatter = ({
decimals,
...restProps
}: CoinToFiatAmountFormatterProps) => {
const networkSymbol = useSelector((state: AccountsRootState) =>
const symbol = useSelector((state: AccountsRootState) =>
selectAccountNetworkSymbol(state, accountKey),
);

const tokenInfo = useSelector((state: TokensRootState) =>
selectAccountTokenInfo(state, accountKey, tokenContract),
);

if (!networkSymbol) {
if (!symbol) {
return null;
}

Expand All @@ -43,12 +43,12 @@ export const CoinToFiatAmountFormatter = ({
<TokenToFiatAmountFormatter
value={value}
contract={tokenInfo.contract}
networkSymbol={networkSymbol}
symbol={symbol}
decimals={decimals ?? tokenInfo.decimals}
{...restProps}
/>
);
}

return <CryptoToFiatAmountFormatter value={value} network={networkSymbol} {...restProps} />;
return <CryptoToFiatAmountFormatter value={value} symbol={symbol} {...restProps} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FiatAmountFormatter } from './FiatAmountFormatter';

type CryptoToFiatAmountFormatterProps = FormatterProps<string | number | null> &
TextProps & {
network: NetworkSymbol;
symbol: NetworkSymbol;
historicRate?: number;
useHistoricRate?: boolean;
isBalance?: boolean;
Expand All @@ -17,15 +17,15 @@ type CryptoToFiatAmountFormatterProps = FormatterProps<string | number | null> &

export const CryptoToFiatAmountFormatter = ({
value,
network,
symbol,
historicRate,
useHistoricRate,
isBalance = false,
isLoading = false,
...otherProps
}: CryptoToFiatAmountFormatterProps) => {
const fiatValue = useFiatFromCryptoValue({
network,
symbol,
historicRate,
useHistoricRate,
isBalance,
Expand All @@ -34,7 +34,7 @@ export const CryptoToFiatAmountFormatter = ({

return (
<FiatAmountFormatter
network={network}
symbol={symbol}
value={fiatValue}
isLoading={isLoading}
{...otherProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ import { AmountText } from './AmountText';

type FiatAmountFormatterProps = FormatterProps<string | null> &
TextProps & {
network?: NetworkSymbol;
symbol?: NetworkSymbol;
isDiscreetText?: boolean;
isForcedDiscreetMode?: boolean;
isLoading?: boolean;
};

export const FiatAmountFormatter = React.memo(
({
network,
symbol,
value,
isDiscreetText = true,
isLoading = false,
...otherProps
}: FiatAmountFormatterProps) => {
const { FiatAmountFormatter: formatter } = useFormatters();

if (!!network && isTestnet(network)) {
if (!!symbol && isTestnet(symbol)) {
return <EmptyAmountText />;
}
if (isLoading || value === null) {
Expand Down
Loading

0 comments on commit 3a820b2

Please sign in to comment.