parent
ee3159cc91
commit
ce5232f339
@ -0,0 +1,92 @@ |
||||
import * as React from 'react'; |
||||
import {DropdownProps} from 'react-bootstrap/Dropdown'; |
||||
import {useRef} from "react"; |
||||
|
||||
interface Props extends DropdownProps { |
||||
id?: string; |
||||
className?: string; |
||||
href?: string; |
||||
title: string |
||||
} |
||||
|
||||
export const DropdownSubmenu: React.FC<Props> = (props:Props) => { |
||||
let refSubMenuContent = useRef(null as HTMLDivElement | null); |
||||
|
||||
let className = 'dropdown-submenu-container'; |
||||
className = props.className |
||||
? className + ' ' + props.className |
||||
: className; |
||||
|
||||
const onClick = (event: React.SyntheticEvent<any>) => { |
||||
event.preventDefault(); |
||||
event.stopPropagation(); |
||||
|
||||
if (refSubMenuContent.current) { |
||||
let show = false; |
||||
if (refSubMenuContent.current.classList.contains('show')) { |
||||
hideChildren(refSubMenuContent.current); |
||||
} else { |
||||
show = true; |
||||
hideSiblings(); |
||||
} |
||||
refSubMenuContent.current.classList.toggle('show'); |
||||
if (typeof props.onToggle === 'function') { |
||||
props.onToggle(show, event, { source: 'select'}); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
const hideSiblings = () => { |
||||
if (refSubMenuContent.current) { |
||||
const parents = getParents( |
||||
refSubMenuContent.current, |
||||
'.dropdown-menu.show' |
||||
); |
||||
if (parents.length > 1) { |
||||
hideChildren(parents[1]); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
const hideChildren = (parent: any) => { |
||||
const children = parent.querySelectorAll('.dropdown-menu.show') as any; |
||||
for (const child of children) { |
||||
child.classList.remove('show'); |
||||
} |
||||
} |
||||
|
||||
const getParents = (elem: any, selector: string) => { |
||||
const nodes = []; |
||||
let element = elem; |
||||
nodes.push(element); |
||||
while (element.parentNode) { |
||||
if ( |
||||
typeof element.parentNode.matches === 'function' && |
||||
element.parentNode.matches(selector) |
||||
) { |
||||
nodes.push(element.parentNode); |
||||
} |
||||
element = element.parentNode; |
||||
} |
||||
return nodes; |
||||
} |
||||
|
||||
return ( |
||||
<div className={className} id={props.id}> |
||||
<a |
||||
href={props.href} |
||||
className="dropdown-item dropdown-submenu dropdown-toggle" |
||||
onClick={onClick} |
||||
> |
||||
{props.title} |
||||
</a> |
||||
<div |
||||
className="dropdown-menu" |
||||
ref={refSubMenuContent} |
||||
> |
||||
{props.children} |
||||
</div> |
||||
</div> |
||||
); |
||||
|
||||
} |
@ -0,0 +1,29 @@ |
||||
import { ethers } from 'ethers' |
||||
|
||||
/** |
||||
* Deploy the given contract |
||||
* @param {string} contractName name of the contract to deploy |
||||
* @param {Array<any>} args list of constructor' parameters |
||||
* @param {Number} accountIndex account index from the exposed account |
||||
* @return {Contract} deployed contract |
||||
*/ |
||||
export const deploy = async (contractName: string, args: Array<any>, accountIndex?: number): Promise<ethers.Contract> => {
|
||||
|
||||
console.log(`deploying ${contractName}`) |
||||
// Note that the script needs the ABI which is generated from the compilation artifact.
|
||||
// Make sure contract is compiled and artifacts are generated
|
||||
const artifactsPath = `browser/contracts/artifacts/${contractName}.json` // Change this for different path
|
||||
|
||||
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', artifactsPath)) |
||||
// 'web3Provider' is a remix global variable object
|
||||
|
||||
const signer = (new ethers.providers.Web3Provider(web3Provider)).getSigner(accountIndex) |
||||
|
||||
const factory = new ethers.ContractFactory(metadata.abi, metadata.data.bytecode.object, signer) |
||||
|
||||
const contract = await factory.deploy(...args)
|
||||
|
||||
// The contract is NOT deployed yet; we must wait until it is mined
|
||||
await contract.deployed() |
||||
return contract |
||||
} |
@ -0,0 +1,7 @@ |
||||
import { contractDeployerScripts } from '../scripts/contract-deployer' |
||||
import { etherscanScripts } from '../scripts/etherscan' |
||||
|
||||
export const scripts = { |
||||
'etherscan': etherscanScripts, |
||||
'deployer': contractDeployerScripts |
||||
} |
Loading…
Reference in new issue