Skip to content

Commit

Permalink
Merge branch 'release/0.15.0' into master-cere
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Navoichyk committed Jun 27, 2022
2 parents 5a62c03 + 698b8f4 commit 11a61a8
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_SUPPORT_URL="https://t.me/ceretroubleshooting"
## These are only required if using Sentry for error logging
REACT_APP_SENTRY_DSN_URL="https://3d39fa05d843482eb93377947b435b5b@o318183.ingest.sentry.io/5987177"
SENTRY_AUTH_TOKEN="db67ae12222811ecabd2564b6436d30d"
REACT_APP_SENTRY_RELEASE="0.14.0"
REACT_APP_SENTRY_RELEASE="0.15.0"

REACT_APP_MAINTENANCE=false
REACT_APP_CONNECT_WITH_SUBSTRATE_WALLET_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_SUPPORT_URL="https://t.me/ceretroubleshooting"
## These are only required if using Sentry for error logging
REACT_APP_SENTRY_DSN_URL="https://3d39fa05d843482eb93377947b435b5b@o318183.ingest.sentry.io/5987177"
SENTRY_AUTH_TOKEN="db67ae12222811ecabd2564b6436d30d"
REACT_APP_SENTRY_RELEASE="0.14.0"
REACT_APP_SENTRY_RELEASE="0.15.0"

REACT_APP_MAINTENANCE=false
REACT_APP_CONNECT_WITH_SUBSTRATE_WALLET_ENABLED=true
Expand Down
2 changes: 1 addition & 1 deletion .env.stage
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_SUPPORT_URL="https://t.me/ceretroubleshooting"
## These are only required if using Sentry for error logging
REACT_APP_SENTRY_DSN_URL="https://3d39fa05d843482eb93377947b435b5b@o318183.ingest.sentry.io/5987177"
SENTRY_AUTH_TOKEN="db67ae12222811ecabd2564b6436d30d"
REACT_APP_SENTRY_RELEASE="0.14.0"
REACT_APP_SENTRY_RELEASE="0.15.0"

REACT_APP_MAINTENANCE=false
REACT_APP_CONNECT_WITH_SUBSTRATE_WALLET_ENABLED=true
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## vNext

- ...
## v0.15.0

- Updated Devnet url
- Fixed duplicate requests to Cere/Polygon/Ethereum

## v0.14.0

