From 06fe03fdd0b2fe0a508a5fd0f51171b7014728fb Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 15:16:52 +0200 Subject: [PATCH 1/8] Fix Catalyst voting registration with HWs --- .../VotingRegistrationDialogContainer.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx b/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx index bd60df2779..638074f538 100644 --- a/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx +++ b/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx @@ -255,7 +255,11 @@ class VotingRegistrationDialogContainer extends Component { const { calculateTransactionFee } = transactions; const { getAddressesByWalletId } = addresses; const { getWalletById } = wallets; - const { selectCoins, initiateTransaction } = hardwareWallets; + const { + selectCoins, + initiateTransaction, + updateTxSignRequest, + } = hardwareWallets; const { prepareVotingData } = voting; const amount = formattedAmountToLovelace( `${VOTING_REGISTRATION_FEE_CALCULATION_AMOUNT}` @@ -269,30 +273,32 @@ class VotingRegistrationDialogContainer extends Component { const selectedWallet = getWalletById(this.selectedWalletId); const [address] = await getAddressesByWalletId(this.selectedWalletId); const isHardwareWallet = get(selectedWallet, 'isHardwareWallet', false); - let fee; + let coinSelection; let votingData; if (isHardwareWallet) { votingData = await prepareVotingData({ walletId: this.selectedWalletId, }); - ({ fee } = await selectCoins({ + coinSelection = await selectCoins({ walletId: this.selectedWalletId, address: address.id, amount, metadata: votingData.metadata, - })); + }); + + updateTxSignRequest(coinSelection); } else { - ({ fee } = await calculateTransactionFee({ + coinSelection = await calculateTransactionFee({ walletId: this.selectedWalletId, address: address.id, amount, - })); + }); } if (this._isMounted) { this.setState({ - transactionFee: fee, + transactionFee: coinSelection.fee, transactionFeeError: null, }); } From 0ead47a4a243aa3c224d1f33a4486237b7e749fa Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 15:17:19 +0200 Subject: [PATCH 2/8] Prevent app from crashing when cancelling save PDF dialog --- source/renderer/app/stores/VotingStore.ts | 7 +++++-- source/renderer/app/utils/votingPDFGenerator.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/renderer/app/stores/VotingStore.ts b/source/renderer/app/stores/VotingStore.ts index 5ab01a9511..58783b3cab 100644 --- a/source/renderer/app/stores/VotingStore.ts +++ b/source/renderer/app/stores/VotingStore.ts @@ -424,7 +424,7 @@ export default class VotingStore extends Store { const intl = i18nContext(currentLocale); try { - await votingPDFGenerator({ + const wasSaved = await votingPDFGenerator({ nextVotingFundNumber, qrCode, walletName, @@ -437,7 +437,10 @@ export default class VotingStore extends Store { intl, }); // @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. - this.actions.voting.saveAsPDFSuccess.trigger(); + + if (wasSaved) { + this.actions.voting.saveAsPDFSuccess.trigger(); + } } catch (error) { throw new Error(error); } diff --git a/source/renderer/app/utils/votingPDFGenerator.ts b/source/renderer/app/utils/votingPDFGenerator.ts index 0b710ba6f4..671fb008d6 100644 --- a/source/renderer/app/utils/votingPDFGenerator.ts +++ b/source/renderer/app/utils/votingPDFGenerator.ts @@ -57,7 +57,7 @@ export const votingPDFGenerator = async ({ network, isMainnet, intl, -}: Params) => { +}: Params): Promise => { // Consolidate data const title = intl.formatMessage(messages.title, { nextVotingFundNumber, @@ -93,6 +93,11 @@ export const votingPDFGenerator = async ({ }; const dialogPath = await showSaveDialogChannel.send(params); const filePath = dialogPath.filePath || ''; + + if (dialogPath.canceled || !!filePath) { + return false; + } + await generateVotingPDFChannel.send({ title, currentLocale, @@ -106,4 +111,6 @@ export const votingPDFGenerator = async ({ filePath, author, }); + + return true; }; From 091d7dfa0d1c892542caefc2ab4eec188d04dbee Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 15:30:50 +0200 Subject: [PATCH 3/8] Cleanup --- source/renderer/app/stores/VotingStore.ts | 33 ++++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/source/renderer/app/stores/VotingStore.ts b/source/renderer/app/stores/VotingStore.ts index 58783b3cab..f2c6d699dc 100644 --- a/source/renderer/app/stores/VotingStore.ts +++ b/source/renderer/app/stores/VotingStore.ts @@ -423,26 +423,21 @@ export default class VotingStore extends Store { const { network, isMainnet } = this.environment; const intl = i18nContext(currentLocale); - try { - const wasSaved = await votingPDFGenerator({ - nextVotingFundNumber, - qrCode, - walletName, - currentLocale, - currentDateFormat, - currentTimeFormat, - desktopDirectoryPath, - network, - isMainnet, - intl, - }); - // @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. + const wasSaved = await votingPDFGenerator({ + nextVotingFundNumber, + qrCode, + walletName, + currentLocale, + currentDateFormat, + currentTimeFormat, + desktopDirectoryPath, + network, + isMainnet, + intl, + }); - if (wasSaved) { - this.actions.voting.saveAsPDFSuccess.trigger(); - } - } catch (error) { - throw new Error(error); + if (wasSaved) { + this.actions.voting.saveAsPDFSuccess.trigger(); } }; _checkVotingRegistrationTransaction = async () => { From 49c142764c73495922403f2838285b195729bc86 Mon Sep 17 00:00:00 2001 From: Daniel Main Date: Tue, 30 Aug 2022 18:18:27 +0200 Subject: [PATCH 4/8] Added japanese translation for new environments --- source/renderer/app/i18n/locales/ja-JP.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index 89cfce7aaa..4223ef84c8 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -157,8 +157,8 @@ "environment.network.alonzo_purple": "Alonzo Purple", "environment.network.development": "開発", "environment.network.mainnet": "メインネット", - "environment.network.preprod": "Pre-Prod", - "environment.network.preview": "Preview", + "environment.network.preprod": "プリプロ", + "environment.network.preview": "プレビュー", "environment.network.selfnode": "Selfnode", "environment.network.shelley_qa": "Shelley QA", "environment.network.staging": "ステージング", @@ -682,8 +682,8 @@ "test.environment.daedalusFlightLabel": "Cardano Mainnet - Daedalus Flight", "test.environment.developmentLabel": "開発", "test.environment.mainnetLabel": "メインネット", - "test.environment.preprodLabel": "Pre-Prod", - "test.environment.previewLabel": "Preview", + "test.environment.preprodLabel": "プリプロ", + "test.environment.previewLabel": "プレビュー", "test.environment.selfnodeLabel": "Selfnode", "test.environment.shelleyQaLabel": "Shelley QA", "test.environment.stagingLabel": "ステージング", @@ -1327,4 +1327,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} \ No newline at end of file +} From ce826103b5dd698599919a54bba9a19520c146e4 Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 19:56:16 +0200 Subject: [PATCH 5/8] Address PR feedback --- source/renderer/app/stores/VotingStore.ts | 11 +++++++---- source/renderer/app/utils/votingPDFGenerator.ts | 13 ++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/renderer/app/stores/VotingStore.ts b/source/renderer/app/stores/VotingStore.ts index f2c6d699dc..fcbb497998 100644 --- a/source/renderer/app/stores/VotingStore.ts +++ b/source/renderer/app/stores/VotingStore.ts @@ -11,10 +11,13 @@ import { formattedArrayBufferToHexString } from '../utils/formatters'; import walletUtils from '../utils/walletUtils'; import { VOTING_PHASE_CHECK_INTERVAL, - VOTING_REGISTRATION_TRANSACTION_POLLING_INTERVAL, VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS, + VOTING_REGISTRATION_TRANSACTION_POLLING_INTERVAL, } from '../config/votingConfig'; -import { votingPDFGenerator } from '../utils/votingPDFGenerator'; +import { + votingPDFGenerator, + VotingPDFGeneratorResult, +} from '../utils/votingPDFGenerator'; import { i18nContext } from '../utils/i18nContext'; import type { PathRoleIdentityType } from '../utils/hardwareWalletUtils'; import type { @@ -423,7 +426,7 @@ export default class VotingStore extends Store { const { network, isMainnet } = this.environment; const intl = i18nContext(currentLocale); - const wasSaved = await votingPDFGenerator({ + const result = await votingPDFGenerator({ nextVotingFundNumber, qrCode, walletName, @@ -436,7 +439,7 @@ export default class VotingStore extends Store { intl, }); - if (wasSaved) { + if (result === VotingPDFGeneratorResult.FileSaved) { this.actions.voting.saveAsPDFSuccess.trigger(); } }; diff --git a/source/renderer/app/utils/votingPDFGenerator.ts b/source/renderer/app/utils/votingPDFGenerator.ts index 671fb008d6..c63b34cb0a 100644 --- a/source/renderer/app/utils/votingPDFGenerator.ts +++ b/source/renderer/app/utils/votingPDFGenerator.ts @@ -34,6 +34,7 @@ const messages = defineMessages({ description: 'PDF author', }, }); + type Params = { nextVotingFundNumber: number; qrCode: string; @@ -46,6 +47,12 @@ type Params = { isMainnet: boolean; intl: Record; }; + +export enum VotingPDFGeneratorResult { + FileSaved = 'FileSaved', + CancelledByUser = 'CancelledByUser', +} + export const votingPDFGenerator = async ({ nextVotingFundNumber, qrCode, @@ -57,7 +64,7 @@ export const votingPDFGenerator = async ({ network, isMainnet, intl, -}: Params): Promise => { +}: Params): Promise => { // Consolidate data const title = intl.formatMessage(messages.title, { nextVotingFundNumber, @@ -95,7 +102,7 @@ export const votingPDFGenerator = async ({ const filePath = dialogPath.filePath || ''; if (dialogPath.canceled || !!filePath) { - return false; + return VotingPDFGeneratorResult.CancelledByUser; } await generateVotingPDFChannel.send({ @@ -112,5 +119,5 @@ export const votingPDFGenerator = async ({ author, }); - return true; + return VotingPDFGeneratorResult.FileSaved; }; From c02f617689c1c728528c1eaaa8ec01ebf3a7af88 Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 20:11:32 +0200 Subject: [PATCH 6/8] Fix translations --- source/renderer/app/i18n/locales/ja-JP.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index 4223ef84c8..773c7ed226 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -1327,4 +1327,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} +} \ No newline at end of file From 6db9488dbc352ea7fc51a2d6f11edbb7c339ff51 Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 20:20:43 +0200 Subject: [PATCH 7/8] Address code review feedback --- .../dialogs/VotingRegistrationDialogContainer.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx b/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx index 638074f538..d9a2340417 100644 --- a/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx +++ b/source/renderer/app/containers/voting/dialogs/VotingRegistrationDialogContainer.tsx @@ -273,14 +273,14 @@ class VotingRegistrationDialogContainer extends Component { const selectedWallet = getWalletById(this.selectedWalletId); const [address] = await getAddressesByWalletId(this.selectedWalletId); const isHardwareWallet = get(selectedWallet, 'isHardwareWallet', false); - let coinSelection; + let fee; let votingData; if (isHardwareWallet) { votingData = await prepareVotingData({ walletId: this.selectedWalletId, }); - coinSelection = await selectCoins({ + const coinSelection = await selectCoins({ walletId: this.selectedWalletId, address: address.id, amount, @@ -288,17 +288,18 @@ class VotingRegistrationDialogContainer extends Component { }); updateTxSignRequest(coinSelection); + fee = coinSelection.fee; } else { - coinSelection = await calculateTransactionFee({ + ({ fee } = await calculateTransactionFee({ walletId: this.selectedWalletId, address: address.id, amount, - }); + })); } if (this._isMounted) { this.setState({ - transactionFee: coinSelection.fee, + transactionFee: fee, transactionFeeError: null, }); } From a652562800f118f19bdd56b1a16b639ab26d917d Mon Sep 17 00:00:00 2001 From: Marcin Mazurek Date: Tue, 30 Aug 2022 20:26:28 +0200 Subject: [PATCH 8/8] Fix logic --- source/renderer/app/utils/votingPDFGenerator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/renderer/app/utils/votingPDFGenerator.ts b/source/renderer/app/utils/votingPDFGenerator.ts index c63b34cb0a..3f3c60567b 100644 --- a/source/renderer/app/utils/votingPDFGenerator.ts +++ b/source/renderer/app/utils/votingPDFGenerator.ts @@ -101,7 +101,7 @@ export const votingPDFGenerator = async ({ const dialogPath = await showSaveDialogChannel.send(params); const filePath = dialogPath.filePath || ''; - if (dialogPath.canceled || !!filePath) { + if (dialogPath.canceled || !filePath) { return VotingPDFGeneratorResult.CancelledByUser; }