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: Fidelity bonds in developer mode #221

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e99869c
dev: add simple fidelity bond screen in advanced mode
theborakompanioni May 31, 2022
cc74b4f
dev: add link to fidelity form page in CurrentWalletAdvanced
theborakompanioni May 31, 2022
c7e8211
dev: fix build errors and remove 'as' tag of translation elements
theborakompanioni Jun 1, 2022
54cd533
refactor: move FidelityBondAdvanced component to own file
theborakompanioni Jun 1, 2022
a601f48
ui: highlight expiry date of fidelity bond address
theborakompanioni Jun 1, 2022
606d490
dev: display Fidelity Bond create form regardless if FBs already exist
theborakompanioni Jun 1, 2022
688178c
dev: avoid flickering when loading new fb address
theborakompanioni Jun 1, 2022
c33c567
fix: rename Locktime to Lockdate
theborakompanioni Jun 1, 2022
f2bfc99
dev: add translation strings to section 'global'
theborakompanioni Jun 1, 2022
5d8131e
Merge branch 'master' into fidelity-bonds
theborakompanioni Jun 2, 2022
2d6831f
Merge branch 'master' into fidelity-bonds
theborakompanioni Jun 6, 2022
fdd3206
review: distinct simple and dev mode Fidelity Bond screens
theborakompanioni Jun 6, 2022
7b99317
review: fix dev FB view in dark mode
theborakompanioni Jun 6, 2022
81b1f98
refactor: rename FidelityBondAdvanced to FidelityBondDevOnly
theborakompanioni Jun 6, 2022
4281778
dev: add link to default view to FidelityBondDevOnly
theborakompanioni Jun 6, 2022
9ff85f4
Merge branch 'master' into fidelity-bonds
theborakompanioni Jun 7, 2022
83595bf
review: render whitespace only when necessary in FB alert
theborakompanioni Jun 7, 2022
03c64d0
review: do not provide time related values to Date.UTC for FB
theborakompanioni Jun 7, 2022
6521da0
Update src/components/FidelityBondDevOnly.tsx
theborakompanioni Jun 7, 2022
b7f4290
review: do not duplicate 'initialLockdate' values
theborakompanioni Jun 7, 2022
784ae27
dev: allow lockdates in the past in dev mode
theborakompanioni Jun 7, 2022
9a4c48d
dev: externalize LockdateForm
theborakompanioni Jun 8, 2022
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
9 changes: 9 additions & 0 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'
import { Route, Routes, Navigate } from 'react-router-dom'
import * as rb from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'
import { isFeatureEnabled } from '../constants/features'
import Wallets from './Wallets'
import CreateWallet from './CreateWallet'
import Jam from './Jam'
Expand All @@ -10,6 +11,8 @@ import Earn from './Earn'
import Receive from './Receive'
import CurrentWalletMagic from './CurrentWalletMagic'
import CurrentWalletAdvanced from './CurrentWalletAdvanced'
import FidelityBond from './FidelityBond'
import { FidelityBondDevOnly } from './FidelityBondDevOnly'
import Settings from './Settings'
import Navbar from './Navbar'
import Layout from './Layout'
Expand Down Expand Up @@ -129,6 +132,12 @@ export default function App() {
<Route path={routes.earn} element={<Earn />} />
<Route path={routes.receive} element={<Receive />} />
<Route path={routes.settings} element={<Settings />} />
{isFeatureEnabled('fidelityBonds') && (
<Route path={routes.fidelityBonds} element={<FidelityBond />} />
)}
{isFeatureEnabled('fidelityBondsDevOnly') && (
<Route path={routes.fidelityBondsDevOnly} element={<FidelityBondDevOnly />} />
)}
</>
)}
</Route>
Expand Down
5 changes: 3 additions & 2 deletions src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export function CopyButton({ value, onSuccess, onError, children, ...props }: Pr

interface CopyButtonWithConfirmationProps extends CopyButtonProps {
text: string
successText: string
successTextTimeout: number
successText?: string
successTextTimeout?: number
disabled?: boolean
}

export function CopyButtonWithConfirmation({
Expand Down
56 changes: 41 additions & 15 deletions src/components/CurrentWalletAdvanced.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react'
import { Link } from 'react-router-dom'
import * as rb from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import { Trans, useTranslation } from 'react-i18next'
// @ts-ignore
import DisplayAccounts from './DisplayAccounts'
// @ts-ignore
Expand All @@ -9,12 +10,16 @@ import DisplayAccountUTXOs from './DisplayAccountUTXOs'
import DisplayUTXOs from './DisplayUTXOs'
// @ts-ignore
import { useCurrentWallet, useCurrentWalletInfo, useReloadCurrentWalletInfo } from '../context/WalletContext'
import { isFeatureEnabled } from '../constants/features'
import { routes } from '../constants/routes'
import styles from './CurrentWalletAdvanced.module.css'

type Utxos = any[]
type Alert = { message: string; variant: string }

export default function CurrentWalletAdvanced() {
const featureFidelityBondsEnabled = isFeatureEnabled('fidelityBonds')

const { t } = useTranslation()
const currentWallet = useCurrentWallet()
const walletInfo = useCurrentWalletInfo()
Expand Down Expand Up @@ -76,21 +81,42 @@ export default function CurrentWalletAdvanced() {
{!isLoading && walletInfo && (
<DisplayAccounts accounts={walletInfo.data.display.walletinfo.accounts} className="mb-4" />
)}
{!!fidelityBonds?.length && (
<div className="mt-5 mb-3 pe-3">
<h5>{t('current_wallet_advanced.title_fidelity_bonds')}</h5>
<DisplayUTXOs utxos={fidelityBonds} className="pe-2" />
</div>
)}

<div className="mt-5 mb-3">
<h5>{t('current_wallet_advanced.title_fidelity_bonds')}</h5>
{isLoading && (
<div>
<rb.Placeholder as="div" animation="wave" className={styles['current-wallet-placeholder-container']}>
<rb.Placeholder xs={12} className={styles['current-wallet-placeholder']} />
</rb.Placeholder>
</div>
)}

{!isLoading && fidelityBonds && (
<>
{fidelityBonds.length === 0 ? (
<rb.Alert variant="info">
<>
<Trans i18nKey="fidelity_bond.alert_no_fidelity_bonds" as="span">
No Fidelity Bond present.
</Trans>{' '}
theborakompanioni marked this conversation as resolved.
Show resolved Hide resolved
{featureFidelityBondsEnabled && (
<Link to={routes.fidelityBonds}>
<Trans i18nKey="current_wallet_advanced.link_fidelity_bonds_create_text" as="span">
Create a Fidelity Bond.
</Trans>
</Link>
)}
theborakompanioni marked this conversation as resolved.
Show resolved Hide resolved
</>
</rb.Alert>
) : (
<DisplayUTXOs utxos={fidelityBonds} />
)}
</>
)}
</div>
<>
<rb.Button
variant="outline-dark"
disabled={isLoading}
onClick={() => {
setShowUTXO(!showUTXO)
}}
className={isLoading ? 'mt-3 mb-3 pe-auto' : 'mb-3'}
>
<rb.Button variant="outline-dark" disabled={isLoading} onClick={() => setShowUTXO(!showUTXO)} className="mb-3">
{showUTXO ? t('current_wallet_advanced.button_hide_utxos') : t('current_wallet_advanced.button_show_utxos')}
</rb.Button>
<rb.Fade in={showUTXO} mountOnEnter={true} unmountOnExit={true}>
Expand Down
4 changes: 4 additions & 0 deletions src/components/FidelityBond.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Firefox */
.fidelity-bond input[type='number'] {
-moz-appearance: unset !important;
}
64 changes: 64 additions & 0 deletions src/components/FidelityBond.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import * as rb from 'react-bootstrap'

// @ts-ignore
import PageTitle from './PageTitle'
import { isFeatureEnabled } from '../constants/features'

import { routes } from '../constants/routes'
import styles from './FidelityBond.module.css'

export default function FidelityBond() {
const featureEnabled = isFeatureEnabled('fidelityBonds')
const featureAdvancedEnabled = isFeatureEnabled('fidelityBondsDevOnly')

const { t } = useTranslation()

if (!featureEnabled) {
return (
<div>
<h2>Feature not enabled</h2>
</div>
)
}

return (
<div className={styles['fidelity-bond']}>
<PageTitle title={t('fidelity_bond.title')} subtitle={t('fidelity_bond.subtitle')} />

<rb.Row>
<rb.Col>
<div className="mb-4">
<Trans i18nKey="fidelity_bond.description">
<a
href="https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/fidelity-bonds.md"
target="_blank"
rel="noopener noreferrer"
className="text-secondary"
>
See the documentation about Fidelity Bonds
</a>{' '}
for more information.
</Trans>
</div>

<rb.Alert variant="danger" className="mb-4">
<Trans i18nKey="fidelity_bond.alert_warning_dev_mode">
Fidelity Bonds are currently only available in developer mode.
{featureAdvancedEnabled && (
<>
{' '}
<Link className="unstyled" to={routes.fidelityBondsDevOnly}>
Switch to developer view.
</Link>
Comment on lines +53 to +55
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I don't think we need that extra step. It's already only in "advanced" mode (which is called developer mode in the app already). Once the user is here I'd say we can let them do their stuff. No need for the extra hurdle imo. What do you think about it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need two distinct modes. As a developer, I want to have access to the actual timelock address, which does not necessarily need to be exposed to a user ever. Do you have a preferred way to do this or do you have different mechanism in mind?

Having a dedicated view for local development seemed to be the easiest solution to me.
e.g. Creating Fidelity Bonds in the past – a user should never be able to do that.. in development it is very useful, though.

</>
)}
</Trans>
</rb.Alert>
</rb.Col>
</rb.Row>
</div>
)
}
Loading