Skip to content

Commit

Permalink
Refactor transactions status to enum
Browse files Browse the repository at this point in the history
- for upcoming pending status
  • Loading branch information
lubej committed Jun 10, 2024
1 parent 812d62e commit 0d65937
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/1970.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor transactions status to enum
11 changes: 6 additions & 5 deletions src/app/components/Transaction/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import copy from 'copy-to-clipboard'

import { Transaction } from '..'
import * as transactionTypes from 'app/state/transaction/types'
import { TransactionStatus } from 'app/state/transaction/types'
import { NetworkType } from 'app/state/network/types'
import type { UseTranslationResponse, Trans } from 'react-i18next'
import type { Trans, UseTranslationResponse } from 'react-i18next'

jest.mock('copy-to-clipboard')

Expand Down Expand Up @@ -57,7 +58,7 @@ describe('<Transaction />', () => {
to: 'destination',
type: transactionTypes.TransactionType.StakingTransfer,
hash: 'ff1234',
status: true,
status: TransactionStatus.Successful,
} as transactionTypes.Transaction
const network = 'mainnet'

Expand Down Expand Up @@ -86,7 +87,7 @@ describe('<Transaction />', () => {
})

it('should mark failed transactions', () => {
renderComponent(store, ref, { ...transaction, status: false }, network)
renderComponent(store, ref, { ...transaction, status: TransactionStatus.UnknownOrConfidential }, network)
expect(screen.getByText('account.transaction.failed')).toBeInTheDocument()
})

Expand All @@ -103,7 +104,7 @@ describe('<Transaction />', () => {
hash: 'ff1234',
fee: undefined,
level: undefined,
status: true,
status: TransactionStatus.Successful,
runtimeName: undefined,
runtimeId: undefined,
round: undefined,
Expand All @@ -126,7 +127,7 @@ describe('<Transaction />', () => {
hash: 'ff1234',
fee: undefined,
level: undefined,
status: true,
status: TransactionStatus.Successful,
runtimeName: undefined,
runtimeId: undefined,
round: undefined,
Expand Down
7 changes: 6 additions & 1 deletion src/app/state/transaction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export enum TransactionType {
ConsensusAccount = 'consensus.Account',
}

export enum TransactionStatus {
UnknownOrConfidential,
Successful

Check warning on line 37 in src/app/state/transaction/types.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
}

export interface Transaction {
amount: StringifiedBigInt | undefined
fee: StringifiedBigInt | undefined
from: string | undefined
hash: string
level: number | undefined
status: boolean | undefined
status: TransactionStatus | undefined
timestamp: number | undefined
to: string | undefined
type: TransactionType
Expand Down
4 changes: 2 additions & 2 deletions src/vendors/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as oasis from '@oasisprotocol/client'
import { StakingDebondingDelegationInfo, StakingDelegationInfo } from '@oasisprotocol/client/dist/types'
import { Account } from 'app/state/account/types'
import { DebondingDelegation, Delegation, Validator } from 'app/state/staking/types'
import { Transaction, TransactionType } from 'app/state/transaction/types'
import { Transaction, TransactionStatus, TransactionType } from 'app/state/transaction/types'
import {
AccountsApi,
AccountsRow,
Expand Down Expand Up @@ -156,7 +156,7 @@ export function parseTransactionsList(transactionsList: OperationsRow[]): Transa
from: t.from,
hash: t.hash!,
level: t.level,
status: t.status,
status: t.status ? TransactionStatus.Successful : TransactionStatus.UnknownOrConfidential,
timestamp: t.timestamp == null ? undefined : t.timestamp * 1000,
to: t.to,
type: transactionMethodMap[t.type!] ?? t.type,
Expand Down
6 changes: 3 additions & 3 deletions src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as oasis from '@oasisprotocol/client'
import { Account } from 'app/state/account/types'
import { DebondingDelegation, Delegation, Validator } from 'app/state/staking/types'
import { Transaction, TransactionType } from 'app/state/transaction/types'
import { Transaction, TransactionStatus, TransactionType } from 'app/state/transaction/types'
import { parseRoseStringToBaseUnitString } from 'app/lib/helpers'
import {
AccountsApi,
Expand Down Expand Up @@ -158,7 +158,7 @@ export function parseTransactionsList(list: (OperationsRow | RuntimeTransactionI
from: t.ctx.from,
hash: t.txHash,
level: undefined,
status: t.result,
status: t.result ? TransactionStatus.Successful : TransactionStatus.UnknownOrConfidential,
timestamp: t.timestamp * 1000,
to: t.ctx.to ?? undefined,
type: transactionMethodMap[t.ctx.method] ?? t.ctx.method,
Expand All @@ -174,7 +174,7 @@ export function parseTransactionsList(list: (OperationsRow | RuntimeTransactionI
from: t.from,
hash: t.txHash,
level: t.height,
status: t.status,
status: t.status ? TransactionStatus.Successful : TransactionStatus.UnknownOrConfidential,
timestamp: t.timestamp * 1000,
to: t.to ?? undefined,
type: transactionMethodMap[t.method] ?? t.method,
Expand Down

0 comments on commit 0d65937

Please sign in to comment.