Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Progress panel #365

Open
wants to merge 16 commits into
base: v2-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/components/deposit/Confirming.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,37 @@ import PropTypes from "prop-types"

import ConfirmingBase from "../lib/Confirming"
import { formatSatsToBtc } from "../../utils"
import DepositPage from "./DepositPage"

const Confirming = ({
signerFee,
error,
requiredConfirmations,
confirmations,
}) => (
<ConfirmingBase
className="pay pay-confirming"
stepStatus="3/5"
error={error}
requiredConfirmations={requiredConfirmations}
confirmations={confirmations}
>
<div>
<p>
We’ll send you a browser notification when your TBTC is ready to be
minted.
</p>
<p>
<i>A watched block never boils.</i>
</p>
</div>
<div className="signer-fee">
<span className="signer-fee-label">Signer Fee: </span>
{signerFee} BTC*
</div>
</ConfirmingBase>
<DepositPage>
<ConfirmingBase
className="pay pay-confirming"
stepStatus="3/5"
error={error}
requiredConfirmations={requiredConfirmations}
confirmations={confirmations}
>
<div>
<p>
We’ll send you a browser notification when your TBTC is ready to be
minted.
</p>
<p>
<i>A watched block never boils.</i>
</p>
</div>
<div className="signer-fee">
<span className="signer-fee-label">Signer Fee: </span>
{signerFee} BTC*
</div>
</ConfirmingBase>
</DepositPage>
)

