Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move fidelity bonds to earn screen #361

Merged
13 commits merged into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
39 changes: 39 additions & 0 deletions public/sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/components/Alert.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, { useState } from 'react'
import { Alert as BsAlert } from 'react-bootstrap'

export default function Alert({ variant, dismissible, message, ...props }) {
export default function Alert({ variant, dismissible, message, onDismissed, ...props }) {
const [show, setShow] = useState(true)

return (
<BsAlert
show={show}
onClose={() => setShow(false)}
onClose={() => {
setShow(false)
onDismissed && onDismissed()
}}
variant={variant}
dismissible={dismissible}
className="my-3"
Expand Down
2 changes: 0 additions & 2 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Earn from './Earn'
import Receive from './Receive'
import CurrentWalletMagic from './CurrentWalletMagic'
import CurrentWalletAdvanced from './CurrentWalletAdvanced'
import FidelityBond from './FidelityBond'
import Settings from './Settings'
import Navbar from './Navbar'
import Layout from './Layout'
Expand Down Expand Up @@ -133,7 +132,6 @@ export default function App() {
<Route path={routes.earn} element={<Earn />} />
<Route path={routes.receive} element={<Receive />} />
<Route path={routes.settings} element={<Settings stopWallet={stopWallet} />} />
<Route path={routes.fidelityBonds} element={<FidelityBond />} />
</>
)}
</Route>
Expand Down
10 changes: 0 additions & 10 deletions src/components/CurrentWalletAdvanced.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
import * as rb from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'
// @ts-ignore
Expand All @@ -10,7 +9,6 @@ import DisplayAccountUTXOs from './DisplayAccountUTXOs'
import DisplayUTXOs from './DisplayUTXOs'
// @ts-ignore
import { useCurrentWallet, useCurrentWalletInfo, useReloadCurrentWalletInfo } from '../context/WalletContext'
import { routes } from '../constants/routes'
import styles from './CurrentWalletAdvanced.module.css'

type Utxos = any[]
Expand Down Expand Up @@ -97,14 +95,6 @@ export default function CurrentWalletAdvanced() {
<Trans i18nKey="fidelity_bond.alert_no_fidelity_bonds" as="span">
No Fidelity Bond present.
</Trans>
<>
{' '}
<Link to={routes.fidelityBonds}>
<Trans i18nKey="current_wallet_advanced.link_fidelity_bonds_create_text" as="span">
Create a Fidelity Bond.
</Trans>
</Link>
</>
</>
</rb.Alert>
) : (
Expand Down
55 changes: 46 additions & 9 deletions src/components/Earn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { Formik } from 'formik'
import * as rb from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import { useSettings } from '../context/SettingsContext'
import { useCurrentWallet } from '../context/WalletContext'
import { useCurrentWallet, useCurrentWalletInfo, useReloadCurrentWalletInfo } from '../context/WalletContext'
import { useServiceInfo, useReloadServiceInfo } from '../context/ServiceInfoContext'
import { useBalanceSummary } from '../hooks/BalanceSummary'
import Sprite from './Sprite'
import PageTitle from './PageTitle'
import SegmentedTabs from './SegmentedTabs'
import { CreateFidelityBond } from './fb/CreateFidelityBond'
import { ExistingFidelityBond } from './fb/ExistingFidelityBond'
import { EarnReportOverlay } from './EarnReport'
import * as Api from '../libs/JmWalletApi'
import styles from './Earn.module.css'
Expand Down Expand Up @@ -82,8 +85,11 @@ export default function Earn() {
const { t } = useTranslation()
const settings = useSettings()
const currentWallet = useCurrentWallet()
const currentWalletInfo = useCurrentWalletInfo()
const reloadCurrentWalletInfo = useReloadCurrentWalletInfo()
const serviceInfo = useServiceInfo()
const reloadServiceInfo = useReloadServiceInfo()
const balanceSummary = useBalanceSummary(currentWalletInfo)

const [isAdvancedView, setIsAdvancedView] = useState(settings.useAdvancedWalletMode)
const [alert, setAlert] = useState(null)
Expand All @@ -93,6 +99,7 @@ export default function Earn() {
const [isWaitingMakerStart, setIsWaitingMakerStart] = useState(false)
const [isWaitingMakerStop, setIsWaitingMakerStop] = useState(false)
const [isShowReport, setIsShowReport] = useState(false)
const [fidelityBonds, setFidelityBonds] = useState([])

const startMakerService = (ordertype, minsize, cjfee_a, cjfee_r) => {
setIsSending(true)
Expand Down Expand Up @@ -146,14 +153,23 @@ export default function Earn() {

setIsLoading(true)

reloadServiceInfo({ signal: abortCtrl.signal })
const reloadingServiceInfo = reloadServiceInfo({ signal: abortCtrl.signal })
const reloadingCurrentWalletInfo = reloadCurrentWalletInfo({ signal: abortCtrl.signal }).then((info) => {
if (info && !abortCtrl.signal.aborted) {
const unspentOutputs = info.data.utxos.utxos
const fbOutputs = unspentOutputs.filter((utxo) => utxo.locktime)
setFidelityBonds(fbOutputs)
}
})

Promise.all([reloadingServiceInfo, reloadingCurrentWalletInfo])
.catch((err) => {
!abortCtrl.signal.aborted && setAlert({ variant: 'danger', message: err.message })
})
.finally(() => !abortCtrl.signal.aborted && setIsLoading(false))

return () => abortCtrl.abort()
}, [currentWallet, isSending, reloadServiceInfo])
}, [currentWallet, isSending, reloadServiceInfo, reloadCurrentWalletInfo])

useEffect(() => {
if (isSending) return
Expand Down Expand Up @@ -255,16 +271,39 @@ export default function Earn() {
{t('earn.alert_coinjoin_in_progress')}
</rb.Alert>
</rb.Fade>

{alert && <rb.Alert variant={alert.variant}>{alert.message}</rb.Alert>}

{serviceInfoAlert && <rb.Alert variant={serviceInfoAlert.variant}>{serviceInfoAlert.message}</rb.Alert>}

{!serviceInfo?.coinjoinInProgress &&
!serviceInfo?.makerRunning &&
!isWaitingMakerStart &&
!isWaitingMakerStop && <p className="text-secondary mb-4">{t('earn.market_explainer')}</p>}

{!serviceInfo?.coinjoinInProgress && (
<>
<PageTitle
title={'Create a Fidelity Bond'}
subtitle={
'Fidelity bonds prevent Sybil attacks by deliberately increasing the cost of creating cryptographic identities. Creating a fidelity bond will increase your chances of being picked for a collaborative transaction.'
}
/>
<div className="d-flex flex-column gap-3">
{fidelityBonds.length > 0 &&
fidelityBonds.map((utxo, index) => <ExistingFidelityBond key={index} utxo={utxo} />)}
{!isLoading && balanceSummary ? (
<CreateFidelityBond
otherFidelityBondExists={fidelityBonds.length > 0}
accountBalances={balanceSummary?.accountBalances}
totalBalance={balanceSummary?.totalBalance}
wallet={currentWallet}
walletInfo={currentWalletInfo}
/>
) : (
<rb.Placeholder as="div" animation="wave">
<rb.Placeholder xs={12} className={styles['fb-loader']} />
</rb.Placeholder>
)}
</div>
</>
)}
{!serviceInfo?.coinjoinInProgress && (
<Formik initialValues={initialValues} validate={validate} onSubmit={onSubmit}>
{({ handleSubmit, setFieldValue, handleChange, handleBlur, values, touched, errors, isSubmitting }) => (
Expand Down Expand Up @@ -423,7 +462,6 @@ export default function Earn() {
<hr />
</div>
)}

<rb.Button
variant="dark"
type="submit"
Expand Down Expand Up @@ -457,7 +495,6 @@ export default function Earn() {
)}
</rb.Col>
</rb.Row>

<rb.Row className="mt-5 mb-3">
<rb.Col className="d-flex justify-content-center">
<EarnReportOverlay show={isShowReport} onHide={() => setIsShowReport(false)} />
Expand Down
5 changes: 5 additions & 0 deletions src/components/Earn.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
border-radius: 0.25rem;
}

.earn .fb-loader {
height: 11rem;
border-radius: 0.25rem;
}

.earn form input:not([type='checkbox']) {
height: 3.5rem;
}
Expand Down
4 changes: 0 additions & 4 deletions src/components/FidelityBond.module.css

This file was deleted.

Loading