From a5d885c5f23751b6d7320b37f0a16607566c9f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Tue, 8 Mar 2022 13:51:55 +0100 Subject: [PATCH 01/15] [DDW-970] Prevent creating new trezor software wallet when provided incorrect passphrase during pairing --- .../hardware-wallet/HardwareWalletStatus.tsx | 100 +- source/renderer/app/domains/Wallet.ts | 3 + .../app/i18n/locales/defaultMessages.json | 102 ++- source/renderer/app/i18n/locales/en-US.json | 3 +- source/renderer/app/i18n/locales/ja-JP.json | 3 +- .../app/stores/HardwareWalletsStore.ts | 861 +++++++++++------- 6 files changed, 668 insertions(+), 404 deletions(-) diff --git a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx index d5af11c3f8..c08ae250b3 100644 --- a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx +++ b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx @@ -46,6 +46,13 @@ const messages = defineMessages({ defaultMessage: '!!!Exporting the public key failed', description: '"Exporting public key failed" device state', }, + incorrect_passphrase_provided: { + id: 'wallet.hardware.deviceStatus.incorrect_passphrase_provided', + defaultMessage: + '!!!The passphrase you have entered does not match the current wallet', + description: + '"Message displayed when user connects different wallet than the current one', + }, exportingPublicKeyError: { id: 'wallet.hardware.deviceStatus.exportingPublicKeyError', defaultMessage: @@ -160,12 +167,54 @@ const messages = defineMessages({ description: '"Address verified" device state', }, }); + +const hwDeviceLoadingStatuses = [ + HwDeviceStatuses.CONNECTING, + HwDeviceStatuses.LAUNCHING_CARDANO_APP, + HwDeviceStatuses.EXPORTING_PUBLIC_KEY, + HwDeviceStatuses.VERIFYING_TRANSACTION, + HwDeviceStatuses.VERIFYING_ADDRESS, + HwDeviceStatuses.VERIFYING_ADDRESS_CONFIRMATION, +]; + +const hwDeviceReadyStatuses = [ + HwDeviceStatuses.READY, + HwDeviceStatuses.VERIFYING_TRANSACTION_SUCCEEDED, + HwDeviceStatuses.VERIFYING_ADDRESS_SUCCEEDED, +]; + +const hwDeviceErrorStatuses = [ + HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED, + HwDeviceStatuses.INCORRECT_PASSPHRASE_PROVIDED, + HwDeviceStatuses.CONNECTING_FAILED, + HwDeviceStatuses.TREZOR_BRIDGE_FAILURE, + HwDeviceStatuses.WRONG_FIRMWARE, + HwDeviceStatuses.WRONG_CARDANO_APP_VERSION, + HwDeviceStatuses.UNSUPPORTED_DEVICE, + HwDeviceStatuses.VERIFYING_TRANSACTION_FAILED, + HwDeviceStatuses.VERIFYING_ADDRESS_FAILED, + HwDeviceStatuses.VERIFYING_ADDRESS_ABORTED, +]; + +const hwDevicePassphraseRelatedStatuses = [ + HwDeviceStatuses.EXPORTING_PUBLIC_KEY, + HwDeviceStatuses.VERIFYING_TRANSACTION, + HwDeviceStatuses.VERIFYING_ADDRESS, +]; + +const hwDeviceInstructionsLinkRelatedStatuses = [ + HwDeviceStatuses.TREZOR_BRIDGE_FAILURE, + HwDeviceStatuses.WRONG_CARDANO_APP_VERSION, + HwDeviceStatuses.WRONG_FIRMWARE, +]; + type Props = { hwDeviceStatus: HwDeviceStatus; onExternalLinkClick?: (...args: Array) => any; walletName?: string; isTrezor: boolean; }; + type State = { hwDeviceStatus: HwDeviceStatus; }; @@ -190,12 +239,14 @@ class HardwareWalletStatus extends Component { setTimeout(() => { // Status remains unchanged in 1.5s - set as new status if (nextProps.hwDeviceStatus === this.props.hwDeviceStatus) { + console.log('HW status', nextProps.hwDeviceStatus); this.setState({ hwDeviceStatus: nextProps.hwDeviceStatus, }); } }, 4000); } else { + console.log('HW status', nextProps.hwDeviceStatus); this.setState({ hwDeviceStatus: nextProps.hwDeviceStatus, }); @@ -207,40 +258,21 @@ class HardwareWalletStatus extends Component { const { intl } = this.context; const { onExternalLinkClick, walletName, isTrezor } = this.props; const { hwDeviceStatus } = this.state; - const isLoading = - hwDeviceStatus === HwDeviceStatuses.CONNECTING || - hwDeviceStatus === HwDeviceStatuses.LAUNCHING_CARDANO_APP || - hwDeviceStatus === HwDeviceStatuses.EXPORTING_PUBLIC_KEY || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_TRANSACTION || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS_CONFIRMATION; - const isReady = - hwDeviceStatus === HwDeviceStatuses.READY || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_TRANSACTION_SUCCEEDED || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS_SUCCEEDED; - const hasErrored = - hwDeviceStatus === HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED || - hwDeviceStatus === HwDeviceStatuses.CONNECTING_FAILED || - hwDeviceStatus === HwDeviceStatuses.TREZOR_BRIDGE_FAILURE || - hwDeviceStatus === HwDeviceStatuses.WRONG_FIRMWARE || - hwDeviceStatus === HwDeviceStatuses.WRONG_CARDANO_APP_VERSION || - hwDeviceStatus === HwDeviceStatuses.UNSUPPORTED_DEVICE || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_TRANSACTION_FAILED || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS_FAILED || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS_ABORTED; - const hasPassphraseLabel = - hwDeviceStatus === HwDeviceStatuses.EXPORTING_PUBLIC_KEY || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_TRANSACTION || - hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS; - const componentClasses = classnames([ - styles.component, - isReady ? styles.isReady : null, - hasErrored ? styles.isError : null, - ]); - const hasInstructionsLink = - hwDeviceStatus === HwDeviceStatuses.TREZOR_BRIDGE_FAILURE || - hwDeviceStatus === HwDeviceStatuses.WRONG_CARDANO_APP_VERSION || - hwDeviceStatus === HwDeviceStatuses.WRONG_FIRMWARE; + const isLoading = hwDeviceLoadingStatuses.includes(hwDeviceStatus); + const isReady = hwDeviceReadyStatuses.includes(hwDeviceStatus); + const hasErrored = hwDeviceErrorStatuses.includes(hwDeviceStatus); + const hasPassphraseLabel = hwDevicePassphraseRelatedStatuses.includes( + hwDeviceStatus + ); + const hasInstructionsLink = hwDeviceInstructionsLinkRelatedStatuses.includes( + hwDeviceStatus + ); + + const componentClasses = classnames(styles.component, { + [styles.isReady]: isReady, + [styles.isError]: hasErrored, + }); + let instructionsLink; let label; diff --git a/source/renderer/app/domains/Wallet.ts b/source/renderer/app/domains/Wallet.ts index 761a385c17..4b089f1673 100644 --- a/source/renderer/app/domains/Wallet.ts +++ b/source/renderer/app/domains/Wallet.ts @@ -44,6 +44,7 @@ export type HwDeviceStatus = | 'launching_cardano_app' | 'exporting_public_key' | 'exporting_public_key_failed' + | 'incorrect_passphrase_provided' | 'ready' | 'verifying_transaction' | 'verifying_transaction_failed' @@ -62,6 +63,7 @@ export const HwDeviceStatuses: { LAUNCHING_CARDANO_APP: HwDeviceStatus; EXPORTING_PUBLIC_KEY: HwDeviceStatus; EXPORTING_PUBLIC_KEY_FAILED: HwDeviceStatus; + INCORRECT_PASSPHRASE_PROVIDED: HwDeviceStatus; READY: HwDeviceStatus; VERIFYING_TRANSACTION: HwDeviceStatus; VERIFYING_TRANSACTION_FAILED: HwDeviceStatus; @@ -82,6 +84,7 @@ export const HwDeviceStatuses: { LAUNCHING_CARDANO_APP: 'launching_cardano_app', EXPORTING_PUBLIC_KEY: 'exporting_public_key', EXPORTING_PUBLIC_KEY_FAILED: 'exporting_public_key_failed', + INCORRECT_PASSPHRASE_PROVIDED: 'incorrect_passphrase_provided', WRONG_FIRMWARE: 'wrong_firmware', WRONG_CARDANO_APP_VERSION: 'wrong_cardano_app_version', UNSUPPORTED_DEVICE: 'unsupported_device', diff --git a/source/renderer/app/i18n/locales/defaultMessages.json b/source/renderer/app/i18n/locales/defaultMessages.json index 167de60e07..07928df092 100644 --- a/source/renderer/app/i18n/locales/defaultMessages.json +++ b/source/renderer/app/i18n/locales/defaultMessages.json @@ -1306,18 +1306,32 @@ "line": 44 } }, + { + "defaultMessage": "!!!The passphrase you have entered does not match the current wallet", + "description": "\"Message displayed when user connects different wallet than the current one", + "end": { + "column": 3, + "line": 55 + }, + "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", + "id": "wallet.hardware.deviceStatus.incorrect_passphrase_provided", + "start": { + "column": 33, + "line": 49 + } + }, { "defaultMessage": "!!!Disconnect and reconnect your device to restart the process.", "description": "\"Disconnect and reconnect your device to start the process again\" device state", "end": { "column": 3, - "line": 55 + "line": 62 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.exportingPublicKeyError", "start": { "column": 27, - "line": 49 + "line": 56 } }, { @@ -1325,13 +1339,13 @@ "description": "\"Enter passphrase if needed\" device sub-state", "end": { "column": 3, - "line": 60 + "line": 67 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.enterPassphrase", "start": { "column": 19, - "line": 56 + "line": 63 } }, { @@ -1339,13 +1353,13 @@ "description": "\"Device ready\" device state", "end": { "column": 3, - "line": 65 + "line": 72 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.ready", "start": { "column": 9, - "line": 61 + "line": 68 } }, { @@ -1353,13 +1367,13 @@ "description": "\"Confirm the transaction using the IOHK Trezor 1 device\" device state", "end": { "column": 3, - "line": 72 + "line": 79 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction", "start": { "column": 25, - "line": 66 + "line": 73 } }, { @@ -1367,13 +1381,13 @@ "description": "\"Transaction verification and signing failed\" device state", "end": { "column": 3, - "line": 77 + "line": 84 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction_failed", "start": { "column": 32, - "line": 73 + "line": 80 } }, { @@ -1381,13 +1395,13 @@ "description": "\"Transaction verified and signed\" device state", "end": { "column": 3, - "line": 82 + "line": 89 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction_succeeded", "start": { "column": 35, - "line": 78 + "line": 85 } }, { @@ -1395,13 +1409,13 @@ "description": "\"Trezor Bridge not installed! {instructionsLink}\" device state", "end": { "column": 3, - "line": 88 + "line": 95 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure", "start": { "column": 25, - "line": 83 + "line": 90 } }, { @@ -1409,13 +1423,13 @@ "description": "Trezor Bridge installation instructions link label", "end": { "column": 3, - "line": 93 + "line": 100 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure.link.label", "start": { "column": 36, - "line": 89 + "line": 96 } }, { @@ -1423,13 +1437,13 @@ "description": "URL for the \"Trezor Bridge\" update", "end": { "column": 3, - "line": 99 + "line": 106 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure.link.url", "start": { "column": 34, - "line": 94 + "line": 101 } }, { @@ -1437,13 +1451,13 @@ "description": "\"Unsupported firmware!\" device state", "end": { "column": 3, - "line": 104 + "line": 111 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware", "start": { "column": 18, - "line": 100 + "line": 107 } }, { @@ -1451,13 +1465,13 @@ "description": "Firmware update installation instructions link label", "end": { "column": 3, - "line": 109 + "line": 116 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware.link.label", "start": { "column": 29, - "line": 105 + "line": 112 } }, { @@ -1465,13 +1479,13 @@ "description": "URL for the \"Firmware Update\"", "end": { "column": 3, - "line": 115 + "line": 122 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware.link.url", "start": { "column": 27, - "line": 110 + "line": 117 } }, { @@ -1479,13 +1493,13 @@ "description": "\"The device is not supported!\" device state", "end": { "column": 3, - "line": 120 + "line": 127 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.unsupported_device", "start": { "column": 22, - "line": 116 + "line": 123 } }, { @@ -1493,13 +1507,13 @@ "description": "\"Unsupported firmware!\" device state", "end": { "column": 3, - "line": 125 + "line": 132 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version", "start": { "column": 29, - "line": 121 + "line": 128 } }, { @@ -1507,13 +1521,13 @@ "description": "Firmware update installation instructions link label", "end": { "column": 3, - "line": 130 + "line": 137 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version.link.label", "start": { "column": 40, - "line": 126 + "line": 133 } }, { @@ -1521,13 +1535,13 @@ "description": "URL for the \"Firmware Update\"", "end": { "column": 3, - "line": 136 + "line": 143 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version.link.url", "start": { "column": 38, - "line": 131 + "line": 138 } }, { @@ -1535,13 +1549,13 @@ "description": "\"Verify receiving address on your Hardware Wallet device", "end": { "column": 3, - "line": 141 + "line": 148 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address", "start": { "column": 21, - "line": 137 + "line": 144 } }, { @@ -1549,13 +1563,13 @@ "description": "\"Confirm receiving address on your Hardware Wallet device", "end": { "column": 3, - "line": 146 + "line": 153 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_confirmation", "start": { "column": 34, - "line": 142 + "line": 149 } }, { @@ -1563,13 +1577,13 @@ "description": "\"Address verification failed\" device state", "end": { "column": 3, - "line": 151 + "line": 158 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_failed", "start": { "column": 28, - "line": 147 + "line": 154 } }, { @@ -1577,13 +1591,13 @@ "description": "\"Address verification aborted\" device state", "end": { "column": 3, - "line": 156 + "line": 163 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_aborted", "start": { "column": 29, - "line": 152 + "line": 159 } }, { @@ -1591,13 +1605,13 @@ "description": "\"Address verified\" device state", "end": { "column": 3, - "line": 161 + "line": 168 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_succeeded", "start": { "column": 31, - "line": 157 + "line": 164 } } ], @@ -4635,7 +4649,7 @@ } }, { - "defaultMessage": "!!!You are already delegating {selectedWalletName} wallet to [{selectedPoolTicker}] stake pool. If you wish to re-delegate your stake, please select a different pool.", + "defaultMessage": "!!!You are already delegating {selectedWalletName} wallet to [{selectedPoolTicker}] stake pool. If you wish to re-delegate your stake, please select a different pool.", "description": "\"You are already delegating to stake pool\" label on the delegation setup \"choose stake pool\" dialog.", "end": { "column": 5, @@ -4649,7 +4663,7 @@ } }, { - "defaultMessage": "!!!You are already pending delegation {selectedWalletName} wallet to [{selectedPoolTicker}] stake pool. If you wish to re-delegate your stake, please select a different pool.", + "defaultMessage": "!!!You are already pending delegation {selectedWalletName} wallet to [{selectedPoolTicker}] stake pool. If you wish to re-delegate your stake, please select a different pool.", "description": "\"You are already delegating to stake pool\" label on the delegation setup \"choose stake pool\" dialog.", "end": { "column": 5, diff --git a/source/renderer/app/i18n/locales/en-US.json b/source/renderer/app/i18n/locales/en-US.json index 178e47ea36..58dc0316a0 100755 --- a/source/renderer/app/i18n/locales/en-US.json +++ b/source/renderer/app/i18n/locales/en-US.json @@ -827,6 +827,7 @@ "wallet.hardware.deviceStatus.exportingPublicKeyError": "Disconnect and reconnect your hardware wallet to restart the process.", "wallet.hardware.deviceStatus.exporting_public_key": "Export the public key on your device", "wallet.hardware.deviceStatus.exporting_public_key_failed": "Exporting the public key failed", + "wallet.hardware.deviceStatus.incorrect_passphrase_provided": "The passphrase you have entered does not match the current wallet", "wallet.hardware.deviceStatus.launching_cardano_app": "Launch Cardano application on your device", "wallet.hardware.deviceStatus.ready": "Device ready", "wallet.hardware.deviceStatus.trezor_bridge_failure": "Trezor Bridge is not installed! {instructionsLink}", @@ -1298,4 +1299,4 @@ "wallet.transferFunds.dialog2.total.label": "Total", "widgets.itemsDropdown.syncingLabel": "Syncing", "widgets.itemsDropdown.syncingLabelProgress": "Syncing {syncingProgress}%" -} +} \ No newline at end of file diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index da75e87abc..08a40ad0d0 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -827,6 +827,7 @@ "wallet.hardware.deviceStatus.exportingPublicKeyError": "ハードウェアウォレットを切断して再接続し、もう一度プロセスを始めてください。", "wallet.hardware.deviceStatus.exporting_public_key": "デバイス上で公開鍵をエクスポートしてください", "wallet.hardware.deviceStatus.exporting_public_key_failed": "公開鍵のエクスポートができません", + "wallet.hardware.deviceStatus.incorrect_passphrase_provided": "!!!The passphrase you have entered does not match the current wallet", "wallet.hardware.deviceStatus.launching_cardano_app": "デバイス上でCardanoアプリケーションを起動してください", "wallet.hardware.deviceStatus.ready": "デバイスの準備ができました", "wallet.hardware.deviceStatus.trezor_bridge_failure": "Trezor Bridgeがインストールされていません。{instructionsLink}", @@ -1298,4 +1299,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} +} \ No newline at end of file diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index eb4f09557b..192dfba332 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -7,7 +7,7 @@ import { } from '@cardano-foundation/ledgerjs-hw-app-cardano'; import Store from './lib/Store'; import Request from './lib/LocalizedRequest'; -import { HwDeviceStatuses } from '../domains/Wallet'; +import Wallet, { HwDeviceStatuses } from '../domains/Wallet'; import WalletAddress from '../domains/WalletAddress'; import { toJS } from '../../../common/utils/helper'; import { @@ -151,6 +151,50 @@ const useCardanoAppInterval = ( addressVerification ); +interface RecognizeSoftwareWalletByExtendedPublicKeyArgs { + extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; +} + +interface DeletePendingDeviceWithGivenPathArgs { + path: string; +} + +interface DiscardConnectedDeviceAndReInitiateTransactionArgs { + walletId?: string; +} + +interface ProceedWithTransactionAfterConnectingDeviceArgs { + isTrezor: boolean; + walletId?: string; + deviceId?: string; + devicePath?: string; +} + +interface DiscardConnectedDeviceAndReInitiateAddressVerificationArgs { + address: WalletAddress; + walletId?: string; +} + +interface ProceedWithAddressVerificationAfterConnectingDeviceArgs { + address: WalletAddress; + devicePath?: string; + isTrezor: boolean; + walletId: string; +} + +interface HandleIdentifiedSoftwareWalletArgs { + address?: WalletAddress | null; + extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; + forcedPath?: string; + recognizedSoftwareWallet: Wallet; + walletId?: string; +} + +interface CreateNewSoftwareWalletForRecognizedPendingDeviceArgs { + extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; + forcedPath?: string; +} + const { network, isDev } = global.environment; const hardwareWalletsNetworkConfig = getHardwareWalletsNetworkConfig(network); export default class HardwareWalletsStore extends Store { @@ -682,11 +726,11 @@ export default class HardwareWalletsStore extends Store { if (this.isExportKeyAborted) { if (isTrezor) { - await this._getExtendedPublicKey( - recognizedPairedHardwareWallet.path, - activeWalletId, - this.unfinishedWalletAddressVerification - ); + await this._identifyAndHandleSoftwareWallet({ + address: this.unfinishedWalletAddressVerification, + path: recognizedPairedHardwareWallet.path, + walletId: activeWalletId, + }); } else { this.cardanoAdaAppPollingInterval = useCardanoAppInterval( this.getCardanoAdaApp, @@ -734,11 +778,11 @@ export default class HardwareWalletsStore extends Store { // Force export again and proceed (continue) with last action if (this.isExportKeyAborted) { if (isTrezor) { - await this._getExtendedPublicKey( - lastDeviceTransport.path, - activeWalletId, - this.unfinishedWalletAddressVerification - ); + await this._identifyAndHandleSoftwareWallet({ + address: this.unfinishedWalletAddressVerification, + path: lastDeviceTransport.path, + walletId: activeWalletId, + }); } else { this.cardanoAdaAppPollingInterval = useCardanoAppInterval( this.getCardanoAdaApp, @@ -858,8 +902,9 @@ export default class HardwareWalletsStore extends Store { }); if (deviceType === DeviceTypes.TREZOR) { - // Jump to exporting public key - await this._getExtendedPublicKey(transportDevice.path); + await this._identifyAndHandleSoftwareWallet({ + path: transportDevice.path, + }); } else { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] HWStore - START cardano app poller'); @@ -961,7 +1006,11 @@ export default class HardwareWalletsStore extends Store { ); } - await this._getExtendedPublicKey(path, walletId, address); + await this._identifyAndHandleSoftwareWallet({ + address, + path, + walletId, + }); } } catch (error) { logger.debug('[HW-DEBUG] HWStore - Cardano app fetching error', { @@ -1194,7 +1243,33 @@ export default class HardwareWalletsStore extends Store { ) || {}; // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type '{}'. devicePath = activeDevice.path || path || newConnectionData.path || null; - await this._getExtendedPublicKey(devicePath, walletId, address); + + const extendedPublicKey = await this._requestExtendedPublicKey( + devicePath, + walletId, + address + ); + const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + { extendedPublicKey } + ); + + if (recognizedSoftwareWallet) { + await this._handleIdentifiedSoftwareWallet({ + recognizedSoftwareWallet, + extendedPublicKey, + forcedPath: devicePath, + walletId, + address, + }); + } else { + logger.debug( + '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' + ); + this._discardConnectedDeviceAndReInitiateAddressVerification({ + address, + walletId, + }); + } } else { logger.debug('[HW-DEBUG] Verify Address with Ledger: ', { address: toJS(address), @@ -1403,12 +1478,24 @@ export default class HardwareWalletsStore extends Store { this.verifyAddress(this.tempAddressToVerify); } }; + @action - _getExtendedPublicKey = async ( - forcedPath: string | null | undefined, + _resetInitiatedConnection = ({ isAborted }) => { + runInAction('HardwareWalletsStore:: Re-run initiated connection', () => { + this.hwDeviceStatus = isAborted + ? HwDeviceStatuses.CONNECTING + : HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED; + this.isListeningForDevice = true; + this.isExportKeyAborted = true; + }); + }; + + @action + _requestExtendedPublicKey = async ( + forcedPath?: string | null, walletId?: string, - address?: WalletAddress | null | undefined - ) => { + address?: WalletAddress | null + ): Promise => { logger.debug('[HW-DEBUG] HWStore - extendedPublicKey', { forcedPath, walletId, @@ -1423,299 +1510,17 @@ export default class HardwareWalletsStore extends Store { ); } - const { deviceType, path, deviceName, deviceModel } = transportDevice; + const { deviceType, path } = transportDevice; const isTrezor = deviceType === DeviceTypes.TREZOR; const devicePath = forcedPath || path; try { - const extendedPublicKey = await getExtendedPublicKeyChannel.request({ + return await getExtendedPublicKeyChannel.request({ path: "1852'/1815'/0'", // Shelley 1852 ADA 1815 indicator for account '0' isTrezor, devicePath, }); - const deviceId = extendedPublicKey.deviceId || transportDevice.deviceId; - logger.debug('[HW-DEBUG] HWStore - EXPORT - deviceID: ', { - deviceId, - }); - const recognizedStoredWallet = find( - this.hardwareWalletsConnectionData, - (hardwareWalletData) => - extendedPublicKey.chainCodeHex === - hardwareWalletData.extendedPublicKey.chainCodeHex && - extendedPublicKey.publicKeyHex === - hardwareWalletData.extendedPublicKey.publicKeyHex - ); - const recognizedWallet = recognizedStoredWallet - ? this.stores.wallets.getWalletById(recognizedStoredWallet.id) - : null; - - // Check if public key matches already restored hardware wallet public key - // Update LC data and redirect to paired wallet - if (recognizedWallet) { - logger.debug('[HW-DEBUG] HWStore - I have recognized wallet: ', { - recognizedWallet: recognizedWallet.id, - }); - - this._setHardwareWalletLocalData({ - walletId: recognizedWallet.id, - data: { - disconnected: false, - // @ts-ignore ts-migrate(2322) FIXME: Type '{ disconnected: false; data: { deviceType: D... Remove this comment to see the full error message - data: { - deviceType, - deviceModel, - deviceName, - path: devicePath, - paired: recognizedWallet.id, - // device paired with software wallet - disconnected: false, // device physically disconnected - }, - }, - }); - - // Delete initiated (pending) device with this path since now is paired to wallet - const recognizedDevice = find( - this.hardwareWalletDevices, - // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type 'HardwareWa... Remove this comment to see the full error message - (device) => device.path === forcedPath - ); - - if (recognizedDevice) { - logger.debug( - '[HW-DEBUG] HWStore - _getExtendedPublicKey - UNSET Device with path: ', - { - recognizedDevice: recognizedDevice.id, - } - ); - await this._unsetHardwareWalletDevice({ - deviceId: recognizedDevice.id, - }); - } - - logger.debug('[HW-DEBUG] HWStore - SET device from key export: ', { - deviceId, - }); - - if (deviceId) { - this._setHardwareWalletDevice({ - deviceId, - data: { - // @ts-ignore ts-migrate(2322) FIXME: Type '{ deviceId: string; deviceType: DeviceType; ... Remove this comment to see the full error message - deviceId, - deviceType, - deviceModel, - deviceName, - path: devicePath, - paired: recognizedWallet.id, - // device paired with software wallet - disconnected: false, - // device physically disconnected - isPending: false, - }, - }); - } - - // Prevent redirect / check if device is valid / proceed with tx - if (this.isTransactionInitiated) { - logger.debug( - '[HW-DEBUG] HWStore - Re-initiate tx from _getExtendedPublicKey: ', - { - walletId, - recognizedWalletId: recognizedWallet.id, - deviceId, - devicePath, - } - ); - - // Check if sender wallet match transaction initialization - if (!walletId || recognizedWallet.id !== walletId) { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug( - '[HW-DEBUG] HWStore - Device not belongs to this wallet' - ); - // Keep isTransactionInitiated active & Set new device listener by initiating transaction - // Show message to reconnect proper software wallet device pair - logger.debug( - '[HW-DEBUG] unfinishedWalletTxSigning SET: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - runInAction( - 'HardwareWalletsStore:: set HW device CONNECTING FAILED', - () => { - this.hwDeviceStatus = HwDeviceStatuses.CONNECTING_FAILED; - this.activeDevicePath = null; - this.unfinishedWalletTxSigning = walletId; - this.isExportKeyAborted = false; - } - ); - } else { - logger.debug( - '[HW-DEBUG] HWStore - Transaction Initiated - Close: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); - runInAction('HardwareWalletsStore:: Initiate transaction', () => { - this.isTransactionInitiated = false; - this.unfinishedWalletTxSigning = null; - this.isExportKeyAborted = false; - }); - - if (isTrezor) { - this._signTransactionTrezor(walletId, deviceId); - } else { - this._signTransactionLedger(walletId, devicePath); - } - } - - return; - } - - // Prevent redirect / check if device is valid / proceed with address verification - if (this.isAddressVerificationInitiated && address) { - logger.debug( - '[HW-DEBUG] HWStore - Re-initiate Address verification from _getExtendedPublicKey: ', - { - address: toJS(address), - devicePath, - walletId, - recognizedWalletId: recognizedWallet.id, - deviceId, - } - ); - - if (!walletId || recognizedWallet.id !== walletId) { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug( - '[HW-DEBUG] HWStore - Device not belongs to this wallet' - ); - // Show message to reconnect proper software wallet device pair - logger.debug( - '[HW-DEBUG] unfinishedWalletAddressVerification SET: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - runInAction( - 'HardwareWalletsStore:: set HW device CONNECTING FAILED', - () => { - this.isAddressVerificationInitiated = false; - this.hwDeviceStatus = HwDeviceStatuses.CONNECTING_FAILED; - this.activeDevicePath = null; - this.unfinishedWalletAddressVerification = address; - this.isExportKeyAborted = false; - } - ); - } else { - logger.debug( - '[HW-DEBUG] HWStore - Address Verification - Close: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); - runInAction('HardwareWalletsStore:: Initiate transaction', () => { - this.isAddressVerificationInitiated = false; - this.unfinishedWalletAddressVerification = null; - this.isExportKeyAborted = false; - }); - this.verifyAddress({ - address, - path: devicePath, - isTrezor, - }); - } - - return; - } - - // --> Else - this.stores.wallets.goToWalletRoute(recognizedStoredWallet.id); - // @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. - this.actions.dialogs.closeActiveDialog.trigger(); - return; - } - - logger.debug( - '[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ', - { - deviceId, - } - ); - - // Software Wallet not recognized and TX initiated. Show error - if (this.isTransactionInitiated) { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); - // Keep isTransactionInitiated active & Set new device listener by initiating transaction - // Show message to reconnect proper software wallet device pair - runInAction( - 'HardwareWalletsStore:: set HW device CONNECTING FAILED', - () => { - this.hwDeviceStatus = HwDeviceStatuses.CONNECTING_FAILED; - this.activeDevicePath = null; - this.unfinishedWalletTxSigning = walletId; - this.isExportKeyAborted = false; - } - ); - return; - } - - // Software Wallet not recognized, create new one with default name - logger.debug('[HW-DEBUG] HWStore - Initiate HW create / restore', { - transportDevice: toJS(transportDevice), - device: { - deviceId, - deviceType, - deviceModel, - deviceName, - path: forcedPath || path, - firmwareVersion: null, - }, - }); - await this.actions.wallets.createHardwareWallet.trigger({ - walletName: deviceName || DEFAULT_HW_NAME, - extendedPublicKey, - device: { - deviceId, - deviceType, - deviceModel, - deviceName, - path: forcedPath || path, - firmwareVersion: null, - }, - }); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug('[HW-DEBUG] HWStore - HW created / restored'); - // Get all Pending devices with this path and delete - const recognizedPendingDevice = find( - this.hardwareWalletDevices, - // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type 'HardwareWa... Remove this comment to see the full error message - (device) => device.path === devicePath - ); - - // @ts-ignore ts-migrate(2339) FIXME: Property 'isPending' does not exist on type 'Hardw... Remove this comment to see the full error message - if (recognizedPendingDevice && recognizedPendingDevice.isPending) { - logger.debug( - '[HW-DEBUG] HWStore - Export key - UNSET Device with path: ', - { - path, - recognizedPendingDevice: recognizedPendingDevice.id, - } - ); - await this._unsetHardwareWalletDevice({ - deviceId: recognizedPendingDevice.id, - }); - } - - // @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. - this.resetInitializedConnection(); - - this._refreshHardwareWalletsLocalData(); - - this._refreshHardwareWalletDevices(); } catch (error) { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] HWStore - Export key error'); @@ -1749,29 +1554,11 @@ export default class HardwareWalletsStore extends Store { setTimeout(() => { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] NOW RESET'); - runInAction( - 'HardwareWalletsStore:: Re-run initiated connection', - () => { - this.hwDeviceStatus = isAborted - ? HwDeviceStatuses.CONNECTING - : HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED; - this.isListeningForDevice = true; - this.isExportKeyAborted = true; - } - ); + this._resetInitiatedConnection({ isAborted }); }, 2000); } else { this.stopCardanoAdaAppFetchPoller(); - runInAction( - 'HardwareWalletsStore:: Re-run initiated connection', - () => { - this.hwDeviceStatus = isAborted - ? HwDeviceStatuses.CONNECTING - : HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED; - this.isListeningForDevice = true; - this.isExportKeyAborted = true; - } - ); + this._resetInitiatedConnection({ isAborted }); } } else { runInAction( @@ -1786,6 +1573,403 @@ export default class HardwareWalletsStore extends Store { throw error; } }; + + @action + _recognizeSoftwareWalletByExtendedPublicKey = async ({ + extendedPublicKey, + }: RecognizeSoftwareWalletByExtendedPublicKeyArgs): Promise => { + const deviceId = + extendedPublicKey?.deviceId || this.transportDevice.deviceId; + logger.debug('[HW-DEBUG] HWStore - EXPORT - deviceID: ', { + deviceId, + }); + + const recognizedStoredWallet = find( + this.hardwareWalletsConnectionData, + (hardwareWalletData) => + extendedPublicKey.chainCodeHex === + hardwareWalletData.extendedPublicKey.chainCodeHex && + extendedPublicKey.publicKeyHex === + hardwareWalletData.extendedPublicKey.publicKeyHex + ); + + return recognizedStoredWallet + ? this.stores.wallets.getWalletById(recognizedStoredWallet.id) + : null; + }; + + // Delete initiated (pending) device with this path since now is paired to wallet + @action + _deletePendingDeviceWithGivenPath = async ({ + path, + }: DeletePendingDeviceWithGivenPathArgs) => { + const recognizedDevice = find( + this.hardwareWalletDevices, + // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type 'HardwareWa... Remove this comment to see the full error message + (device) => device.path === path + ); + + if (!recognizedDevice) return; + + logger.debug( + '[HW-DEBUG] HWStore - __deletePendingDeviceWithGivenPath - UNSET Device with path: ', + { + recognizedDevice: recognizedDevice.id, + } + ); + await this._unsetHardwareWalletDevice({ + deviceId: recognizedDevice.id, + }); + }; + + @action + _discardConnectedDeviceAndReInitiateTransaction = ({ + walletId, + }: DiscardConnectedDeviceAndReInitiateTransactionArgs = {}) => { + // Keep isTransactionInitiated active & Set new device listener by initiating transaction + // Show message to reconnect proper software wallet device pair + logger.debug( + '[HW-DEBUG] unfinishedWalletTxSigning SET: ', + // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message + walletId + ); + runInAction( + 'HardwareWalletsStore:: set HW device CONNECTING FAILED', + () => { + this.hwDeviceStatus = HwDeviceStatuses.CONNECTING_FAILED; + this.activeDevicePath = null; + this.unfinishedWalletTxSigning = walletId; + this.isExportKeyAborted = false; + } + ); + }; + + @action + _proceedWithTransactionAfterConnectingDevice = ({ + isTrezor, + walletId, + deviceId, + devicePath, + }: ProceedWithTransactionAfterConnectingDeviceArgs) => { + logger.debug( + '[HW-DEBUG] HWStore - Transaction Initiated - Close: ', + // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message + walletId + ); + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); + runInAction('HardwareWalletsStore:: Initiate transaction', () => { + this.isTransactionInitiated = false; + this.unfinishedWalletTxSigning = null; + this.isExportKeyAborted = false; + }); + + if (isTrezor) { + this._signTransactionTrezor(walletId, deviceId); + } else { + this._signTransactionLedger(walletId, devicePath); + } + }; + + @action + _discardConnectedDeviceAndReInitiateAddressVerification = ({ + address, + walletId, + }: DiscardConnectedDeviceAndReInitiateAddressVerificationArgs) => { + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); + // Show message to reconnect proper software wallet device pair + logger.debug( + '[HW-DEBUG] unfinishedWalletAddressVerification SET: ', + // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message + walletId + ); + runInAction( + 'HardwareWalletsStore:: set HW device CONNECTING FAILED', + () => { + this.isAddressVerificationInitiated = false; + this.hwDeviceStatus = HwDeviceStatuses.INCORRECT_PASSPHRASE_PROVIDED; + this.activeDevicePath = null; + this.unfinishedWalletAddressVerification = address; + this.isExportKeyAborted = false; + } + ); + }; + + @action + _proceedWithAddressVerificationAfterConnectingDevice = ({ + address, + devicePath, + isTrezor, + walletId, + }: ProceedWithAddressVerificationAfterConnectingDeviceArgs) => { + logger.debug( + '[HW-DEBUG] HWStore - Address Verification - Close: ', + // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message + walletId + ); + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); + runInAction('HardwareWalletsStore:: Initiate transaction', () => { + this.isAddressVerificationInitiated = false; + this.unfinishedWalletAddressVerification = null; + this.isExportKeyAborted = false; + }); + + this.verifyAddress({ + address, + path: devicePath, + isTrezor, + }); + }; + + @action + _handleIdentifiedSoftwareWallet = async ({ + address, + extendedPublicKey, + forcedPath, + recognizedSoftwareWallet, + walletId, + }: HandleIdentifiedSoftwareWalletArgs) => { + const { deviceType, path, deviceName, deviceModel } = this.transportDevice; + const isTrezor = deviceType === DeviceTypes.TREZOR; + const devicePath = forcedPath || path; + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + + // Check if public key matches already restored hardware wallet public key + // Update LC data and redirect to paired wallet + + logger.debug('[HW-DEBUG] HWStore - I have recognized wallet: ', { + recognizedWallet: recognizedSoftwareWallet.id, + }); + + this._setHardwareWalletLocalData({ + walletId: recognizedSoftwareWallet.id, + data: { + disconnected: false, + // @ts-ignore ts-migrate(2322) FIXME: Type '{ disconnected: false; data: { deviceType: D... Remove this comment to see the full error message + data: { + deviceType, + deviceModel, + deviceName, + path: devicePath, + paired: recognizedSoftwareWallet.id, + // device paired with software wallet + disconnected: false, // device physically disconnected + }, + }, + }); + + await this._deletePendingDeviceWithGivenPath({ path: forcedPath }); + + if (deviceId) { + logger.debug('[HW-DEBUG] HWStore - SET device from key export: ', { + deviceId, + }); + + this._setHardwareWalletDevice({ + deviceId, + data: { + // @ts-ignore ts-migrate(2322) FIXME: Type '{ deviceId: string; deviceType: DeviceType; ... Remove this comment to see the full error message + deviceId, + deviceType, + deviceModel, + deviceName, + path: devicePath, + paired: recognizedSoftwareWallet.id, + // device paired with software wallet + disconnected: false, + // device physically disconnected + isPending: false, + }, + }); + } + + // Prevent redirect / check if device is valid / proceed with tx + if (this.isTransactionInitiated) { + logger.debug( + '[HW-DEBUG] HWStore - Re-initiate tx from _handleIdentifiedSoftwareWallet: ', + { + walletId, + recognizedWalletId: recognizedSoftwareWallet.id, + deviceId, + devicePath, + } + ); + + // Check if sender wallet match transaction initialization + if (!walletId || recognizedSoftwareWallet.id !== walletId) { + if (walletId) { + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug( + '[HW-DEBUG] HWStore - Device not belongs to this wallet' + ); + } + this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); + } else { + this._proceedWithTransactionAfterConnectingDevice({ + isTrezor, + deviceId, + devicePath, + walletId, + }); + } + + return; + } + + // Prevent redirect / check if device is valid / proceed with address verification + if (this.isAddressVerificationInitiated && address) { + logger.debug( + '[HW-DEBUG] HWStore - Re-initiate Address verification from _handleIdentifiedSoftwareWallet: ', + { + address: toJS(address), + devicePath, + walletId, + recognizedWalletId: recognizedSoftwareWallet.id, + deviceId, + } + ); + + if (!walletId || recognizedSoftwareWallet.id !== walletId) { + this._discardConnectedDeviceAndReInitiateAddressVerification({ + address, + walletId, + }); + } else { + this._proceedWithAddressVerificationAfterConnectingDevice({ + address, + devicePath, + isTrezor, + walletId, + }); + } + + return; + } + + // --> Else + this.stores.wallets.goToWalletRoute(recognizedSoftwareWallet.id); + this.actions.dialogs.closeActiveDialog.trigger(); + }; + + @action + _createNewSoftwareWalletForRecognizedPendingDevice = async ({ + extendedPublicKey, + forcedPath, + }: CreateNewSoftwareWalletForRecognizedPendingDeviceArgs) => { + const { deviceType, path, deviceName, deviceModel } = this.transportDevice; + const devicePath = forcedPath || path; + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + + // Software Wallet not recognized, create new one with default name + logger.debug('[HW-DEBUG] HWStore - Initiate HW create / restore', { + transportDevice: toJS(this.transportDevice), + device: { + deviceId, + deviceType, + deviceModel, + deviceName, + path: devicePath, + firmwareVersion: null, + }, + }); + await this.actions.wallets.createHardwareWallet.trigger({ + walletName: deviceName || DEFAULT_HW_NAME, + extendedPublicKey, + device: { + deviceId, + deviceType, + deviceModel, + deviceName, + path: devicePath, + firmwareVersion: null, + }, + }); + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] HWStore - HW created / restored'); + // Get all Pending devices with this path and delete + const recognizedPendingDevice = find( + this.hardwareWalletDevices, + // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type 'HardwareWa... Remove this comment to see the full error message + (device) => device.path === devicePath + ); + + // @ts-ignore ts-migrate(2339) FIXME: Property 'isPending' does not exist on type 'Hardw... Remove this comment to see the full error message + if (recognizedPendingDevice && recognizedPendingDevice.isPending) { + logger.debug( + '[HW-DEBUG] HWStore - Export key - UNSET Device with path: ', + { + path, + recognizedPendingDevice: recognizedPendingDevice.id, + } + ); + await this._unsetHardwareWalletDevice({ + deviceId: recognizedPendingDevice.id, + }); + } + + // @ts-ignore ts-migrate(2554) FIXME: Expected 1 arguments, but got 0. + this.resetInitializedConnection(); + + this._refreshHardwareWalletsLocalData(); + + this._refreshHardwareWalletDevices(); + }; + + @action + _identifyAndHandleSoftwareWallet = async ({ + address, + path, + walletId, + }: { + address?: WalletAddress; + path?: string; + walletId?: string; + }) => { + const extendedPublicKey = await this._requestExtendedPublicKey( + path, + walletId, + address + ); + const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + { extendedPublicKey } + ); + + if (recognizedSoftwareWallet) { + await this._handleIdentifiedSoftwareWallet({ + recognizedSoftwareWallet, + walletId, + extendedPublicKey, + forcedPath: path, + address, + }); + } else { + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + logger.debug( + '[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ', + { + deviceId, + } + ); + + if (this.isTransactionInitiated) { + // Software Wallet not recognized and TX initiated. Show error + this._discardConnectedDeviceAndReInitiateTransaction({ + walletId, + }); + } else { + await this._createNewSoftwareWalletForRecognizedPendingDevice({ + extendedPublicKey, + forcedPath: path, + }); + } + } + }; + // Trezor - Shelley only @action _signTransactionTrezor = async ( @@ -2419,7 +2603,36 @@ export default class HardwareWalletsStore extends Store { this.transportDevice = transportDevice; } ); - await this._getExtendedPublicKey(transportDevice.path, walletId); + + const forcedPath = transportDevice.path; + const extendedPublicKey = await this._requestExtendedPublicKey( + forcedPath, + walletId + ); + const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + { extendedPublicKey } + ); + + if (recognizedSoftwareWallet) { + await this._handleIdentifiedSoftwareWallet({ + recognizedSoftwareWallet, + walletId, + extendedPublicKey, + forcedPath, + }); + } else { + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + logger.debug( + '[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ', + { + deviceId, + } + ); + + // Software Wallet not recognized and TX initiated. Show error + this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); + } } } else { logger.debug( From 396022a7fd168e9fd67c81d80f47d7340b4e63bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Tue, 8 Mar 2022 14:44:42 +0100 Subject: [PATCH 02/15] [DDW-970] Remove redundant console.logs --- .../app/components/hardware-wallet/HardwareWalletStatus.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx index c08ae250b3..067c5c700d 100644 --- a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx +++ b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx @@ -239,14 +239,12 @@ class HardwareWalletStatus extends Component { setTimeout(() => { // Status remains unchanged in 1.5s - set as new status if (nextProps.hwDeviceStatus === this.props.hwDeviceStatus) { - console.log('HW status', nextProps.hwDeviceStatus); this.setState({ hwDeviceStatus: nextProps.hwDeviceStatus, }); } }, 4000); } else { - console.log('HW status', nextProps.hwDeviceStatus); this.setState({ hwDeviceStatus: nextProps.hwDeviceStatus, }); From 11bf1c3bd10c9a8aa56190be08f9750bc2d82251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Tue, 8 Mar 2022 14:47:10 +0100 Subject: [PATCH 03/15] [DDW-970] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a58e5c3381..92a9e31bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Fixes +- Fixed incorrect behaviour of creating new wallet when paired incorrect hardware wallet during address verification ([PR 2906](https://github.com/input-output-hk/daedalus/pull/2906)) - Fixed discrete tooltip being clipped by loading overlay when stake pools are adjusted ([PR 2902](https://github.com/input-output-hk/daedalus/pull/2902)) ## 4.9.0 From ea732c3a4d753156f2a1f9fbd6dbec898b087dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 11 Mar 2022 11:14:12 +0100 Subject: [PATCH 04/15] [DDW-970] Small styling and code quality fixes --- .../hardware-wallet/HardwareWalletStatus.tsx | 13 ++++++------- .../wallet/receive/WalletReceiveDialog.scss | 3 ++- source/renderer/app/components/widgets/Dialog.scss | 8 ++++---- source/renderer/app/components/widgets/Dialog.tsx | 10 +++++++--- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx index 067c5c700d..419a07d0cd 100644 --- a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx +++ b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx @@ -258,17 +258,16 @@ class HardwareWalletStatus extends Component { const { hwDeviceStatus } = this.state; const isLoading = hwDeviceLoadingStatuses.includes(hwDeviceStatus); const isReady = hwDeviceReadyStatuses.includes(hwDeviceStatus); - const hasErrored = hwDeviceErrorStatuses.includes(hwDeviceStatus); - const hasPassphraseLabel = hwDevicePassphraseRelatedStatuses.includes( - hwDeviceStatus - ); + const isError = hwDeviceErrorStatuses.includes(hwDeviceStatus); + const passphraseLabelVisible = + isTrezor && hwDevicePassphraseRelatedStatuses.includes(hwDeviceStatus); const hasInstructionsLink = hwDeviceInstructionsLinkRelatedStatuses.includes( hwDeviceStatus ); const componentClasses = classnames(styles.component, { [styles.isReady]: isReady, - [styles.isError]: hasErrored, + [styles.isError]: isError, }); let instructionsLink; @@ -328,7 +327,7 @@ class HardwareWalletStatus extends Component { label )} - {hasPassphraseLabel && isTrezor && ( + {passphraseLabelVisible && (
{intl.formatMessage(messages.enterPassphrase)}
@@ -340,7 +339,7 @@ class HardwareWalletStatus extends Component { {isReady && ( )} - {hasErrored && ( + {isError && ( )} diff --git a/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss b/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss index 31bee3111f..f24dc43524 100644 --- a/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss +++ b/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss @@ -134,7 +134,7 @@ .verificationInstructions { font-family: var(--font-light); line-height: 1.38; - margin: 20px 0 12px; + margin-top: 20px; b { font-family: var(--font-medium); @@ -144,6 +144,7 @@ :global { .RadioSet_component { margin-bottom: 0; + margin-top: 12px; .RadioSet_label { margin: 0 0 20px 0; diff --git a/source/renderer/app/components/widgets/Dialog.scss b/source/renderer/app/components/widgets/Dialog.scss index 265b8191e9..fccc8e5c7f 100644 --- a/source/renderer/app/components/widgets/Dialog.scss +++ b/source/renderer/app/components/widgets/Dialog.scss @@ -42,16 +42,16 @@ margin-bottom: 12px; margin-top: 12px; } + } - .content { - margin-bottom: 20px; - } + & > .footer { + margin-top: 20px; } & > .actions { display: flex; flex-shrink: 0; - margin-top: 10px; + margin-top: 30px; &.columnDirection { align-items: center; diff --git a/source/renderer/app/components/widgets/Dialog.tsx b/source/renderer/app/components/widgets/Dialog.tsx index 83975aa567..751f0f10ad 100644 --- a/source/renderer/app/components/widgets/Dialog.tsx +++ b/source/renderer/app/components/widgets/Dialog.tsx @@ -69,16 +69,20 @@ export default class Dialog extends Component { fullSize, scrollWrapperRef, } = this.props; + const { items, direction } = Array.isArray(actions) ? { ...defaultActionOptions, items: actions } : { ...defaultActionOptions, ...actions }; + let themeOverrides; if (defaultThemeOverrides) themeOverrides = dialogOverrides; else if (fullSize) themeOverrides = dialogFullSizeOverride; + const classActionsClasses = classnames([ styles.actions, styles[`${direction}Direction`], ]); + return ( { if (scrollWrapperRef) scrollWrapperRef.current = ref; }} > -
{children}
+ {children} )} - {footer &&
{footer}
} + {footer &&
{actions}
} - {items && ( + {!!items?.length && (
{map(items, (action, key) => { const buttonClasses = classnames([ From de43ddf516bbb89fd6dbde737c569769566c4c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 11 Mar 2022 11:16:09 +0100 Subject: [PATCH 05/15] [DDW-970] Change few names in the HardwareWalletStore after the code review --- .../app/stores/HardwareWalletsStore.ts | 172 +++++++++--------- 1 file changed, 88 insertions(+), 84 deletions(-) diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index 192dfba332..6d738c8248 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -151,7 +151,7 @@ const useCardanoAppInterval = ( addressVerification ); -interface RecognizeSoftwareWalletByExtendedPublicKeyArgs { +interface FindAssociatedWalletByExtendedPublicKeyArgs { extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; } @@ -182,17 +182,23 @@ interface ProceedWithAddressVerificationAfterConnectingDeviceArgs { walletId: string; } -interface HandleIdentifiedSoftwareWalletArgs { +interface HandleAssociatedWalletArgs { address?: WalletAddress | null; + associatedWallet: Wallet; + expectedWalletId?: string; extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; - forcedPath?: string; - recognizedSoftwareWallet: Wallet; - walletId?: string; + path?: string; } -interface CreateNewSoftwareWalletForRecognizedPendingDeviceArgs { +interface CreateNewWalletForRecognizedPendingDeviceArgs { extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; - forcedPath?: string; + path?: string; +} + +interface IdentifyAndHandleAssociatedWalletArgs { + address?: WalletAddress; + path?: string; + expectedWalletId?: string; } const { network, isDev } = global.environment; @@ -726,10 +732,10 @@ export default class HardwareWalletsStore extends Store { if (this.isExportKeyAborted) { if (isTrezor) { - await this._identifyAndHandleSoftwareWallet({ + await this._identifyAndHandleAssociatedWallet({ address: this.unfinishedWalletAddressVerification, + expectedWalletId: activeWalletId, path: recognizedPairedHardwareWallet.path, - walletId: activeWalletId, }); } else { this.cardanoAdaAppPollingInterval = useCardanoAppInterval( @@ -778,10 +784,10 @@ export default class HardwareWalletsStore extends Store { // Force export again and proceed (continue) with last action if (this.isExportKeyAborted) { if (isTrezor) { - await this._identifyAndHandleSoftwareWallet({ + await this._identifyAndHandleAssociatedWallet({ address: this.unfinishedWalletAddressVerification, + expectedWalletId: activeWalletId, path: lastDeviceTransport.path, - walletId: activeWalletId, }); } else { this.cardanoAdaAppPollingInterval = useCardanoAppInterval( @@ -902,7 +908,7 @@ export default class HardwareWalletsStore extends Store { }); if (deviceType === DeviceTypes.TREZOR) { - await this._identifyAndHandleSoftwareWallet({ + await this._identifyAndHandleAssociatedWallet({ path: transportDevice.path, }); } else { @@ -1006,10 +1012,10 @@ export default class HardwareWalletsStore extends Store { ); } - await this._identifyAndHandleSoftwareWallet({ + await this._identifyAndHandleAssociatedWallet({ address, + expectedWalletId: walletId, path, - walletId, }); } } catch (error) { @@ -1249,17 +1255,17 @@ export default class HardwareWalletsStore extends Store { walletId, address ); - const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( { extendedPublicKey } ); - if (recognizedSoftwareWallet) { - await this._handleIdentifiedSoftwareWallet({ - recognizedSoftwareWallet, - extendedPublicKey, - forcedPath: devicePath, - walletId, + if (associatedWallet) { + await this._handleAssociatedWallet({ address, + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: devicePath, }); } else { logger.debug( @@ -1575,16 +1581,16 @@ export default class HardwareWalletsStore extends Store { }; @action - _recognizeSoftwareWalletByExtendedPublicKey = async ({ + _findAssociatedWalletByExtendedPublicKey = async ({ extendedPublicKey, - }: RecognizeSoftwareWalletByExtendedPublicKeyArgs): Promise => { + }: FindAssociatedWalletByExtendedPublicKeyArgs): Promise => { const deviceId = extendedPublicKey?.deviceId || this.transportDevice.deviceId; logger.debug('[HW-DEBUG] HWStore - EXPORT - deviceID: ', { deviceId, }); - const recognizedStoredWallet = find( + const recognizedHardwareWalletConnectionData = find( this.hardwareWalletsConnectionData, (hardwareWalletData) => extendedPublicKey.chainCodeHex === @@ -1593,8 +1599,10 @@ export default class HardwareWalletsStore extends Store { hardwareWalletData.extendedPublicKey.publicKeyHex ); - return recognizedStoredWallet - ? this.stores.wallets.getWalletById(recognizedStoredWallet.id) + return recognizedHardwareWalletConnectionData + ? this.stores.wallets.getWalletById( + recognizedHardwareWalletConnectionData.id + ) : null; }; @@ -1724,28 +1732,27 @@ export default class HardwareWalletsStore extends Store { }; @action - _handleIdentifiedSoftwareWallet = async ({ + _handleAssociatedWallet = async ({ address, + associatedWallet, + expectedWalletId, extendedPublicKey, - forcedPath, - recognizedSoftwareWallet, - walletId, - }: HandleIdentifiedSoftwareWalletArgs) => { - const { deviceType, path, deviceName, deviceModel } = this.transportDevice; + path, + }: HandleAssociatedWalletArgs) => { + const { deviceType, deviceName, deviceModel } = this.transportDevice; const isTrezor = deviceType === DeviceTypes.TREZOR; - const devicePath = forcedPath || path; + const devicePath = path || this.transportDevice.path; const deviceId = extendedPublicKey.deviceId || this.transportDevice.deviceId; // Check if public key matches already restored hardware wallet public key // Update LC data and redirect to paired wallet - logger.debug('[HW-DEBUG] HWStore - I have recognized wallet: ', { - recognizedWallet: recognizedSoftwareWallet.id, + recognizedWallet: associatedWallet.id, }); this._setHardwareWalletLocalData({ - walletId: recognizedSoftwareWallet.id, + walletId: associatedWallet.id, data: { disconnected: false, // @ts-ignore ts-migrate(2322) FIXME: Type '{ disconnected: false; data: { deviceType: D... Remove this comment to see the full error message @@ -1754,14 +1761,14 @@ export default class HardwareWalletsStore extends Store { deviceModel, deviceName, path: devicePath, - paired: recognizedSoftwareWallet.id, + paired: associatedWallet.id, // device paired with software wallet disconnected: false, // device physically disconnected }, }, }); - await this._deletePendingDeviceWithGivenPath({ path: forcedPath }); + await this._deletePendingDeviceWithGivenPath({ path }); if (deviceId) { logger.debug('[HW-DEBUG] HWStore - SET device from key export: ', { @@ -1777,7 +1784,7 @@ export default class HardwareWalletsStore extends Store { deviceModel, deviceName, path: devicePath, - paired: recognizedSoftwareWallet.id, + paired: associatedWallet.id, // device paired with software wallet disconnected: false, // device physically disconnected @@ -1789,30 +1796,32 @@ export default class HardwareWalletsStore extends Store { // Prevent redirect / check if device is valid / proceed with tx if (this.isTransactionInitiated) { logger.debug( - '[HW-DEBUG] HWStore - Re-initiate tx from _handleIdentifiedSoftwareWallet: ', + '[HW-DEBUG] HWStore - Re-initiate tx from _handleAssociatedWallet: ', { - walletId, - recognizedWalletId: recognizedSoftwareWallet.id, + expectedWalletId, + recognizedWalletId: associatedWallet.id, deviceId, devicePath, } ); // Check if sender wallet match transaction initialization - if (!walletId || recognizedSoftwareWallet.id !== walletId) { - if (walletId) { + if (!expectedWalletId || associatedWallet.id !== expectedWalletId) { + if (expectedWalletId) { // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug( '[HW-DEBUG] HWStore - Device not belongs to this wallet' ); } - this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); + this._discardConnectedDeviceAndReInitiateTransaction({ + walletId: expectedWalletId, + }); } else { this._proceedWithTransactionAfterConnectingDevice({ isTrezor, deviceId, devicePath, - walletId, + walletId: expectedWalletId, }); } @@ -1822,27 +1831,27 @@ export default class HardwareWalletsStore extends Store { // Prevent redirect / check if device is valid / proceed with address verification if (this.isAddressVerificationInitiated && address) { logger.debug( - '[HW-DEBUG] HWStore - Re-initiate Address verification from _handleIdentifiedSoftwareWallet: ', + '[HW-DEBUG] HWStore - Re-initiate Address verification from _handleAssociatedWallet: ', { address: toJS(address), devicePath, - walletId, - recognizedWalletId: recognizedSoftwareWallet.id, + expectedWalletId, + recognizedWalletId: associatedWallet.id, deviceId, } ); - if (!walletId || recognizedSoftwareWallet.id !== walletId) { + if (!expectedWalletId || associatedWallet.id !== expectedWalletId) { this._discardConnectedDeviceAndReInitiateAddressVerification({ address, - walletId, + walletId: expectedWalletId, }); } else { this._proceedWithAddressVerificationAfterConnectingDevice({ address, devicePath, isTrezor, - walletId, + walletId: expectedWalletId, }); } @@ -1850,17 +1859,17 @@ export default class HardwareWalletsStore extends Store { } // --> Else - this.stores.wallets.goToWalletRoute(recognizedSoftwareWallet.id); + this.stores.wallets.goToWalletRoute(associatedWallet.id); this.actions.dialogs.closeActiveDialog.trigger(); }; @action - _createNewSoftwareWalletForRecognizedPendingDevice = async ({ + _createNewWalletForRecognizedPendingDevice = async ({ extendedPublicKey, - forcedPath, - }: CreateNewSoftwareWalletForRecognizedPendingDeviceArgs) => { - const { deviceType, path, deviceName, deviceModel } = this.transportDevice; - const devicePath = forcedPath || path; + path, + }: CreateNewWalletForRecognizedPendingDeviceArgs) => { + const { deviceType, deviceName, deviceModel } = this.transportDevice; + const devicePath = path || this.transportDevice.path; const deviceId = extendedPublicKey.deviceId || this.transportDevice.deviceId; @@ -1920,31 +1929,27 @@ export default class HardwareWalletsStore extends Store { }; @action - _identifyAndHandleSoftwareWallet = async ({ + _identifyAndHandleAssociatedWallet = async ({ address, path, - walletId, - }: { - address?: WalletAddress; - path?: string; - walletId?: string; - }) => { + expectedWalletId, + }: IdentifyAndHandleAssociatedWalletArgs) => { const extendedPublicKey = await this._requestExtendedPublicKey( path, - walletId, + expectedWalletId, address ); - const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( { extendedPublicKey } ); - if (recognizedSoftwareWallet) { - await this._handleIdentifiedSoftwareWallet({ - recognizedSoftwareWallet, - walletId, - extendedPublicKey, - forcedPath: path, + if (associatedWallet) { + await this._handleAssociatedWallet({ address, + associatedWallet, + expectedWalletId, + extendedPublicKey, + path, }); } else { const deviceId = @@ -1959,12 +1964,12 @@ export default class HardwareWalletsStore extends Store { if (this.isTransactionInitiated) { // Software Wallet not recognized and TX initiated. Show error this._discardConnectedDeviceAndReInitiateTransaction({ - walletId, + walletId: expectedWalletId, }); } else { - await this._createNewSoftwareWalletForRecognizedPendingDevice({ + await this._createNewWalletForRecognizedPendingDevice({ extendedPublicKey, - forcedPath: path, + path, }); } } @@ -2604,21 +2609,20 @@ export default class HardwareWalletsStore extends Store { } ); - const forcedPath = transportDevice.path; const extendedPublicKey = await this._requestExtendedPublicKey( - forcedPath, + transportDevice.path, walletId ); - const recognizedSoftwareWallet = await this._recognizeSoftwareWalletByExtendedPublicKey( + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( { extendedPublicKey } ); - if (recognizedSoftwareWallet) { - await this._handleIdentifiedSoftwareWallet({ - recognizedSoftwareWallet, - walletId, + if (associatedWallet) { + await this._handleAssociatedWallet({ + associatedWallet, + expectedWalletId: walletId, extendedPublicKey, - forcedPath, + path: transportDevice.path, }); } else { const deviceId = From ca54de36e2cd07caf97e47480a98804a407e649b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 11 Mar 2022 13:29:03 +0100 Subject: [PATCH 06/15] [DDW-970] Minor code quality improvements after self review --- .../app/stores/HardwareWalletsStore.ts | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index 31cf022f12..25bf2e1a5e 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -151,6 +151,10 @@ const useCardanoAppInterval = ( addressVerification ); +interface ResetInitiatedConnectionArgs { + isAborted: boolean; +} + interface FindAssociatedWalletByExtendedPublicKeyArgs { extendedPublicKey: HardwareWalletExtendedPublicKeyResponse; } @@ -1486,7 +1490,7 @@ export default class HardwareWalletsStore extends Store { }; @action - _resetInitiatedConnection = ({ isAborted }) => { + _resetInitiatedConnection = ({ isAborted }: ResetInitiatedConnectionArgs) => { runInAction('HardwareWalletsStore:: Re-run initiated connection', () => { this.hwDeviceStatus = isAborted ? HwDeviceStatuses.CONNECTING @@ -1590,7 +1594,7 @@ export default class HardwareWalletsStore extends Store { deviceId, }); - const recognizedHardwareWalletConnectionData = find( + const hardwareWalletConnectionData = find( this.hardwareWalletsConnectionData, (hardwareWalletData) => extendedPublicKey.chainCodeHex === @@ -1599,10 +1603,8 @@ export default class HardwareWalletsStore extends Store { hardwareWalletData.extendedPublicKey.publicKeyHex ); - return recognizedHardwareWalletConnectionData - ? this.stores.wallets.getWalletById( - recognizedHardwareWalletConnectionData.id - ) + return hardwareWalletConnectionData + ? this.stores.wallets.getWalletById(hardwareWalletConnectionData.id) : null; }; @@ -1611,22 +1613,22 @@ export default class HardwareWalletsStore extends Store { _deletePendingDeviceWithGivenPath = async ({ path, }: DeletePendingDeviceWithGivenPathArgs) => { - const recognizedDevice = find( + const device = find( this.hardwareWalletDevices, // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type 'HardwareWa... Remove this comment to see the full error message (device) => device.path === path ); - if (!recognizedDevice) return; + if (!device) return; logger.debug( '[HW-DEBUG] HWStore - __deletePendingDeviceWithGivenPath - UNSET Device with path: ', { - recognizedDevice: recognizedDevice.id, + deviceId: device.id, } ); await this._unsetHardwareWalletDevice({ - deviceId: recognizedDevice.id, + deviceId: device.id, }); }; @@ -1726,8 +1728,8 @@ export default class HardwareWalletsStore extends Store { this.verifyAddress({ address, - path: devicePath, isTrezor, + path: devicePath, }); }; @@ -1807,12 +1809,8 @@ export default class HardwareWalletsStore extends Store { // Check if sender wallet match transaction initialization if (!expectedWalletId || associatedWallet.id !== expectedWalletId) { - if (expectedWalletId) { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. - logger.debug( - '[HW-DEBUG] HWStore - Device not belongs to this wallet' - ); - } + // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); this._discardConnectedDeviceAndReInitiateTransaction({ walletId: expectedWalletId, }); @@ -1842,6 +1840,7 @@ export default class HardwareWalletsStore extends Store { ); if (!expectedWalletId || associatedWallet.id !== expectedWalletId) { + logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); this._discardConnectedDeviceAndReInitiateAddressVerification({ address, walletId: expectedWalletId, From f2ca3786829a800db8746046e9c2411e050abfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 11 Mar 2022 13:32:41 +0100 Subject: [PATCH 07/15] [DDW-970] Remove unnecessary ts ignore comments --- .../app/stores/HardwareWalletsStore.ts | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index 25bf2e1a5e..426f25c0cd 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -1661,12 +1661,9 @@ export default class HardwareWalletsStore extends Store { deviceId, devicePath, }: ProceedWithTransactionAfterConnectingDeviceArgs) => { - logger.debug( - '[HW-DEBUG] HWStore - Transaction Initiated - Close: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] HWStore - Transaction Initiated - Close: ', { + walletId, + }); logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); runInAction('HardwareWalletsStore:: Initiate transaction', () => { this.isTransactionInitiated = false; @@ -1686,14 +1683,11 @@ export default class HardwareWalletsStore extends Store { address, walletId, }: DiscardConnectedDeviceAndReInitiateAddressVerificationArgs) => { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); // Show message to reconnect proper software wallet device pair - logger.debug( - '[HW-DEBUG] unfinishedWalletAddressVerification SET: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); + logger.debug('[HW-DEBUG] unfinishedWalletAddressVerification SET: ', { + walletId, + }); runInAction( 'HardwareWalletsStore:: set HW device CONNECTING FAILED', () => { @@ -1713,12 +1707,9 @@ export default class HardwareWalletsStore extends Store { isTrezor, walletId, }: ProceedWithAddressVerificationAfterConnectingDeviceArgs) => { - logger.debug( - '[HW-DEBUG] HWStore - Address Verification - Close: ', - // @ts-ignore ts-migrate(2345) FIXME: Argument of type 'string' is not assignable to par... Remove this comment to see the full error message - walletId - ); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. + logger.debug('[HW-DEBUG] HWStore - Address Verification - Close: ', { + walletId, + }); logger.debug('[HW-DEBUG] unfinishedWalletTxSigning UNSET'); runInAction('HardwareWalletsStore:: Initiate transaction', () => { this.isAddressVerificationInitiated = false; @@ -1809,7 +1800,6 @@ export default class HardwareWalletsStore extends Store { // Check if sender wallet match transaction initialization if (!expectedWalletId || associatedWallet.id !== expectedWalletId) { - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] HWStore - Device not belongs to this wallet'); this._discardConnectedDeviceAndReInitiateTransaction({ walletId: expectedWalletId, @@ -1896,7 +1886,6 @@ export default class HardwareWalletsStore extends Store { firmwareVersion: null, }, }); - // @ts-ignore ts-migrate(2554) FIXME: Expected 2 arguments, but got 1. logger.debug('[HW-DEBUG] HWStore - HW created / restored'); // Get all Pending devices with this path and delete const recognizedPendingDevice = find( From ddb7411bff7b2df6344fbadf43984fc92a182814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 11 Mar 2022 15:50:53 +0100 Subject: [PATCH 08/15] [DDW-970] Revert dialog related css changes --- .../components/wallet/receive/WalletReceiveDialog.scss | 3 +-- source/renderer/app/components/widgets/Dialog.scss | 8 ++++---- source/renderer/app/components/widgets/Dialog.tsx | 10 +++------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss b/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss index f24dc43524..31bee3111f 100644 --- a/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss +++ b/source/renderer/app/components/wallet/receive/WalletReceiveDialog.scss @@ -134,7 +134,7 @@ .verificationInstructions { font-family: var(--font-light); line-height: 1.38; - margin-top: 20px; + margin: 20px 0 12px; b { font-family: var(--font-medium); @@ -144,7 +144,6 @@ :global { .RadioSet_component { margin-bottom: 0; - margin-top: 12px; .RadioSet_label { margin: 0 0 20px 0; diff --git a/source/renderer/app/components/widgets/Dialog.scss b/source/renderer/app/components/widgets/Dialog.scss index fccc8e5c7f..265b8191e9 100644 --- a/source/renderer/app/components/widgets/Dialog.scss +++ b/source/renderer/app/components/widgets/Dialog.scss @@ -42,16 +42,16 @@ margin-bottom: 12px; margin-top: 12px; } - } - & > .footer { - margin-top: 20px; + .content { + margin-bottom: 20px; + } } & > .actions { display: flex; flex-shrink: 0; - margin-top: 30px; + margin-top: 10px; &.columnDirection { align-items: center; diff --git a/source/renderer/app/components/widgets/Dialog.tsx b/source/renderer/app/components/widgets/Dialog.tsx index 751f0f10ad..83975aa567 100644 --- a/source/renderer/app/components/widgets/Dialog.tsx +++ b/source/renderer/app/components/widgets/Dialog.tsx @@ -69,20 +69,16 @@ export default class Dialog extends Component { fullSize, scrollWrapperRef, } = this.props; - const { items, direction } = Array.isArray(actions) ? { ...defaultActionOptions, items: actions } : { ...defaultActionOptions, ...actions }; - let themeOverrides; if (defaultThemeOverrides) themeOverrides = dialogOverrides; else if (fullSize) themeOverrides = dialogFullSizeOverride; - const classActionsClasses = classnames([ styles.actions, styles[`${direction}Direction`], ]); - return ( { if (scrollWrapperRef) scrollWrapperRef.current = ref; }} > - {children} +
{children}
)} - {footer &&
{actions}
} + {footer &&
{footer}
} - {!!items?.length && ( + {items && (
{map(items, (action, key) => { const buttonClasses = classnames([ From 719f4a608f8ff0510cf11de8d066454066d69897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Wed, 16 Mar 2022 08:42:24 +0100 Subject: [PATCH 09/15] [DDW-970] Rename one of refactored methods in HardwareWalletStore after code review --- .../app/stores/HardwareWalletsStore.ts | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index 426f25c0cd..fd0ca44653 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -1264,13 +1264,15 @@ export default class HardwareWalletsStore extends Store { ); if (associatedWallet) { - await this._handleAssociatedWallet({ - address, - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: devicePath, - }); + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + address, + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: devicePath, + } + ); } else { logger.debug( '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' @@ -1725,7 +1727,7 @@ export default class HardwareWalletsStore extends Store { }; @action - _handleAssociatedWallet = async ({ + _storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting = async ({ address, associatedWallet, expectedWalletId, @@ -1789,7 +1791,7 @@ export default class HardwareWalletsStore extends Store { // Prevent redirect / check if device is valid / proceed with tx if (this.isTransactionInitiated) { logger.debug( - '[HW-DEBUG] HWStore - Re-initiate tx from _handleAssociatedWallet: ', + '[HW-DEBUG] HWStore - Re-initiate tx from _storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting: ', { expectedWalletId, recognizedWalletId: associatedWallet.id, @@ -1819,7 +1821,7 @@ export default class HardwareWalletsStore extends Store { // Prevent redirect / check if device is valid / proceed with address verification if (this.isAddressVerificationInitiated && address) { logger.debug( - '[HW-DEBUG] HWStore - Re-initiate Address verification from _handleAssociatedWallet: ', + '[HW-DEBUG] HWStore - Re-initiate Address verification from _storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting: ', { address: toJS(address), devicePath, @@ -1932,13 +1934,15 @@ export default class HardwareWalletsStore extends Store { ); if (associatedWallet) { - await this._handleAssociatedWallet({ - address, - associatedWallet, - expectedWalletId, - extendedPublicKey, - path, - }); + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + address, + associatedWallet, + expectedWalletId, + extendedPublicKey, + path, + } + ); } else { const deviceId = extendedPublicKey.deviceId || this.transportDevice.deviceId; @@ -2606,12 +2610,14 @@ export default class HardwareWalletsStore extends Store { ); if (associatedWallet) { - await this._handleAssociatedWallet({ - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: transportDevice.path, - }); + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: transportDevice.path, + } + ); } else { const deviceId = extendedPublicKey.deviceId || this.transportDevice.deviceId; From 0b4a9b0e7d72679ca8364d4cdbb82f1287a8c7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 22 Apr 2022 10:58:41 +0200 Subject: [PATCH 10/15] [DDW-970] Use a UNRECOGNIZED_WALLET status and new translations in place of previous INCORRECT_PASSPHRASE_PROVIDED status --- .../hardware-wallet/HardwareWalletStatus.scss | 1 + .../hardware-wallet/HardwareWalletStatus.tsx | 17 +++++++++-------- source/renderer/app/domains/Wallet.ts | 9 +++++---- source/renderer/app/i18n/locales/en-US.json | 4 ++-- source/renderer/app/i18n/locales/ja-JP.json | 4 ++-- .../renderer/app/stores/HardwareWalletsStore.ts | 6 +++--- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.scss b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.scss index aee5cf2426..9f1985e03a 100644 --- a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.scss +++ b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.scss @@ -47,6 +47,7 @@ } .clearIcon { + flex-shrink: 0; height: 14px; margin-right: 6px; object-fit: contain; diff --git a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx index e5b1a2de5d..385d375f40 100644 --- a/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx +++ b/source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx @@ -46,12 +46,11 @@ const messages = defineMessages({ defaultMessage: '!!!Exporting the public key failed', description: '"Exporting public key failed" device state', }, - incorrect_passphrase_provided: { - id: 'wallet.hardware.deviceStatus.incorrect_passphrase_provided', + unrecognized_wallet: { + id: 'wallet.hardware.deviceStatus.unrecognized_wallet', defaultMessage: - '!!!The passphrase you have entered does not match the current wallet', - description: - '"Message displayed when user connects different wallet than the current one', + '!!!We do not recognize this wallet on your device. Please ensure that you are using the same device that you selected for pairing {walletName} and that you have entered the correct passphrase.', + description: '"Unrecognized wallet" device state', }, exportingPublicKeyError: { id: 'wallet.hardware.deviceStatus.exportingPublicKeyError', @@ -185,7 +184,6 @@ const hwDeviceReadyStatuses = [ const hwDeviceErrorStatuses = [ HwDeviceStatuses.EXPORTING_PUBLIC_KEY_FAILED, - HwDeviceStatuses.INCORRECT_PASSPHRASE_PROVIDED, HwDeviceStatuses.CONNECTING_FAILED, HwDeviceStatuses.TREZOR_BRIDGE_FAILURE, HwDeviceStatuses.WRONG_FIRMWARE, @@ -194,6 +192,7 @@ const hwDeviceErrorStatuses = [ HwDeviceStatuses.VERIFYING_TRANSACTION_FAILED, HwDeviceStatuses.VERIFYING_ADDRESS_FAILED, HwDeviceStatuses.VERIFYING_ADDRESS_ABORTED, + HwDeviceStatuses.UNRECOGNIZED_WALLET, ]; const hwDevicePassphraseRelatedStatuses = [ @@ -259,8 +258,9 @@ class HardwareWalletStatus extends Component { const isLoading = hwDeviceLoadingStatuses.includes(hwDeviceStatus); const isReady = hwDeviceReadyStatuses.includes(hwDeviceStatus); const isError = hwDeviceErrorStatuses.includes(hwDeviceStatus); - const hasInstructionsLink = - hwDeviceInstructionsLinkRelatedStatuses.includes(hwDeviceStatus); + const hasInstructionsLink = hwDeviceInstructionsLinkRelatedStatuses.includes( + hwDeviceStatus + ); const passphraseLabelVisible = isTrezor && hwDevicePassphraseRelatedStatuses.includes(hwDeviceStatus); @@ -301,6 +301,7 @@ class HardwareWalletStatus extends Component { (hwDeviceStatus === HwDeviceStatuses.CONNECTING || hwDeviceStatus === HwDeviceStatuses.VERIFYING_TRANSACTION || hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS || + hwDeviceStatus === HwDeviceStatuses.UNRECOGNIZED_WALLET || hwDeviceStatus === HwDeviceStatuses.VERIFYING_ADDRESS_CONFIRMATION) ) { const message = diff --git a/source/renderer/app/domains/Wallet.ts b/source/renderer/app/domains/Wallet.ts index 4b089f1673..4906a9c560 100644 --- a/source/renderer/app/domains/Wallet.ts +++ b/source/renderer/app/domains/Wallet.ts @@ -44,7 +44,6 @@ export type HwDeviceStatus = | 'launching_cardano_app' | 'exporting_public_key' | 'exporting_public_key_failed' - | 'incorrect_passphrase_provided' | 'ready' | 'verifying_transaction' | 'verifying_transaction_failed' @@ -56,14 +55,15 @@ export type HwDeviceStatus = | 'verifying_address_confirmation' | 'verifying_address_failed' | 'verifying_address_aborted' - | 'verifying_address_succeeded'; + | 'verifying_address_succeeded' + | 'unrecognized_wallet'; + export const HwDeviceStatuses: { CONNECTING: HwDeviceStatus; CONNECTING_FAILED: HwDeviceStatus; LAUNCHING_CARDANO_APP: HwDeviceStatus; EXPORTING_PUBLIC_KEY: HwDeviceStatus; EXPORTING_PUBLIC_KEY_FAILED: HwDeviceStatus; - INCORRECT_PASSPHRASE_PROVIDED: HwDeviceStatus; READY: HwDeviceStatus; VERIFYING_TRANSACTION: HwDeviceStatus; VERIFYING_TRANSACTION_FAILED: HwDeviceStatus; @@ -77,6 +77,7 @@ export const HwDeviceStatuses: { VERIFYING_ADDRESS_FAILED: HwDeviceStatus; VERIFYING_ADDRESS_ABORTED: HwDeviceStatus; VERIFYING_ADDRESS_SUCCEEDED: HwDeviceStatus; + UNRECOGNIZED_WALLET: HwDeviceStatus; } = { CONNECTING: 'connecting', CONNECTING_FAILED: 'connecting_failed', @@ -84,7 +85,6 @@ export const HwDeviceStatuses: { LAUNCHING_CARDANO_APP: 'launching_cardano_app', EXPORTING_PUBLIC_KEY: 'exporting_public_key', EXPORTING_PUBLIC_KEY_FAILED: 'exporting_public_key_failed', - INCORRECT_PASSPHRASE_PROVIDED: 'incorrect_passphrase_provided', WRONG_FIRMWARE: 'wrong_firmware', WRONG_CARDANO_APP_VERSION: 'wrong_cardano_app_version', UNSUPPORTED_DEVICE: 'unsupported_device', @@ -97,6 +97,7 @@ export const HwDeviceStatuses: { VERIFYING_ADDRESS_FAILED: 'verifying_address_failed', VERIFYING_ADDRESS_ABORTED: 'verifying_address_aborted', VERIFYING_ADDRESS_SUCCEEDED: 'verifying_address_succeeded', + UNRECOGNIZED_WALLET: 'unrecognized_wallet', }; export const WalletUnits: { ADA: WalletUnit; diff --git a/source/renderer/app/i18n/locales/en-US.json b/source/renderer/app/i18n/locales/en-US.json index 572c65cba8..e931151b8b 100755 --- a/source/renderer/app/i18n/locales/en-US.json +++ b/source/renderer/app/i18n/locales/en-US.json @@ -832,12 +832,12 @@ "wallet.hardware.deviceStatus.exportingPublicKeyError": "Disconnect and reconnect your hardware wallet to restart the process.", "wallet.hardware.deviceStatus.exporting_public_key": "Export the public key on your device", "wallet.hardware.deviceStatus.exporting_public_key_failed": "Exporting the public key failed", - "wallet.hardware.deviceStatus.incorrect_passphrase_provided": "The passphrase you have entered does not match the current wallet", "wallet.hardware.deviceStatus.launching_cardano_app": "Launch Cardano application on your device", "wallet.hardware.deviceStatus.ready": "Device ready", "wallet.hardware.deviceStatus.trezor_bridge_failure": "Trezor Bridge is not installed! {instructionsLink}", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.label": "Installation instructions", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.url": "https://wallet.trezor.io/#/bridge", + "wallet.hardware.deviceStatus.unrecognized_wallet": "We do not recognize this wallet on your device. Please ensure that you are using the same device that you selected for pairing \"{walletName}\" and that you have entered the correct passphrase.", "wallet.hardware.deviceStatus.unsupported_device": "The device is not supported!", "wallet.hardware.deviceStatus.verifying_address": "Verify address on your \"{walletName}\" device", "wallet.hardware.deviceStatus.verifying_address_aborted": "Verification was aborted by the user", @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "Total", "widgets.itemsDropdown.syncingLabel": "Syncing", "widgets.itemsDropdown.syncingLabelProgress": "Syncing {syncingProgress}%" -} \ No newline at end of file +} diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index 657df3f6a3..f8197b2895 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -832,12 +832,12 @@ "wallet.hardware.deviceStatus.exportingPublicKeyError": "ハードウェアウォレットを切断して再接続し、もう一度プロセスを始めてください。", "wallet.hardware.deviceStatus.exporting_public_key": "デバイス上で公開鍵をエクスポートしてください", "wallet.hardware.deviceStatus.exporting_public_key_failed": "公開鍵のエクスポートができません", - "wallet.hardware.deviceStatus.incorrect_passphrase_provided": "!!!The passphrase you have entered does not match the current wallet", "wallet.hardware.deviceStatus.launching_cardano_app": "デバイス上でCardanoアプリケーションを起動してください", "wallet.hardware.deviceStatus.ready": "デバイスの準備ができました", "wallet.hardware.deviceStatus.trezor_bridge_failure": "Trezor Bridgeがインストールされていません。{instructionsLink}", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.label": "インストールガイド", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.url": "https://wallet.trezor.io/#/bridge", + "wallet.hardware.deviceStatus.unrecognized_wallet": "ご使用のデバイスでこのウォレットを認識できません。{walletname}のペアリングに選択したデバイスと同じものを使用していること、正しいパスフレーズを入力していることを確認してください。", "wallet.hardware.deviceStatus.unsupported_device": "このデバイスはサポートされていません", "wallet.hardware.deviceStatus.verifying_address": "「{walletName}」デバイスのアドレスを検証してください", "wallet.hardware.deviceStatus.verifying_address_aborted": "検証はユーザーにより中止されました", @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} \ No newline at end of file +} diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index fd0ca44653..2909334421 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -1646,9 +1646,9 @@ export default class HardwareWalletsStore extends Store { walletId ); runInAction( - 'HardwareWalletsStore:: set HW device CONNECTING FAILED', + 'HardwareWalletsStore:: set HW device UNRECOGNIZED_WALLET', () => { - this.hwDeviceStatus = HwDeviceStatuses.CONNECTING_FAILED; + this.hwDeviceStatus = HwDeviceStatuses.UNRECOGNIZED_WALLET; this.activeDevicePath = null; this.unfinishedWalletTxSigning = walletId; this.isExportKeyAborted = false; @@ -1694,7 +1694,7 @@ export default class HardwareWalletsStore extends Store { 'HardwareWalletsStore:: set HW device CONNECTING FAILED', () => { this.isAddressVerificationInitiated = false; - this.hwDeviceStatus = HwDeviceStatuses.INCORRECT_PASSPHRASE_PROVIDED; + this.hwDeviceStatus = HwDeviceStatuses.UNRECOGNIZED_WALLET; this.activeDevicePath = null; this.unfinishedWalletAddressVerification = address; this.isExportKeyAborted = false; From 2961975150e453222bef6e261a503cb685cd84d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Mon, 25 Apr 2022 13:58:40 +0200 Subject: [PATCH 11/15] [DDW-970] Fix prettier issues --- CHANGELOG.md | 2 +- source/main/config.ts | 5 +- source/renderer/app/api/api.ts | 51 ++++++---- .../renderer/app/components/assets/Asset.tsx | 9 +- .../staking/stake-pools/StakePoolsSearch.tsx | 5 +- .../WalletSendAssetsConfirmationDialog.tsx | 17 +++- .../WalletSelectImportDialog.tsx | 4 +- .../wallet-restore/WalletTypeDialog.tsx | 18 ++-- .../staking/RedeemItnRewardsContainer.tsx | 7 +- .../app/i18n/locales/defaultMessages.json | 94 +++++++++---------- source/renderer/app/i18n/locales/en-US.json | 2 +- source/renderer/app/i18n/locales/ja-JP.json | 2 +- storybook/stories/_support/utils.ts | 14 ++- 13 files changed, 132 insertions(+), 98 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1656cbc8d7..a31a7d1927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,8 @@ ### Fixes -- Fixed stake pool list styling ([PR 2920](https://github.com/input-output-hk/daedalus/pull/2920)) - Fixed incorrect behaviour of creating new wallet when paired incorrect hardware wallet during address verification ([PR 2906](https://github.com/input-output-hk/daedalus/pull/2906)) +- Fixed stake pool list styling ([PR 2920](https://github.com/input-output-hk/daedalus/pull/2920)) - Fixed PopOver overlap ([PR 2954](https://github.com/input-output-hk/daedalus/pull/2954)) - Fixed tooltip being hidden in several places ([PR-2934](https://github.com/input-output-hk/daedalus/pull/2934)) - Adjusted padding for search field in stake pools ([PR 2945](https://github.com/input-output-hk/daedalus/pull/2945)) diff --git a/source/main/config.ts b/source/main/config.ts index 9dd57d40b9..c5ea5c0972 100644 --- a/source/main/config.ts +++ b/source/main/config.ts @@ -109,8 +109,9 @@ export const windowOptions: WindowOptionsType = { }, useContentSize: true, }; -export const launcherConfig: LauncherConfig = - readLauncherConfig(LAUNCHER_CONFIG); +export const launcherConfig: LauncherConfig = readLauncherConfig( + LAUNCHER_CONFIG +); export const { cluster, nodeImplementation, diff --git a/source/renderer/app/api/api.ts b/source/renderer/app/api/api.ts index d6773d0aed..f1c7dbd24a 100644 --- a/source/renderer/app/api/api.ts +++ b/source/renderer/app/api/api.ts @@ -663,8 +663,7 @@ export default class AdaApi { logger.debug('AdaApi::getAssets success', { assets: response, }); - const assetsLocaldata = - await global.daedalus.api.localStorage.getAssetsLocalData(); + const assetsLocaldata = await global.daedalus.api.localStorage.getAssetsLocalData(); logger.debug('AdaApi::getAssetsLocalData success', { assetsLocaldata, }); @@ -905,11 +904,13 @@ export default class AdaApi { }) .where('code', 'transaction_is_too_big'); - const { requiresAdaToRemainToSupportNativeTokens, adaToRemain } = - doesWalletRequireAdaToRemainToSupportTokens( - error, - hasAssetsRemainingAfterTransaction - ); + const { + requiresAdaToRemainToSupportNativeTokens, + adaToRemain, + } = doesWalletRequireAdaToRemainToSupportTokens( + error, + hasAssetsRemainingAfterTransaction + ); if (requiresAdaToRemainToSupportNativeTokens) { apiError.set('cannotLeaveWalletEmpty', true, { adaToRemain }); } @@ -1631,8 +1632,9 @@ export default class AdaApi { getCurrencyList = async (): Promise => { try { const apiResponse = await getCurrencyList(); - const response: GetCurrencyListResponse = - currencyConfig.responses.list(apiResponse); + const response: GetCurrencyListResponse = currencyConfig.responses.list( + apiResponse + ); logger.debug('AdaApi::getCurrencyList success', { response, }); @@ -1649,8 +1651,9 @@ export default class AdaApi { ): Promise => { try { const apiResponse = await getCurrencyRate(currency); - const response: GetCurrencyRateResponse = - currencyConfig.responses.rate(apiResponse); + const response: GetCurrencyRateResponse = currencyConfig.responses.rate( + apiResponse + ); logger.debug('AdaApi::getCurrencyRate success', { response, }); @@ -2156,8 +2159,9 @@ export default class AdaApi { logger.debug('AdaApi::getSmashSettings called'); try { - const { pool_metadata_source: poolMetadataSource } = - await getSmashSettings(this.config); + const { + pool_metadata_source: poolMetadataSource, + } = await getSmashSettings(this.config); logger.debug('AdaApi::getSmashSettings success', { poolMetadataSource, }); @@ -2181,8 +2185,12 @@ export default class AdaApi { return true; } - const { health }: CheckSmashServerHealthApiResponse = - await checkSmashServerHealth(this.config, url); + const { + health, + }: CheckSmashServerHealthApiResponse = await checkSmashServerHealth( + this.config, + url + ); const isValid = health === SMASH_SERVER_STATUSES.AVAILABLE; logger.debug('AdaApi::checkSmashServerIsValid success', { isValid, @@ -2395,10 +2403,12 @@ export default class AdaApi { }); try { - const response: TransferFundsCalculateFeeApiResponse = - await transferFundsCalculateFee(this.config, { + const response: TransferFundsCalculateFeeApiResponse = await transferFundsCalculateFee( + this.config, + { sourceWalletId, - }); + } + ); logger.debug('AdaApi::transferFundsCalculateFee success', { response, }); @@ -2600,8 +2610,9 @@ export default class AdaApi { logger.debug('AdaApi::getNetworkParameters called'); try { - const networkParameters: GetNetworkParametersApiResponse = - await getNetworkParameters(this.config); + const networkParameters: GetNetworkParametersApiResponse = await getNetworkParameters( + this.config + ); logger.debug('AdaApi::getNetworkParameters success', { networkParameters, }); diff --git a/source/renderer/app/components/assets/Asset.tsx b/source/renderer/app/components/assets/Asset.tsx index 7a252b4fe2..4822fc4097 100644 --- a/source/renderer/app/components/assets/Asset.tsx +++ b/source/renderer/app/components/assets/Asset.tsx @@ -173,8 +173,13 @@ class Asset extends Component { hasWarning, hasError, } = this.props; - const { fingerprint, metadata, decimals, recommendedDecimals, assetName } = - asset; + const { + fingerprint, + metadata, + decimals, + recommendedDecimals, + assetName, + } = asset; const hasMetadataName = !!metadata?.name; const name = metadata?.name || (assetName && `ASCII: ${hexToString(assetName)}`) || ''; diff --git a/source/renderer/app/components/staking/stake-pools/StakePoolsSearch.tsx b/source/renderer/app/components/staking/stake-pools/StakePoolsSearch.tsx index 1224920fcb..83d71ce9cc 100644 --- a/source/renderer/app/components/staking/stake-pools/StakePoolsSearch.tsx +++ b/source/renderer/app/components/staking/stake-pools/StakePoolsSearch.tsx @@ -53,8 +53,9 @@ function StakePoolsSearchComponent({ isGridRewardsView, intl, }: Props) { - const searchInput = - useRef<{ inputElement: { current: HTMLInputElement } }>(null); + const searchInput = useRef<{ inputElement: { current: HTMLInputElement } }>( + null + ); const [isSearchInputFocused, setSearchInputFocused] = useState(false); diff --git a/source/renderer/app/components/wallet/send-form/WalletSendAssetsConfirmationDialog.tsx b/source/renderer/app/components/wallet/send-form/WalletSendAssetsConfirmationDialog.tsx index 8f1529b966..b8d3d3205c 100644 --- a/source/renderer/app/components/wallet/send-form/WalletSendAssetsConfirmationDialog.tsx +++ b/source/renderer/app/components/wallet/send-form/WalletSendAssetsConfirmationDialog.tsx @@ -138,8 +138,12 @@ class WalletSendAssetsConfirmationDialog extends Component { this.form.submit({ onSuccess: (form) => { const { selectedAssets, assetsAmounts } = this.state; - const { receiver, amount, amountToNaturalUnits, isHardwareWallet } = - this.props; + const { + receiver, + amount, + amountToNaturalUnits, + isHardwareWallet, + } = this.props; const { passphrase } = form.values(); const hasAssetsRemainingAfterTransaction = this.props.selectedAssets.length < @@ -168,8 +172,13 @@ class WalletSendAssetsConfirmationDialog extends Component { ): React.ReactElement, any> | null => { const passphraseField = this.form.$('passphrase'); const { areTermsAccepted } = this.state; - const { hwDeviceStatus, isFlight, onExternalLinkClick, wallet, isTrezor } = - this.props; + const { + hwDeviceStatus, + isFlight, + onExternalLinkClick, + wallet, + isTrezor, + } = this.props; let returnJSX = null; if (!isFlight || (isFlight && areTermsAccepted)) { diff --git a/source/renderer/app/components/wallet/wallet-import/WalletSelectImportDialog.tsx b/source/renderer/app/components/wallet/wallet-import/WalletSelectImportDialog.tsx index 0e80562979..2af9bdfa88 100644 --- a/source/renderer/app/components/wallet/wallet-import/WalletSelectImportDialog.tsx +++ b/source/renderer/app/components/wallet/wallet-import/WalletSelectImportDialog.tsx @@ -186,8 +186,8 @@ class WalletSelectImportDialog extends Component { ); if (checkboxes[index] && topWrapper.length) { - const checkboxTopOffset = - checkboxes[index].getBoundingClientRect().top; + const checkboxTopOffset = checkboxes[index].getBoundingClientRect() + .top; const topWrapperTopOffset = topWrapper[0].getBoundingClientRect().top; const topPart = topWrapperTopOffset + 121; const spaceForTooltip = checkboxTopOffset - topPart; diff --git a/source/renderer/app/components/wallet/wallet-restore/WalletTypeDialog.tsx b/source/renderer/app/components/wallet/wallet-restore/WalletTypeDialog.tsx index f6fae22512..7e3d3eafa5 100644 --- a/source/renderer/app/components/wallet/wallet-restore/WalletTypeDialog.tsx +++ b/source/renderer/app/components/wallet/wallet-restore/WalletTypeDialog.tsx @@ -50,25 +50,29 @@ const messages = defineMessages({ description: 'Label for the "labelDaedalusWalletKind" checkbox.', }, labelDaedalusWalletKind12WordByron: { - id: 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind12WordByron', + id: + 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind12WordByron', defaultMessage: '!!!12 words (Byron legacy wallet)', description: 'Label for the "labelDaedalusWalletKind12WordByron" checkbox.', }, labelDaedalusWalletKind15WordShelley: { - id: 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind15WordShelley', + id: + 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind15WordShelley', defaultMessage: '!!!15 words (Incentivized Testnet Rewards wallet)', description: 'Label for the "labelDaedalusWalletKind15WordShelley" checkbox.', }, labelDaedalusWalletKind24WordShelley: { - id: 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind24WordShelley', + id: + 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind24WordShelley', defaultMessage: '!!!24 words (Shelley wallet)', description: 'Label for the "labelDaedalusWalletKind24WordShelley" checkbox.', }, labelDaedalusWalletKind27WordPaper: { - id: 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind27WordPaper', + id: + 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind27WordPaper', defaultMessage: '!!!27 words - paper wallet (Byron legacy wallet)', description: 'Label for the "labelDaedalusWalletKind27WordPaper" checkbox.', }, @@ -78,12 +82,14 @@ const messages = defineMessages({ description: 'Label for the "labelYoroiWalletKind" checkbox.', }, labelYoroiWalletKind15WordByron: { - id: 'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindByronLegacy15Word', + id: + 'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindByronLegacy15Word', defaultMessage: '!!!15 words (Byron legacy wallet)', description: 'Label for the "labelDaedalusWalletKind15WordByron" checkbox.', }, labelYoroiWalletKind15WordShelley: { - id: 'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindShelley15Word', + id: + 'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindShelley15Word', defaultMessage: '!!!15 words (Shelley wallet)', description: 'Label for the "labelDaedalusWalletKind15WordShelley" checkbox.', diff --git a/source/renderer/app/containers/staking/RedeemItnRewardsContainer.tsx b/source/renderer/app/containers/staking/RedeemItnRewardsContainer.tsx index bd35021362..6c16fd19a6 100644 --- a/source/renderer/app/containers/staking/RedeemItnRewardsContainer.tsx +++ b/source/renderer/app/containers/staking/RedeemItnRewardsContainer.tsx @@ -39,8 +39,11 @@ class RedeemItnRewardsContainer extends Component { render() { const { stores, actions } = this.props; const { allWallets } = stores.wallets; - const { redeemStep, isSubmittingReedem, isCalculatingReedemFees } = - stores.staking; + const { + redeemStep, + isSubmittingReedem, + isCalculatingReedemFees, + } = stores.staking; const { isSynced } = stores.networkStatus; const { onRedeemStart, closeRedeemDialog } = actions.staking; if (!redeemStep) return null; diff --git a/source/renderer/app/i18n/locales/defaultMessages.json b/source/renderer/app/i18n/locales/defaultMessages.json index 3ec74cbc93..a9596a031b 100644 --- a/source/renderer/app/i18n/locales/defaultMessages.json +++ b/source/renderer/app/i18n/locales/defaultMessages.json @@ -1307,16 +1307,16 @@ } }, { - "defaultMessage": "!!!The passphrase you have entered does not match the current wallet", - "description": "\"Message displayed when user connects different wallet than the current one", + "defaultMessage": "!!!We do not recognize this wallet on your device. Please ensure that you are using the same device that you selected for pairing {walletName} and that you have entered the correct passphrase.", + "description": "\"Unrecognized wallet\" device state", "end": { "column": 3, - "line": 55 + "line": 54 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", - "id": "wallet.hardware.deviceStatus.incorrect_passphrase_provided", + "id": "wallet.hardware.deviceStatus.unrecognized_wallet", "start": { - "column": 33, + "column": 23, "line": 49 } }, @@ -1325,13 +1325,13 @@ "description": "\"Disconnect and reconnect your device to start the process again\" device state", "end": { "column": 3, - "line": 62 + "line": 61 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.exportingPublicKeyError", "start": { "column": 27, - "line": 56 + "line": 55 } }, { @@ -1339,13 +1339,13 @@ "description": "\"Enter passphrase if needed\" device sub-state", "end": { "column": 3, - "line": 67 + "line": 66 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.enterPassphrase", "start": { "column": 19, - "line": 63 + "line": 62 } }, { @@ -1353,13 +1353,13 @@ "description": "\"Device ready\" device state", "end": { "column": 3, - "line": 72 + "line": 71 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.ready", "start": { "column": 9, - "line": 68 + "line": 67 } }, { @@ -1367,13 +1367,13 @@ "description": "\"Confirm the transaction using the IOHK Trezor 1 device\" device state", "end": { "column": 3, - "line": 79 + "line": 78 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction", "start": { "column": 25, - "line": 73 + "line": 72 } }, { @@ -1381,13 +1381,13 @@ "description": "\"Transaction verification and signing failed\" device state", "end": { "column": 3, - "line": 84 + "line": 83 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction_failed", "start": { "column": 32, - "line": 80 + "line": 79 } }, { @@ -1395,13 +1395,13 @@ "description": "\"Transaction verified and signed\" device state", "end": { "column": 3, - "line": 89 + "line": 88 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_transaction_succeeded", "start": { "column": 35, - "line": 85 + "line": 84 } }, { @@ -1409,13 +1409,13 @@ "description": "\"Trezor Bridge not installed! {instructionsLink}\" device state", "end": { "column": 3, - "line": 95 + "line": 94 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure", "start": { "column": 25, - "line": 90 + "line": 89 } }, { @@ -1423,13 +1423,13 @@ "description": "Trezor Bridge installation instructions link label", "end": { "column": 3, - "line": 100 + "line": 99 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure.link.label", "start": { "column": 36, - "line": 96 + "line": 95 } }, { @@ -1437,13 +1437,13 @@ "description": "URL for the \"Trezor Bridge\" update", "end": { "column": 3, - "line": 106 + "line": 105 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.trezor_bridge_failure.link.url", "start": { "column": 34, - "line": 101 + "line": 100 } }, { @@ -1451,13 +1451,13 @@ "description": "\"Unsupported firmware!\" device state", "end": { "column": 3, - "line": 111 + "line": 110 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware", "start": { "column": 18, - "line": 107 + "line": 106 } }, { @@ -1465,13 +1465,13 @@ "description": "Firmware update installation instructions link label", "end": { "column": 3, - "line": 116 + "line": 115 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware.link.label", "start": { "column": 29, - "line": 112 + "line": 111 } }, { @@ -1479,13 +1479,13 @@ "description": "URL for the \"Firmware Update\"", "end": { "column": 3, - "line": 122 + "line": 121 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_firmware.link.url", "start": { "column": 27, - "line": 117 + "line": 116 } }, { @@ -1493,13 +1493,13 @@ "description": "\"The device is not supported!\" device state", "end": { "column": 3, - "line": 127 + "line": 126 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.unsupported_device", "start": { "column": 22, - "line": 123 + "line": 122 } }, { @@ -1507,13 +1507,13 @@ "description": "\"Unsupported firmware!\" device state", "end": { "column": 3, - "line": 132 + "line": 131 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version", "start": { "column": 29, - "line": 128 + "line": 127 } }, { @@ -1521,13 +1521,13 @@ "description": "Firmware update installation instructions link label", "end": { "column": 3, - "line": 137 + "line": 136 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version.link.label", "start": { "column": 40, - "line": 133 + "line": 132 } }, { @@ -1535,13 +1535,13 @@ "description": "URL for the \"Firmware Update\"", "end": { "column": 3, - "line": 143 + "line": 142 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.wrong_cardano_app_version.link.url", "start": { "column": 38, - "line": 138 + "line": 137 } }, { @@ -1549,13 +1549,13 @@ "description": "\"Verify receiving address on your Hardware Wallet device", "end": { "column": 3, - "line": 148 + "line": 147 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address", "start": { "column": 21, - "line": 144 + "line": 143 } }, { @@ -1563,13 +1563,13 @@ "description": "\"Confirm receiving address on your Hardware Wallet device", "end": { "column": 3, - "line": 153 + "line": 152 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_confirmation", "start": { "column": 34, - "line": 149 + "line": 148 } }, { @@ -1577,13 +1577,13 @@ "description": "\"Address verification failed\" device state", "end": { "column": 3, - "line": 158 + "line": 157 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_failed", "start": { "column": 28, - "line": 154 + "line": 153 } }, { @@ -1591,13 +1591,13 @@ "description": "\"Address verification aborted\" device state", "end": { "column": 3, - "line": 163 + "line": 162 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_aborted", "start": { "column": 29, - "line": 159 + "line": 158 } }, { @@ -1605,13 +1605,13 @@ "description": "\"Address verified\" device state", "end": { "column": 3, - "line": 168 + "line": 167 }, "file": "source/renderer/app/components/hardware-wallet/HardwareWalletStatus.tsx", "id": "wallet.hardware.deviceStatus.verifying_address_succeeded", "start": { "column": 31, - "line": 164 + "line": 163 } } ], diff --git a/source/renderer/app/i18n/locales/en-US.json b/source/renderer/app/i18n/locales/en-US.json index e931151b8b..4bd1a69263 100755 --- a/source/renderer/app/i18n/locales/en-US.json +++ b/source/renderer/app/i18n/locales/en-US.json @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "Total", "widgets.itemsDropdown.syncingLabel": "Syncing", "widgets.itemsDropdown.syncingLabelProgress": "Syncing {syncingProgress}%" -} +} \ No newline at end of file diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index f8197b2895..a3ec24a876 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} +} \ No newline at end of file diff --git a/storybook/stories/_support/utils.ts b/storybook/stories/_support/utils.ts index da0139e63c..9ce6d2c72f 100644 --- a/storybook/stories/_support/utils.ts +++ b/storybook/stories/_support/utils.ts @@ -252,13 +252,11 @@ export const generateAddress = (used = false): WalletAddress => used, spendingPath: "1852'/1815'/0'/0/19", }); -export const promise = - (returnValue: any): (() => Promise) => - () => - new Promise((resolve) => { - setTimeout(() => { - resolve(returnValue); - }, 2000); - }); +export const promise = (returnValue: any): (() => Promise) => () => + new Promise((resolve) => { + setTimeout(() => { + resolve(returnValue); + }, 2000); + }); export const isShelleyTestnetTheme = (currentTheme: string) => currentTheme === 'shelley-testnet'; From 30b9207ae3a746f6891e2dd9814106b675f6a149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Wed, 27 Apr 2022 10:11:50 +0200 Subject: [PATCH 12/15] [DDW-970] Fix JP translation for the unrecognized_wallet status --- source/renderer/app/i18n/locales/ja-JP.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index a3ec24a876..b3a2b6f8b9 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -837,7 +837,7 @@ "wallet.hardware.deviceStatus.trezor_bridge_failure": "Trezor Bridgeがインストールされていません。{instructionsLink}", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.label": "インストールガイド", "wallet.hardware.deviceStatus.trezor_bridge_failure.link.url": "https://wallet.trezor.io/#/bridge", - "wallet.hardware.deviceStatus.unrecognized_wallet": "ご使用のデバイスでこのウォレットを認識できません。{walletname}のペアリングに選択したデバイスと同じものを使用していること、正しいパスフレーズを入力していることを確認してください。", + "wallet.hardware.deviceStatus.unrecognized_wallet": "ご使用のデバイスでこのウォレットを認識できません。{walletName}のペアリングに選択したデバイスと同じものを使用していること、正しいパスフレーズを入力していることを確認してください。", "wallet.hardware.deviceStatus.unsupported_device": "このデバイスはサポートされていません", "wallet.hardware.deviceStatus.verifying_address": "「{walletName}」デバイスのアドレスを検証してください", "wallet.hardware.deviceStatus.verifying_address_aborted": "検証はユーザーにより中止されました", @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} \ No newline at end of file +} From 7a1fe760745f9527a3a813491f69ccd5b22ae90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Thu, 28 Apr 2022 13:48:44 +0200 Subject: [PATCH 13/15] [DDW-970] Fix HardwareWalletStore implementaion after meging master --- .../app/stores/HardwareWalletsStore.ts | 199 +++++++++--------- 1 file changed, 105 insertions(+), 94 deletions(-) diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index e24b294dd5..8c720a66de 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -1377,33 +1377,38 @@ export default class HardwareWalletsStore extends Store { // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type '{}'. devicePath = activeDevice.path || path || newConnectionData.path || null; - const extendedPublicKey = await this._requestExtendedPublicKey( - devicePath, - walletId, - address - ); - const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( - { extendedPublicKey } - ); - - if (associatedWallet) { - await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( - { - address, - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: devicePath, - } + try { + const extendedPublicKey = await this._requestExtendedPublicKey( + devicePath, + walletId, + address ); - } else { - logger.debug( - '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( + { extendedPublicKey } ); - this._discardConnectedDeviceAndReInitiateAddressVerification({ - address, - walletId, - }); + + if (associatedWallet) { + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + address, + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: devicePath, + } + ); + } else { + logger.debug( + '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' + ); + this._discardConnectedDeviceAndReInitiateAddressVerification({ + address, + walletId, + }); + } + } catch (e) { + await this.resetWalletPairing(); + throw e; } } else { logger.debug('[HW-DEBUG] Verify Address with Ledger: ', { @@ -1667,7 +1672,7 @@ export default class HardwareWalletsStore extends Store { if (!transportDevice) { logger.debug( - '[HW-DEBUG] HWStore::_getExtendedPublicKey:: Device not recognized ' + '[HW-DEBUG] HWStore::_requestExtendedPublicKey:: Device not recognized ' ); throw new Error( @@ -2076,46 +2081,51 @@ export default class HardwareWalletsStore extends Store { path, expectedWalletId, }: IdentifyAndHandleAssociatedWalletArgs) => { - const extendedPublicKey = await this._requestExtendedPublicKey( - path, - expectedWalletId, - address - ); - const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( - { extendedPublicKey } - ); - - if (associatedWallet) { - await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( - { - address, - associatedWallet, - expectedWalletId, - extendedPublicKey, - path, - } + try { + const extendedPublicKey = await this._requestExtendedPublicKey( + path, + expectedWalletId, + address ); - } else { - const deviceId = - extendedPublicKey.deviceId || this.transportDevice.deviceId; - logger.debug( - '[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ', - { - deviceId, - } + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( + { extendedPublicKey } ); - if (this.isTransactionInitiated) { - // Software Wallet not recognized and TX initiated. Show error - this._discardConnectedDeviceAndReInitiateTransaction({ - walletId: expectedWalletId, - }); + if (associatedWallet) { + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + address, + associatedWallet, + expectedWalletId, + extendedPublicKey, + path, + } + ); } else { - await this._createNewWalletForRecognizedPendingDevice({ - extendedPublicKey, - path, - }); + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + logger.debug( + '[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ', + { + deviceId, + } + ); + + if (this.isTransactionInitiated) { + // Software Wallet not recognized and TX initiated. Show error + this._discardConnectedDeviceAndReInitiateTransaction({ + walletId: expectedWalletId, + }); + } else { + await this._createNewWalletForRecognizedPendingDevice({ + extendedPublicKey, + path, + }); + } } + } catch (e) { + await this.resetWalletPairing(); + throw e; } }; @@ -2761,35 +2771,40 @@ export default class HardwareWalletsStore extends Store { } ); - const extendedPublicKey = await this._requestExtendedPublicKey( - transportDevice.path, - walletId - ); - const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( - { extendedPublicKey } - ); - - if (associatedWallet) { - await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( - { - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: transportDevice.path, - } + try { + const extendedPublicKey = await this._requestExtendedPublicKey( + transportDevice.path, + walletId ); - } else { - const deviceId = - extendedPublicKey.deviceId || this.transportDevice.deviceId; - logger.debug( - '[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ', - { - deviceId, - } + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( + { extendedPublicKey } ); - // Software Wallet not recognized and TX initiated. Show error - this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); + if (associatedWallet) { + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: transportDevice.path, + } + ); + } else { + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + logger.debug( + '[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ', + { + deviceId, + } + ); + + // Software Wallet not recognized and TX initiated. Show error + this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); + } + } catch (e) { + await this.resetWalletPairing(); + throw e; } } } else { @@ -3153,13 +3168,9 @@ export default class HardwareWalletsStore extends Store { id: key, })); - const pendingHardwareWallets = transformedData.filter( - ({ isPending }) => isPending - ); - - const pendingHardwareWalletsIds = pendingHardwareWallets.map( - ({ id }) => id - ); + const pendingHardwareWalletsIds = transformedData + .filter(({ isPending }) => isPending) + .map(({ id }) => id); logger.debug('[HW-DEBUG] HWStore - cleanUpPendingDevices - cleanup ids: ', { pendingHardwareWalletsIds, From 42977dea7bc42b879603bdc9141b4126e5a9b21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Thu, 28 Apr 2022 16:06:05 +0200 Subject: [PATCH 14/15] [DDW-970] Remove unnecessary calls of the resetWalletPairing function --- source/renderer/app/i18n/locales/ja-JP.json | 2 +- .../app/stores/HardwareWalletsStore.ts | 112 ++++++++---------- yarn.lock | 13 +- 3 files changed, 53 insertions(+), 74 deletions(-) diff --git a/source/renderer/app/i18n/locales/ja-JP.json b/source/renderer/app/i18n/locales/ja-JP.json index b3a2b6f8b9..21986a2885 100755 --- a/source/renderer/app/i18n/locales/ja-JP.json +++ b/source/renderer/app/i18n/locales/ja-JP.json @@ -1304,4 +1304,4 @@ "wallet.transferFunds.dialog2.total.label": "合計", "widgets.itemsDropdown.syncingLabel": "同期", "widgets.itemsDropdown.syncingLabelProgress": "同期中 {syncingProgress}%" -} +} \ No newline at end of file diff --git a/source/renderer/app/stores/HardwareWalletsStore.ts b/source/renderer/app/stores/HardwareWalletsStore.ts index 8c720a66de..5ad8b1fe9e 100644 --- a/source/renderer/app/stores/HardwareWalletsStore.ts +++ b/source/renderer/app/stores/HardwareWalletsStore.ts @@ -1377,38 +1377,33 @@ export default class HardwareWalletsStore extends Store { // @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type '{}'. devicePath = activeDevice.path || path || newConnectionData.path || null; - try { - const extendedPublicKey = await this._requestExtendedPublicKey( - devicePath, - walletId, - address - ); - const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( - { extendedPublicKey } - ); + const extendedPublicKey = await this._requestExtendedPublicKey( + devicePath, + walletId, + address + ); + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( + { extendedPublicKey } + ); - if (associatedWallet) { - await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( - { - address, - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: devicePath, - } - ); - } else { - logger.debug( - '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' - ); - this._discardConnectedDeviceAndReInitiateAddressVerification({ + if (associatedWallet) { + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { address, - walletId, - }); - } - } catch (e) { - await this.resetWalletPairing(); - throw e; + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: devicePath, + } + ); + } else { + logger.debug( + '[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states' + ); + this._discardConnectedDeviceAndReInitiateAddressVerification({ + address, + walletId, + }); } } else { logger.debug('[HW-DEBUG] Verify Address with Ledger: ', { @@ -2771,40 +2766,35 @@ export default class HardwareWalletsStore extends Store { } ); - try { - const extendedPublicKey = await this._requestExtendedPublicKey( - transportDevice.path, - walletId + const extendedPublicKey = await this._requestExtendedPublicKey( + transportDevice.path, + walletId + ); + const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( + { extendedPublicKey } + ); + + if (associatedWallet) { + await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( + { + associatedWallet, + expectedWalletId: walletId, + extendedPublicKey, + path: transportDevice.path, + } ); - const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey( - { extendedPublicKey } + } else { + const deviceId = + extendedPublicKey.deviceId || this.transportDevice.deviceId; + logger.debug( + '[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ', + { + deviceId, + } ); - if (associatedWallet) { - await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting( - { - associatedWallet, - expectedWalletId: walletId, - extendedPublicKey, - path: transportDevice.path, - } - ); - } else { - const deviceId = - extendedPublicKey.deviceId || this.transportDevice.deviceId; - logger.debug( - '[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ', - { - deviceId, - } - ); - - // Software Wallet not recognized and TX initiated. Show error - this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); - } - } catch (e) { - await this.resetWalletPairing(); - throw e; + // Software Wallet not recognized and TX initiated. Show error + this._discardConnectedDeviceAndReInitiateTransaction({ walletId }); } } } else { diff --git a/yarn.lock b/yarn.lock index c882034827..37fdf9ad1c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3155,10 +3155,6 @@ version "1.0.0" resolved "https://registry.yarnpkg.com/@types/is-function/-/is-function-1.0.0.tgz#1b0b819b1636c7baf0d6785d030d12edf70c3e83" -"@types/istanbul-lib-coverage@*": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44" - "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": version "2.0.3" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762" @@ -13558,14 +13554,7 @@ promise@^7.1.1: dependencies: asap "~2.0.3" -prompts@2.4.2: - version "2.4.2" - resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069" - dependencies: - kleur "^3.0.3" - sisteransi "^1.0.5" - -prompts@^2.0.1: +prompts@2.4.2, prompts@^2.0.1: version "2.4.2" resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069" dependencies: From 9b4de1ea2bab480e0fc014a1cb3c5930905c05e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mas=C5=82owski?= Date: Fri, 20 May 2022 10:09:48 +0200 Subject: [PATCH 15/15] [DDW-970] Move changelog entry to the appropiate section --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a6ae42a6..417b47e1dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Fixed incorrect behaviour of creating new wallet when paired incorrect hardware wallet during address verification ([PR 2906](https://github.com/input-output-hk/daedalus/pull/2906)) - Fixed phrasing of insufficient funds for tokens message ([PR 2966](https://github.com/input-output-hk/daedalus/pull/2966)) ### Features @@ -28,7 +29,6 @@ ### Fixes -- Fixed incorrect behaviour of creating new wallet when paired incorrect hardware wallet during address verification ([PR 2906](https://github.com/input-output-hk/daedalus/pull/2906)) - Fixed dialogs being closed after receiving address shared ([PR 2965](https://github.com/input-output-hk/daedalus/pull/2965)) - Fixed no progress shown on loading screen on Windows ([PR 2967](https://github.com/input-output-hk/daedalus/pull/2967)) - Fixes hardware wallet issues on Windows ([PR 2900](https://github.com/input-output-hk/daedalus/pull/2900))