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
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const sentRecord = async () => {
const [record] = await getPendingTransactionRecords({
address: SENDER,
scope: ETH_SCOPE,
listedIds: new Set(),
})
return record
}
Expand Down
43 changes: 42 additions & 1 deletion apps/mobile/src/__integration__/ethereum-nonce-gap.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ import {
useBlockingGapQuery,
useFillNonceGapMutation,
} from '@perawallet/wallet-core-transactions'
import { server } from '@test-utils/msw-server'
import { http, HttpResponse, server } from '@test-utils/msw-server'
import { createTestQueryClient } from '@test-utils/render'
import { renderWithNavigation } from '@test-utils/renderWithNavigation'
import { AccountHistory } from '@modules/accounts/components/AccountHistory/AccountHistory'
import {
resetTestDatabase,
setupTestDatabase,
Expand All @@ -72,6 +74,8 @@ import {
} from '@test-utils/signing-review'
import { VIEM_TRANSFER_NONCE_2 } from '@packages/chain-ethereum/src/signing/__tests__/fixtures'
import { readReplaceableTransaction } from '@packages/chain-ethereum/src/transfer/replacement'
import { historyPath } from '@packages/chain-ethereum/src/history/api/endpoints'
import { SLOW_WAIT_TIMEOUT_MS } from './__fixtures__/timeouts'

const RPC_URL = 'https://mainnet.rpc.test/'

Expand Down Expand Up @@ -316,6 +320,43 @@ describe('Flow: unblock an Ethereum send stuck behind a dropped nonce', () => {
expect(settled.status).toBe('confirmed')
})

// A build listing an EVM history service reads the pinned 503; CI's lists
// none, so its read is unavailable instead. Either way the send stays listed.
it('Given a send stuck behind a dropped nonce and the history read failing, when History opens, then the send lists with its waiting notice and the failure is named beside it', async () => {
server.use(
http.get(`*${historyPath(':chainId', ':address')}`, () =>
HttpResponse.json({}, { status: 503 }),
),
)
await recordDroppedSend()
const stuck = await broadcastStuckSend()

renderWithNavigation(AccountHistory, 'AccountHistory')

const notice = await screen.findByTestId(
`transaction_row_notice_${stuck}`,
undefined,
{ timeout: SLOW_WAIT_TIMEOUT_MS },
)
await waitFor(() =>
expect(notice.textContent).toContain(
'transactions.notice.waiting_on_earlier',
),
)
const failed = await screen.findByTestId(
'history_network_failed',
undefined,
{ timeout: SLOW_WAIT_TIMEOUT_MS },
)
expect(failed.textContent).toMatch(
/asset_details\.transaction_list\.network_(failed|unavailable)/,
)
expect(screen.queryByText('common.error.title')).toBeNull()
expect(
screen.queryByText('common.network_unavailable.title'),
).toBeNull()
})

it('Given a send at nonce 2 whose earlier nonce the node holds, when its row asks, then it is not flagged and unblocking is refused', async () => {
const stuck = await broadcastStuckSend()
minedNonces = '0x2'
Expand Down
53 changes: 34 additions & 19 deletions apps/mobile/src/__integration__/ethereum-pending-history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// broadcast, survives an offline read, and gives way to the chain's own row.
// The flow enters at the broadcaster's submit transport.

import { createElement, type ReactNode } from 'react'
import {
afterAll,
beforeAll,
Expand All @@ -23,6 +24,7 @@ import {
it,
vi,
} from 'vitest'
import { renderHook, waitFor } from '@testing-library/react'
import {
i18nKey,
type ChainContext,
Expand Down Expand Up @@ -57,8 +59,10 @@ vi.mock('@perawallet/wallet-core-config', async importOriginal => {
// mock exists, and the client reads its deployments once, so every module under
// test is loaded afresh.
vi.resetModules()
const { getPendingTransactionRecords, getTransactionHistoryWithPending } =
const { getPendingTransactionRecords, useTransactionRecordsQuery } =
await import('@perawallet/wallet-core-transactions')
const { QueryClientProvider } = await import('@tanstack/react-query')
const { createTestQueryClient } = await import('@test-utils/render')
const { evmHistoryItem, evmRpcHandlers, evmTransactionReceipt } =
await import('@perawallet/wallet-core-chain-ethereum/test-handlers')
const { createEvmBroadcasterAdapter } =
Expand Down Expand Up @@ -112,6 +116,29 @@ const serveHistory = (results: EvmHistoryItemResponse[]) =>
),
)

// What History lists once its read settles with `hash` among the records.
const historyOf = async (address: string, hash: string) => {
const client = createTestQueryClient()
const wrapper = ({ children }: { children: ReactNode }) =>
createElement(QueryClientProvider, { client }, children)
const { result, unmount } = renderHook(
() =>
useTransactionRecordsQuery({
accountAddress: address,
scope: SCOPE,
}),
{ wrapper },
)
await waitFor(() => {
expect(result.current.isFetched).toBe(true)
expect(result.current.records.map(record => record.id)).toContain(hash)
})
const { records } = result.current
unmount()
client.clear()
return records
}

describe('Flow: an Ethereum send in history', () => {
beforeAll(async () => {
await setupTestDatabase()
Expand Down Expand Up @@ -143,13 +170,10 @@ describe('Flow: an Ethereum send in history', () => {
serveHistory([])

// The ledger holds the checksummed sender; the stored address is lowercase.
const page = await getTransactionHistoryWithPending(
SENDER.toLowerCase(),
SCOPE,
)
const items = await historyOf(SENDER.toLowerCase(), hash)

expect(page.items).toHaveLength(1)
expect(page.items[0]).toMatchObject({
expect(items).toHaveLength(1)
expect(items[0]).toMatchObject({
id: hash,
status: 'pending',
summary: { title: { key: SUMMARY_TITLE } },
Expand All @@ -163,7 +187,6 @@ describe('Flow: an Ethereum send in history', () => {
const records = await getPendingTransactionRecords({
address: SENDER.toLowerCase(),
scope: SCOPE,
listedIds: new Set(),
})

expect(records.map(record => record.id)).toEqual([hash])
Expand Down Expand Up @@ -192,12 +215,7 @@ describe('Flow: an Ethereum send in history', () => {
evmChainOf('ethereum'),
).reconcileOpenSubmissions()
const recordOf = async () =>
(
await getTransactionHistoryWithPending(
SENDER.toLowerCase(),
SCOPE,
)
).items[0]
(await historyOf(SENDER.toLowerCase(), hash))[0]

await reconcile()
const confirming = await recordOf()
Expand All @@ -221,12 +239,9 @@ describe('Flow: an Ethereum send in history', () => {
const hash = await broadcast()
serveHistory([evmHistoryItem({ hash, from: SENDER })])

const page = await getTransactionHistoryWithPending(
SENDER.toLowerCase(),
SCOPE,
)
const items = await historyOf(SENDER.toLowerCase(), hash)

const matching = page.items.filter(record => record.id === hash)
const matching = items.filter(record => record.id === hash)
expect(matching).toHaveLength(1)
expect(matching[0].status).toBe('confirmed')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ const sentRecord = async () => {
const [record] = await getPendingTransactionRecords({
address: SENDER,
scope: ETH_SCOPE,
listedIds: new Set(),
})
return record
}
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "Keine Transaktionen gefunden",
"empty_on_network_body": "Noch keine Transaktionen auf {{network}}",
"network_failed": "Transaktionen auf {{networks}} konnten nicht geladen werden",
"network_unavailable": "Transaktionen sind auf {{networks}} nicht verfügbar",
"offline_empty_title": "Du bist offline",
"offline_empty_body": "Auf diesem Gerät sind noch keine Transaktionen gespeichert. Sie erscheinen, sobald du wieder online bist.",
"search_paused_body": "Keine Transaktionen im jüngsten Verlauf gefunden.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "No transactions found",
"empty_on_network_body": "No transactions yet on {{network}}",
"network_failed": "Couldn't load transactions on {{networks}}",
"network_unavailable": "Transactions aren't available on {{networks}}",
"offline_empty_title": "You're offline",
"offline_empty_body": "No transactions are saved on this device yet. They'll appear once you're back online.",
"search_paused_body": "No transactions found in recent history.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "No se encontraron transacciones",
"empty_on_network_body": "Aún no hay transacciones en {{network}}",
"network_failed": "No se pudieron cargar las transacciones en {{networks}}",
"network_unavailable": "Las transacciones no están disponibles en {{networks}}",
"offline_empty_title": "Estás sin conexión",
"offline_empty_body": "Todavía no hay transacciones guardadas en este dispositivo. Aparecerán cuando vuelvas a estar en línea.",
"search_paused_body": "No se encontraron transacciones en el historial reciente.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "Aucune transaction trouvée",
"empty_on_network_body": "Aucune transaction pour le moment sur {{network}}",
"network_failed": "Impossible de charger les transactions sur {{networks}}",
"network_unavailable": "Les transactions ne sont pas disponibles sur {{networks}}",
"offline_empty_title": "Vous êtes hors ligne",
"offline_empty_body": "Aucune transaction n’est encore enregistrée sur cet appareil. Elles apparaîtront dès que vous serez de retour en ligne.",
"search_paused_body": "Aucune transaction trouvée dans l’historique récent.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "Nenhuma transação encontrada",
"empty_on_network_body": "Ainda não há transações em {{network}}",
"network_failed": "Não foi possível carregar as transações em {{networks}}",
"network_unavailable": "As transações não estão disponíveis em {{networks}}",
"offline_empty_title": "Você está offline",
"offline_empty_body": "Ainda não há transações salvas neste dispositivo. Elas aparecerão quando você voltar a ficar online.",
"search_paused_body": "Nenhuma transação encontrada no histórico recente.",
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/i18n/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
"empty_body": "İşlem bulunamadı",
"empty_on_network_body": "{{network}} ağında henüz işlem yok",
"network_failed": "{{networks}} ağındaki işlemler yüklenemedi",
"network_unavailable": "{{networks}} ağında işlemler kullanılamıyor",
"offline_empty_title": "Çevrimdışısın",
"offline_empty_body": "Bu cihazda henüz kayıtlı işlem yok. Yeniden çevrimiçi olduğunda görünecekler.",
"search_paused_body": "Yakın geçmişte işlem bulunamadı.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const AccountHistory = ({ scrollEnabled }: AccountHistoryProps) => {
handleSelectChain,
historyFeeds,
failedNetworkNames,
isFailedRetryable,
emptyBody,
isOfflineEmpty,
isRefreshing,
Expand All @@ -65,6 +66,7 @@ export const AccountHistory = ({ scrollEnabled }: AccountHistoryProps) => {
chainFilterOptions={chainFilterOptions}
onSelectChain={handleSelectChain}
failedNetworkNames={failedNetworkNames}
isFailedRetryable={isFailedRetryable}
onRetryFailed={handleRetry}
isCsvExportVisible={isCsvExportVisible}
isExportingCsv={isExportingCsv}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
limitations under the License
*/

import { memo, useMemo } from 'react'
import { memo } from 'react'
import type { ChainId } from '@perawallet/wallet-core-chain-contract'
import type { Nullable } from '@perawallet/wallet-core-shared'
import { PWButton, PWText, PWView } from '@components/core'
import { ChainNotice } from '@components/ChainNotice'
import { FilterSelection, type FilterOption } from '@components/FilterSelection'
import { ChainLabel } from '@modules/chain-ui/icon'
import { HistoryFailedNotice } from '@modules/transactions'
import { useLanguage } from '@hooks/useLanguage'
import { useStyles } from './styles'

Expand All @@ -28,6 +28,8 @@ export type AccountHistoryTitleBarProps = {
onSelectChain: (chainId: Nullable<ChainId>) => void
/** Networks whose history failed while others' rows show; empty hides the notice. */
failedNetworkNames: string[]
/** False on a network without the service: the notice says so, with no retry. */
isFailedRetryable: boolean
onRetryFailed: () => void
isCsvExportVisible: boolean
isExportingCsv: boolean
Expand All @@ -47,6 +49,7 @@ export const AccountHistoryTitleBar = memo(
chainFilterOptions,
onSelectChain,
failedNetworkNames,
isFailedRetryable,
onRetryFailed,
isCsvExportVisible,
isExportingCsv,
Expand All @@ -55,15 +58,6 @@ export const AccountHistoryTitleBar = memo(
}: AccountHistoryTitleBarProps) => {
const styles = useStyles()
const { t } = useLanguage()
const failedParams = useMemo(
() => ({ networks: failedNetworkNames.join(', ') }),
[failedNetworkNames],
)
const retryAction = useMemo(
() => ({ labelKey: 'common.retry.label', onPress: onRetryFailed }),
[onRetryFailed],
)

return (
<PWView style={styles.headerContainer}>
<PWView style={styles.titleBar}>
Expand Down Expand Up @@ -107,16 +101,13 @@ export const AccountHistoryTitleBar = memo(
) : (
chainId !== null && <ChainLabel chainId={chainId} />
)}
{failedNetworkNames.length > 0 && (
<ChainNotice
kind='error'
titleKey='asset_details.transaction_list.network_failed'
params={failedParams}
action={retryAction}
style={styles.failedNotice}
testID='history_network_failed'
/>
)}
<HistoryFailedNotice
networkNames={failedNetworkNames}
isRetryable={isFailedRetryable}
onRetry={onRetryFailed}
style={styles.failedNotice}
testID='history_network_failed'
/>
</PWView>
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ describe('useAccountHistory', () => {
isFetching: false,
isFetchingNextPage: false,
isError: false,
isNextPageError: false,
error: null,
hasNextPage: false,
isSearchPaused: false,
Expand Down Expand Up @@ -620,6 +621,7 @@ describe('useAccountHistory', () => {
isFetching: false,
isFetchingNextPage: false,
isError: false,
isNextPageError: false,
error: null,
hasNextPage: false,
isSearchPaused: false,
Expand Down Expand Up @@ -761,6 +763,7 @@ describe('useAccountHistory', () => {
isFetching: false,
isFetchingNextPage: false,
isError: false,
isNextPageError: false,
error: null,
hasNextPage: true,
isSearchPaused: true,
Expand Down
Loading
Loading