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 #307

Merged
108 commits merged into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 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
2d9f186
wip: FidelityBondSimple
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
5756f6f
Merge branch 'fidelity-bonds' into fidelity-bonds-simple
theborakompanioni Jun 6, 2022
4281778
dev: add link to default view to FidelityBondDevOnly
theborakompanioni Jun 6, 2022
0d35db6
Merge branch 'fidelity-bonds' into fidelity-bonds-simple
theborakompanioni Jun 6, 2022
8ead4c3
dev: sort utxo by value
theborakompanioni Jun 7, 2022
6e03a96
dev: reset user confirmation on data change
theborakompanioni Jun 7, 2022
acb041e
dev: create fidelity bond with collaborative transaction WIP
theborakompanioni Jun 7, 2022
7b94c7a
dev: wait for collaborative transaction to finish
theborakompanioni Jun 7, 2022
edacd3f
dev: unfreeze utxos after creating sweep tx
theborakompanioni Jun 7, 2022
9ff85f4
Merge branch 'master' into fidelity-bonds
theborakompanioni Jun 7, 2022
f6e7b0b
Merge branch 'fidelity-bonds' into fidelity-bonds-simple
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
7c1e0bb
Merge branch 'fidelity-bonds' into fidelity-bonds-simple
theborakompanioni Jun 7, 2022
18debb6
dev: display percentage of utxo to total value in account
theborakompanioni Jun 7, 2022
14c54b2
dev: style percentage bar
theborakompanioni Jun 8, 2022
a16a6d0
dev: display percentage bar in account selector
theborakompanioni Jun 8, 2022
10907b7
dev: i18n for 'time elapsed' phrase
theborakompanioni Jun 8, 2022
628bf89
dev: externalize components UtxoSelector and UtxoCheckbox
theborakompanioni Jun 8, 2022
4b9f23e
dev: externalize components AccountSelector and AccountCheckbox
theborakompanioni Jun 8, 2022
9a4c48d
dev: externalize LockdateForm
theborakompanioni Jun 8, 2022
7c31230
Merge branch 'fidelity-bonds' into fidelity-bonds-simple
theborakompanioni Jun 8, 2022
efbcd76
dev: externalize FidelityBondDetailsSetupForm
theborakompanioni Jun 8, 2022
4e98f92
dev: display all accounts by default in FB form
theborakompanioni Jun 8, 2022
ce4cec7
refactor: remove unused vars and imports
theborakompanioni Jun 8, 2022
f4c081e
dev: fix comments and add todos
theborakompanioni Jun 8, 2022
871d1c7
dev: minimal i18n for FB form
theborakompanioni Jun 8, 2022
6f44c54
ui: remove account/utxo checkbox overlay
theborakompanioni Jun 8, 2022
bfe046d
dev: add checkbox-card component
theborakompanioni Jun 8, 2022
53f8d20
dev: show unit of funds according to settings in FB form
theborakompanioni Jun 8, 2022
7032e64
dev: allow already expired lockdates in dev mode
theborakompanioni Jun 8, 2022
fd3bf5b
dev: use minimum makers to create fb
theborakompanioni Jun 9, 2022
2a00885
refactor: combine FidelityBond and FidelityBondSimple
theborakompanioni Jun 9, 2022
8159b1c
dev: undo coin control setup on errors
theborakompanioni Jun 9, 2022
e7a8705
dev: perform coin control actions sequentially
theborakompanioni Jun 9, 2022
c42ddca
dev: use direct-send when renewing an expired fidelity bond
theborakompanioni Jun 9, 2022
b205fda
review: improve code readability
theborakompanioni Jun 9, 2022
19dbb31
review: do not return value from function 'sweepToFidelityBond'
theborakompanioni Jun 9, 2022
a088b2b
dev: log timelocked address to console in dev mode
theborakompanioni Jun 9, 2022
e7fd8ef
review: remove FidelityBondDevOnly component
theborakompanioni Jun 9, 2022
c3fe2a2
review: use dropdowns in lockdate form
theborakompanioni Jun 9, 2022
76b3ceb
Merge branch 'master' into fidelity-bonds-simple
theborakompanioni Jun 9, 2022
4492cdc
Update src/components/FidelityBond.tsx
theborakompanioni Jun 9, 2022
b850ca9
dev: add debug feature 'allowCreatingExpiredFidelityBond'
theborakompanioni Jun 9, 2022
0f927e8
review: fix var naming
theborakompanioni Jun 9, 2022
ee4929a
review: fix comment
theborakompanioni Jun 9, 2022
e2db0d6
Update src/components/FidelityBond.tsx
theborakompanioni Jun 9, 2022
0550b89
Update src/components/FidelityBond.tsx
theborakompanioni Jun 9, 2022
4ff12d9
dev: unfreeze sequentially after fidelity bond tx was created
theborakompanioni Jun 9, 2022
789103a
review: remove ability to select multiple jars
theborakompanioni Jun 9, 2022
2a448e1
review: add tests for fb utils
theborakompanioni Jun 9, 2022
a82d4bb
Merge branch 'master' into fidelity-bonds-simple
theborakompanioni Jun 10, 2022
5d6ee92
review: remove coin control
theborakompanioni Jun 10, 2022
8bc10e6
review: reflect missing coin control in account checkbox
theborakompanioni Jun 10, 2022
6573ce6
review: remove time elapsed string from fb summary
theborakompanioni Jun 10, 2022
de52a59
dev: add taker started alert to FB screen
theborakompanioni Jun 10, 2022
aa7f5af
dev: reset lockdate form if date is invalid
theborakompanioni Jun 10, 2022
93348c7
dev: reload after taker operation
theborakompanioni Jun 10, 2022
0a01dc0
dev: add calculated total balance to useBalanceSummary hook
theborakompanioni Jun 10, 2022
fd23398
dev: handle expired timelocked funds in useBalanceSummary hook
theborakompanioni Jun 10, 2022
66809ec
dev: use isLocked to detect if freeze/unfreeze is enabled
theborakompanioni Jun 10, 2022
b517191
dev: fix build
theborakompanioni Jun 10, 2022
7127078
refactor: proper var names
theborakompanioni Jun 12, 2022
86fc702
dev: show success msg only if fb has been created successfully
theborakompanioni Jun 12, 2022
782d0d9
dev: do not wait for collaborative tx to finish
theborakompanioni Jun 12, 2022
5ab5e71
dev: direct-send if renewing FB
theborakompanioni Jun 12, 2022
c45782f
dev: utilize 'isLocked' in CurrentWalletAdvanced and Jam view
theborakompanioni Jun 12, 2022
94f13fe
dev: link to FB view in Cheatsheet
theborakompanioni Jun 12, 2022
191550c
dev: utilize 'calculatedTotalBalanceInSats' where possible
theborakompanioni Jun 12, 2022
426d994
Update src/components/FidelityBond.tsx
theborakompanioni Jun 13, 2022
9aeba9b
review: adapt error handling style on FB sweep tx
theborakompanioni Jun 13, 2022
f03193e
review: always show all accounts in FB form
theborakompanioni Jun 13, 2022
488cc17
review: initial lockdate should be 3 month from now
theborakompanioni Jun 13, 2022
f2b4b52
review: move YearsRange and initialLockdate to fb_utils
theborakompanioni Jun 13, 2022
69df82d
review: display month names
theborakompanioni Jun 13, 2022
7dc8caf
review: wrap rows in container
theborakompanioni Jun 13, 2022
0980adf
review: remove unnecessary comment
theborakompanioni Jun 13, 2022
41d44b3
review: left-align confirmation toggle in FB form
theborakompanioni Jun 13, 2022
ba1c7e3
review: turn accountBalances from array to object
theborakompanioni Jun 13, 2022
841ed2a
Merge branch 'master' into fidelity-bonds-simple
theborakompanioni Jun 14, 2022
16a2e11
Merge branch 'master' into fidelity-bonds-simple
theborakompanioni Jun 14, 2022
4ea2a64
Update src/i18n/locales/en/translation.json
theborakompanioni Jun 14, 2022
e94ab78
Update src/components/FidelityBond.tsx
theborakompanioni Jun 14, 2022
ae68dc4
review: remove initializing flag
theborakompanioni Jun 15, 2022
833dd64
review: show timelocked address in confirmation step
theborakompanioni Jun 15, 2022
6e919a3
test: add test for LockdateForm component
theborakompanioni Jun 15, 2022
245afc6
test: add test for _minMonth
theborakompanioni Jun 15, 2022
bb563f2
test: add test for _selectableYears
theborakompanioni Jun 15, 2022
80b9f5a
test: add test for _selectableMonths
theborakompanioni Jun 15, 2022
d7c9682
Merge branch 'master' into fidelity-bonds-simple
theborakompanioni Jun 15, 2022
7781854
ui: fix table in light theme
theborakompanioni Jun 15, 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
4 changes: 4 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.
5 changes: 5 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,7 @@ 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 @@ -129,6 +131,9 @@ export default function App() {
<Route path={routes.earn} element={<Earn />} />
<Route path={routes.receive} element={<Receive />} />
<Route path={routes.settings} element={<Settings stopWallet={stopWallet} />} />
{isFeatureEnabled('fidelityBonds') && (
<Route path={routes.fidelityBonds} element={<FidelityBond />} />
)}
</>
)}
</Route>
Expand Down
15 changes: 11 additions & 4 deletions src/components/Cheatsheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
import { Trans, useTranslation } from 'react-i18next'
import { routes } from '../constants/routes'
import Sprite from './Sprite'
import { isFeatureEnabled } from '../constants/features'
import styles from './Cheatsheet.module.css'

