From 0d659379549246d2388098fdc524c5f400d8e361 Mon Sep 17 00:00:00 2001 From: Matej Lubej Date: Mon, 10 Jun 2024 07:35:57 +0200 Subject: [PATCH] Refactor transactions status to enum - for upcoming pending status --- .changelog/1970.internal.md | 1 + .../components/Transaction/__tests__/index.test.tsx | 11 ++++++----- src/app/state/transaction/types.ts | 7 ++++++- src/vendors/monitor.ts | 4 ++-- src/vendors/oasisscan.ts | 6 +++--- 5 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 .changelog/1970.internal.md diff --git a/.changelog/1970.internal.md b/.changelog/1970.internal.md new file mode 100644 index 0000000000..0994496974 --- /dev/null +++ b/.changelog/1970.internal.md @@ -0,0 +1 @@ +Refactor transactions status to enum diff --git a/src/app/components/Transaction/__tests__/index.test.tsx b/src/app/components/Transaction/__tests__/index.test.tsx index 1390365988..c3ef75480b 100644 --- a/src/app/components/Transaction/__tests__/index.test.tsx +++ b/src/app/components/Transaction/__tests__/index.test.tsx @@ -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') @@ -57,7 +58,7 @@ describe('', () => { to: 'destination', type: transactionTypes.TransactionType.StakingTransfer, hash: 'ff1234', - status: true, + status: TransactionStatus.Successful, } as transactionTypes.Transaction const network = 'mainnet' @@ -86,7 +87,7 @@ describe('', () => { }) 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() }) @@ -103,7 +104,7 @@ describe('', () => { hash: 'ff1234', fee: undefined, level: undefined, - status: true, + status: TransactionStatus.Successful, runtimeName: undefined, runtimeId: undefined, round: undefined, @@ -126,7 +127,7 @@ describe('', () => { hash: 'ff1234', fee: undefined, level: undefined, - status: true, + status: TransactionStatus.Successful, runtimeName: undefined, runtimeId: undefined, round: undefined, diff --git a/src/app/state/transaction/types.ts b/src/app/state/transaction/types.ts index 669e7fdb0d..9436947b8e 100644 --- a/src/app/state/transaction/types.ts +++ b/src/app/state/transaction/types.ts @@ -32,13 +32,18 @@ export enum TransactionType { ConsensusAccount = 'consensus.Account', } +export enum TransactionStatus { + UnknownOrConfidential, + 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 diff --git a/src/vendors/monitor.ts b/src/vendors/monitor.ts index 5e81f4b093..f86a80a153 100644 --- a/src/vendors/monitor.ts +++ b/src/vendors/monitor.ts @@ -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, @@ -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, diff --git a/src/vendors/oasisscan.ts b/src/vendors/oasisscan.ts index e600087cfb..a87c9fb951 100644 --- a/src/vendors/oasisscan.ts +++ b/src/vendors/oasisscan.ts @@ -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, @@ -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, @@ -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,