diff --git a/apps/demo-react/providers/sdk.tsx b/apps/demo-react/providers/sdk.tsx index 5a997425..92efa9b2 100644 --- a/apps/demo-react/providers/sdk.tsx +++ b/apps/demo-react/providers/sdk.tsx @@ -29,7 +29,7 @@ export const LidoSDKProvider: React.FC = ({ children }) => { chainId: chainId as any, rpcUrls: [getBackendRPCPath(chainId)], web3Provider: client as any, - logMode: 'debug', + logMode: 'none', }); // inject lido_sdk for console access if (typeof window !== 'undefined') (window as any).lido_sdk = sdk; diff --git a/packages/connect-wallet-modal/CHANGELOG.md b/packages/connect-wallet-modal/CHANGELOG.md index dc8f99aa..f2835555 100644 --- a/packages/connect-wallet-modal/CHANGELOG.md +++ b/packages/connect-wallet-modal/CHANGELOG.md @@ -1,5 +1,11 @@ # @reef-knot/connect-wallet-modal +## 5.5.2 + +### Patch Changes + +- 3bfcb7c: Fix modals props passing + ## 5.5.1 ### Patch Changes diff --git a/packages/connect-wallet-modal/package.json b/packages/connect-wallet-modal/package.json index 4c96a3a1..8895a1be 100644 --- a/packages/connect-wallet-modal/package.json +++ b/packages/connect-wallet-modal/package.json @@ -1,6 +1,6 @@ { "name": "@reef-knot/connect-wallet-modal", - "version": "5.5.1", + "version": "5.5.2", "main": "dist/index.js", "types": "dist/index.d.ts", "exports": { @@ -51,7 +51,7 @@ "@reef-knot/ui-react": "^2.1.1", "@reef-knot/wallets-helpers": "^2.0.1", "@reef-knot/web3-react": "^4.0.1", - "@reef-knot/ledger-connector": "^4.1.0", + "@reef-knot/ledger-connector": "^4.1.3", "eslint-config-custom": "*", "react": "18.2.0", "react-dom": "^18.2.0", diff --git a/packages/connect-wallet-modal/src/components/WalletsModal/WalletsModal.tsx b/packages/connect-wallet-modal/src/components/WalletsModal/WalletsModal.tsx index 65293809..1d6d6a55 100644 --- a/packages/connect-wallet-modal/src/components/WalletsModal/WalletsModal.tsx +++ b/packages/connect-wallet-modal/src/components/WalletsModal/WalletsModal.tsx @@ -9,11 +9,13 @@ import { useReefKnotModal } from '@reef-knot/core-react'; export function WalletsModal({ children, - ...props + metrics, + termsLink, + privacyNoticeLink, + onClickWalletsLess, + onClickWalletsMore, + ...passedDownProps }: React.PropsWithChildren) { - const { metrics, termsLink, privacyNoticeLink } = props; - const { onClickWalletsLess, onClickWalletsMore, ...passedDownProps } = props; - const { currentModal, closeModal, forceCloseAllModals } = useReefKnotModal(); const termsProps: WalletModalConnectTermsProps = { diff --git a/packages/connectors/ledger-connector/CHANGELOG.md b/packages/connectors/ledger-connector/CHANGELOG.md index 8306a2fa..b3871104 100644 --- a/packages/connectors/ledger-connector/CHANGELOG.md +++ b/packages/connectors/ledger-connector/CHANGELOG.md @@ -1,5 +1,11 @@ # @reef-knot/ledger-connector +## 4.1.3 + +### Patch Changes + +- 3bfcb7c: Fix Ledger reconnection: after explicit disconnect and after page reloading + ## 4.1.2 ### Patch Changes diff --git a/packages/connectors/ledger-connector/package.json b/packages/connectors/ledger-connector/package.json index 0882b229..8845d848 100644 --- a/packages/connectors/ledger-connector/package.json +++ b/packages/connectors/ledger-connector/package.json @@ -1,6 +1,6 @@ { "name": "@reef-knot/ledger-connector", - "version": "4.1.2", + "version": "4.1.3", "main": "dist/index.js", "types": "dist/index.d.ts", "exports": { diff --git a/packages/connectors/ledger-connector/src/hid/connector.ts b/packages/connectors/ledger-connector/src/hid/connector.ts index c03d0e7c..c6f25c5c 100644 --- a/packages/connectors/ledger-connector/src/hid/connector.ts +++ b/packages/connectors/ledger-connector/src/hid/connector.ts @@ -4,7 +4,7 @@ import { createConnector, } from 'wagmi'; import { Chain } from 'wagmi/chains'; -import { checkError } from '../hid/helpers'; +import { checkError, clearLedgerDerivationPath } from '../hid/helpers'; import type { LedgerHQProvider } from './provider'; export const idLedgerHid = 'ledgerHID'; @@ -57,9 +57,9 @@ export function ledgerHIDConnector({ async disconnect() { // Handles programmatic disconnect. - // We don't need to do anything specific for HID Ledger connection in this case. const provider = await this.getProvider(); provider.removeListener('disconnect', this.onDisconnect); + clearLedgerDerivationPath(); }, async getAccounts() { @@ -81,7 +81,10 @@ export function ledgerHIDConnector({ if (!provider) throw new ConnectorNotFoundError(); const [account] = await this.getAccounts(); return !!account; - } catch { + } catch (e) { + // The errors caught here are generally expected in most use cases. + // However, unexpected errors may still occur, so they should at least be logged to the console. + console.error(e); return false; } }, diff --git a/packages/connectors/ledger-connector/src/hid/constants.ts b/packages/connectors/ledger-connector/src/hid/constants.ts new file mode 100644 index 00000000..bae73203 --- /dev/null +++ b/packages/connectors/ledger-connector/src/hid/constants.ts @@ -0,0 +1 @@ +export const LS_KEY_DERIVATION_PATH = 'reef-knot_ledger-derivation-path'; diff --git a/packages/connectors/ledger-connector/src/hid/helpers.ts b/packages/connectors/ledger-connector/src/hid/helpers.ts index 597f9940..f430af6c 100644 --- a/packages/connectors/ledger-connector/src/hid/helpers.ts +++ b/packages/connectors/ledger-connector/src/hid/helpers.ts @@ -1,6 +1,7 @@ import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; import { resolveProperties } from '@ethersproject/properties'; import { TransactionRequestExtended, UnsignedTransactionStrict } from './types'; +import { LS_KEY_DERIVATION_PATH } from './constants'; export const isHIDSupported = () => { try { @@ -82,3 +83,7 @@ export const checkError = (error: any): never => { throw error; }; + +export const clearLedgerDerivationPath = () => { + window?.localStorage.removeItem(LS_KEY_DERIVATION_PATH); +}; diff --git a/packages/connectors/ledger-connector/src/hid/index.ts b/packages/connectors/ledger-connector/src/hid/index.ts index 2ccc7090..05ca6618 100644 --- a/packages/connectors/ledger-connector/src/hid/index.ts +++ b/packages/connectors/ledger-connector/src/hid/index.ts @@ -1,2 +1,2 @@ export { idLedgerHid, ledgerHIDConnector } from './connector'; -export { LS_KEY_DERIVATION_PATH } from './signer'; +export { LS_KEY_DERIVATION_PATH } from './constants'; diff --git a/packages/connectors/ledger-connector/src/hid/provider.ts b/packages/connectors/ledger-connector/src/hid/provider.ts index 93615287..bb6f3bf7 100644 --- a/packages/connectors/ledger-connector/src/hid/provider.ts +++ b/packages/connectors/ledger-connector/src/hid/provider.ts @@ -17,6 +17,15 @@ export class LedgerHQProvider extends JsonRpcBatchProvider { this.signer = this.getSigner(); } + async loadTransport() { + if (!this.transport) { + const { default: TransportWebHID } = await import( + '@ledgerhq/hw-transport-webhid' + ); + this.transport = TransportWebHID; + } + } + getSigner(): LedgerHQSigner { return new LedgerHQSigner(this); } @@ -30,7 +39,7 @@ export class LedgerHQProvider extends JsonRpcBatchProvider { } async getTransport(): Promise { - invariant(this.transport, 'Transport is not defined'); + await this.loadTransport(); try { const transportInstance = @@ -45,10 +54,7 @@ export class LedgerHQProvider extends JsonRpcBatchProvider { async enable(): Promise { try { - const { default: TransportWebHID } = await import( - '@ledgerhq/hw-transport-webhid' - ); - this.transport = TransportWebHID; + await this.loadTransport(); const { hid } = window.navigator; diff --git a/packages/connectors/ledger-connector/src/hid/signer.ts b/packages/connectors/ledger-connector/src/hid/signer.ts index dac50b71..be07c11f 100644 --- a/packages/connectors/ledger-connector/src/hid/signer.ts +++ b/packages/connectors/ledger-connector/src/hid/signer.ts @@ -18,30 +18,30 @@ import { toUtf8Bytes } from '@ethersproject/strings'; import { Bytes, hexlify, joinSignature } from '@ethersproject/bytes'; import { _TypedDataEncoder } from '@ethersproject/hash'; -import type { LedgerHQProvider } from './provider'; import { checkError, convertToUnsigned, toNumber } from './helpers'; -import { UnsignedTransactionStrict } from './types'; +import { LS_KEY_DERIVATION_PATH } from './constants'; + +import type { LedgerHQProvider } from './provider'; +import type { UnsignedTransactionStrict } from './types'; -export const LS_KEY_DERIVATION_PATH = 'reef-knot_ledger-derivation-path'; const defaultPath = "m/44'/60'/0'/0/0"; export class LedgerHQSigner extends Signer implements TypedDataSigner { - readonly path: string; - readonly provider: LedgerHQProvider; - _index = 0; + get path() { + if (typeof window !== 'undefined') { + return window.localStorage.getItem(LS_KEY_DERIVATION_PATH) || defaultPath; + } + return defaultPath; + } + // required by JsonRpcSigner type + _index = 0; _address = ''; - constructor(provider: LedgerHQProvider, path = '') { + constructor(provider: LedgerHQProvider) { super(); - - let pathFromLS; - if (typeof window !== 'undefined') { - pathFromLS = window.localStorage.getItem(LS_KEY_DERIVATION_PATH); - } - this.path = path || pathFromLS || defaultPath; this.provider = provider; } @@ -63,11 +63,8 @@ export class LedgerHQSigner extends Signer implements TypedDataSigner { } async getAddress(): Promise { - if (!this._address) { - const account = await this.withEthApp((eth) => eth.getAddress(this.path)); - this._address = this.provider.formatter.address(account.address); - } - + const account = await this.withEthApp((eth) => eth.getAddress(this.path)); + this._address = this.provider.formatter.address(account.address); return this._address; } @@ -132,7 +129,7 @@ export class LedgerHQSigner extends Signer implements TypedDataSigner { } connect(provider: LedgerHQProvider): JsonRpcSigner { - return new LedgerHQSigner(provider, this.path); + return new LedgerHQSigner(provider); } // eslint-disable-next-line class-methods-use-this diff --git a/packages/reef-knot/CHANGELOG.md b/packages/reef-knot/CHANGELOG.md index be245d9f..cdaf1586 100644 --- a/packages/reef-knot/CHANGELOG.md +++ b/packages/reef-knot/CHANGELOG.md @@ -1,5 +1,13 @@ # reef-knot +## 5.7.4 + +### Patch Changes + +- Updated dependencies [3bfcb7c] + - @reef-knot/connect-wallet-modal@5.5.2 + - @reef-knot/ledger-connector@4.1.3 + ## 5.7.3 ### Patch Changes diff --git a/packages/reef-knot/package.json b/packages/reef-knot/package.json index cb45a2aa..4bb0329d 100644 --- a/packages/reef-knot/package.json +++ b/packages/reef-knot/package.json @@ -1,6 +1,6 @@ { "name": "reef-knot", - "version": "5.7.3", + "version": "5.7.4", "main": "dist/index.js", "types": "dist/index.d.ts", "exports": { @@ -41,14 +41,14 @@ "lint": "eslint --ext ts,tsx,js,mjs ." }, "dependencies": { - "@reef-knot/connect-wallet-modal": "5.5.1", + "@reef-knot/connect-wallet-modal": "5.5.2", "@reef-knot/core-react": "4.3.0", "@reef-knot/web3-react": "4.0.1", "@reef-knot/ui-react": "2.1.4", "@reef-knot/wallets-list": "2.3.0", "@reef-knot/wallets-helpers": "2.1.0", "@reef-knot/types": "2.1.0", - "@reef-knot/ledger-connector": "4.1.2" + "@reef-knot/ledger-connector": "4.1.3" }, "peerDependencies": { "@lidofinance/lido-ui": "^3.18.0",