Skip to content

Commit

Permalink
fix: BX-1582 (#1647)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sinclair <[email protected]>
  • Loading branch information
estebanmino and DanielSinclair authored Aug 2, 2024
1 parent 9362195 commit 6c07087
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/entries/background/handlers/handleProviderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,10 @@ export const handleProviderRequest = ({
};
const rainbowChain = rainbowChains[chainObject.id];
const alreadyAddedRpcUrl = rainbowChain.chains.find(
(chain: Chain) =>
chain.rpcUrls.default.http[0] === rpcUrl &&
rainbowChain.activeRpcUrl === rpcUrl,
(chain: Chain) => chain.rpcUrls.default.http[0] === rpcUrl,
);
const activeRpc = rainbowChain.activeRpcUrl === rpcUrl;
const isActiveRpc = rainbowChain.activeRpcUrl === rpcUrl;

if (!alreadyAddedRpcUrl) {
addCustomRPC({ chain: chainObject });
addUserChain({ chainId: chainObject.id });
Expand All @@ -311,7 +310,7 @@ export const handleProviderRequest = ({

let rpcStatus;
if (alreadyAddedRpcUrl) {
if (activeRpc) {
if (isActiveRpc) {
rpcStatus = IN_DAPP_NOTIFICATION_STATUS.already_active;
} else {
rpcStatus = IN_DAPP_NOTIFICATION_STATUS.already_added;
Expand Down
32 changes: 23 additions & 9 deletions src/entries/popup/pages/settings/rpcs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,35 @@ export function SettingsNetworksRPCs() {
},
];

const supportedTestnetChains = useMemo(
() =>
getSupportedChains({
testnets: true,
}).filter((chain) => {
return chainIdMap[chainId]?.includes(chain.id) && chain.id !== chainId;
}),
[chainId],
);

const testnetChains = useMemo(() => {
const customTestnetChains =
rainbowChains[Number(chainId)]?.chains?.filter(
(chain) => chain.testnet,
) || [];
const supportedTestnetChains = getSupportedChains({
testnets: true,
}).filter((chain) => {
return chainIdMap[chainId]?.includes(chain.id) && chain.id !== chainId;
});

return [...customTestnetChains, ...supportedTestnetChains];
}, [chainId, rainbowChains]);
}, [chainId, rainbowChains, supportedTestnetChains]);

const handleRemoveRPC = useCallback(
(chain: Chain) => {
removeCustomRPC({
rpcUrl: chain.rpcUrls.default.http[0],
});
removeRainbowChainAssets({ chainId });
removeUserChain({ chainId });
// If there's no default chain & only had one chain, go back
const allChainsCount = [...mainnetChains, ...testnetChains].length;
if (!supportedChain && allChainsCount === 1) {
removeUserChain({ chainId });
navigate(-1);
}
},
Expand Down Expand Up @@ -254,7 +260,8 @@ export function SettingsNetworksRPCs() {
<ContextMenu>
<ContextMenuTrigger
disabled={
mainnetChains[index].name === supportedChain?.name
supportedChain?.rpcUrls.default.http[0] ===
chain.rpcUrls.default.http[0]
}
>
<MenuItem
Expand Down Expand Up @@ -517,7 +524,14 @@ export function SettingsNetworksRPCs() {
testId={`network-row-${chain.name}`}
>
<ContextMenu>
<ContextMenuTrigger>
<ContextMenuTrigger
disabled={
supportedTestnetChains.find(
(testNetChain) => testNetChain.id === chain.id,
)?.rpcUrls.default.http[0] ===
chain.rpcUrls.default.http[0]
}
>
<MenuItem
first={!supportedChain && index === 0}
leftComponent={
Expand Down

0 comments on commit 6c07087

Please sign in to comment.