Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor transactions status to enum #1970

Merged
merged 2 commits into from
Jun 12, 2024
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
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.Failed }, 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
9 changes: 7 additions & 2 deletions src/app/components/Transaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { intlDateTimeFormat } from '../DateFormatter/intlDateTimeFormat'
import { trimLongString } from '../ShortAddress/trimLongString'
import { InfoBox } from './InfoBox'
import * as transactionTypes from 'app/state/transaction/types'
import { TransactionStatus } from 'app/state/transaction/types'
import { NetworkType } from 'app/state/network/types'
import { config } from 'config'
import { backend } from 'vendors/backend'
Expand Down Expand Up @@ -479,8 +480,12 @@ export function Transaction(props: TransactionProps) {
<Text weight="bold" size={isMobile ? 'medium' : 'xlarge'}>
<AmountFormatter amount={transaction.amount!} smallTicker />
</Text>
<Text color={transaction.status ? 'successful-label' : 'status-error'} size="small" weight="bold">
{transaction.status ? (
<Text
color={transaction.status === TransactionStatus.Successful ? 'successful-label' : 'status-error'}
size="small"
weight="bold"
>
{transaction.status === TransactionStatus.Successful ? (
<span>{t('account.transaction.successful', 'Successful')}</span>
) : (
<span>{t('account.transaction.failed', 'Failed')}</span>
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 {
Failed,
Successful,
}

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
26 changes: 13 additions & 13 deletions src/vendors/__tests__/__snapshots__/monitor.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644903000,
"to": "oasis1qpm97z4c28juhdea220jtq2e3mz4gruyg54xktlm",
"type": "staking.Transfer",
Expand All @@ -55,7 +55,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645107000,
"to": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"type": "staking.AddEscrow",
Expand All @@ -69,7 +69,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644147000,
"to": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"type": "staking.ReclaimEscrow",
Expand All @@ -83,7 +83,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645526644000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "staking.AmendCommissionSchedule",
Expand All @@ -97,7 +97,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645260000,
"to": "oasis1qzvlg0grjxwgjj58tx2xvmv26era6t2csqn22pte",
"type": "staking.Allow",
Expand All @@ -111,7 +111,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645506000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "roothash.ExecutorCommit",
Expand All @@ -125,7 +125,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": false,
"status": 0,
"timestamp": 1645644585000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "roothash.ExecutorProposerTimeout",
Expand All @@ -139,7 +139,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645567265000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "registry.RegisterEntity",
Expand All @@ -153,7 +153,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645670000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "registry.RegisterNode",
Expand All @@ -167,7 +167,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1638867315000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "registry.RegisterRuntime",
Expand All @@ -181,7 +181,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1629793437000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "governance.CastVote",
Expand All @@ -195,7 +195,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645642579000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "beacon.PVSSCommit",
Expand All @@ -209,7 +209,7 @@ exports[`monitor parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644962000,
"to": "oasis1qpg3hpf3vtuueyl8f8jzgsy8clqqw6qgxgurwfy5",
"type": "beacon.PVSSReveal",
Expand Down
28 changes: 14 additions & 14 deletions src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": 997775,
"runtimeId": "000000000000000000000000000000000000000000000000e2eaa99fc008f87f",
"runtimeName": "Emerald",
"status": true,
"status": 1,
"timestamp": 1649604086000,
"to": "oasis1qzgc7dvlls36q47z5y6dvu6ylaa78rkrduqtxgdr",
"type": "consensus.Deposit",
Expand All @@ -61,7 +61,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644903000,
"to": "oasis1qpm97z4c28juhdea220jtq2e3mz4gruyg54xktlm",
"type": "staking.Transfer",
Expand All @@ -75,7 +75,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645107000,
"to": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"type": "staking.AddEscrow",
Expand All @@ -89,7 +89,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644147000,
"to": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm",
"type": "staking.ReclaimEscrow",
Expand All @@ -103,7 +103,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645526644000,
"to": undefined,
"type": "staking.AmendCommissionSchedule",
Expand All @@ -117,7 +117,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645260000,
"to": "oasis1qzvlg0grjxwgjj58tx2xvmv26era6t2csqn22pte",
"type": "staking.Allow",
Expand All @@ -131,7 +131,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645506000,
"to": undefined,
"type": "roothash.ExecutorCommit",
Expand All @@ -145,7 +145,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": false,
"status": 0,
"timestamp": 1645644585000,
"to": undefined,
"type": "roothash.ExecutorProposerTimeout",
Expand All @@ -159,7 +159,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645567265000,
"to": undefined,
"type": "registry.RegisterEntity",
Expand All @@ -173,7 +173,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645645670000,
"to": undefined,
"type": "registry.RegisterNode",
Expand All @@ -187,7 +187,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1638867315000,
"to": undefined,
"type": "registry.RegisterRuntime",
Expand All @@ -201,7 +201,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1629793437000,
"to": undefined,
"type": "governance.CastVote",
Expand All @@ -215,7 +215,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645740165000,
"to": undefined,
"type": "beacon.PVSSCommit",
Expand All @@ -229,7 +229,7 @@ exports[`oasisscan parse transaction list 1`] = `
"round": undefined,
"runtimeId": undefined,
"runtimeName": undefined,
"status": true,
"status": 1,
"timestamp": 1645644962000,
"to": undefined,
"type": "beacon.PVSSReveal",
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.Failed,
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.Failed,
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.Failed,
timestamp: t.timestamp * 1000,
to: t.to ?? undefined,
type: transactionMethodMap[t.method] ?? t.method,
Expand Down
Loading