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 multiples connections to Cere,Ethereum,Polygon #87

Merged
merged 3 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ export const EVMDestinationAdaptorProvider = ({
setFallback,
address,
analytics,
destinationBridge,
setDestinationBridge,
} = useNetworkManager();

const [destinationBridge, setDestinationBridge] = useState<
Bridge | undefined
>(undefined);

useEffect(() => {
if (destinationBridge) return;
const provider = getProvider(destinationChainConfig);
Expand All @@ -48,7 +45,7 @@ export const EVMDestinationAdaptorProvider = ({
);
setDestinationBridge(bridge);
}
}, [destinationChainConfig, destinationBridge, transactionStatus]);
}, [destinationChainConfig]);

useEffect(() => {
if (
Expand Down
3 changes: 2 additions & 1 deletion src/Contexts/Adaptors/EVMAdaptors/EVMHomeAdaptorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const EVMHomeAdaptorProvider = ({
fallback,
analytics,
setAddress,
setApi,
api,
} = useNetworkManager();

const [homeBridge, setHomeBridge] = useState<Bridge | undefined>(undefined);
Expand All @@ -103,7 +105,6 @@ export const EVMHomeAdaptorProvider = ({
const [wrapTokenConfig, setWrapperConfig] = useState<TokenConfig | undefined>(
undefined
);
const [api, setApi] = useState<ApiPromise | undefined>();
const [initialising, setInitialising] = useState(false);
const [walletSelected, setWalletSelected] = useState(false);

Expand Down
4 changes: 2 additions & 2 deletions src/Contexts/Adaptors/EVMAdaptors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const getRpcProviderFromHttpUrl = (url: string) => {
user: urlInstance.username,
password: urlInstance.password,
};
return new ethers.providers.JsonRpcProvider(urlInfo);
return new ethers.providers.StaticJsonRpcProvider(urlInfo);
AndreiNavoichyk marked this conversation as resolved.
Show resolved Hide resolved
}
return new ethers.providers.JsonRpcProvider(url);
return new ethers.providers.StaticJsonRpcProvider(url);
};

export function getProvider(destinationChainConfig?: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/Contexts/Adaptors/SubstrateDestinationAdaptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export const SubstrateDestinationAdaptorProvider = ({
fallback,
address,
analytics,
api,
setApi,
} = useNetworkManager();

const [api, setApi] = useState<ApiPromise | undefined>();

const [initiaising, setInitialising] = useState(false);
useEffect(() => {
// Once the chain ID has been set in the network context, the destination configuration will be automatically
Expand Down
3 changes: 2 additions & 1 deletion src/Contexts/Adaptors/SubstrateHomeAdaptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const SubstrateHomeAdaptorProvider = ({
children,
}: IHomeBridgeProviderProps) => {
const registry = new TypeRegistry();
const [api, setApi] = useState<ApiPromise | undefined>();
const [isReady, setIsReady] = useState(false);
const [accounts, setAccounts] = useState<InjectedAccountType[]>([]);

Expand All @@ -41,6 +40,8 @@ export const SubstrateHomeAdaptorProvider = ({
address,
setAddress,
analytics,
api,
setApi,
} = useNetworkManager();

const [relayerThreshold, setRelayerThreshold] = useState<number | undefined>(
Expand Down
18 changes: 18 additions & 0 deletions src/Contexts/NetworkManagerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
import { blockchainChainIds } from "../Constants/constants";
import { Fallback } from "../Utils/Fallback";
import AnalyticsService from "../Services/Analytics";
import { Bridge } from "@chainsafe/chainbridge-contracts";
import { ApiPromise } from "@polkadot/api";

interface INetworkManagerProviderProps {
children: React.ReactNode | React.ReactNode[];
Expand Down Expand Up @@ -103,6 +105,12 @@ interface NetworkManagerContext {
address: string | undefined;

analytics: AnalyticsService;

setDestinationBridge: (input: Bridge | undefined) => void;
destinationBridge: Bridge | undefined;

setApi: (input: ApiPromise | undefined) => void;
api: ApiPromise | undefined;
}

const NetworkManagerContext = React.createContext<
Expand Down Expand Up @@ -158,6 +166,12 @@ const NetworkManagerProvider = ({ children }: INetworkManagerProviderProps) => {
})
);

const [destinationBridge, setDestinationBridge] = useState<
Bridge | undefined
>(undefined);

const [api, setApi] = useState<ApiPromise | undefined>();

const handleSetHomeChain = useCallback(
(chainId: number | undefined) => {
if (!chainId && chainId !== 0) {
Expand Down Expand Up @@ -294,6 +308,10 @@ const NetworkManagerProvider = ({ children }: INetworkManagerProviderProps) => {
address,
setAddress,
analytics,
destinationBridge,
setDestinationBridge,
api,
setApi,
}}
>
{walletType === "Ethereum" ? (
Expand Down