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: show address reuse warning #411

Merged
5 commits merged into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
85 changes: 55 additions & 30 deletions src/components/Send.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export default function Send() {
const [isSweep, setIsSweep] = useState(false)
const [destinationJarPickerShown, setDestinationJarPickerShown] = useState(false)
const [destinationJar, setDestinationJar] = useState(null)
const [destinationIsReusedAddress, setDesitnationIsReusedAddress] = useState(false)
This conversation was marked as resolved.
Show resolved Hide resolved

const [waitForUtxosToBeSpent, setWaitForUtxosToBeSpent] = useState([])
const [paymentSuccessfulInfoAlert, setPaymentSuccessfulInfoAlert] = useState(null)
Expand Down Expand Up @@ -425,6 +426,17 @@ export default function Send() {
return () => abortCtrl.abort()
}, [isOperationDisabled, wallet, reloadCurrentWalletInfo, reloadServiceInfo, loadConfigValue, t])

useEffect(() => {
if (walletInfo?.addressSummary[destination]) {
theborakompanioni marked this conversation as resolved.
Show resolved Hide resolved
if (walletInfo?.addressSummary[destination].status !== 'new') {
setDesitnationIsReusedAddress(true)
return
}
}

setDesitnationIsReusedAddress(false)
}, [walletInfo, destination])

const sendPayment = async (account, destination, amount_sats) => {
setAlert(null)
setPaymentSuccessfulInfoAlert(null)
Expand Down Expand Up @@ -807,42 +819,55 @@ export default function Send() {
})}
value={destinationJar !== null ? `Jar #${destinationJar} (${destination})` : destination || ''}
required
onChange={(e) => setDestination(e.target.value)}
isInvalid={destination !== null && !isValidAddress(destination)}
disabled={isOperationDisabled || destinationJar !== null}
/>
<rb.Button
variant="outline-dark"
className={styles['button-jar-selector']}
onClick={() => {
if (destinationJar !== null) {
setDestinationJar(null)
setDestination(INITIAL_DESTINATION)
onChange={(e) => {
const value = e.target.value
if (value === '') {
setDestination(null)
} else {
setDestinationJarPickerShown(true)
setDestination(e.target.value)
}
}}
disabled={isOperationDisabled}
>
{destinationJar !== null ? (
<div className="d-flex justify-content-center align-items-center">
<Sprite symbol="cancel" width="26" height="26" />
</div>
) : (
<div className="d-flex justify-content-center align-items-center">
<Sprite
symbol="jar-closed-empty"
width="28px"
height="28px"
style={{ paddingBottom: '0.2rem' }}
/>
</div>
)}
</rb.Button>
isInvalid={(destination !== null && !isValidAddress(destination)) || destinationIsReusedAddress}
disabled={isOperationDisabled || destinationJar !== null}
/>
{destinationIsReusedAddress && (
<rb.Form.Control.Feedback type="invalid">
{t('send.feedback_reused_address')}
</rb.Form.Control.Feedback>
)}
{!destinationIsReusedAddress && (
<rb.Button
variant="outline-dark"
className={styles['button-jar-selector']}
onClick={() => {
if (destinationJar !== null) {
setDestinationJar(null)
setDestination(INITIAL_DESTINATION)
} else {
setDestinationJarPickerShown(true)
}
}}
disabled={isOperationDisabled}
>
{destinationJar !== null ? (
<div className="d-flex justify-content-center align-items-center">
<Sprite symbol="cancel" width="26" height="26" />
</div>
) : (
<div className="d-flex justify-content-center align-items-center">
<Sprite
symbol="jar-closed-empty"
width="28px"
height="28px"
style={{ paddingBottom: '0.2rem' }}
/>
</div>
)}
</rb.Button>
)}
</>
)}
</div>
<rb.Form.Control.Feedback type="invalid">{t('send.feedback_invalid_recipient')}</rb.Form.Control.Feedback>
</rb.Form.Group>
<rb.Form.Group controlId="isCoinjoin" className={`${isCoinjoin ? 'mb-3' : ''}`}>
<ToggleSwitch
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"text_coinjoin_already_running": "A collaborative transaction is currently in progress.",
"label_recipient": "Recipient",
"placeholder_recipient": "Enter address or choose jar from wallet...",
"feedback_invalid_recipient": "Please provide a recipient address.",
"feedback_reused_address": "This address is already used. To preserve your privacy please chose another one.",
This conversation was marked as resolved.
Show resolved Hide resolved
"label_account": "Send from",
"label_account_dev_mode": "Account to send from",
"account_selector_option": "Jar {{ number }}",
Expand Down