From 2951df6df973739b90dd2202971a6d313b3af051 Mon Sep 17 00:00:00 2001 From: Matej Lubej Date: Mon, 10 Jun 2024 07:35:57 +0200 Subject: [PATCH 1/2] Refactor transactions status to enum - for upcoming pending status --- .changelog/1970.internal.md | 1 + .../components/Transaction/__tests__/index.test.tsx | 11 ++++++----- src/app/components/Transaction/index.tsx | 9 +++++++-- src/app/state/transaction/types.ts | 7 ++++++- src/vendors/monitor.ts | 4 ++-- src/vendors/oasisscan.ts | 6 +++--- 6 files changed, 25 insertions(+), 13 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..d2e1de0d10 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.Failed }, 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/components/Transaction/index.tsx b/src/app/components/Transaction/index.tsx index cf65184270..b85e62e2e6 100644 --- a/src/app/components/Transaction/index.tsx +++ b/src/app/components/Transaction/index.tsx @@ -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' @@ -479,8 +480,12 @@ export function Transaction(props: TransactionProps) { - - {transaction.status ? ( + + {transaction.status === TransactionStatus.Successful ? ( {t('account.transaction.successful', 'Successful')} ) : ( {t('account.transaction.failed', 'Failed')} diff --git a/src/app/state/transaction/types.ts b/src/app/state/transaction/types.ts index 669e7fdb0d..e072b5bcd8 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 { + 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 diff --git a/src/vendors/monitor.ts b/src/vendors/monitor.ts index 5e81f4b093..0443c22016 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.Failed, 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..00688bd79e 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.Failed, 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.Failed, timestamp: t.timestamp * 1000, to: t.to ?? undefined, type: transactionMethodMap[t.method] ?? t.method, From 3defe190c59461b1805602ba69308a2c8f91287b Mon Sep 17 00:00:00 2001 From: Matej Lubej Date: Mon, 10 Jun 2024 07:48:44 +0200 Subject: [PATCH 2/2] Update test snapshots for tx.status changes --- .../__snapshots__/monitor.test.ts.snap | 26 ++++++++--------- .../__snapshots__/oasisscan.test.ts.snap | 28 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/vendors/__tests__/__snapshots__/monitor.test.ts.snap b/src/vendors/__tests__/__snapshots__/monitor.test.ts.snap index 0fa853f877..ba235c41bf 100644 --- a/src/vendors/__tests__/__snapshots__/monitor.test.ts.snap +++ b/src/vendors/__tests__/__snapshots__/monitor.test.ts.snap @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap b/src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap index 2fb2dd4ecf..bad7647c66 100644 --- a/src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap +++ b/src/vendors/__tests__/__snapshots__/oasisscan.test.ts.snap @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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",