Skip to content

Commit 235900a

Browse files
committed
chore(optional_sender): cleanup to remove repeated tests and optional fields that got required
1 parent 59aca01 commit 235900a

File tree

3 files changed

+8
-151
lines changed

3 files changed

+8
-151
lines changed

src/features/transaction-wizard/transaction-wizard-page.test.tsx

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,11 @@ describe('transaction-wizard-page', () => {
289289
target: { value: walletAccount.addr },
290290
})
291291

292-
const receiverInput = await component.findByLabelText(/Receiver/)
293-
fireEvent.input(receiverInput, {
294-
target: { value: walletAccount.addr },
295-
})
296-
297292
const closeToInput = await component.findByLabelText(/Close remainder to/)
298293
fireEvent.input(closeToInput, {
299294
target: { value: testAccount2.addr },
300295
})
301296

302-
const amountInput = await component.findByLabelText(/Amount to pay/)
303-
fireEvent.input(amountInput, { target: { value: '0' } })
304-
305297
const addButton = await waitFor(() => {
306298
const addButton = component.getByRole('button', { name: 'Add' })
307299
expect(addButton).not.toBeDisabled()
@@ -347,66 +339,6 @@ describe('transaction-wizard-page', () => {
347339
}
348340
)
349341
})
350-
351-
it('can simulate a close account transaction without defining a sender address', async () => {
352-
const testAccount2 = await localnet.context.generateAccount({ initialFunds: algo(0) })
353-
354-
await executeComponentTest(
355-
() => {
356-
return render(<TransactionWizardPage />)
357-
},
358-
async (component, user) => {
359-
const addTransactionButton = await waitFor(() => {
360-
const addTransactionButton = component.getByRole('button', { name: addTransactionLabel })
361-
expect(addTransactionButton).not.toBeDisabled()
362-
return addTransactionButton!
363-
})
364-
await user.click(addTransactionButton)
365-
366-
await selectOption(component.baseElement, user, transactionTypeLabel, 'Account Close (pay)')
367-
368-
const receiverInput = await component.findByLabelText(/Receiver/)
369-
fireEvent.input(receiverInput, {
370-
target: { value: walletAccount.addr },
371-
})
372-
373-
const closeToInput = await component.findByLabelText(/Close remainder to/)
374-
fireEvent.input(closeToInput, {
375-
target: { value: testAccount2.addr },
376-
})
377-
378-
const amountInput = await component.findByLabelText(/Amount to pay/)
379-
fireEvent.input(amountInput, { target: { value: '0' } })
380-
381-
const addButton = await waitFor(() => {
382-
const addButton = component.getByRole('button', { name: 'Add' })
383-
expect(addButton).not.toBeDisabled()
384-
return addButton!
385-
})
386-
await user.click(addButton)
387-
388-
await waitFor(() => {
389-
const table = component.getByLabelText('transaction-group-table')
390-
expect(table).toBeInTheDocument()
391-
expect(component.queryByText('No transactions.')).not.toBeInTheDocument()
392-
})
393-
394-
const simulateButton = await waitFor(() => {
395-
const simulateButton = component.getByRole('button', { name: 'Simulate' })
396-
expect(simulateButton).not.toBeDisabled()
397-
return simulateButton!
398-
})
399-
400-
await user.click(simulateButton)
401-
await waitFor(
402-
() => {
403-
expect(component.queryByText(/error/i)).not.toBeInTheDocument()
404-
},
405-
{ timeout: 5_000 }
406-
)
407-
}
408-
)
409-
})
410342
})
411343

