Skip to content

Commit

Permalink
trezor: Add udev error and instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed May 28, 2024
1 parent 11e55dd commit 728b813
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 16 deletions.
37 changes: 24 additions & 13 deletions app/actions/TrezorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SIGNMESSAGE_SUCCESS
} from "./ControlActions";
import { getAmountFromTxInputs, getTxFromInputs } from "./TransactionActions";
import { push as pushHistory } from "connected-react-router";

const session = require("trezor-connect").default;
const {
Expand Down Expand Up @@ -82,6 +83,7 @@ export const initTransport = async (session, debug) => {
export const TRZ_CONNECT_ATTEMPT = "TRZ_CONNECT_ATTEMPT";
export const TRZ_CONNECT_FAILED = "TRZ_CONNECT_FAILED";
export const TRZ_CONNECT_SUCCESS = "TRZ_CONNECT_SUCCESS";
export const TRZ_UDEV_ERROR = "TREZOR_UDEV_ERROR";

export const connect = () => async (dispatch, getState) => {
const {
Expand All @@ -97,8 +99,23 @@ export const connect = () => async (dispatch, getState) => {
dispatch({ error, type: TRZ_CONNECT_FAILED });
return;
});
try {
await dispatch(getFeatures());
} catch (err) {
dispatch({
error: err.message,
type: TRZ_CONNECT_FAILED
});
const needRules = await trezord.needsUdevRules();
if (needRules.needs) {
dispatch({ type: TRZ_UDEV_ERROR });
setTimeout(() => {
dispatch(pushHistory("/error"));
}, 1000);
}
return;
}
dispatch({ type: TRZ_CONNECT_SUCCESS });
dispatch(getFeatures());
};

export const TRZ_TREZOR_DISABLED = "TRZ_TREZOR_DISABLED";
Expand Down Expand Up @@ -129,7 +146,6 @@ function onChange(dispatch, getState, features) {
if (device == currentDevice) return;
const deviceLabel = features.label;
dispatch({ deviceLabel, device, type: TRZ_SELECTEDDEVICE_CHANGED });
dispatch(getFeatures());
}

function onConnect(dispatch, getState, features) {
Expand All @@ -140,7 +156,6 @@ function onConnect(dispatch, getState, features) {
device = BOOTLOADER_MODE;
}
dispatch({ deviceLabel, device, type: TRZ_LOADDEVICE });
dispatch(getFeatures());
return device;
}

Expand Down Expand Up @@ -330,16 +345,12 @@ async function deviceRun(dispatch, getState, fn) {

export const TRZ_GETFEATURES_SUCCESS = "TRZ_GETFEATURES_SUCCESS";
export const getFeatures = () => async (dispatch, getState) => {
try {
const features = await deviceRun(dispatch, getState, async () => {
const res = await session.getFeatures();
return res.payload;
});
dispatch({ type: TRZ_GETFEATURES_SUCCESS, features });
return features;
} catch (error) {
return null;
}
const features = await deviceRun(dispatch, getState, async () => {
const res = await session.getFeatures();
return res.payload;
});
dispatch({ type: TRZ_GETFEATURES_SUCCESS, features });
return features;
};

export const TRZ_CANCELOPERATION_SUCCESS = "TRZ_CANCELOPERATION_SUCCESS";
Expand Down
22 changes: 22 additions & 0 deletions app/components/views/FatalErrorPage/FatalErrorPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function FatalErrorPage() {
const {
daemonError,
walletError,
trezorUdevError,
isAdvancedDaemon,
shutdownApp,
backToCredentials,
Expand Down Expand Up @@ -125,6 +126,14 @@ function FatalErrorPage() {
<textarea rows="10" value={walletError} disabled />
</>
)}
{trezorUdevError && (
<>
<div className={styles.error}>
<T id="fatal.trezor.udev.title" m="Udev Rules Error" />
</div>
<T id="fatal.trezor.udev.details" m="Udev rules were not found at /etc/udev/rules.d/51-trezor.rules" />
</>
)}
</div>
</div>
<div className={styles.title}>
Expand All @@ -136,6 +145,19 @@ function FatalErrorPage() {
</div>
<div className={styles.suggestion}>
{daemonError && getErrorAction()}
{trezorUdevError && (
<T
id="fatal.trezor.suggestion.udev"
m="Follow the instuctions at {link}."
values={{
link: (
<ExternalLink href="https://trezor.io/learn/a/udev-rules">
https://trezor.io/learn/a/udev-rules
</ExternalLink>
)
}}
/>
)}
</div>
<div className={styles.toolbar}>
{isAdvancedDaemon && (
Expand Down
4 changes: 3 additions & 1 deletion app/components/views/FatalErrorPage/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export function useFatalErrorPage() {
const isAdvancedDaemon = useSelector(sel.isAdvancedDaemon);
const daemonError = useSelector(sel.daemonError);
const walletError = useSelector(sel.walletError);
const trezorUdevError = useSelector(sel.trezorUdevError);

const shutdownApp = () => dispatch(da.shutdownApp());
const backToCredentials = () => dispatch(da.backToCredentials());
Expand All @@ -18,6 +19,7 @@ export function useFatalErrorPage() {
isAdvancedDaemon,
shutdownApp,
backToCredentials,
deleteDaemonData
deleteDaemonData,
trezorUdevError
};
}
3 changes: 3 additions & 0 deletions app/main.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
removeDcrlnd,
startTrezord,
stopTrezord,
needUdevRules,
lnScbInfo,
startDex,
stopDex,
Expand Down Expand Up @@ -412,6 +413,8 @@ handle("start-dex", startDex);

handle("stop-dex", stopDex);

handle("needs-udev-rules", needUdevRules);

handle("start-trezord", startTrezord);

handle("stop-trezord", stopTrezord);
Expand Down
5 changes: 5 additions & 0 deletions app/main_dev/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
launchTrezord,
GetTrezordPID,
closeTrezord,
needsUdevRules,
launchDex,
initCheckDex,
initDexCall,
Expand Down Expand Up @@ -251,6 +252,10 @@ export const startDcrlnd = async (
}
};

export const needUdevRules = () => {
return { needs: needsUdevRules() };
};

export const startTrezord = async () => {
if (GetTrezordPID() && GetTrezordPID() !== -1) {
logger.log(
Expand Down
11 changes: 11 additions & 0 deletions app/main_dev/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ export const closeDcrlnd = () => {
return true;
};

export function needsUdevRules() {
if (os.platform() != "linux") {
return false;
}
const distRules = "/etc/udev/rules.d/51-trezor.rules";
if (fs.existsSync(distRules)) {
return false;
}
return true;
}

export function closeTrezord() {
if (trezordPID === -1) {
// process is not started by decrediton
Expand Down
11 changes: 9 additions & 2 deletions app/reducers/trezor.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
TRZ_GETWALLETCREATIONMASTERPUBKEY_ATTEMPT,
TRZ_GETWALLETCREATIONMASTERPUBKEY_FAILED,
TRZ_GETWALLETCREATIONMASTERPUBKEY_SUCCESS,
TRZ_GETFEATURES_SUCCESS
TRZ_GETFEATURES_SUCCESS,
TRZ_UDEV_ERROR
} from "actions/TrezorActions";
import {
SIGNTX_ATTEMPT,
Expand All @@ -77,7 +78,8 @@ export default function trezor(state = {}, action) {
case TRZ_CONNECT_SUCCESS:
return {
...state,
connectAttempt: false
connectAttempt: false,
trezorUdevError: false
};
case TRZ_CONNECT_FAILED:
return {
Expand Down Expand Up @@ -327,6 +329,11 @@ export default function trezor(state = {}, action) {
};
case CLOSEWALLET_SUCCESS:
return { ...state, enabled: false };
case TRZ_UDEV_ERROR:
return {
...state,
trezorUdevError: true
};
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions app/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ export const confirmationDialogModalVisible = bool(

export const isTrezor = get(["trezor", "enabled"]);
export const isPerformingTrezorUpdate = get(["trezor", "performingUpdate"]);
export const trezorUdevError = get(["trezor", "trezorUdevError"]);

export const isLedger = get(["ledger", "enabled"]);

Expand Down
1 change: 1 addition & 0 deletions app/wallet/trezord/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { invocable } from "helpers/electronRenderer";

export const needsUdevRules = invocable("needs-udev-rules");
export const start = invocable("start-trezord");
export const stop = invocable("stop-trezord");

0 comments on commit 728b813

Please sign in to comment.