Skip to content

Commit ce77002

Browse files
meeh0wryanml
andauthored
fix: allow reattaching forgotten ledger device (#16)
Co-authored-by: ryanml <[email protected]>
1 parent 8385aea commit ce77002

File tree

6 files changed

+106
-42
lines changed

6 files changed

+106
-42
lines changed

.github/workflows/e2e_testing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
types: [opened, reopened, 'synchronize', 'ready_for_review']
1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest-16-cores
12+
runs-on: ubuntu-latest-16-cores-core-extension
1313
if: ${{ !github.event.pull_request.draft }}
1414
environment: alpha
1515
steps:

src/localization/locales/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@
183183
"Connect the Ledger device to your computer.": "Connect the Ledger device to your computer.",
184184
"Connect your Ledger": "Connect your Ledger",
185185
"Connect your Ledger device and open the <bold>Avalanche App</bold> to approve this transaction": "Connect your Ledger device and open the <bold>Avalanche App</bold> to approve this transaction",
186-
"Connect your Ledger device and open the Avalanche App to approve this transaction": "Connect your Ledger device and open the Avalanche App to approve this transaction",
187186
"Connect your Wallet": "Connect your Wallet",
188187
"Connect your wallet via the <br /> \"Connect Wallet\" button on the site": "Connect your wallet via the <br /> \"Connect Wallet\" button on the site",
189188
"Connected": "Connected",
@@ -212,6 +211,7 @@
212211
"Core estimates the maximum gas (maxFeePerGas) a transaction could consume based on network conditions. This transaction will likely consume less gas than estimated.": "Core estimates the maximum gas (maxFeePerGas) a transaction could consume based on network conditions. This transaction will likely consume less gas than estimated.",
213212
"Core functionality may be unstable with custom RPC URLs.": "Core functionality may be unstable with custom RPC URLs.",
214213
"Core is committed to protecting your privacy. We will <b>never</b> sell or share your data. If you wish, you can disable this at any time in the settings menu.": "Core is committed to protecting your privacy. We will <b>never</b> sell or share your data. If you wish, you can disable this at any time in the settings menu.",
214+
"Core is no longer connected to your Ledger device. Reconnect your Ledger to continue.": "Core is no longer connected to your Ledger device. Reconnect your Ledger to continue.",
215215
"Core supports Bitcoin via Fireblocks with a few extra steps. If you choose to skip, you will not be able to bridge or use the Bitcoin Network.": "Core supports Bitcoin via Fireblocks with a few extra steps. If you choose to skip, you will not be able to bridge or use the Bitcoin Network.",
216216
"Core will <b>never</b> sell or share data.": "Core will <b>never</b> sell or share data.",
217217
"Core would like to gather data using local storage and similar technologies to help us understand how our users interact with Core.": "Core would like to gather data using local storage and similar technologies to help us understand how our users interact with Core.",
@@ -646,6 +646,7 @@
646646
"Recents": "Recents",
647647
"Recipient": "Recipient",
648648
"Recipients": "Recipients",
649+
"Reconnect": "Reconnect",
649650
"Recovery Methods": "Recovery Methods",
650651
"Recovery Phrase": "Recovery Phrase",
651652
"Recovery Phrase {{number}}": "Recovery Phrase {{number}}",
@@ -767,6 +768,7 @@
767768
"Subnet ID": "Subnet ID",
768769
"Success!": "Success!",
769770
"Successfully imported the keystore file.": "Successfully imported the keystore file.",
771+
"Successfully reconnected!": "Successfully reconnected!",
770772
"Successfully swapped {{srcAmount}} {{srcToken}} to {{destAmount}} {{destToken}}": "Successfully swapped {{srcAmount}} {{srcToken}} to {{destAmount}} {{destToken}}",
771773
"Suggested slippage – your transaction will fail if the price changes unfavorably more than this percentage": "Suggested slippage – your transaction will fail if the price changes unfavorably more than this percentage",
772774
"Supplied": "Supplied",
@@ -882,6 +884,7 @@
882884
"Turkish": "Turkish",
883885
"URI": "URI",
884886
"Unable to connect. View the troubleshoot guide <linkText>here</linkText>": "Unable to connect. View the troubleshoot guide <linkText>here</linkText>",
887+
"Unable to connect?": "Unable to connect?",
885888
"Unable to set TOTP configuration": "Unable to set TOTP configuration",
886889
"Unauthorized": "Unauthorized",
887890
"Unavailable": "Unavailable",

src/pages/Ledger/LedgerDisconnected.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ import {
33
Box,
44
Stack,
55
CircularProgress,
6+
Button,
67
} from '@avalabs/core-k2-components';
7-
import { Trans } from 'react-i18next';
8+
import { Trans, useTranslation } from 'react-i18next';
9+
import { useCallback } from 'react';
10+
import { tabs } from 'webextension-polyfill';
811

912
export const LedgerDisconnected = () => {
13+
const { t } = useTranslation();
14+
const openTroubleshootingPopup = useCallback(() => {
15+
// Open in a full screen tab to avoid popup hell
16+
tabs.create({
17+
url: '/fullscreen.html#/ledger/troubleshooting',
18+
});
19+
}, []);
20+
1021
return (
1122
<>
1223
<Typography
@@ -27,6 +38,14 @@ export const LedgerDisconnected = () => {
2738
<Stack sx={{ mt: '48px', mb: '16px', alignItems: 'center' }}>
2839
<CircularProgress size={48} />
2940
</Stack>
41+
<Button
42+
variant="text"
43+
color="primary"
44+
onClick={openTroubleshootingPopup}
45+
sx={{ mt: 2 }}
46+
>
47+
{t('Unable to connect?')}
48+
</Button>
3049
</>
3150
);
3251
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { useTranslation } from 'react-i18next';
2+
import { Button, Stack, Typography } from '@avalabs/core-k2-components';
3+
4+
import { Overlay } from '@src/components/common/Overlay';
5+
import { useLedgerContext } from '@src/contexts/LedgerProvider';
6+
import { useState } from 'react';
7+
8+
export const LedgerTroubleshooting = () => {
9+
const { t } = useTranslation();
10+
const { popDeviceSelection } = useLedgerContext();
11+
12+
const [isConnected, setIsConnected] = useState(false);
13+
14+
return (
15+
<Overlay isBackgroundFilled>
16+
<Stack
17+
sx={{
18+
width: 375,
19+
p: 3,
20+
gap: 2,
21+
alignSelf: 'center',
22+
backgroundColor: 'grey.900',
23+
borderRadius: 1,
24+
textAlign: 'center',
25+
}}
26+
>
27+
{isConnected && (
28+
<>
29+
<Typography variant="h5">
30+
{t('Successfully reconnected!')}
31+
</Typography>
32+
<Button
33+
color="primary"
34+
size="large"
35+
sx={{ mt: 3 }}
36+
onClick={window.close}
37+
>
38+
{t('Close')}
39+
</Button>
40+
</>
41+
)}
42+
{!isConnected && (
43+
<>
44+
<Typography variant="h5">{t('Ledger Disconnected')}</Typography>
45+
<Typography variant="body2">
46+
{t(
47+
'Core is no longer connected to your Ledger device. Reconnect your Ledger to continue.'
48+
)}
49+
</Typography>
50+
<Button
51+
color="primary"
52+
size="large"
53+
onClick={async () => {
54+
try {
55+
await popDeviceSelection();
56+
setIsConnected(true);
57+
} catch {
58+
setIsConnected(false);
59+
}
60+
}}
61+
sx={{ mt: 3 }}
62+
>
63+
{t('Reconnect')}
64+
</Button>
65+
</>
66+
)}
67+
</Stack>
68+
</Overlay>
69+
);
70+
};

src/pages/SignTransaction/components/LedgerDisconnectDialog.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/popup/AppRoutes.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,19 @@ const DefiProtocolDetails = lazy(() => {
193193
}));
194194
});
195195

196+
const LedgerTroubleshootingPopup = lazy(() => {
197+
return import('../pages/Ledger/LedgerTroubleshooting').then((m) => ({
198+
default: m.LedgerTroubleshooting,
199+
}));
200+
});
201+
196202
export const AppRoutes = () => (
197203
<Switch>
204+
<Route path="/ledger/troubleshooting">
205+
<Suspense fallback={<CircularProgress />}>
206+
<LedgerTroubleshootingPopup />
207+
</Suspense>
208+
</Route>
198209
<Route path="/token/add">
199210
<Suspense fallback={<CircularProgress />}>
200211
<AddToken />

0 commit comments

Comments
 (0)