interface CheatsheetProps {
Expand Down Expand Up @@ -41,6 +42,7 @@ function ListItem({ number, children, ...props }: PropsWithChildren<NumberedProp

export default function Cheatsheet({ show = false, onHide }: CheatsheetProps) {
const { t } = useTranslation()
const featureFidelityBondsEnabled = isFeatureEnabled('fidelityBonds')

return (
<rb.Offcanvas className={styles.cheatsheet} show={show} onHide={onHide} placement="bottom" onClick={onHide}>
Expand Down Expand Up @@ -95,17 +97,22 @@ export default function Cheatsheet({ show = false, onHide }: CheatsheetProps) {
</h6>
<div className="small text-secondary">{t('cheatsheet.item_2.description')}</div>
</ListItem>
<ListItem number={3} className={styles['upcoming-feature']}>
<ListItem number={3} className={featureFidelityBondsEnabled ? '' : styles['upcoming-feature']}>
<h6>
<Trans i18nKey="cheatsheet.item_3.title">
Optional: <Link to={routes.earn}>Lock</Link> funds in a fidelity bond.
Optional: <Link to={featureFidelityBondsEnabled ? routes.fidelityBonds : routes.home}>Lock</Link> funds
in a fidelity bond.
</Trans>
</h6>
<div className="small text-secondary">
{t('cheatsheet.item_3.description')}
<br />
{/* the following phrase is intentionally not translated because it will be removed soon */}
<strong>Feature not implemented yet. Coming soon!</strong>
{!featureFidelityBondsEnabled && (
<>
<br />
<strong>Feature not implemented yet. Coming soon!</strong>
</>
)}
</div>
</ListItem>
<ListItem number={4}>
Expand Down
2 changes: 2 additions & 0 deletions src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function CopyButton({
successTextTimeout = 1_500,
className,
showSprites = true,
...props
}: CopyButtonProps) {
const [showValueCopiedConfirmation, setShowValueCopiedConfirmation] = useState(false)
const [valueCopiedFlag, setValueCopiedFlag] = useState(0)
Expand All @@ -101,6 +102,7 @@ export function CopyButton({

return (
<Copyable
{...props}
className={`btn ${className || ''}`}
value={value}
onError={onError}
Expand Down
63 changes: 46 additions & 17 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 @@ -43,8 +48,8 @@ export default function CurrentWalletAdvanced() {
const unspentOutputs = info.data.utxos.utxos
setUtxos(unspentOutputs)

const lockedOutputs = unspentOutputs.filter((utxo) => utxo.locktime)
setFidelityBonds(lockedOutputs)
const fbOutputs = unspentOutputs.filter((utxo) => utxo.locktime)
setFidelityBonds(fbOutputs)
}
})
.catch((err) => {
Expand Down Expand Up @@ -76,21 +81,45 @@ 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>
{featureFidelityBondsEnabled && (
<>
{' '}
<Link to={routes.fidelityBonds}>
<Trans i18nKey="current_wallet_advanced.link_fidelity_bonds_create_text" as="span">
Create a Fidelity Bond.
theborakompanioni marked this conversation as resolved.
Show resolved Hide resolved
</Trans>
</Link>
</>
)}
</>
</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
3 changes: 2 additions & 1 deletion src/components/DisplayUTXOs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Alert from './Alert'
import { useSettings } from '../context/SettingsContext'
import { useCurrentWallet } from '../context/WalletContext'
import { useServiceInfo } from '../context/ServiceInfoContext'
import { isLocked } from '../hooks/BalanceSummary'
import * as Api from '../libs/JmWalletApi'

const Utxo = ({ utxo, ...props }) => {
Expand All @@ -21,7 +22,7 @@ const Utxo = ({ utxo, ...props }) => {
const isOperationEnabled = useCallback(() => {
const noServiceIsRunning = serviceInfo && !serviceInfo.makerRunning && !serviceInfo.coinjoinInProgress

const isUnfreezeEnabled = !utxo.locktime || new Date(utxo.locktime).getTime() < Date.now()
const isUnfreezeEnabled = !isLocked(utxo)
const allowedToExecute = !utxo.frozen || isUnfreezeEnabled

return noServiceIsRunning && allowedToExecute
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;
}
Loading