Skip to content

Commit 14e78ff

Browse files
committed
Wire up actual calls to the controller to poll for ledger connectivity
1 parent 7b49b0b commit 14e78ff

File tree

7 files changed

+133
-33
lines changed

7 files changed

+133
-33
lines changed

app/scripts/metamask-controller.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ export default class MetamaskController extends EventEmitter {
11581158
establishLedgerTransportPreference: this.establishLedgerTransportPreference.bind(
11591159
this,
11601160
),
1161+
checkLedgerReady: this.checkLedgerReady.bind(this),
11611162

11621163
// qr hardware devices
11631164
submitQRHardwareCryptoHDKey: qrHardwareKeyring.submitCryptoHDKey.bind(
@@ -1991,6 +1992,28 @@ export default class MetamaskController extends EventEmitter {
19911992
return { ...keyState, identities };
19921993
}
19931994

1995+
async checkLedgerReady(address) {
1996+
console.log('checkLedgerReady; called for address: ', address);
1997+
1998+
const keyring = await this.keyringController.getKeyringForAccount(address);
1999+
2000+
console.log('checkLedgerReady; keyring is: ', keyring);
2001+
if (!keyring) {
2002+
throw new Error('No keyring could be found for this address');
2003+
}
2004+
2005+
const isReady = Boolean(keyring?.isConnected?.());
2006+
2007+
console.log(
2008+
'[checkLedgerReady] keyring is: ',
2009+
keyring,
2010+
'; isReady: ',
2011+
isReady,
2012+
);
2013+
2014+
return isReady;
2015+
}
2016+
19942017
//
19952018
// Account Management
19962019
//

ui/components/app/confirm-page-container/confirm-page-container-content/confirm-page-container-content.component.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,24 @@ export default class ConfirmPageContainerContent extends Component {
143143
/>
144144
</div>
145145
)}
146-
{showingHardwareConnectionContents ? null : (<ConfirmPageContainerSummary
147-
className={classnames({
148-
'confirm-page-container-summary--border':
149-
!detailsComponent || !dataComponent,
150-
})}
151-
action={action}
152-
title={title}
153-
image={image}
154-
titleComponent={titleComponent}
155-
subtitleComponent={subtitleComponent}
156-
hideSubtitle={hideSubtitle}
157-
identiconAddress={identiconAddress}
158-
nonce={nonce}
159-
origin={origin}
160-
hideTitle={hideTitle}
161-
/>)}
146+
{showingHardwareConnectionContents ? null : (
147+
<ConfirmPageContainerSummary
148+
className={classnames({
149+
'confirm-page-container-summary--border':
150+
!detailsComponent || !dataComponent,
151+
})}
152+
action={action}
153+
title={title}
154+
image={image}
155+
titleComponent={titleComponent}
156+
subtitleComponent={subtitleComponent}
157+
hideSubtitle={hideSubtitle}
158+
identiconAddress={identiconAddress}
159+
nonce={nonce}
160+
origin={origin}
161+
hideTitle={hideTitle}
162+
/>
163+
)}
162164
{this.renderContent()}
163165
{!supportsEIP1559V2 &&
164166
!hasSimulationError &&

ui/components/app/confirm-page-container/confirm-page-container.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import AdvancedGasFeePopover from '../advanced-gas-fee-popover';
1616
import EditGasFeePopover from '../edit-gas-fee-popover/edit-gas-fee-popover';
1717
import EditGasPopover from '../edit-gas-popover';
1818

19-
import EnableEIP1559V2Notice from './enableEIP1559V2-notice';
2019
import HardwareConnectivityPopover from '../../../pages/confirm-transaction-base/hardware-connectivity/hardware-connectivity-popover';
20+
import EnableEIP1559V2Notice from './enableEIP1559V2-notice';
2121
import {
2222
ConfirmPageContainerHeader,
2323
ConfirmPageContainerContent,

ui/pages/confirm-transaction-base/confirm-transaction-base.component.js

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
getGasFeeEstimatesAndStartPolling,
5757
addPollingTokenToAppState,
5858
removePollingTokenFromAppState,
59+
checkLedgerReady,
5960
} from '../../store/actions';
6061

6162
import Typography from '../../components/ui/typography/typography';
@@ -144,6 +145,7 @@ export default class ConfirmTransactionBase extends Component {
144145
nativeCurrency: PropTypes.string,
145146
supportsEIP1559: PropTypes.bool,
146147
hardwareWalletRequiresConnection: PropTypes.bool,
148+
connectHardwareWallet: PropTypes.func,
147149
isMultiLayerFeeNetwork: PropTypes.bool,
148150
eip1559V2Enabled: PropTypes.bool,
149151
};
@@ -155,10 +157,64 @@ export default class ConfirmTransactionBase extends Component {
155157
ethGasPriceWarning: '',
156158
editingGas: false,
157159
userAcknowledgedGasMissing: false,
158-
showingHardwareConnectionContents: /* false */ true,
159-
showingHardwareConnectionAdvancedPopover: /* false */ true,
160+
showingHardwareConnectionContents: false,
161+
showingHardwareConnectionAdvancedPopover: false,
162+
pollingIntervalId: null,
163+
hardwareIsReady: true, // Optimistic
160164
};
161165

166+
async pollLedgerReady() {
167+
const { fromAddress } = this.props;
168+
const { pollingIntervalId } = this.state;
169+
170+
console.log(
171+
'[confirm-transaction-base] pollLedgerReadycalled; id: ',
172+
pollingIntervalId,
173+
);
174+
175+
// Don't set off multiple calls to checkLedgerReady
176+
if (pollingIntervalId !== null) {
177+
console.log(
178+
'[confirm-transaction-base] avoiding multiple calls for ; id: ',
179+
pollingIntervalId,
180+
);
181+
return undefined;
182+
}
183+
184+
let hardwareIsReady = true;
185+
try {
186+
console.log(
187+
`[confirm-transaction-base] about to call checkLedgerReady for ${fromAddress}`,
188+
);
189+
hardwareIsReady = await checkLedgerReady(fromAddress);
190+
console.log(`[confirm-transaction-base] RETURNED! ${hardwareIsReady}`);
191+
} catch (e) {
192+
console.error(
193+
'[confirm-transaction-base] ERROR checking ledger ready!',
194+
e,
195+
);
196+
}
197+
198+
this.setState({ hardwareIsReady, pollingIntervalId: null });
199+
return undefined;
200+
}
201+
202+
UNSAFE_componentWillMount() {
203+
console.log('UNSAFE_componentWillMount!');
204+
205+
const { showLedgerSteps } = this.props;
206+
207+
if (!showLedgerSteps) {
208+
return;
209+
}
210+
211+
this.pollLedgerReady();
212+
const intervalId = setInterval(() => {
213+
this.pollLedgerReady();
214+
}, 2000);
215+
this.setState({ pollingIntervalId: intervalId });
216+
}
217+
162218
componentDidUpdate(prevProps) {
163219
const {
164220
transactionStatus,
@@ -329,7 +385,7 @@ export default class ConfirmTransactionBase extends Component {
329385
nativeCurrency,
330386
connectHardwareWallet,
331387
} = this.props;
332-
const { showingHardwareConnectionContents } = this.state;
388+
const { showingHardwareConnectionContents, hardwareIsReady } = this.state;
333389
const { t } = this.context;
334390
const { userAcknowledgedGasMissing } = this.state;
335391

@@ -652,16 +708,15 @@ export default class ConfirmTransactionBase extends Component {
652708
showDataInstruction={Boolean(txData.txParams?.data)}
653709
/>
654710
) : null}
655-
{
656-
/* showLedgerSteps */ true ? (
657-
<HardwareConnectivityMessage
658-
onClick={() => {
659-
console.log('Opening the modal!');
660-
this.setState({ showingHardwareConnectionContents: true });
661-
}}
662-
/>
663-
) : null
664-
}
711+
{showLedgerSteps ? (
712+
<HardwareConnectivityMessage
713+
connected={hardwareIsReady}
714+
onClick={() => {
715+
console.log('Opening the modal!');
716+
this.setState({ showingHardwareConnectionContents: true });
717+
}}
718+
/>
719+
) : null}
665720
</div>
666721
);
667722
}
@@ -1011,6 +1066,11 @@ export default class ConfirmTransactionBase extends Component {
10111066
componentWillUnmount() {
10121067
this._beforeUnloadForGasPolling();
10131068
this._removeBeforeUnload();
1069+
1070+
const { pollingIntervalId } = this.state;
1071+
if (pollingIntervalId) {
1072+
clearInterval(pollingIntervalId);
1073+
}
10141074
}
10151075

10161076
supportsEIP1559V2 =

ui/pages/confirm-transaction-base/confirm-transaction-base.container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const mapStateToProps = (state, ownProps) => {
246246
maxPriorityFeePerGas: gasEstimationObject.maxPriorityFeePerGas,
247247
baseFeePerGas: gasEstimationObject.baseFeePerGas,
248248
gasFeeIsCustom,
249-
showLedgerSteps: true /* fromAddressIsLedger */,
249+
showLedgerSteps: fromAddressIsLedger,
250250
nativeCurrency,
251251
hardwareWalletRequiresConnection,
252252
isMultiLayerFeeNetwork,

ui/pages/confirm-transaction-base/hardware-connectivity/index.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.hardware-connectivity-content {
2-
32
&-list-container {
43
display: flex;
54
justify-content: center;
@@ -8,7 +7,7 @@
87
ol {
98
list-style-type: decimal;
109
padding-inline-start: 20px;
11-
10+
1211
li {
1312
font-size: 0.875rem;
1413
line-height: 35px;

ui/store/actions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,22 @@ export function unlockHardwareWalletAccounts(
482482
};
483483
}
484484

485+
export async function checkLedgerReady(fromAddress) {
486+
console.log('[actions] checkLedgerReady for address: ', fromAddress);
487+
console.log(
488+
'[actions] About to call to server : ',
489+
promisifiedBackground.checkLedgerReady,
490+
);
491+
let isReady = false;
492+
try {
493+
isReady = await promisifiedBackground.checkLedgerReady(fromAddress);
494+
} catch (e) {
495+
console.log('[actions]] ERROR! ', e);
496+
}
497+
console.log('[actions] checkLedgerReady response: ', isReady);
498+
return isReady;
499+
}
500+
485501
export function showQrScanner() {
486502
return (dispatch) => {
487503
dispatch(

0 commit comments

Comments
 (0)