Skip to content

Commit 7a1fe76

Browse files
[DDW-970] Fix HardwareWalletStore implementaion after meging master
1 parent 67ec172 commit 7a1fe76

File tree

1 file changed

+105
-94
lines changed

1 file changed

+105
-94
lines changed

source/renderer/app/stores/HardwareWalletsStore.ts

Lines changed: 105 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,33 +1377,38 @@ export default class HardwareWalletsStore extends Store {
13771377
// @ts-ignore ts-migrate(2339) FIXME: Property 'path' does not exist on type '{}'.
13781378
devicePath = activeDevice.path || path || newConnectionData.path || null;
13791379

1380-
const extendedPublicKey = await this._requestExtendedPublicKey(
1381-
devicePath,
1382-
walletId,
1383-
address
1384-
);
1385-
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
1386-
{ extendedPublicKey }
1387-
);
1388-
1389-
if (associatedWallet) {
1390-
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
1391-
{
1392-
address,
1393-
associatedWallet,
1394-
expectedWalletId: walletId,
1395-
extendedPublicKey,
1396-
path: devicePath,
1397-
}
1380+
try {
1381+
const extendedPublicKey = await this._requestExtendedPublicKey(
1382+
devicePath,
1383+
walletId,
1384+
address
13981385
);
1399-
} else {
1400-
logger.debug(
1401-
'[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states'
1386+
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
1387+
{ extendedPublicKey }
14021388
);
1403-
this._discardConnectedDeviceAndReInitiateAddressVerification({
1404-
address,
1405-
walletId,
1406-
});
1389+
1390+
if (associatedWallet) {
1391+
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
1392+
{
1393+
address,
1394+
associatedWallet,
1395+
expectedWalletId: walletId,
1396+
extendedPublicKey,
1397+
path: devicePath,
1398+
}
1399+
);
1400+
} else {
1401+
logger.debug(
1402+
'[HW-DEBUG] HWStore - Software wallet not recognized - Setting error states'
1403+
);
1404+
this._discardConnectedDeviceAndReInitiateAddressVerification({
1405+
address,
1406+
walletId,
1407+
});
1408+
}
1409+
} catch (e) {
1410+
await this.resetWalletPairing();
1411+
throw e;
14071412
}
14081413
} else {
14091414
logger.debug('[HW-DEBUG] Verify Address with Ledger: ', {
@@ -1667,7 +1672,7 @@ export default class HardwareWalletsStore extends Store {
16671672

16681673
if (!transportDevice) {
16691674
logger.debug(
1670-
'[HW-DEBUG] HWStore::_getExtendedPublicKey:: Device not recognized '
1675+
'[HW-DEBUG] HWStore::_requestExtendedPublicKey:: Device not recognized '
16711676
);
16721677

16731678
throw new Error(
@@ -2076,46 +2081,51 @@ export default class HardwareWalletsStore extends Store {
20762081
path,
20772082
expectedWalletId,
20782083
}: IdentifyAndHandleAssociatedWalletArgs) => {
2079-
const extendedPublicKey = await this._requestExtendedPublicKey(
2080-
path,
2081-
expectedWalletId,
2082-
address
2083-
);
2084-
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
2085-
{ extendedPublicKey }
2086-
);
2087-
2088-
if (associatedWallet) {
2089-
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
2090-
{
2091-
address,
2092-
associatedWallet,
2093-
expectedWalletId,
2094-
extendedPublicKey,
2095-
path,
2096-
}
2084+
try {
2085+
const extendedPublicKey = await this._requestExtendedPublicKey(
2086+
path,
2087+
expectedWalletId,
2088+
address
20972089
);
2098-
} else {
2099-
const deviceId =
2100-
extendedPublicKey.deviceId || this.transportDevice.deviceId;
2101-
logger.debug(
2102-
'[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ',
2103-
{
2104-
deviceId,
2105-
}
2090+
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
2091+
{ extendedPublicKey }
21062092
);
21072093

2108-
if (this.isTransactionInitiated) {
2109-
// Software Wallet not recognized and TX initiated. Show error
2110-
this._discardConnectedDeviceAndReInitiateTransaction({
2111-
walletId: expectedWalletId,
2112-
});
2094+
if (associatedWallet) {
2095+
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
2096+
{
2097+
address,
2098+
associatedWallet,
2099+
expectedWalletId,
2100+
extendedPublicKey,
2101+
path,
2102+
}
2103+
);
21132104
} else {
2114-
await this._createNewWalletForRecognizedPendingDevice({
2115-
extendedPublicKey,
2116-
path,
2117-
});
2105+
const deviceId =
2106+
extendedPublicKey.deviceId || this.transportDevice.deviceId;
2107+
logger.debug(
2108+
'[HW-DEBUG] HWStore - I don not have recognized wallet - create new one or reject TX: ',
2109+
{
2110+
deviceId,
2111+
}
2112+
);
2113+
2114+
if (this.isTransactionInitiated) {
2115+
// Software Wallet not recognized and TX initiated. Show error
2116+
this._discardConnectedDeviceAndReInitiateTransaction({
2117+
walletId: expectedWalletId,
2118+
});
2119+
} else {
2120+
await this._createNewWalletForRecognizedPendingDevice({
2121+
extendedPublicKey,
2122+
path,
2123+
});
2124+
}
21182125
}
2126+
} catch (e) {
2127+
await this.resetWalletPairing();
2128+
throw e;
21192129
}
21202130
};
21212131

@@ -2761,35 +2771,40 @@ export default class HardwareWalletsStore extends Store {
27612771
}
27622772
);
27632773

2764-
const extendedPublicKey = await this._requestExtendedPublicKey(
2765-
transportDevice.path,
2766-
walletId
2767-
);
2768-
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
2769-
{ extendedPublicKey }
2770-
);
2771-
2772-
if (associatedWallet) {
2773-
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
2774-
{
2775-
associatedWallet,
2776-
expectedWalletId: walletId,
2777-
extendedPublicKey,
2778-
path: transportDevice.path,
2779-
}
2774+
try {
2775+
const extendedPublicKey = await this._requestExtendedPublicKey(
2776+
transportDevice.path,
2777+
walletId
27802778
);
2781-
} else {
2782-
const deviceId =
2783-
extendedPublicKey.deviceId || this.transportDevice.deviceId;
2784-
logger.debug(
2785-
'[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ',
2786-
{
2787-
deviceId,
2788-
}
2779+
const associatedWallet = await this._findAssociatedWalletByExtendedPublicKey(
2780+
{ extendedPublicKey }
27892781
);
27902782

2791-
// Software Wallet not recognized and TX initiated. Show error
2792-
this._discardConnectedDeviceAndReInitiateTransaction({ walletId });
2783+
if (associatedWallet) {
2784+
await this._storeWalletDataInLocalStorageAndHandleTransactionOrAddressVerificationOrRouting(
2785+
{
2786+
associatedWallet,
2787+
expectedWalletId: walletId,
2788+
extendedPublicKey,
2789+
path: transportDevice.path,
2790+
}
2791+
);
2792+
} else {
2793+
const deviceId =
2794+
extendedPublicKey.deviceId || this.transportDevice.deviceId;
2795+
logger.debug(
2796+
'[HW-DEBUG] HWStore - I don not have recognized wallet - reject TX: ',
2797+
{
2798+
deviceId,
2799+
}
2800+
);
2801+
2802+
// Software Wallet not recognized and TX initiated. Show error
2803+
this._discardConnectedDeviceAndReInitiateTransaction({ walletId });
2804+
}
2805+
} catch (e) {
2806+
await this.resetWalletPairing();
2807+
throw e;
27932808
}
27942809
}
27952810
} else {
@@ -3153,13 +3168,9 @@ export default class HardwareWalletsStore extends Store {
31533168
id: key,
31543169
}));
31553170

3156-
const pendingHardwareWallets = transformedData.filter(
3157-
({ isPending }) => isPending
3158-
);
3159-
3160-
const pendingHardwareWalletsIds = pendingHardwareWallets.map(
3161-
({ id }) => id
3162-
);
3171+
const pendingHardwareWalletsIds = transformedData
3172+
.filter(({ isPending }) => isPending)
3173+
.map(({ id }) => id);
31633174

31643175
logger.debug('[HW-DEBUG] HWStore - cleanUpPendingDevices - cleanup ids: ', {
31653176
pendingHardwareWalletsIds,

0 commit comments

Comments
 (0)