Expand Down
2 changes: 1 addition & 1 deletion config/chainbridge-runtime-config.cere.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ window.__RUNTIME_CONFIG__ = {
networkId: 2,
name: "Cere Devnet",
decimals: cereTokenDecimals,
rpcUrl: "wss://rpc.devnet.cere.network:9945",
rpcUrl: "wss://rpc.v2.devnet.cere.network/ws",
type: "Substrate",
nativeTokenSymbol: "CERE",
availableAsHomeNetwork: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@Cerebellum-Network/chainbridge-ui",
"version": "0.14.0",
"version": "0.15.0",
"private": true,
"dependencies": {
"@babel/core": "^7.12.3",
Expand Down
12 changes: 9 additions & 3 deletions src/Components/Pages/TransferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ type PreflightDetails = {

const TransferPage = () => {
const classes = useStyles();
const { walletType, setWalletType, handleSetHomeChain } = useNetworkManager();
const {
walletType,
setWalletType,
handleSetHomeChain,
setAddress,
} = useNetworkManager();
const destinationBridge = useDestinationBridge();

const {
Expand Down Expand Up @@ -588,13 +593,14 @@ const TransferPage = () => {
className={classes.changeButton}
variant="body1"
onClick={async () => {
handleSetHomeChain(undefined);
setDestinationChain(undefined);
await Promise.all([
destinationBridge.disconnect(),
disconnect(),
]);
handleSetHomeChain(undefined);
setDestinationChain(undefined);
setWalletType("unset");
setAddress(undefined);
}}
>
Change
Expand Down
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
19 changes: 2 additions & 17 deletions src/Contexts/Adaptors/EVMAdaptors/EVMHomeAdaptorProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { HomeBridgeContext } from "../../HomeBridgeContext";
import { parseUnits } from "ethers/lib/utils";
import { decodeAddress } from "@polkadot/util-crypto";
import { getPriceCompatibility } from "./helpers";
import { createApi, hasTokenSupplies } from "../SubstrateApis/ChainBridgeAPI";
import { hasTokenSupplies } from "../SubstrateApis/ChainBridgeAPI";
import { ApiPromise } from "@polkadot/api";

export const EVMHomeAdaptorProvider = ({
Expand Down Expand Up @@ -88,6 +88,7 @@ export const EVMHomeAdaptorProvider = ({
fallback,
analytics,
setAddress,
api,
} = useNetworkManager();

const [homeBridge, setHomeBridge] = useState<Bridge | undefined>(undefined);
Expand All @@ -103,25 +104,9 @@ 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);

useEffect(() => {
if (destinationChainConfig?.type !== "Substrate" || initialising || api)
return;
setInitialising(true);
createApi(
destinationChainConfig.rpcUrl,
destinationChainConfig.rpcFallbackUrls
)
.then((api) => {
setApi(api);
setInitialising(false);
})
.catch(console.error);
}, [destinationChainConfig, initialising]);

useEffect(() => {
if (network) {
const chain = homeChains.find((chain) => chain.networkId === network);
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);
}
return new ethers.providers.JsonRpcProvider(url);
return new ethers.providers.StaticJsonRpcProvider(url);
};

export function getProvider(destinationChainConfig?: any) {
Expand Down
32 changes: 13 additions & 19 deletions src/Contexts/Adaptors/SubstrateDestinationAdaptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { IDestinationBridgeProviderProps } from "./interfaces";

import { ApiPromise } from "@polkadot/api";
import { UnsubscribePromise } from "@polkadot/api/types";
import {
SubstrateBridgeConfig,
getСhainTransferFallbackConfig,
Expand All @@ -34,31 +33,29 @@ export const SubstrateDestinationAdaptorProvider = ({
fallback,
address,
analytics,
api,
setApi,
listenerActive,
setListenerActive,
} = useNetworkManager();

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

const [initiaising, setInitialising] = useState(false);
const [initialising, setInitialising] = useState(false);
useEffect(() => {
// Once the chain ID has been set in the network context, the destination configuration will be automatically
// set thus triggering this
if (!destinationChainConfig || initiaising || api) return;
if (!destinationChainConfig || initialising || api) return;
setInitialising(true);
createApi(
destinationChainConfig.rpcUrl,
destinationChainConfig.rpcFallbackUrls
)
.then((api) => {
.then(async (api) => {
await api.isReady;
setApi(api);
setInitialising(false);
})
.catch(console.error);
}, [destinationChainConfig, api, initiaising, transactionStatus]);

const [listenerActive, setListenerActive] = useState<
UnsubscribePromise | undefined
>(undefined);

}, [destinationChainConfig, initialising]);
useEffect(() => {
if (api && !listenerActive && depositNonce) {
// Wire up event listeners
Expand Down Expand Up @@ -121,19 +118,15 @@ export const SubstrateDestinationAdaptorProvider = ({
}
});
});
setListenerActive(unsubscribe);
setListenerActive(true);
} else if (listenerActive && !depositNonce) {
const unsubscribeCall = async () => {
setListenerActive(undefined);
};
unsubscribeCall();
setListenerActive(false);
}
}, [
api,
depositNonce,
depositVotes,
destinationChainConfig,
listenerActive,
setDepositVotes,
setTransactionStatus,
tokensDispatch,
Expand Down Expand Up @@ -219,7 +212,8 @@ export const SubstrateDestinationAdaptorProvider = ({
<DestinationBridgeContext.Provider
value={{
disconnect: async () => {
await api?.disconnect();
if (api?.isConnected) await api?.disconnect();
setApi(undefined);
},
}}
>
Expand Down
24 changes: 11 additions & 13 deletions src/Contexts/Adaptors/SubstrateHomeAdaptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import { hasTokenSupplies } from "./EVMAdaptors/helpers";
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 +39,8 @@ export const SubstrateHomeAdaptorProvider = ({
address,
setAddress,
analytics,
api,
setApi,
} = useNetworkManager();

const [relayerThreshold, setRelayerThreshold] = useState<number | undefined>(
Expand All @@ -57,18 +57,20 @@ export const SubstrateHomeAdaptorProvider = ({
handleConnect();
});

const [initiaising, setInitialising] = useState(false);
const [initialising, setInitialising] = useState(false);
useEffect(() => {
// Once the chain ID has been set in the network context, the homechain configuration will be automatically set thus triggering this
if (!homeChainConfig || initiaising || api) return;
if (!homeChainConfig || initialising || api) return;
setInitialising(true);
createApi(homeChainConfig.rpcUrl, homeChainConfig.rpcFallbackUrls)
.then((api) => {
.then(async (api) => {
await api.isReady;
setApi(api);
setIsReady(true);
setInitialising(false);
})
.catch(console.error);
}, [homeChainConfig, registry, api, initiaising]);
}, [homeChainConfig, initialising]);

const getRelayerThreshold = useCallback(async () => {
if (api) {
Expand Down Expand Up @@ -208,12 +210,6 @@ export const SubstrateHomeAdaptorProvider = ({
}
}, [isReady, handleSetHomeChain, homeChains]);

useEffect(() => {
// This is a simple check
// The reason for having a isReady is that the UI can lazy load data from this point
api?.isReady.then(() => setIsReady(true));
}, [api, setIsReady]);

const selectAccount = useCallback(
(index: number) => {
setAddress(accounts[index].address);
Expand Down Expand Up @@ -344,7 +340,9 @@ export const SubstrateHomeAdaptorProvider = ({
value={{
connect: handleConnect,
disconnect: async () => {
await api?.disconnect();
if (api?.isConnected) await api?.disconnect();
setApi(undefined);
setIsReady(false);
},
getNetworkName: () => homeChainConfig?.name || "undefined",
bridgeFee,
Expand Down
25 changes: 25 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,15 @@ interface NetworkManagerContext {
address: string | undefined;

analytics: AnalyticsService;

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

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

setListenerActive: (input: boolean) => void;
listenerActive: boolean;
}

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

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

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

const [listenerActive, setListenerActive] = useState(false);

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

0 comments on commit 11a61a8

Please sign in to comment.