412344
describe('and an application create transaction is being sent', () => {
@@ -555,76 +487,6 @@ describe('transaction-wizard-page', () => {
555487
}
556488
)
557489
})
558-
559-
it('succeeds when sending an op-up transaction', async () => {
560-
await executeComponentTest(
561-
() => {
562-
return render(<TransactionWizardPage />)
563-
},
564-
async (component, user) => {
565-
const addTransactionButton = await waitFor(() => {
566-
const addTransactionButton = component.getByRole('button', { name: addTransactionLabel })
567-
expect(addTransactionButton).not.toBeDisabled()
568-
return addTransactionButton!
569-
})
570-
await user.click(addTransactionButton)
571-
572-
await selectOption(component.baseElement, user, transactionTypeLabel, 'Application Create (appl)')
573-
574-
const senderInput = await component.findByLabelText(/Sender/)
575-
fireEvent.input(senderInput, {
576-
target: { value: walletAccount.addr },
577-
})
578-
579-
const approvalProgramInput = await component.findByLabelText(/Approval program/)
580-
fireEvent.input(approvalProgramInput, {
581-
target: { value: 'CoEBQw==' },
582-
})
583-
584-
const clearStateProgramInput = await component.findByLabelText(/Clear state program/)
585-
fireEvent.input(clearStateProgramInput, {
586-
target: { value: 'CoEBQw==' },
587-
})
588-
589-
await selectOption(component.baseElement, user, /On complete/, 'Delete')
590-
591-
const addButton = await waitFor(() => {
592-
const addButton = component.getByRole('button', { name: 'Add' })
593-
expect(addButton).not.toBeDisabled()
594-
return addButton!
595-
})
596-
await user.click(addButton)
597-
598-
const sendButton = await waitFor(() => {
599-
const sendButton = component.getByRole('button', { name: sendButtonLabel })
600-
expect(sendButton).not.toBeDisabled()
601-
return sendButton!
602-
})
603-
await user.click(sendButton)
604-
605-
const resultsDiv = await waitFor(
606-
() => {
607-
expect(component.queryByText('Required')).not.toBeInTheDocument()
608-
return component.getByText(groupSendResultsLabel).parentElement!
609-
},
610-
{ timeout: 10_000 }
611-
)
612-
613-
const transactionId = await waitFor(
614-
() => {
615-
const transactionLink = within(resultsDiv)
616-
.getAllByRole('link')
617-
.find((a) => a.getAttribute('href')?.startsWith('/localnet/transaction'))!
618-
return transactionLink.getAttribute('href')!.split('/').pop()!
619-
},
620-
{ timeout: 10_000 }
621-
)
622-
623-
const result = await localnet.context.waitForIndexerTransaction(transactionId)
624-
expect(result.transaction.sender).toBe(walletAccount.addr.toString())
625-
}
626-
)
627-
})
628490
})
629491

630492
describe('and an application update transaction is being sent', () => {

src/features/transaction-wizard/utils/transform-search-params-transactions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const transformAssetOptInTransaction = async (params: BaseSearchParamTransaction
132132
id: BigInt(params.assetid),
133133
decimals: params.decimals ? Number(params.decimals) : undefined,
134134
unitName: params.unitname,
135+
clawback: params.clawback,
135136
},
136137
fee: params.fee ? { setAutomatically: false, value: microAlgo(Number(params.fee)).algo } : { setAutomatically: true },
137138
validRounds: {
@@ -151,6 +152,7 @@ const transformAssetOptOutTransaction = async (params: BaseSearchParamTransactio
151152
id: BigInt(params.assetid),
152153
decimals: params.decimals ? Number(params.decimals) : undefined,
153154
unitName: params.unitname,
155+
clawback: params.clawback,
154156
},
155157
closeRemainderTo: {
156158
value: params.closeto,
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useState } from 'react'
1+
import { useEffect, useState } from 'react'
22
import { useSearchParams } from 'react-router-dom'
33
import { toast } from 'react-toastify'
44
import { transformSearchParamsTransactions } from './transform-search-params-transactions'
@@ -7,29 +7,21 @@ import type { BaseSearchParamTransaction, BuildTransactionResult } from '../mode
77
const transformSearchParams = (searchParams: URLSearchParams) => {
88
const entries = Array.from(searchParams.entries())
99

10-
const grouped = entries.reduce<BaseSearchParamTransaction[]>((acc, [key, value]) => {
10+
const groupedParams = entries.reduce<BaseSearchParamTransaction[]>((acc, [key, value]) => {
1111
const match = key.match(/^([^[]+)\[(\d+)\]$/)
1212
if (!match) return acc
1313
const [, paramName, index] = match
1414
const idx = parseInt(index, 10)
15-
acc[idx] ??= { type: '' } // ensure slot exists; keep your original default
15+
acc[idx] ??= { type: '' }
1616
acc[idx][paramName] = value
1717
return acc
1818
}, [])
1919

20-
return grouped.filter((entry) => Object.keys(entry).length > 0)
20+
return groupedParams.filter((entry) => Object.keys(entry).length > 0)
2121
}
2222

2323
export function useTransactionSearchParamsBuilder() {
2424
const [searchParams] = useSearchParams()
25-
26-
// memoize the parsed params so effect only runs when params actually change
27-
const transformedParams = useMemo(
28-
() => transformSearchParams(searchParams),
29-
// URLSearchParams is mutable; tie memoization to its string form
30-
[searchParams]
31-
)
32-
3325
const [transactions, setTransactions] = useState<BuildTransactionResult[]>([])
3426
const [loading, setLoading] = useState(false)
3527

@@ -38,6 +30,7 @@ export function useTransactionSearchParamsBuilder() {
3830
const loadTransactions = async () => {
3931
setLoading(true)
4032
try {
33+
const transformedParams = transformSearchParams(searchParams)
4134
const { transactions, errors = [] } = await transformSearchParamsTransactions(transformedParams)
4235
if (!mounted) return
4336
setTransactions(transactions)
@@ -53,7 +46,7 @@ export function useTransactionSearchParamsBuilder() {
5346
return () => {
5447
mounted = false
5548
}
56-
}, [transformedParams])
49+
}, [searchParams])
5750

5851
return { transactions, loading }
5952
}

0 commit comments

Comments
 (0)