Skip to content

Commit

Permalink
enable wallets based on runtime config (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Oct 12, 2021
1 parent 4e78d9a commit 8e5310d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ if (

const App: React.FC<{}> = () => {
const {
__RUNTIME_CONFIG__: { UI: { wrapTokenPage = false } = {} },
__RUNTIME_CONFIG__: {
UI: { wrapTokenPage = false } = {},
CHAINBRIDGE: { chains },
},
} = window;
const tokens = chainbridgeConfig.chains
.filter((c) => c.type === "Ethereum")
Expand Down Expand Up @@ -88,7 +91,7 @@ const App: React.FC<{}> = () => {
gasPriceSetting="fast"
>
<NetworkManagerProvider>
<ChainbridgeProvider>
<ChainbridgeProvider chains={chains}>
<Router>
<AppWrapper wrapTokenPage={wrapTokenPage}>
<ChainbridgeRoutes wrapTokenPage={wrapTokenPage} />
Expand Down
11 changes: 10 additions & 1 deletion src/Contexts/ChainbridgeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useCallback, useContext } from "react";
import {
BridgeConfig,
chainbridgeConfig,
EvmBridgeConfig,
SubstrateBridgeConfig,
TokenConfig,
} from "../chainbridgeConfig";
import { Tokens } from "@chainsafe/web3-context/dist/context/tokensReducer";
Expand All @@ -15,6 +17,7 @@ import NetworkSelectModal from "../Modules/NetworkSelectModal";

interface IChainbridgeContextProps {
children: React.ReactNode | React.ReactNode[];
chains?: Array<EvmBridgeConfig | SubstrateBridgeConfig>;
}

type ChainbridgeContext = {
Expand Down Expand Up @@ -52,13 +55,17 @@ type ChainbridgeContext = {
tokenAddress: string,
destinationChainId: number
) => Promise<boolean | undefined>;
chains?: Array<EvmBridgeConfig | SubstrateBridgeConfig>;
};

const ChainbridgeContext = React.createContext<ChainbridgeContext | undefined>(
undefined
);

const ChainbridgeProvider = ({ children }: IChainbridgeContextProps) => {
const ChainbridgeProvider = ({
children,
chains,
}: IChainbridgeContextProps) => {
const {
handleSetHomeChain,
destinationChainConfig,
Expand Down Expand Up @@ -167,8 +174,10 @@ const ChainbridgeProvider = ({ children }: IChainbridgeContextProps) => {
address,
chainId,
checkSupplies,
chains,
}}
>
{/*TODO: we should remove this on refactor task. Context provider single responsibility is to provide share state */}
<NetworkSelectModal />
{children}
</ChainbridgeContext.Provider>
Expand Down
22 changes: 15 additions & 7 deletions src/Modules/NetworkSelectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useStyles = makeStyles(({ constants, palette, zIndex }: ITheme) => {

const NetworkSelectModal = () => {
const classes = useStyles();
const { isReady } = useChainbridge();
const { isReady, chains } = useChainbridge();
const { walletType, setWalletType } = useNetworkManager();

return (
Expand All @@ -50,12 +50,20 @@ const NetworkSelectModal = () => {
Please select a wallet type
</Typography>
<section className={classes.buttons}>
<Button onClick={() => setWalletType("Ethereum")}>
Use Ethereum wallet
</Button>
<Button onClick={() => setWalletType("Substrate")}>
Use Substrate wallet
</Button>
{chains?.every((item) => item.type === "Ethereum") ? (
<Button onClick={() => setWalletType("Ethereum")}>
Use Ethereum wallet
</Button>
) : (
<>
<Button onClick={() => setWalletType("Ethereum")}>
Use Ethereum wallet
</Button>
<Button onClick={() => setWalletType("Substrate")}>
Use Substrate wallet
</Button>
</>
)}
</section>
</>
)}
Expand Down

0 comments on commit 8e5310d

Please sign in to comment.