Skip to content

Commit

Permalink
Fix Hardware Wallets delegation (#2369)
Browse files Browse the repository at this point in the history
* Fix Hardware Wallets delegation

* Adds CHANGELOG

Co-authored-by: Nikola Glumac <[email protected]>
  • Loading branch information
Tomislav Horaček and nikolaglumac authored Feb 17, 2021
1 parent dc14636 commit e034c90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

## 3.3.0

### Fixes

- Fixed issue with hardware wallet delegation ([PR 2369](https://github.com/input-output-hk/daedalus/pull/2369))

### Chores

- Updated `cardano-launcher` to version `0.20210215.0` ([PR 2363](https://github.com/input-output-hk/daedalus/pull/2363))
Expand Down
18 changes: 14 additions & 4 deletions source/renderer/app/stores/HardwareWalletsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class HardwareWalletsStore extends Store {
@observable isListeningForDevice: boolean = false;
@observable isConnectInitiated: boolean = false;
@observable isExportKeyAborted: boolean = false;
@observable activeDelegationWalletId: ?string = null;

cardanoAdaAppPollingInterval: ?IntervalID = null;
checkTransactionTimeInterval: ?IntervalID = null;
Expand Down Expand Up @@ -432,7 +433,16 @@ export default class HardwareWalletsStore extends Store {
// Check if active wallet exist - this means that hw exist but we need to check if relevant device connected to it
let recognizedPairedHardwareWallet;
let relatedConnectionData;
const activeWalletId = get(this.stores.wallets, ['active', 'id']);

let activeWalletId;
if (this.activeDelegationWalletId && this.isTransactionInitiated) {
// Active wallet can be different that wallet we want to delegate
activeWalletId = this.activeDelegationWalletId;
} else {
// For regular tx we are using active wallet
activeWalletId = get(this.stores.wallets, ['active', 'id']);
}

if (activeWalletId) {
// Check if device connected to wallet
logger.debug('[HW-DEBUG] HWStore - active wallet exists');
Expand Down Expand Up @@ -1375,11 +1385,12 @@ export default class HardwareWalletsStore extends Store {
};

initiateTransaction = async (params: { walletId: ?string }) => {
const { walletId } = params;
runInAction('HardwareWalletsStore:: Initiate Transaction', () => {
this.isTransactionInitiated = true;
this.hwDeviceStatus = HwDeviceStatuses.CONNECTING;
this.activeDelegationWalletId = walletId;
});
const { walletId } = params;
const hardwareWalletConnectionData = get(
this.hardwareWalletsConnectionData,
walletId
Expand Down Expand Up @@ -1444,7 +1455,6 @@ export default class HardwareWalletsStore extends Store {
throw e;
}
}

runInAction(
'HardwareWalletsStore:: Set active device path for Transaction send',
() => {
Expand All @@ -1455,7 +1465,6 @@ export default class HardwareWalletsStore extends Store {
// Add more cases / edge cases if needed
if (deviceType === DeviceTypes.TREZOR && walletId) {
logger.debug('[HW-DEBUG] Sign Trezor: ', { id });

const transportDevice = await this.establishHardwareWalletConnection();
if (transportDevice) {
runInAction(
Expand Down Expand Up @@ -1505,6 +1514,7 @@ export default class HardwareWalletsStore extends Store {
this.txBody = null;
this.activeDevicePath = null;
this.unfinishedWalletTxSigning = null;
this.activeDelegationWalletId = null;
});
};

Expand Down

0 comments on commit e034c90

Please sign in to comment.