diff --git a/src/components/app-body/balance.js b/src/components/app-body/balance.js index 0a41d41..9aef4e5 100644 --- a/src/components/app-body/balance.js +++ b/src/components/app-body/balance.js @@ -14,7 +14,8 @@ function GetBalance (props) { const [textInput, setTextInput] = useState('') // Button click handler - const handleGetBalance = async (event) => { + const handleGetBalance = async (e) => { + e.preventDefault() try { // Exit on invalid input if (!textInput) return @@ -43,7 +44,7 @@ function GetBalance (props) { -
+ Enter any BCH address to query its balance on the blockchain. setTextInput(e.target.value)} /> diff --git a/src/components/app-body/bch-send/send-card.js b/src/components/app-body/bch-send/send-card.js index 19b7d5e..9c85126 100644 --- a/src/components/app-body/bch-send/send-card.js +++ b/src/components/app-body/bch-send/send-card.js @@ -259,7 +259,7 @@ function SendCard (props) { - + e.preventDefault()}> - + { e.preventDefault(); handleSendBch({ sendCardData, appData }) }}> { - + e.preventDefault()}> } /> } /> } /> + } /> {/** Show in all paths except the servers view */} {appData.currentPath !== '/servers' && } diff --git a/src/components/app-body/sign/index.js b/src/components/app-body/sign/index.js new file mode 100644 index 0000000..2da9e2e --- /dev/null +++ b/src/components/app-body/sign/index.js @@ -0,0 +1,120 @@ +/* +Component for signing a message with a WIF private key. +*/ + +// Global npm libraries +import React, { useState } from 'react' +import { Container, Row, Col, Form, Button } from 'react-bootstrap' +import { faCopy } from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' + +function SignMessage (props) { + // Convert class state to hooks + const { wallet, appUtil } = props.appData + + const [sign, setSign] = useState('') + const [msg, setMsg] = useState('') + const [bchAddr] = useState(wallet.walletInfo.cashAddress) + const [slpAddr] = useState(wallet.walletInfo.slpAddress) + const [err, setErr] = useState('') + const [copied, setCopied] = useState(false) + + const handleSignMessage = (event) => { + try { + event.preventDefault() + + if (!msg) throw new Error('Enter a message to sign.') + + const bchjs = wallet.bchjs + + const wif = props.appData.wallet.walletInfo.privateKey + const sig = bchjs.BitcoinCash.signMessageWithPrivKey(wif, msg) + + setSign(sig) + setErr('') + } catch (err) { + console.log('Error in handleSignMessage(): ', err) + setErr(err.message) + setSign('') + } + } + + // Function to copy the value to the clipboard. + const handleCopyToClipboard = async (value) => { + appUtil.copyToClipboard(value) + + // show the copied message + setCopied(true) + + // hide copied message after 1 second + setTimeout(function () { + setCopied(false) + }, 1000) + } + + const copyIcon = (value) => { + return handleCopyToClipboard(value)} style={{ cursor: 'pointer', marginLeft: '10px' }} /> + } + + return ( + <> + + + +

+ This view allows you cryptographically sign a message with your + wallet. These signatures are used in a wide range of applications, + such as gaining access to + the PSF VIP Telegram channel. +

+

+ Enter any message into the form below and click the button. This + view will generate a cryptographic signature. +

+ +
+ + + + + Enter a message to sign. + setMsg(e.target.value)} /> + + {err &&

{`Error: ${err}`}

} + + + + +
+
+ {sign && ( +
+ + +

+ Signature: {sign} {copyIcon(sign)} +

+

+ BCH Address: {bchAddr} {copyIcon(bchAddr)} +

+

+ SLP Address: {slpAddr} {copyIcon(slpAddr)} +

+ + +
+ {copied && ( + + Copied! + + )} +
+ )} +
+ + ) +} + +export default SignMessage diff --git a/src/components/app-body/slp-tokens/send-token-button.js b/src/components/app-body/slp-tokens/send-token-button.js index 7e407ba..b268f74 100644 --- a/src/components/app-body/slp-tokens/send-token-button.js +++ b/src/components/app-body/slp-tokens/send-token-button.js @@ -51,7 +51,8 @@ function SendTokenButton ({ token, appData, refreshTokens }) { // Click handler that fires when the user clicks the 'Send' button. - const handleSendTokens = async () => { + const handleSendTokens = async (e) => { + e.preventDefault() try { setStatusMsg('Preparing to send tokens...') setHideSpinner(false) @@ -131,7 +132,7 @@ function SendTokenButton ({ token, appData, refreshTokens }) { -
+ e.preventDefault()}> - + { } // Handle sweep function - const handleSweep = async () => { + const handleSweep = async (e) => { + e.preventDefault() try { console.log(`Sweeping this WIF: ${wifToSweep}`) @@ -183,7 +184,7 @@ const SweepWif = (props) => { - + Sweep + + Sign +