Skip to content

Commit

Permalink
Merge pull request #2123 from oasisprotocol/lw/fix-paratime-tx-status
Browse files Browse the repository at this point in the history
Fix paratime transaction status in the first few seconds
  • Loading branch information
lukaw3d authored Feb 25, 2025
2 parents 693900f + ea0d13d commit 42031b2
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions .changelog/2123.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix paratime transaction status in the first few seconds
4 changes: 4 additions & 0 deletions src/app/state/account/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DeepPartialRootState } from 'types/RootState'
import * as matchers from 'redux-saga-test-plan/matchers'
import { getExplorerAPIs } from '../network/saga'
import { getAccountBalanceWithFallback } from '../../lib/getAccountBalanceWithFallback'
import delayP from '@redux-saga/delay-p'

const address = 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk'
const state: DeepPartialRootState = {
Expand Down Expand Up @@ -46,6 +47,9 @@ describe('Account Sagas', () => {
it('Should refresh account on paraTime transaction', () => {
return expectSaga(accountSaga)
.withState(state)
.provide([
[matchers.call.fn(delayP), null], // https://github.com/jfairbank/redux-saga-test-plan/issues/257
])
.dispatch(transactionActions.paraTimeTransactionSent('dummyAddress'))
.put.actionType(accountActions.fetchAccount.type)
.put.actionType(stakingActions.fetchAccount.type)
Expand Down
7 changes: 7 additions & 0 deletions src/app/state/account/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export function* refreshAccountOnParaTimeTransaction() {
while (true) {
const { payload } = yield* take(transactionActions.paraTimeTransactionSent)

// Increase the chance to get updated transactions from API.
// Note: We can't rely on nonce to detect pending paratime transactions
yield* delay(3000)
yield* call(refreshAccount, payload)
yield* delay(6000)
yield* call(refreshAccount, payload)
yield* delay(6000)
yield* call(refreshAccount, payload)
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/state/account/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RootState } from 'types'
import { initialState } from '.'
import { selectSelectedNetwork } from '../network/selectors'
import { TRANSACTIONS_LIMIT } from '../../../config'
import { TransactionStatus } from '../transaction/types'

const selectSlice = (state: RootState) => state.account || initialState

Expand Down Expand Up @@ -31,6 +32,11 @@ export const hasAccountUnknownPendingTransactions = createSelector(
// Account have nonce and 0 transactions due to last correctly indexed block 16817956 (2023-11-29)
return false
}
if (transactions.some(tx => tx.status === TransactionStatus.Pending)) {
// After paratime deposit transaction is submitted, Nexus API returns empty status until one block later.
// https://github.com/oasisprotocol/explorer/issues/528
return true
}
const noncesFromTxs = transactions
.filter(tx => !tx.runtimeId)
.filter(tx => tx.from !== undefined)
Expand Down
5 changes: 1 addition & 4 deletions src/app/state/transaction/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { hex2uint, isValidAddress, parseRoseStringToBaseUnitString, uint2bigintS
import { LedgerSigner } from 'app/lib/ledger'
import { OasisTransaction, signerFromEthPrivateKey, signerFromPrivateKey, TW } from 'app/lib/transaction'
import { getEvmBech32Address, privateToEthAddress } from 'app/lib/eth-helpers'
import { call, delay, put, race, select, take, takeEvery } from 'typed-redux-saga'
import { call, put, race, select, take, takeEvery } from 'typed-redux-saga'
import { ErrorPayload, ExhaustedTypeError, WalletError, WalletErrors } from 'types/errors'
import { transactionActions } from '.'
import { sign } from '../importaccounts/saga'
Expand Down Expand Up @@ -275,8 +275,6 @@ export function* setAllowance(
}
}

const transactionSentDelay = 1000 // to increase a chance to get updated account data from BE

export function* submitParaTimeTransaction(runtime: Runtime, transaction: ParaTimeTransaction) {
const fromAddress = transaction.ethPrivateKey
? yield* call(getEvmBech32Address, privateToEthAddress(transaction.ethPrivateKey))
Expand All @@ -302,7 +300,6 @@ export function* submitParaTimeTransaction(runtime: Runtime, transaction: ParaTi

yield* call(OasisTransaction.signParaTime, chainContext, paraTimeTransactionSigner as Signer, rtw)
yield* call(OasisTransaction.submit, nic, rtw)
yield* delay(transactionSentDelay)
yield* put(transactionActions.paraTimeTransactionSent(transaction.recipient))
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/state/wallet/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { addWallet, rootWalletSaga } from './saga'
import { AddWalletPayload, WalletType } from './types'
import { importAccountsActions } from '../importaccounts'
import { getAccountBalanceWithFallback } from '../../lib/getAccountBalanceWithFallback'
import delayP from '@redux-saga/delay-p'

describe('Wallet Sagas', () => {
const validPrivateKeyHex =
Expand All @@ -18,6 +19,7 @@ describe('Wallet Sagas', () => {

const providers: (EffectProviders | StaticProvider)[] = [
[matchers.call.fn(getAccountBalanceWithFallback), {}],
[matchers.call.fn(delayP), null], // https://github.com/jfairbank/redux-saga-test-plan/issues/257
]
const state: DeepPartialRootState = {
importAccounts: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/state/wallet/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ function* refreshAccountOnParaTimeTransaction() {
while (true) {
const { payload } = yield* take(transactionActions.paraTimeTransactionSent)

// Increase the chance to get updated balance from API.
yield* delay(3000)
yield* call(refreshAccount, payload)
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/vendors/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,14 @@ function parseTransactionsList(list: (NexusTransaction | ExtendedRuntimeTransact
from: t.sender_0_eth || t.sender_0,
hash: t.hash,
level: undefined,
status: t.success ? TransactionStatus.Successful : TransactionStatus.Failed,
status:
t.success === undefined
? TransactionStatus.Pending
: t.success
? TransactionStatus.Successful
: TransactionStatus.Failed,
timestamp: transactionDate.getTime(),
to: (t.body as { to?: string }).to ?? undefined,
to: t.to_eth ?? t.to ?? (t.body as { to?: string }).to ?? undefined,
type: getTransactionType(t.method),
runtimeName: t.runtimeName,
runtimeId: t.runtimeId,
Expand Down

0 comments on commit 42031b2

Please sign in to comment.