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

fix: networks fixes #1245

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion src/entries/background/handlers/handleProviderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ export const handleProviderRequest = ({
isCustomChain(Number(proposedChainId)) ||
isSupportedChainId(Number(proposedChainId));
if (!supportedChainId) throw new Error('Chain Id not supported');
response = null;
} else {
const {
chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
import { SWAP_INPUT_MASK_ID } from '../InputMask/SwapInputMask/SwapInputMask';
import { ShortcutHint } from '../ShortcutHint/ShortcutHint';

const MENU_SELECTOR_MAX_HEIGHT = DROPDOWN_MENU_ITEM_HEIGHT * 5.5;
const MENU_SELECTOR_MAX_HEIGHT = DROPDOWN_MENU_ITEM_HEIGHT * 6;

export const SwitchNetworkMenuSelector = ({
selectedValue,
Expand Down
4 changes: 3 additions & 1 deletion src/entries/popup/pages/messages/AccountSigningWith.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { i18n } from '~/core/languages';
import { ActiveSession } from '~/core/state/appSessions';
import { ChainId, ChainNameDisplay } from '~/core/types/chains';
import { getChain } from '~/core/utils/chains';
import { Inline, Stack, Text } from '~/design-system';
import { ChainBadge } from '~/entries/popup/components/ChainBadge/ChainBadge';
import { WalletAvatar } from '~/entries/popup/components/WalletAvatar/WalletAvatar';
Expand All @@ -18,6 +19,7 @@ export interface SelectedNetwork {

function WalletNativeBalance({ session }: { session: ActiveSession }) {
const chainId = session?.chainId || ChainId.mainnet;
const chain = getChain({ chainId });
const { nativeAsset } = useNativeAsset({
chainId,
address: session?.address,
Expand All @@ -42,7 +44,7 @@ function WalletNativeBalance({ session }: { session: ActiveSession }) {
</Text>
<Text size="12pt" weight="semibold" color="labelQuaternary">
{i18n.t('approve_request.on_chain', {
chain: ChainNameDisplay[chainId],
chain: ChainNameDisplay[chainId] || chain.name,
})}
</Text>
</Inline>
Expand Down
97 changes: 54 additions & 43 deletions src/entries/popup/pages/settings/rpcs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { useLocation } from 'react-router-dom';
import { Address, Chain } from 'wagmi';

import { i18n } from '~/core/languages';
import { SUPPORTED_CHAINS, getDefaultRPC } from '~/core/references';
import {
SUPPORTED_CHAINS,
SUPPORTED_CHAIN_IDS,
getDefaultRPC,
} from '~/core/references';
import { selectUserAssetsDictByChain } from '~/core/resources/_selectors/assets';
import { useCustomNetworkAssets } from '~/core/resources/assets/customNetworkAssets';
import { useCurrentAddressStore, useCurrentCurrencyStore } from '~/core/state';
Expand Down Expand Up @@ -69,7 +73,9 @@ export function SettingsNetworksRPCs() {
},
);

const customNetworkAssetsForChain = customNetworkAssets?.[chainId];
const customNetworkAssetsForChain = Object.values(
customNetworkAssets?.[chainId] || {},
).filter((asset) => !asset.isNativeAsset);

const navigate = useRainbowNavigate();
const { developerToolsEnabled } = useDeveloperToolsEnabledStore();
Expand Down Expand Up @@ -243,7 +249,7 @@ export function SettingsNetworksRPCs() {
key={chain.name}
rightComponent={
chain.rpcUrls.default.http[0] ===
rainbowChain.activeRpcUrl ? (
rainbowChain.activeRpcUrl ? (
<MenuItem.SelectionIcon />
) : null
}
Expand All @@ -259,8 +265,8 @@ export function SettingsNetworksRPCs() {
rpcUrl: chain.rpcUrls.default.http[0],
})
? i18n.t(
'settings.networks.custom_rpc.rainbow_default_rpc',
)
'settings.networks.custom_rpc.rainbow_default_rpc',
)
: chain.rpcUrls.default.http[0]}
</TextOverflow>
}
Expand All @@ -285,7 +291,7 @@ export function SettingsNetworksRPCs() {
) : null}

{featureFlags.custom_rpc &&
(activeCustomRPC?.name || supportedChain?.name) ? (
(activeCustomRPC?.name || supportedChain?.name) ? (
<Menu>
<MenuItem
first
Expand Down Expand Up @@ -372,10 +378,10 @@ export function SettingsNetworksRPCs() {
weight={'medium'}
>
{chainIdMap[chainId]?.includes(chain.id) &&
chain.id !== chainId
chain.id !== chainId
? i18n.t(
'settings.networks.custom_rpc.rainbow_default',
)
'settings.networks.custom_rpc.rainbow_default',
)
: chain.rpcUrls.default.http[0]}
</Text>
}
Expand All @@ -398,20 +404,17 @@ export function SettingsNetworksRPCs() {
</Box>
</Menu>
) : null}
</MenuContainer>

{featureFlags.custom_rpc &&
Object.values(customNetworkAssetsForChain || {}).length ? (
<Menu>
<Box padding="20px">
<Stack space="14px">
<Text align="left" color="label" size="14pt" weight="medium">
{i18n.t('settings.networks.custom_rpc.tokens')}
</Text>
{featureFlags.custom_rpc && customNetworkAssetsForChain.length ? (
<Menu>
<Box padding="20px">
<Stack space="14px">
<Text align="left" color="label" size="14pt" weight="medium">
{i18n.t('settings.networks.custom_rpc.tokens')}
</Text>

<Box width="full">
{Object.values(customNetworkAssetsForChain || {})?.map(
(asset, i) => (
<Box width="full">
{customNetworkAssetsForChain?.map((asset, i) => (
<ContextMenu key={i}>
<ContextMenuTrigger>
<Box marginHorizontal="-12px">
Expand Down Expand Up @@ -475,29 +478,37 @@ export function SettingsNetworksRPCs() {
</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
),
)}
</Box>
</Stack>
</Box>
</Menu>
) : null}
<Menu>
<MenuItem
first
last
leftComponent={
<Symbol symbol="trash.fill" weight="medium" size={18} color="red" />
}
onClick={() => handleRemoveNetwork({ chainId })}
titleComponent={
<MenuItem.Title
color="red"
text={i18n.t('settings.networks.custom_rpc.remove_network')}
))}
</Box>
</Stack>
</Box>
</Menu>
) : null}

{!SUPPORTED_CHAIN_IDS.includes(chainId) ? (
<Menu>
<MenuItem
first
last
leftComponent={
<Symbol
symbol="trash.fill"
weight="medium"
size={18}
color="red"
/>
}
onClick={() => handleRemoveNetwork({ chainId })}
titleComponent={
<MenuItem.Title
color="red"
text={i18n.t('settings.networks.custom_rpc.remove_network')}
/>
}
/>
}
/>
</Menu>
</Menu>
) : null}
</MenuContainer>
</Box>
);
}
Loading