From 383fcfbd9e1347f4b9a0608c6f794d568fec0e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomislav=20Hora=C4=8Dek?= Date: Thu, 10 Dec 2020 19:30:56 +0100 Subject: [PATCH] Transaction expired status (#2272) * Introduce Transaction EXPIRED status in transactions list * Delete tx improvement while tx in failed state * Testing command for creating expired transaction added * Adds CHANGELOG entry * Update cardano-wallet version tag * Run translation manager Co-authored-by: Nikola Glumac --- CHANGELOG.md | 1 + nix/sources.json | 2 +- source/renderer/app/api/api.js | 80 ++++++++++++++- source/renderer/app/api/transactions/types.js | 2 +- .../transactions/CancelTransactionButton.js | 13 ++- .../wallet/transactions/Transaction.js | 97 +++++++++++++------ .../wallet/transactions/Transaction.scss | 7 ++ .../transactions/TransactionTypeIcon.js | 17 +++- .../transactions/TransactionTypeIcon.scss | 4 + .../renderer/app/domains/WalletTransaction.js | 1 + .../app/i18n/locales/defaultMessages.json | 70 +++++++++++-- source/renderer/app/i18n/locales/en-US.json | 6 +- source/renderer/app/i18n/locales/ja-JP.json | 6 +- .../renderer/app/themes/daedalus/cardano.js | 2 + .../renderer/app/themes/daedalus/dark-blue.js | 2 + .../app/themes/daedalus/dark-cardano.js | 2 + .../app/themes/daedalus/flight-candidate.js | 2 + .../themes/daedalus/incentivized-testnet.js | 2 + .../app/themes/daedalus/light-blue.js | 2 + .../app/themes/daedalus/shelley-testnet.js | 2 + source/renderer/app/themes/daedalus/white.js | 2 + source/renderer/app/themes/daedalus/yellow.js | 2 + .../renderer/app/themes/utils/createTheme.js | 3 + .../_utils/WalletsTransactionsWrapper.js | 6 ++ 24 files changed, 287 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db12ae3187..a158c43eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changelog ### Fixes +- Fixed handling of expired transactions ([PR 2272](https://github.com/input-output-hk/daedalus/pull/2272)) - Fixed visual glitch on the transaction list switching between filters ([PR 2261](https://github.com/input-output-hk/daedalus/pull/2261)) ### Chores diff --git a/nix/sources.json b/nix/sources.json index 995c936033..04e36c5374 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -34,7 +34,7 @@ "type": "tarball", "url": "https://github.com/input-output-hk/cardano-wallet/archive/bcbed39dbe61b978453d6dee94140504bd0f6f9b.tar.gz", "url_template": "https://github.com///archive/.tar.gz", - "version": "v2020-11-26" + "version": "v2020-12-08" }, "gitignore": { "branch": "master", diff --git a/source/renderer/app/api/api.js b/source/renderer/app/api/api.js index a98a30ac69..1240701333 100644 --- a/source/renderer/app/api/api.js +++ b/source/renderer/app/api/api.js @@ -695,6 +695,74 @@ export default class AdaApi { } }; + // For testing purpose ONLY + createExpiredTransaction = async (request: any): Promise<*> => { + if (global.environment.isDev) { + logger.debug('AdaApi::createTransaction called', { + parameters: filterLogData(request), + }); + const { + walletId, + address, + amount, + passphrase, + isLegacy, + withdrawal = TransactionWithdrawal, + ttl, + } = request; + try { + const data = { + payments: [ + { + address, + amount: { + quantity: amount, + unit: WalletUnits.LOVELACE, + }, + }, + ], + passphrase, + time_to_live: { + quantity: ttl, + unit: 'second', + }, + }; + + let response: Transaction; + if (isLegacy) { + response = await createByronWalletTransaction(this.config, { + walletId, + data, + }); + } else { + response = await createTransaction(this.config, { + walletId, + data: { ...data, withdrawal }, + }); + } + + logger.debug('AdaApi::createTransaction success', { + transaction: response, + }); + + return _createTransactionFromServerData(response); + } catch (error) { + logger.error('AdaApi::createTransaction error', { error }); + throw new ApiError(error) + .set('wrongEncryptionPassphrase') + .where('code', 'bad_request') + .inc('message', 'passphrase is too short') + .set('transactionIsTooBig', true, { + linkLabel: 'tooBigTransactionErrorLinkLabel', + linkURL: 'tooBigTransactionErrorLinkURL', + }) + .where('code', 'transaction_is_too_big') + .result(); + } + } + return null; + }; + calculateTransactionFee = async ( request: GetTransactionFeeRequest ): Promise => { @@ -2113,8 +2181,16 @@ const _createAddressFromServerData = action( } ); -const _conditionToTxState = (condition: string) => - TransactionStates[condition === 'pending' ? 'PENDING' : 'OK']; +const _conditionToTxState = (condition: string) => { + switch (condition) { + case 'pending': + return TransactionStates.PENDING; + case 'expired': + return TransactionStates.FAILED; + default: + return TransactionStates.OK; + } +}; const _createTransactionFromServerData = action( 'AdaApi::_createTransactionFromServerData', diff --git a/source/renderer/app/api/transactions/types.js b/source/renderer/app/api/transactions/types.js index d1a7c434c0..50864603cf 100644 --- a/source/renderer/app/api/transactions/types.js +++ b/source/renderer/app/api/transactions/types.js @@ -64,7 +64,7 @@ export type TransactionWithdrawals = { }; export type TransactionWithdrawalType = 'self' | Array; -export type TransactionState = 'pending' | 'in_ledger'; +export type TransactionState = 'pending' | 'in_ledger' | 'expired'; export type TrasactionAddresses = { from: Array, diff --git a/source/renderer/app/components/wallet/transactions/CancelTransactionButton.js b/source/renderer/app/components/wallet/transactions/CancelTransactionButton.js index 5c6632c24d..ea9bd0f268 100644 --- a/source/renderer/app/components/wallet/transactions/CancelTransactionButton.js +++ b/source/renderer/app/components/wallet/transactions/CancelTransactionButton.js @@ -6,15 +6,21 @@ import { ButtonSkin } from 'react-polymorph/lib/skins/simple/ButtonSkin'; import styles from './CancelTransactionButton.scss'; const messages = defineMessages({ - label: { + cancelLabel: { id: 'wallet.transaction.pending.cancelTransactionButton', defaultMessage: '!!!Cancel pending transaction', description: 'Label for the cancel pending transaction button', }, + removeLabel: { + id: 'wallet.transaction.failed.removeTransactionButton', + defaultMessage: '!!!Remove failed transaction', + description: 'Label for the remove failed transaction button', + }, }); type Props = { onClick: Function, + state: 'cancel' | 'remove', }; export default class CancelTransactionButton extends Component { @@ -23,8 +29,9 @@ export default class CancelTransactionButton extends Component { }; render() { - const { onClick } = this.props; - const label = this.context.intl.formatMessage(messages.label); + const { onClick, state } = this.props; + const label = this.context.intl.formatMessage(messages[`${state}Label`]); + return (