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

Testing for direct send rpc api #809

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ RUN apt-get update \
tor \
&& rm -rf /var/lib/apt/lists/*

ENV REPO https://github.com/JoinMarket-Org/joinmarket-clientserver
ENV REPO_BRANCH master
ENV REPO_REF master
ENV REPO https://github.com/amitx13/joinmarket-clientserver
ENV REPO_BRANCH Updating_Direct-Send_RPC-API_to_accept_UTXOs
ENV REPO_REF Updating_Direct-Send_RPC-API_to_accept_UTXOs

WORKDIR /src
RUN git clone "$REPO" . --depth=10 --branch "$REPO_BRANCH" && git checkout "$REPO_REF"
Expand Down
1 change: 1 addition & 0 deletions src/components/Send/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export interface SendFormValues {
txFee?: TxFee
isCoinJoin: boolean
numCollaborators?: number
consideredUtxos?: string[]
}

interface InnerSendFormProps {
Expand Down
22 changes: 18 additions & 4 deletions src/components/Send/SourceJarSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useField, useFormikContext } from 'formik'
import * as rb from 'react-bootstrap'
import { jarFillLevel, SelectableJar } from '../jars/Jar'
import { noop } from '../../utils'
import { WalletInfo, CurrentWallet, useReloadCurrentWalletInfo, Utxo } from '../../context/WalletContext'
import { WalletInfo, CurrentWallet, useReloadCurrentWalletInfo, Utxo, Utxos } from '../../context/WalletContext'
import styles from './SourceJarSelector.module.css'
import { ShowUtxos } from './ShowUtxos'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -38,6 +38,7 @@ export const SourceJarSelector = ({
}: SourceJarSelectorProps) => {
const { t } = useTranslation()
const [field] = useField<JarIndex>(name)
const [consideredUtxos] = useField<Utxos | undefined>('consideredUtxos')
const form = useFormikContext<any>()
const reloadCurrentWalletInfo = useReloadCurrentWalletInfo()

Expand Down Expand Up @@ -109,9 +110,21 @@ export const SourceJarSelector = ({

if (res.length !== 0) {
setIsUtxosLoading(true)
await reloadCurrentWalletInfo.reloadUtxos({ signal: abortCtrl.signal })
const allUtxosData = await reloadCurrentWalletInfo.reloadUtxos({ signal: abortCtrl.signal })
if (allUtxosData) {
const selectedUtxos = allUtxosData.utxos
.filter((utxo) => utxo.mixdepth === field.value && !utxo.frozen)
.map((utxo) => utxo.utxo)
form.setFieldValue(consideredUtxos.name, selectedUtxos, true)
}
} else {
if (walletInfo) {
const selectedUtxos = walletInfo.utxosByJar[field.value]
.filter((utxo) => !utxo.frozen)
.map((utxo) => utxo.utxo)
form.setFieldValue(consideredUtxos.name, selectedUtxos, true)
}
}

setShowUtxos(undefined)
} catch (err: any) {
if (!abortCtrl.signal.aborted) {
Expand All @@ -120,7 +133,7 @@ export const SourceJarSelector = ({
} finally {
setIsUtxosLoading(false)
}
}, [frozenUtxos, unFrozenUtxos, wallet, reloadCurrentWalletInfo])
}, [frozenUtxos, unFrozenUtxos, wallet, reloadCurrentWalletInfo, consideredUtxos, form, field, walletInfo])

return (
<>
Expand Down Expand Up @@ -165,6 +178,7 @@ export const SourceJarSelector = ({
variant={it.accountIndex === field.value ? variant : undefined}
onClick={(jarIndex: number) => {
form.setFieldValue(field.name, jarIndex, true)
form.setFieldValue(consideredUtxos.name, undefined, false)
if (
it.accountIndex === field.value &&
!disabled &&
Expand Down
57 changes: 53 additions & 4 deletions src/components/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import { scrollToTop } from '../../utils'
import { PaymentConfirmModal } from '../PaymentConfirmModal'
import FeeConfigModal, { FeeConfigSectionKey } from '../settings/FeeConfigModal'
import { FeeValues, TxFee, useFeeConfigValues } from '../../hooks/Fees'
import { useReloadCurrentWalletInfo, useCurrentWalletInfo, CurrentWallet } from '../../context/WalletContext'
import { useReloadCurrentWalletInfo, useCurrentWalletInfo, CurrentWallet, Utxos } from '../../context/WalletContext'
import { useServiceInfo, useReloadServiceInfo } from '../../context/ServiceInfoContext'
import { useLoadConfigValue } from '../../context/ServiceConfigContext'
import { useWaitForUtxosToBeSpent } from '../../hooks/WaitForUtxosToBeSpent'
import { routes } from '../../constants/routes'
import { JM_MINIMUM_MAKERS_DEFAULT } from '../../constants/config'

import { initialNumCollaborators } from './helpers'
import { Divider, UtxoListDisplay } from './ShowUtxos'
import { useSettings } from '../../context/SettingsContext'

const INITIAL_DESTINATION = null
const INITIAL_SOURCE_JAR_INDEX = null
Expand Down Expand Up @@ -79,6 +81,29 @@ const createInitialValues = (numCollaborators: number, feeConfigValues: FeeValue
}
}

type ReviewConsideredUtxosProps = {
utxos: Utxos
}
const ReviewConsideredUtxos = ({ utxos }: ReviewConsideredUtxosProps) => {
const { t } = useTranslation()
const settings = useSettings()
const [isOpen, setIsOpen] = useState<boolean>(false)

return (
<rb.Row className="mt-3">
<rb.Col xs={4} md={3} className="text-end">
<strong>{t('show_utxos.considered_utxos')}</strong>
</rb.Col>
<rb.Col xs={8} md={9}>
<Divider isState={isOpen} setIsState={setIsOpen} className="mb-3" />
{isOpen && (
<UtxoListDisplay utxos={utxos} settings={settings} showRadioButton={false} showBackgroundColor={false} />
)}
</rb.Col>
</rb.Row>
)
}

type SendProps = {
wallet: CurrentWallet
}
Expand Down Expand Up @@ -238,6 +263,7 @@ export default function Send({ wallet }: SendProps) {
destination: Api.BitcoinAddress,
amountSats: Api.AmountSats,
txFee: TxFee,
consideredUtxos?: string[],
) => {
setAlert(undefined)
setPaymentSuccessfulInfoAlert(undefined)
Expand All @@ -247,7 +273,13 @@ export default function Send({ wallet }: SendProps) {
try {
const res = await Api.postDirectSend(
{ ...wallet },
{ mixdepth: sourceJarIndex, amount_sats: amountSats, destination, txfee: txFee.value },
{
mixdepth: sourceJarIndex,
amount_sats: amountSats,
destination,
txfee: txFee.value,
selected_utxos: consideredUtxos,
},
)

if (res.ok) {
Expand Down Expand Up @@ -395,7 +427,13 @@ export default function Send({ wallet }: SendProps) {
values.numCollaborators!,
values.txFee!,
)
: await sendPayment(values.sourceJarIndex!, values.destination!.value!, values.amount!.value, values.txFee!)
: await sendPayment(
values.sourceJarIndex!,
values.destination!.value!,
values.amount!.value,
values.txFee!,
values.consideredUtxos,
)

if (success) {
formRef.current?.resetForm({ values: initialValues })
Expand Down Expand Up @@ -516,7 +554,18 @@ export default function Send({ wallet }: SendProps) {
numCollaborators: showConfirmSendModal.numCollaborators!,
feeConfigValues: { ...feeConfigValues, tx_fees: showConfirmSendModal.txFee },
}}
/>
>
{showConfirmSendModal.consideredUtxos &&
walletInfo &&
showConfirmSendModal.sourceJarIndex !== undefined &&
(() => {
const selectedUtxosList = showConfirmSendModal.consideredUtxos
const utxoList = walletInfo.utxosByJar[showConfirmSendModal.sourceJarIndex].filter((utxo) =>
selectedUtxosList.some((selectedUtxos) => selectedUtxos === utxo.utxo),
)
return <ReviewConsideredUtxos utxos={utxoList} />
})()}
</PaymentConfirmModal>
)}
</div>
)
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 @@ -703,7 +703,7 @@
},
"show_utxos": {
"select_utxos": "Select UTXOs",
"selected_utxos": "Selected UTXOs",
"considered_utxos": "Considered UTXOs",
"show_utxo_title": "Select UTXOs to be considered",
"show_utxo_subtitle": "The following UTXOs are considered in the transaction. Every unselected UTXO will be frozen and can be unfrozen later on.",
"show_utxo_subtitle_when_allutxos_are_frozen": "The following UTXOs are frozen. Please select them to be considered in the transaction.",
Expand Down
1 change: 1 addition & 0 deletions src/libs/JmWalletApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ interface DirectSendRequest {
destination: BitcoinAddress
amount_sats: AmountSats
txfee?: number
selected_utxos?: string[]
}

interface DoCoinjoinRequest {
Expand Down