Skip to content

Commit

Permalink
Fix small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Comp0te committed May 17, 2024
1 parent 91471c4 commit 974a13c
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export const ConnectedLedger: React.FC<IConnectedLedgerProps> = ({
});
setMaxItemsToRender(prevState => prevState + 5);
} catch (e) {
console.log('-------- e', JSON.stringify(e, null, ' '));
setIsLoadingMore(false);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/apps/popup/pages/import-account-from-ledger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const ImportAccountFromLedgerPage = () => {
<ConnectedLedger onClose={closeNewLedgerWindowsAndClearState} />
) : (
<LedgerConnectionView
isAccountSelection
event={ledgerEventStatusToRender}
onConnect={makeSubmitLedgerAction}
closeNewLedgerWindowsAndClearState={closeNewLedgerWindowsAndClearState}
Expand Down
2 changes: 1 addition & 1 deletion src/background/redux/ledger/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const selectLedgerDeploy = (state: RootState): string | null =>

export const selectLedgerRecipientToSaveOnSuccess = (
state: RootState
): string | null => state.ledger.deploy;
): string | null => state.ledger.recipientToSaveOnSuccess;
3 changes: 1 addition & 2 deletions src/hooks/use-ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const useLedger = ({
});
}
} catch (e) {
console.log('-------- e', e);
setIsLedgerConnected(false);
}
}
Expand Down Expand Up @@ -157,7 +156,7 @@ export const useLedger = ({
}

isFirstEventRef.current = false;
console.log('-------- event', JSON.stringify(event, null, ' '));
console.log('-------- event', JSON.stringify(event.status, null, ' '));
});

