Skip to content

Commit

Permalink
fix: Add network change injection method (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Sep 6, 2023
1 parent 93b5008 commit a4b491a
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { InjectionMessage, InjectionMessageInstance } from '../message';
import { InjectCore } from './core';
import { NetworkMetainfo } from '@states/network';

function existsChainId(network: NetworkMetainfo, chainId: string) {
function matchChainId(network: NetworkMetainfo, chainId: string) {
return network.chainId === chainId;
}
function existsRPCUrl(network: NetworkMetainfo, rpcUrl: string) {
return network.rpcUrl === rpcUrl;
function matchRPCUrl(network: NetworkMetainfo, rpcUrl: string) {
return network.rpcUrl === rpcUrl.replace(/\/$/, '');
}

export const addNetwork = async (
Expand All @@ -30,7 +30,7 @@ export const addNetwork = async (
const existNetwork =
networks.findIndex(
(current) =>
(existsChainId(current, chainId) || existsRPCUrl(current, chainId)) &&
(matchChainId(current, chainId) || matchRPCUrl(current, rpcUrl)) &&
current.deleted !== true,
) > -1;
if (existNetwork) {
Expand Down

0 comments on commit a4b491a

Please sign in to comment.