Skip to content

Commit

Permalink
feat: added localhost network for hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Jan 13, 2024
1 parent c404976 commit ee8dcd1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/js/components/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Form from './Form/Form';
const AppLayout = () => (
<Page.BlankPage>
<Container.FlexRow className="justify-between items-center py-4 bg-brand px-4">
<span className="text-xl text-white">NFT WebUI</span>
<span className="text-xl text-white">ERC20 WebUI</span>
<MetamaskConnect />
</Container.FlexRow>
<Container.PageContent className="py-8">
Expand Down
20 changes: 18 additions & 2 deletions app/src/js/components/MetamaskConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ export enum ChainId {
Rinkeby = '0x4',
Goerli = '0x5',
Kovan = '0x2a',
Hardhat = '0x7a69',
}

const MetamaskConnect = () => {
const [chainId, setChainId] = React.useState<ChainId>();

const {
status,
connect,
account,
chainId: currentChainId,
switchChain,
} = useMetaMask();
const [chainId, setChainId] = React.useState<ChainId>(
currentChainId as ChainId,
);

const disabled =
['initializing', 'unavailable', 'connecting', 'connected'].includes(
status,
Expand Down Expand Up @@ -53,6 +56,18 @@ const MetamaskConnect = () => {
return undefined;
};

React.useEffect(() => {
if (currentChainId && chainId && currentChainId !== chainId) {
switchChain(chainId);
}
}, [chainId, switchChain]);

React.useEffect(() => {
if (!chainId) {
setChainId(currentChainId as ChainId);
}
}, [currentChainId]);

return (
<Container.FlexRow className="items-center gap-8">
<Select
Expand All @@ -69,6 +84,7 @@ const MetamaskConnect = () => {
)}
<option value={ChainId.Mainnet}>Mainnet</option>
<option value={ChainId.Goerli}>Goerli</option>
<option value={ChainId.Hardhat}>Hardhat</option>
</Select>
<Button.Alternative
className="my-0 !mb-0"
Expand Down
2 changes: 2 additions & 0 deletions app/src/js/web3/contracts/MyToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ interface ContractAddress {
[ChainId.Mainnet]: string;
[ChainId.Rinkeby]: string;
[ChainId.Ropsten]: string;
[ChainId.Hardhat]: string;
}

export const CONTRACT_ADDRESS: ContractAddress = {
Expand All @@ -430,4 +431,5 @@ export const CONTRACT_ADDRESS: ContractAddress = {
[ChainId.Mainnet]: '0xa0647F0Da8B541C8876C234Bc9C4dC50F19515ea',
[ChainId.Rinkeby]: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
[ChainId.Ropsten]: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
[ChainId.Hardhat]: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
};

0 comments on commit ee8dcd1

Please sign in to comment.