Confirming.propTypes = {
Expand Down
22 changes: 9 additions & 13 deletions src/components/deposit/Congratulations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import PropTypes from "prop-types"
import StatusIndicator from "../svgs/StatusIndicator"
import * as tbtcLogoAnimationData from "../animation/tBTC-logo-animate.json"
import CopyAddressField from "../lib/CopyAddressField"
import { formatSatsToBtc, getEtherscanUrl } from "../../utils"
import { getEtherscanUrl, getLotInTbtc } from "../../utils"
import DepositPage from "./DepositPage"

const Congratulations = ({ depositAddress, lotInTbtc, chainId }) => {
return (
<div className="congratulations">
<DepositPage className="congratulations">
<div className="page-top">
<StatusIndicator donut fadeIn>
<Lottie
Expand Down Expand Up @@ -48,7 +49,7 @@ const Congratulations = ({ depositAddress, lotInTbtc, chainId }) => {
</a>
</div>
</div>
</div>
</DepositPage>
)
}

Expand All @@ -58,15 +59,10 @@ Congratulations.propTypes = {
chainId: PropTypes.number,
}

const mapStateToProps = (state) => {
const { depositAddress, lotInSatoshis, signerFeeInSatoshis } = state.deposit
const mintedSatoshis = lotInSatoshis.sub(signerFeeInSatoshis)

return {
depositAddress,
lotInTbtc: formatSatsToBtc(mintedSatoshis),
chainId: state.tbtc.web3.chainId,
}
}
const mapStateToProps = (state) => ({
depositAddress: state.deposit.depositAddress,
lotInTbtc: getLotInTbtc(state),
chainId: state.tbtc.web3.chainId,
})

export default connect(mapStateToProps)(Congratulations)
103 changes: 103 additions & 0 deletions src/components/deposit/DepositPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React from "react"
import PropTypes from "prop-types"
import classNames from "classnames"
import { connect } from "react-redux"

import ProgressPanel, {
Step,
StepDetailSuccessOrError,
} from "../lib/ProgressPanel"
import { useClickToCopy } from "../hooks"
import { formatSatsToBtc, getLotInTbtc } from "../../utils"

const DepositPage = ({
children,
className,
completedStepIndex,
activeStepIndex,
btcAmount,
tbtcAmount,
btcAddress,
btcConfirmingError,
proveDepositError,
}) => {
const { isCopied, hiddenCopyFieldRef, handleCopyClick } = useClickToCopy()
return (
<div className={classNames("page", "deposit-page", className)}>
<div className="page-content">{children}</div>
<ProgressPanel
className="deposit-progress"
completedStepIndex={completedStepIndex}
activeStepIndex={activeStepIndex}
>
<Step title="Start" />
<Step title="Deposit Size">
{btcAmount && tbtcAmount ? (
<div>{`${btcAmount} BTC > ${tbtcAmount} TBTC`}</div>
) : (
""
)}
</Step>
<Step title="Send BTC">
{btcAddress ? (
<>
<div className="btc-address-copy-click" onClick={handleCopyClick}>
<span>{btcAddress}</span>
<button>{isCopied ? "COPIED" : "COPY"}</button>
</div>
<textarea
className="hidden-copy-field"
ref={hiddenCopyFieldRef}
defaultValue={btcAddress || ""}
/>
</>
) : (
""
)}
</Step>
<Step title="BTC Block Confirmation">
<StepDetailSuccessOrError
completedStepIndex={completedStepIndex}
minCompletedStepIndex={3}
error={btcConfirmingError}
/>
</Step>
<Step title="Prove Deposit">
<StepDetailSuccessOrError
completedStepIndex={completedStepIndex}
minCompletedStepIndex={4}
error={proveDepositError}
/>
</Step>
<Step title="Complete" />
</ProgressPanel>
</div>
)
}

DepositPage.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
className: PropTypes.string,
completedStepIndex: PropTypes.number,
activeStepIndex: PropTypes.number,
btcAmount: PropTypes.string,
tbtcAmount: PropTypes.string,
btcAddress: PropTypes.string,
btcConfirmingError: PropTypes.string,
proveDepositError: PropTypes.string,
}

const mapStateToProps = (state) => ({
completedStepIndex: state.progressPanel.deposit.completedStepIndex,
activeStepIndex: state.progressPanel.deposit.activeStepIndex,
btcAmount: formatSatsToBtc(state.deposit.lotInSatoshis),
tbtcAmount: getLotInTbtc(state),
btcAddress: state.deposit.btcAddress,
btcConfirmingError: state.deposit.btcConfirmingError,
proveDepositError: state.deposit.proveDepositError,
})

export default connect(mapStateToProps, null)(DepositPage)
5 changes: 3 additions & 2 deletions src/components/deposit/GetAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from "prop-types"

import Description from "../lib/Description"
import StatusIndicator from "../svgs/StatusIndicator"
import DepositPage from "./DepositPage"

const GetAddress = ({ status, error }) => {
const [statusText, setStatusText] = useState("Generating BTC address...")
Expand All @@ -14,7 +15,7 @@ const GetAddress = ({ status, error }) => {
}, [status])

return (
<div className="invoice">
<DepositPage className="invoice">
<div className="page-top">
<StatusIndicator pulse />
</div>
Expand All @@ -26,7 +27,7 @@ const GetAddress = ({ status, error }) => {
<hr />
<Description error={error}>{statusText}</Description>
</div>
</div>
</DepositPage>
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/deposit/Invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import PropTypes from "prop-types"
import { requestADeposit } from "../../actions"
import Description from "../lib/Description"
import StatusIndicator from "../svgs/StatusIndicator"
import DepositPage from "./DepositPage"

const Invoice = ({ requestADeposit, error }) => {
useEffect(() => {
requestADeposit()
}, [requestADeposit])

return (
<div className="invoice">
<DepositPage className="invoice">
<div className="page-top">
<StatusIndicator pulse />
</div>
Expand All @@ -25,7 +26,7 @@ const Invoice = ({ requestADeposit, error }) => {
<hr />
<Description error={error}>Initiating...</Description>
</div>
</div>
</DepositPage>
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/deposit/Pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useParams } from "react-router-dom"
import StatusIndicator from "../svgs/StatusIndicator"
import CopyAddressField from "../lib/CopyAddressField"
import Description from "../lib/Description"
import DepositPage from "./DepositPage"

import { formatSatsToBtc } from "../../utils"

Expand All @@ -23,7 +24,7 @@ const PayComponent = ({ btcAddress, btcAmount, signerFee, error }) => {
const btcURL = `bitcoin:${btcAddress}?amount=${btcAmount}&label=Single-Use+tBTC+Deposit+Wallet`

return (
<div className="pay">
<DepositPage className="pay">
<div className="page-top">
<StatusIndicator />
</div>
Expand Down Expand Up @@ -53,7 +54,7 @@ const PayComponent = ({ btcAddress, btcAmount, signerFee, error }) => {
<CopyAddressField address={btcAddress} qrCodeUrl={btcURL} />
</Description>
</div>
</div>
</DepositPage>
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/deposit/Prove.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from "prop-types"

import Description from "../lib/Description"
import StatusIndicator from "../svgs/StatusIndicator"
import DepositPage from "./DepositPage"

function Prove(props) {
const params = useParams()
Expand All @@ -25,7 +26,7 @@ class ProveComponent extends Component {
const { provingDeposit, error } = this.props

return (
<div className="prove">
<DepositPage className="prove">
<div className="page-top">
<StatusIndicator pulse />
</div>
Expand All @@ -45,7 +46,7 @@ class ProveComponent extends Component {
: "Finally, let’s submit proof to the sidechain and get you your TBTC."}
</Description>
</div>
</div>
</DepositPage>
)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/deposit/Start.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import BTCLogo from "../svgs/btclogo"
import { useWeb3React } from "@web3-react/core"
import LotSizeSelector from "./LotSizeSelector"
import { formatSatsToBtc } from "../../utils"
import DepositPage from "./DepositPage"

const handleClickPay = (evt) => {
evt.preventDefault()
Expand Down Expand Up @@ -54,7 +55,7 @@ const Start = ({
}, [account, requestAvailableLotSizes])

return (
<div className="deposit-start">
<DepositPage className="deposit-start">
<div className="page-top">
<StatusIndicator>
<BTCLogo height={100} width={100} />
Expand All @@ -81,7 +82,7 @@ const Start = ({
</button>
</div>
</div>
</div>
</DepositPage>
)
}

Expand Down
8 changes: 8 additions & 0 deletions src/components/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ export function useClickToCopy() {
const [isCopied, setIsCopied] = useState(false)
const hiddenCopyFieldRef = useRef(null)

const scheduleReset = () => {
clearTimeout(scheduleReset)
setTimeout(() => {
setIsCopied(false)
}, 8000)
}

const handleCopyClick = () => {
hiddenCopyFieldRef.current.select()
document.execCommand("copy")
hiddenCopyFieldRef.current.blur()
setIsCopied(true)
scheduleReset()
}

return { isCopied, setIsCopied, hiddenCopyFieldRef, handleCopyClick }
Expand Down
Loading