Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/components/receive/ReceivePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const mocks = vi.hoisted(() => {

return {
developerMode: false,
rescanning: false,
getAddress: vi.fn(),
defaultJars,
jars: defaultJars,
Expand Down Expand Up @@ -107,6 +108,12 @@ vi.mock('@/context/JamWalletInfoContext', () => ({
}),
}))

vi.mock('@/context/JamSessionInfoContext', () => ({
useRescanStatus: () => ({
rescanInfo: { rescanning: mocks.rescanning },
}),
}))

vi.mock('@/hooks/useApiClient', () => ({
useApiClient: () => ({}),
}))
Expand Down Expand Up @@ -148,6 +155,7 @@ vi.mock('./ReceiveForm', () => ({
describe('ReceivePage', () => {
beforeEach(() => {
mocks.developerMode = false
mocks.rescanning = false
mocks.jars = mocks.defaultJars
mocks.getAddress.mockReset()
mocks.getAddress.mockResolvedValue({ data: { address: 'bc1qexample' } })
Expand Down Expand Up @@ -175,6 +183,17 @@ describe('ReceivePage', () => {
await flushActUpdates()
})

it('prevents loading addresses while rescanning', () => {
mocks.rescanning = true

render(<ReceivePage walletFileName="wallet.jmdat" />)

expect(screen.getByRole('button', { name: 'receive.button_reveal_address' })).toBeDisabled()
expect(screen.getByRole('button', { name: 'receive.button_new_address' })).toBeDisabled()
fireEvent.click(screen.getByRole('button', { name: 'receive.button_new_address' }))
expect(mocks.getAddress).not.toHaveBeenCalled()
Comment thread
parrth20 marked this conversation as resolved.
})

it('uses a secondary jar badge when no jar is available', () => {
mocks.jars = []

Expand Down
11 changes: 9 additions & 2 deletions src/components/receive/ReceivePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import PageTitle from '@/components/ui/jam/PageTitle'
import { Skeleton } from '@/components/ui/skeleton'
import { useRescanStatus } from '@/context/JamSessionInfoContext'
import { useJars } from '@/context/JamWalletInfoContext'
import { useApiClient } from '@/hooks/useApiClient'
import { withMutationDelay } from '@/lib/queryClient'
Expand All @@ -34,6 +35,7 @@ interface ReceivePageProps {
export const ReceivePage = ({ walletFileName }: ReceivePageProps) => {
const { t } = useTranslation()
const { jars } = useJars()
const { rescanInfo } = useRescanStatus()

const [selectedSourceJarIndex, setSelectedSourceJarIndex] = useState(jars.length > 0 ? jars[0].jarIndex : undefined)
const [amount, setAmount] = useState<AmountSats>()
Expand Down Expand Up @@ -107,6 +109,7 @@ export const ReceivePage = ({ walletFileName }: ReceivePageProps) => {
}

const fetchNewAddress = async () => {
if (rescanInfo.rescanning) return

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this be removed or externalized into a variable (e.g. !operationEnabled) so there is a single place to change, should there be further restrictions?

e.g. imho this might also be true if the maker is running, since collaborative tx outputs come from purpose "receive" (m/84'/0'/{jarIndex}'/0/x) instead of the "change" (m/84'/0'/{jarIndex}'/1/x).

Is that taken care of in joinmarket-ng (maker does not use address already shown to the user and vice versa) @m0wer ?

await getAddressMutation.mutateAsync()
}

Expand All @@ -132,7 +135,7 @@ export const ReceivePage = ({ walletFileName }: ReceivePageProps) => {
variant={jarButtonVariant(selectedSourceJarIndex)}
size="lg"
onClick={() => void fetchNewAddress()}
disabled={getAddressMutation.isPending}
disabled={getAddressMutation.isPending || rescanInfo.rescanning}
>
<HatGlassesIcon />
{t('receive.button_reveal_address')}
Expand Down Expand Up @@ -189,7 +192,11 @@ export const ReceivePage = ({ walletFileName }: ReceivePageProps) => {
</div>

<div className="mt-4 flex flex-wrap items-center justify-center gap-2">
<Button variant="outline" onClick={() => void fetchNewAddress()} disabled={getAddressMutation.isPending}>
<Button
variant="outline"
onClick={() => void fetchNewAddress()}
disabled={getAddressMutation.isPending || rescanInfo.rescanning}
>
{getAddressMutation.isPending ? (
<>
<RefreshCwIcon className="animate-spin motion-reduce:hidden" />
Expand Down