return () => sub.unsubscribe();
Expand Down
2 changes: 1 addition & 1 deletion src/libs/services/ledger/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ledgerErrorsData: Record<LedgerEventStatus, ILedgerErrorData> = {
[LedgerEventStatus.CasperAppNotLoaded]: {
title: 'Casper app isn’t open on Ledger',
description:
'Please make sure to open Casper app on your ledger and try connecting again.'
'Please make sure to open Casper app on your Ledger and try connecting again.'
},
[LedgerEventStatus.DeviceLocked]: {
title: 'The Ledger device is locked',
Expand Down
9 changes: 3 additions & 6 deletions src/libs/services/ledger/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export class Ledger {

try {
this.#transport = await transportCreator();
console.log('-------- this.#transport', this.#transport);
this.#transport?.on('disconnect', this.#onDisconnect);
this.#ledgerApp = new LedgerCasperApp(this.#transport);
} catch (e) {
Expand Down Expand Up @@ -132,7 +131,7 @@ export class Ledger {
async checkAppInfo(): Promise<LedgerEventStatus | null> {
if (this.#ledgerConnected && this.#ledgerApp) {
const appInfo = await this.#ledgerApp?.getAppInfo();
console.log('-------- appInfo', appInfo);

await this.#processDelayAfterAction();

if (appInfo.returnCode === 65535) {
Expand Down Expand Up @@ -174,7 +173,6 @@ export class Ledger {
status: LedgerEventStatus.CasperAppNotLoaded
});
} else {
console.log('-------- get acc response', response);
this.#processError({ status: LedgerEventStatus.AccountListFailed });
}
}
Expand Down Expand Up @@ -491,7 +489,7 @@ export class Ledger {
try {
const appInfo = await this.#ledgerApp.getAppInfo();
await this.#processDelayAfterAction();
console.log('-------- appInfo', JSON.stringify(appInfo, null, ' '));

if (appInfo.returnCode === 0xffff || appInfo.returnCode === 21781) {
subscriber.next({ status: LedgerEventStatus.DeviceLocked });

Expand All @@ -504,7 +502,6 @@ export class Ledger {
}

if (appInfo.appName !== 'Casper') {
console.debug('Ledger device app info:' + appInfo.appName, appInfo);
subscriber.next({ status: LedgerEventStatus.CasperAppNotLoaded });

return false;
Expand All @@ -515,7 +512,7 @@ export class Ledger {

return true;
} catch (err) {
console.debug('-------- err', err);
console.error('-------- err', err);
}

return false;
Expand Down
12 changes: 8 additions & 4 deletions src/libs/ui/components/account-list/account-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components';
import { isLedgerAvailable } from '@src/utils';

import { useAccountManager } from '@popup/hooks/use-account-actions-with-events';
import { RouterPath, useTypedNavigate } from '@popup/router';
import { RouterPath, useTypedLocation, useTypedNavigate } from '@popup/router';

import { WindowApp } from '@background/create-open-window';
import {
Expand Down Expand Up @@ -34,8 +34,8 @@ interface AccountListProps {
}

export const AccountList = ({ closeModal }: AccountListProps) => {
const { pathname } = useTypedLocation();
const [accountListRows, setAccountListRows] = useState<AccountListRows[]>([]);

const { changeActiveAccountWithEvent: changeActiveAccount } =
useAccountManager();
const { t } = useTranslation();
Expand Down Expand Up @@ -111,8 +111,12 @@ export const AccountList = ({ closeModal }: AccountListProps) => {
{isLedgerAvailable && (
<Button
color="secondaryBlue"
onClick={() => {
navigate(RouterPath.ImportAccountFromLedger);
onClick={evt => {
if (pathname === RouterPath.ImportAccountFromLedger) {
closeModal(evt);
} else {
navigate(RouterPath.ImportAccountFromLedger);
}
}}
>
<Trans t={t}>Connect Ledger</Trans>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ interface INotConnectedLedgerProps {
event: ILedgerEvent;
onConnect: (tr?: LedgerTransport) => () => Promise<void>;
closeNewLedgerWindowsAndClearState: () => void;
isAccountSelection?: boolean;
}

export const LedgerConnectionView: React.FC<INotConnectedLedgerProps> = ({
event,
onConnect,
closeNewLedgerWindowsAndClearState
closeNewLedgerWindowsAndClearState,
isAccountSelection = false
}) => {
const navigate = useTypedNavigate();

Expand All @@ -43,7 +45,12 @@ export const LedgerConnectionView: React.FC<INotConnectedLedgerProps> = ({
)}
/>
)}
renderContent={() => <LedgerEventView event={event} />}
renderContent={() => (
<LedgerEventView
event={event}
isAccountSelection={isAccountSelection}
/>
)}
renderFooter={renderLedgerFooter({
event,
onConnect,
Expand Down
10 changes: 8 additions & 2 deletions src/libs/ui/components/ledger-event-view/ledger-event-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import {

interface ILedgerEventViewProps {
event: ILedgerEvent;
isAccountSelection?: boolean;
}

export const LedgerEventView: React.FC<ILedgerEventViewProps> = ({ event }) => {
export const LedgerEventView: React.FC<ILedgerEventViewProps> = ({
event,
isAccountSelection = false
}) => {
const [available, setAvailable] = useState(true);

useEffect(() => {
Expand Down Expand Up @@ -47,5 +51,7 @@ export const LedgerEventView: React.FC<ILedgerEventViewProps> = ({ event }) => {
return <LedgerErrorView event={event} />;
}

return <NoConnectedLedger event={event} />;
return (
<NoConnectedLedger event={event} isAccountSelection={isAccountSelection} />
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const LedgerDisconnectedFooter: React.FC<
}}
>
<Trans t={t}>
{ledgerTransport ? 'Continue with USB' : 'Connect via USB'}
{ledgerTransport ? 'Continue' : 'Connect via USB'}
</Trans>
</Button>
)}
Expand All @@ -100,9 +100,7 @@ export const LedgerDisconnectedFooter: React.FC<
}}
>
<Trans t={t}>
{ledgerTransport
? 'Continue with Bluetooth'
: 'Connect via Bluetooth'}
{ledgerTransport ? 'Continue' : 'Connect via Bluetooth'}
</Trans>
</Button>
)}
Expand Down
46 changes: 25 additions & 21 deletions src/libs/ui/components/no-connected-ledger/no-connected-ledger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Player } from '@lottiefiles/react-lottie-player';
import React, { useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import styled from 'styled-components';

Expand All @@ -24,31 +24,38 @@ const ItemContainer = styled(AlignedFlexRow)`
padding: 16px;
`;

const steps = [
{
id: 1,
text: 'Plug in your Ledger to the device'
},
{
id: 2,
text: 'Open Casper app on your Ledger'
},
{
id: 3,
text: 'Get back here to see txn details'
}
];

interface INoConnectedLedgerProps {
event?: ILedgerEvent;
isAccountSelection: boolean;
}

export const NoConnectedLedger: React.FC<INoConnectedLedgerProps> = ({
event
event,
isAccountSelection
}) => {
const { t } = useTranslation();
const isDarkMode = useIsDarkMode();

const steps = useMemo(
() => [
{
id: 1,
text: 'Connect Ledger to your device'
},
{
id: 2,
text: 'Open Casper app on your Ledger'
},
{
id: 3,
text: isAccountSelection
? 'Get back here to see list of accounts'
: 'Get back here to see Txn hash'
}
],
[isAccountSelection]
);

useEffect(() => {
const container = document.querySelector('#ms-container');

Expand Down Expand Up @@ -91,9 +98,7 @@ export const NoConnectedLedger: React.FC<INoConnectedLedgerProps> = ({
<Trans t={t}>Open the Casper app on your Ledger device</Trans>
)}
{event.status === LedgerEventStatus.LedgerAskPermission && (
<Trans t={t}>
Now please provide permission to connect Ledger device
</Trans>
<Trans t={t}>Next, approve access to your Ledger device</Trans>
)}
</Typography>
</ParagraphContainer>
Expand All @@ -108,7 +113,6 @@ export const NoConnectedLedger: React.FC<INoConnectedLedgerProps> = ({
)}
{event.status === LedgerEventStatus.Disconnected && (
<Typography type="body" color="contentSecondary">
<Trans t={t}>to connect with Casper Wallet.</Trans>{' '}
<Link
color="contentAction"
target="_blank"
Expand Down

0 comments on commit 974a13c

Please sign in to comment.