import axios from "axios"; import React from "react"; import { withRouter } from "next/router"; import Button from "../inputs/Button"; import { createMultisigFromCompressedSecp256k1Pubkeys } from "../../lib/multisigHelpers"; import Input from "../inputs/Input"; import StackableContainer from "../layout/StackableContainer"; import ThresholdInput from "../inputs/ThresholdInput"; let emptyPubKeyGroup = () => { return { compressedPubkey: "", keyError: "" }; }; class MultiSigForm extends React.Component { constructor(props) { super(props); this.state = { pubkeys: [emptyPubKeyGroup(), emptyPubKeyGroup()], threshold: 2, processing: false, }; } handleChangeThreshold = (e) => { const threshold = e.target.value <= this.state.pubkeys.length ? e.target.value : this.state.pubkeys.length; this.setState({ threshold }); }; handleKeyGroupChange = (index, e) => { const { pubkeys } = this.state; pubkeys[index][e.target.name] = e.target.value; this.setState({ pubkeys }); }; handleAddKey = () => { this.setState({ pubkeys: this.state.pubkeys.concat(emptyPubKeyGroup()) }); }; handleRemove = (index) => { this.setState((prevState) => { const pubkeys = Array.from(prevState.pubkeys); pubkeys.splice(index, 1); const threshold = prevState.threshold > pubkeys.length ? pubkeys.length : prevState.threshold; return { pubkeys, threshold }; }); }; handleKeyBlur = (index, e) => { try { let compressedPubkey = e.target.value; if (compressedPubkey.length !== 44) { throw new Error("Invalid Secp256k1 pubkey"); } const { pubkeys } = this.state; pubkeys[index].compressedPubkey = compressedPubkey; pubkeys[index].keyError = ""; this.setState({ pubkeys }); } catch (error) { console.log(error); const { pubkeys } = this.state; pubkeys[index].keyError = error.message; this.setState({ pubkeys }); } }; handleCreate = async () => { this.setState({ processing: true }); const compressedPubkeys = this.state.pubkeys.map( (item) => item.compressedPubkey ); let multisigAddress; try { multisigAddress = await createMultisigFromCompressedSecp256k1Pubkeys( compressedPubkeys, parseInt(this.state.threshold, 10) ); this.props.router.push(`/multi/${multisigAddress}`); } catch (error) { console.log("Failed to creat multisig: ", error); } }; render() { return ( <>

Add the Public Keys that will make up this multisig.

Note this only supports compressed Secp256k1 pubkeys, double check this is the algo used to create your account.

{this.state.pubkeys.map((pubkeyGroup, index) => (
{this.state.pubkeys.length > 2 && ( )}
{ this.handleKeyGroupChange(index, e); }} value={pubkeyGroup.compressedPubkey} label="Public Key" name="compressedPubkey" width="100%" placeholder="Akd/qKMWdZXyiMnSu6aFLpQEGDO0ijyal9mXUIcVaPNX" error={pubkeyGroup.keyError} onBlur={(e) => { this.handleKeyBlur(index, e); }} />
))}