Skip to content

Commit

Permalink
Merge pull request #1009 from madfish-solutions/TW-904-device-bridge-…
Browse files Browse the repository at this point in the history
…is-no-longer-available-error-appears-after-interacting-with-updated-ledger-live

TW-904 Remove Ledger Live support completely
  • Loading branch information
lourenc authored Oct 26, 2023
2 parents b3c892e + cef1cc2 commit 084b856
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 240 deletions.
9 changes: 0 additions & 9 deletions public/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,6 @@
"unknownAccount": {
"message": "Unbekanntes Konto"
},
"ledgerLiveBridgeGuide": {
"message": "Um eine Verbindung zum Ledger herzustellen, aktivieren Sie bitte die Ledger-Live-Anwendung auf Ihrem Gerät, öffnen Sie die Tezos Wallet-Anwendung und erlauben Sie eine WebSocket-Verbindung zu Ihrem Temple-Konto."
},
"noExchangerFoundForToken": {
"message": "Für Token $symbol$ ($name$) wurde kein Austauscher gefunden.",
"placeholders": {
Expand Down Expand Up @@ -2074,12 +2071,6 @@
"deleteTokenConfirm": {
"message": "Möchten Sie dieses Token wirklich löschen?"
},
"ledgerLiveSettings": {
"message": "Ledger-Live verwenden"
},
"ledgerLiveSettingsDescription": {
"message": "Mit der neuen Ledger-Live Bridge können Sie Ihr Ledger auf andere Weise verwenden."
},
"totalBalance": {
"message": "Gesamtguthaben"
},
Expand Down
9 changes: 0 additions & 9 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2379,9 +2379,6 @@
"unknownAccount": {
"message": "Unknown account"
},
"ledgerLiveBridgeGuide": {
"message": "To connect to Ledger, please activate the Ledger Live application on your device, open Tezos Wallet application and allow a WebSocket connection to your Temple account."
},
"ledgerBridgeGuide": {
"message": "To connect the Ledger, please activate your device and open Tezos Wallet application."
},
Expand Down Expand Up @@ -2608,12 +2605,6 @@
"deleteTokenConfirm": {
"message": "Are you sure you want to delete this token?"
},
"ledgerLiveSettings": {
"message": "Use Ledger Live"
},
"ledgerLiveSettingsDescription": {
"message": "The new Ledger Live bridge allows you to use your Ledger in a different way."
},
"lockUpSettings": {
"message": "Extension lock-up"
},
Expand Down
9 changes: 0 additions & 9 deletions public/_locales/pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,6 @@
"unknownAccount": {
"message": "Conta desconhecida"
},
"ledgerLiveBridgeGuide": {
"message": "Para ligar ao Ledger, ative a aplicação Ledger Live no seu dispositivo, abra a aplicação Carteira Tezos e permita uma ligação WebSocket à sua conta Temple."
},
"noExchangerFoundForToken": {
"message": "Não foi encontrado nenhum permutador para o token $symbol$ ($name$).",
"placeholders": {
Expand Down Expand Up @@ -2074,12 +2071,6 @@
"deleteTokenConfirm": {
"message": "Tem a certeza de que pretende eliminar este token?"
},
"ledgerLiveSettings": {
"message": "Usar o Ledger Live"
},
"ledgerLiveSettingsDescription": {
"message": "A nova ponte Ledger Live permite-lhe utilizar o seu Ledger de uma forma diferente."
},
"totalBalance": {
"message": "Saldo total"
},
Expand Down
9 changes: 0 additions & 9 deletions public/_locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,6 @@
"unknownAccount": {
"message": "Bilinmeyen hesap"
},
"ledgerLiveBridgeGuide": {
"message": "Kayıt Defterine bağlanmak için lütfen cihazınızda Ledger Live uygulamasını etkinleştirin, Tezos Wallet uygulamasını açın ve Temple hesabınıza WebSocket bağlantısına izin verin."
},
"noExchangerFoundForToken": {
"message": "Token $symbol$ ($name$) için alım satım yapan kimse bulunamadı.",
"placeholders": {
Expand Down Expand Up @@ -2074,12 +2071,6 @@
"deleteTokenConfirm": {
"message": "Bu token'ı silmek istediğinizden emin misiniz?"
},
"ledgerLiveSettings": {
"message": "Ledger Live Uygulamasını Kullan"
},
"ledgerLiveSettingsDescription": {
"message": "Yeni Ledger Live, Kayıt Defterinizi farklı bir şekilde kullanmanıza olanak tanır."
},
"totalBalance": {
"message": "Toplam Bakiye"
},
Expand Down
14 changes: 3 additions & 11 deletions src/app/atoms/ConfirmLedgerOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import CSSTransition from 'react-transition-group/CSSTransition';

import { ReactComponent as LedgerNanoIcon } from 'app/misc/ledger.svg';
import { T } from 'lib/i18n';
import { TransportType } from 'lib/ledger/types';
import { getLedgerTransportType } from 'lib/temple/ledger';

type ConfirmLedgerOverlayProps = {
displayed: boolean;
Expand Down Expand Up @@ -48,15 +46,9 @@ const ConfirmLedgerOverlay: FC<ConfirmLedgerOverlayProps> = ({ displayed }) => (

<LedgerNanoIcon className="animate-pulse" style={{ width: '10rem', height: 'auto' }} />

{getLedgerTransportType() === TransportType.WEBHID ? (
<p className={classNames('mt-8', 'text-center', 'text-sm text-gray-600', 'max-w-xs')}>
<T id="ledgerBridgeGuide" />
</p>
) : (
<p className={classNames('mt-8', 'text-center', 'text-sm text-gray-600', 'max-w-xs')}>
<T id="ledgerLiveBridgeGuide" />
</p>
)}
<p className={classNames('mt-8', 'text-center', 'text-sm text-gray-600', 'max-w-xs')}>
<T id="ledgerBridgeGuide" />
</p>
</div>
</CSSTransition>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/ConnectLedger/ConnectLedger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { ReactComponent as OkIcon } from 'app/icons/ok.svg';
import PageLayout from 'app/layouts/PageLayout';
import { useFormAnalytics } from 'lib/analytics';
import { T, t } from 'lib/i18n';
import { getLedgerTransportType } from 'lib/ledger/helpers';
import { useAllAccounts, useSetAccountPkh, useTempleClient, validateDerivationPath } from 'lib/temple/front';
import { getLedgerTransportType } from 'lib/temple/ledger';
import { DerivationType, TempleAccountType } from 'lib/temple/types';
import { delay } from 'lib/utils';
import { navigate } from 'lib/woozie';
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/templates/SettingsGeneral/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { FC } from 'react';
import AnalyticsSettings from 'app/templates/SettingsGeneral/Components/AnalyticsSettings';
import BlockExplorerSelect from 'app/templates/SettingsGeneral/Components/BlockExplorerSelect';
import FiatCurrencySelect from 'app/templates/SettingsGeneral/Components/FiatCurrencySelect';
import LedgerLiveSettings from 'app/templates/SettingsGeneral/Components/LedgerLiveSettings';
import LocaleSelect from 'app/templates/SettingsGeneral/Components/LocaleSelect';
import LockUpSettings from 'app/templates/SettingsGeneral/Components/LockUpSettings';
import PopupSettings from 'app/templates/SettingsGeneral/Components/PopupSettings';
Expand All @@ -26,8 +25,6 @@ const GeneralSettings: FC = () => {

<AnalyticsSettings />

<LedgerLiveSettings />

<NotificationsSettings />

<PartnersPromotionSettings />
Expand Down
1 change: 0 additions & 1 deletion src/app/templates/SettingsGeneral/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export enum SettingsGeneralSelectors {
popUpCheckBox = 'Setting General/Pop-up Check Box',
extensionLockUpCheckBox = 'Setting General/Extension Lock-up Check Box',
anonymousAnalyticsCheckBox = 'Setting General/Anonymous Analytics Check Box',
useLedgerLiveCheckBox = 'Setting General/Use Ledger Live Check Box',
notificationCheckBox = 'Setting General/Notification Check Box',
partnersPromotion = 'Setting General/Partners Promotion Check Box'
}
3 changes: 1 addition & 2 deletions src/lib/ledger/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { TransportType } from './transport/types';

export const removeMFromDerivationPath = (dPath: string) => (dPath.startsWith('m/') ? dPath.substring(2) : dPath);

export const pickTransportType = (isLedgerLive: boolean) => {
if (isLedgerLive) return TransportType.LEDGERLIVE;
export const getLedgerTransportType = () => {
if (isSupportedHID()) return TransportType.WEBHID;
if (isSupportedWebAuthn()) return TransportType.WEBAUTHN;
return TransportType.U2F;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createLedgerSigner = async (
publicKeyHash
);

// After Ledger Live bridge was setuped, we don't close transport
// Ledger Live is not available but we still don't close transport
// Probably we do not need to close it
// But if we need, we can close it after not use timeout
const cleanup = () => {};
Expand Down
12 changes: 1 addition & 11 deletions src/lib/ledger/proxy/foreground.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import browser from 'webextension-polyfill';

import { isPopupWindow } from 'app/env';
import { getLedgerTransportType } from 'lib/temple/ledger';
import { stringToUInt8Array } from 'lib/utils';

import { getLedgerTransportType } from '../helpers';
import type { TempleLedgerSigner } from '../signer';
import { TransportType } from '../types';
import type { RequestMessage, ForegroundResponse, CreatorArguments } from './types';
Expand Down Expand Up @@ -31,15 +30,6 @@ browser.runtime.onMessage.addListener((message: unknown): Promise<ForegroundResp

const pagesWindows = getPagesWindows();

if (transportType === TransportType.LEDGERLIVE) {
/*
In case of the only opened extension window being 'popup',
it will close and thus, lose connection to 'ledger-live'.
(i) Consider using a fallback transport in this case.
*/
if (isPopupWindow() && pagesWindows.length === 1) return Promise.resolve({ type: 'refusal', transportType });
}

/* Only letting the first page to respond */
if (pagesWindows[0]! !== window) return;

Expand Down
46 changes: 18 additions & 28 deletions src/lib/ledger/transport/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import U2FTransport from '@ledgerhq/hw-transport-u2f';
import WebAuthnTransport from '@ledgerhq/hw-transport-webauthn';
import TransportWebHID from '@ledgerhq/hw-transport-webhid';

import { isLedgerLiveAppOpen, openLedgerLiveApp, openLedgerLiveTransport } from './ledger-live.utils';
import { TransportType, BridgeExchangeRequest } from './types';

export class TransportBridge {
Expand Down Expand Up @@ -42,38 +41,29 @@ export class TransportBridge {

if (transport == null) return await this.createTransport(transportType);

if (transportType === TransportType.LEDGERLIVE) {
if (await isLedgerLiveAppOpen()) return transport;
else {
await openLedgerLiveApp();
this.transport = await openLedgerLiveTransport();
return this.transport!;
}
} else {
if (transportType === TransportType.WEBHID && transport instanceof TransportWebHID) {
const device = transport.device;
const nameOfDeviceType = device && device.constructor.name;
const deviceIsOpen = device && device.opened;
if (nameOfDeviceType === 'HIDDevice' && deviceIsOpen) return transport;
if (transportType === TransportType.WEBHID && transport instanceof TransportWebHID) {
const device = transport.device;
const nameOfDeviceType = device && device.constructor.name;
const deviceIsOpen = device && device.opened;
if (nameOfDeviceType === 'HIDDevice' && deviceIsOpen) return transport;

const bufferTransport = await TransportWebHID.openConnected();
if (bufferTransport) this.transport = bufferTransport;
}

return this.transport!;
const bufferTransport = await TransportWebHID.openConnected();
if (bufferTransport) this.transport = bufferTransport;
}

return this.transport!;
}

private async createTransport(transportType: TransportType) {
if (transportType === TransportType.LEDGERLIVE) {
if (!(await isLedgerLiveAppOpen())) await openLedgerLiveApp();
this.transport = await openLedgerLiveTransport();
} else if (transportType === TransportType.WEBHID) {
this.transport = await TransportWebHID.create();
} else if (transportType === TransportType.WEBAUTHN) {
this.transport = await WebAuthnTransport.create();
} else {
this.transport = await U2FTransport.create();
switch (transportType) {
case TransportType.WEBHID:
this.transport = await TransportWebHID.create();
break;
case TransportType.WEBAUTHN:
this.transport = await WebAuthnTransport.create();
break;
default:
this.transport = await U2FTransport.create();
}

return this.transport!;
Expand Down
Loading

0 comments on commit 084b856

Please sign in to comment.