Skip to content

Commit

Permalink
[DDW-197] Cancel all device action on tx dialog close. Reset listener…
Browse files Browse the repository at this point in the history
…s on app refresh
  • Loading branch information
Tomislav Horaček committed Oct 29, 2020
1 parent e5b093c commit d9f741a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
16 changes: 16 additions & 0 deletions source/main/ipc/getHardwareWalletChannel.js
Expand Up @@ -243,6 +243,9 @@ export const handleHardwareWalletRequests = async (mainWindow) => {

handleInitTrezorConnectChannel.onRequest(async () => {
console.debug('>>> Trezor Init: ', TrezorConnect);
// Remove all listeners if exist - e.g. on app refresh
TrezorConnect.removeAllListeners();
// Initialize new device listeners
TrezorConnect.on(TRANSPORT_EVENT, event => {
console.debug('>>> TRANSPORT_EVENT: ', event);

Expand Down Expand Up @@ -458,10 +461,23 @@ export const handleHardwareWalletRequests = async (mainWindow) => {
ttl,
networkId,
certificates,
reset
} = params;
if (!TrezorConnect) {
throw new Error('Device not connected!');
}

if (reset) {
TrezorConnect.cancel('Method_Cancel');
return {
success: false,
payload: {
code: 'Method_Cancel',
error: 'Signing Cancelled',
}
}
}

try {
console.debug('>>> Signing REQ: ', params);
const signedTransaction = await TrezorConnect.cardanoSignTransaction({
Expand Down
Expand Up @@ -55,7 +55,7 @@ export default class WalletSendConfirmationDialogContainer extends Component<Pro
} = this.props;
const { stores } = this.props;
const { sendMoneyRequest, active: activeWallet } = stores.wallets;
const { sendMoneyRequest: sendMoneyExternalRequest, isTransactionPending } = stores.hardwareWallets;
const { _resetTransaction: resetHardwareWalletTransaction, sendMoneyRequest: sendMoneyExternalRequest, isTransactionPending } = stores.hardwareWallets;
const { isFlight } = global;

if (!activeWallet)
Expand All @@ -77,7 +77,7 @@ export default class WalletSendConfirmationDialogContainer extends Component<Pro
onCancel={() => {
actions.dialogs.closeActiveDialog.trigger();
sendMoneyRequest.reset();
sendMoneyExternalRequest.reset();
resetHardwareWalletTransaction({ cancelDeviceAction: true });
}}
error={error}
currencyUnit={currencyUnit}
Expand Down
14 changes: 11 additions & 3 deletions source/renderer/app/stores/HardwareWalletsStore.js
Expand Up @@ -751,14 +751,22 @@ export default class HardwareWalletsStore extends Store {
}
};

_resetTransaction = async () => {
this.selectCoinsRequest.reset();
_resetTransaction = async (params: ?{
cancelDeviceAction: boolean;
}) => {
const { cancelDeviceAction } = params;
console.debug('>>> CANCEL: ', cancelDeviceAction);
if (cancelDeviceAction) {
signTransactionTrezorChannel.request({
reset: true,
});
}
this.sendMoneyRequest.reset();
runInAction(
'HardwareWalletsStore:: reset Transaction verifying',
() => {
this.hwDeviceStatus = HwDeviceStatuses.READY;
this.txBody = null;
this.txSignRequest = {};
}
);
};
Expand Down

0 comments on commit d9f741a

Please sign in to comment.