diff --git a/web/package.json b/web/package.json index a80a87194..916fb2f44 100644 --- a/web/package.json +++ b/web/package.json @@ -44,7 +44,10 @@ "eject": "react-scripts eject", "ethers": "typechain --target ethers-v4 --outDir src/contracts 'contracts/*.json'", "deploy": "gh-pages -d build", - "deploy:ar": "arweave deploy-dir build --key-file " + "deploy:ar": "arweave deploy-dir build --key-file ", + "rm-contracts": "rm -rf src/contracts && rm -rf contracts", + "import-contracts": "mkdir -p ./contracts && cp -r ../ethereum/build/contracts/* ./contracts/ && npm run ethers", + "refresh-contracts": "npm run rm-contracts && npm run import-contracts" }, "eslintConfig": { "extends": "react-app" diff --git a/web/src/App/App.tsx b/web/src/App/App.tsx index 8e08223f2..a64f84e0c 100644 --- a/web/src/App/App.tsx +++ b/web/src/App/App.tsx @@ -12,6 +12,7 @@ import WalletContext from '../providers/WalletContext'; import Wallet from "@project-serum/sol-wallet-adapter"; import {BridgeProvider} from "../providers/BridgeContext"; import Assistant from "../pages/Assistant"; +import Message from "../pages/Message"; import {SOLANA_HOST} from "../config"; const {Header, Content, Footer} = Layout; @@ -39,7 +40,8 @@ function App() {
- Assistant + Message + Assistant Ethereum Solana { @@ -63,7 +65,7 @@ function App() { - + @@ -72,6 +74,9 @@ function App() { + + + diff --git a/web/src/config.ts b/web/src/config.ts index 2e7fb971c..17bafd03e 100644 --- a/web/src/config.ts +++ b/web/src/config.ts @@ -1,13 +1,13 @@ import {PublicKey} from "@solana/web3.js"; -const BRIDGE_ADDRESS = "0xf92cD566Ea4864356C5491c177A430C222d7e678"; +const BRIDGE_ADDRESS = "0x254dffcd3277c0b1660f6d42efbb754edababc2b"; const WRAPPED_MASTER = "9A5e27995309a03f8B583feBdE7eF289FcCdC6Ae" -const SOLANA_BRIDGE_PROGRAM = new PublicKey("WormT3McKhFJ2RkiGpdw9GKvNCrB2aB54gb2uV9MfQC"); +const SOLANA_BRIDGE_PROGRAM = new PublicKey("Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"); const TOKEN_PROGRAM = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); -const SOLANA_HOST = "https://solana-api.projectserum.com"; +const SOLANA_HOST = "http://localhost:8899"; export { BRIDGE_ADDRESS, diff --git a/web/src/pages/Message.tsx b/web/src/pages/Message.tsx new file mode 100644 index 000000000..3a9a351b4 --- /dev/null +++ b/web/src/pages/Message.tsx @@ -0,0 +1,101 @@ +import React, { useState, useEffect } from 'react'; +import { Form, Input, Button, List } from 'antd'; +import { ethers } from "ethers"; +import { BRIDGE_ADDRESS } from "../config"; +import { ImplementationFactory } from '../contracts/ImplementationFactory'; + +// @ts-ignore +if (window.ethereum === undefined) { + alert("Please install the MetaMask extension before using this experimental demo web UI"); +} + +// @ts-ignore +window.ethereum.enable(); +// @ts-ignore +const provider = new ethers.providers.Web3Provider(window.ethereum); +const signer = provider.getSigner(); + +function Message() { + const [form] = Form.useForm(); + const [, forceUpdate] = useState({}); + + // map: { txHash: payloadString } + const [txHashToPayload, setTxHashToPayload] = useState<{ [txHash: string]: string }>({}) + + // To disable submit button at the beginning. + useEffect(() => { + forceUpdate({}); + }, []); + + const sendMessage = async ({ payload }: { payload: string }) => { + + let nonceConst = Math.random() * 100000 + let nonceBuffer = Buffer.alloc(4); + nonceBuffer.writeUInt32LE(nonceConst, 0) + + let i = ImplementationFactory.connect(BRIDGE_ADDRESS, signer) + + let res = await i.publishMessage(nonceBuffer, Buffer.from(payload, 'utf16le'), true) + + await res.wait(1) + + if (res.hash) { + setTxHashToPayload({ ...txHashToPayload, [res.hash]: payload }) + } + + form.resetFields(['payload']) + } + const rmTxHash = (txHash: string) => { + const { [txHash]: rm, ...others } = txHashToPayload + setTxHashToPayload(others) + return undefined // for typescript + } + + return ( + <> +
+ +

publishMessage

+
+ + + + + {() => ( + + )} + +
+ {Object.keys(txHashToPayload).length >= 1 ? ( + ( + rmTxHash(item)} >X]} + > +
+

{item}

+

{txHashToPayload[item]}

+
+
+ )} + /> + + ) : null} + + ); +} + +export default Message;