Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/keyring-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Change `KeyringWrapper.capabilities` from a readonly property to a getter ([#447](https://github.com/MetaMask/accounts/pull/447))
- Allows subclasses to override and return capabilities dynamically based on runtime state.
- Refine `EthAddressStruct` in order to make it compatible with the `Hex` type from `@metamask/utils` ([#405](https://github.com/MetaMask/accounts/pull/405))

## [21.3.0]
Expand Down
16 changes: 14 additions & 2 deletions packages/keyring-api/src/api/v2/wrapper/keyring-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export abstract class KeyringWrapper<
{
readonly type: `${KeyringType}`;

readonly capabilities: KeyringCapabilities;
readonly #capabilities: KeyringCapabilities;

protected readonly inner: InnerKeyring;

Expand All @@ -74,7 +74,19 @@ export abstract class KeyringWrapper<
constructor(options: KeyringWrapperOptions<InnerKeyring>) {
this.inner = options.inner;
this.type = `${options.type}`;
this.capabilities = options.capabilities;
this.#capabilities = options.capabilities;
}

/**
* Get the capabilities of this keyring.
*
* Subclasses can override this getter to return capabilities dynamically
* based on runtime state.
*
* @returns The keyring's capabilities.
*/
get capabilities(): KeyringCapabilities {
Comment thread
mathieuartu marked this conversation as resolved.
return this.#capabilities;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-eth-qr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `QrKeyringV2` class implementing `KeyringV2` interface ([#411](https://github.com/MetaMask/accounts/pull/411))
- Add `QrKeyringV2` class implementing `KeyringV2` interface ([#411](https://github.com/MetaMask/accounts/pull/411)), ([#447](https://github.com/MetaMask/accounts/pull/447))
- Wraps legacy `QrKeyring` to expose accounts via the unified `KeyringV2` API and the `KeyringAccount` type.
- Extends `EthKeyringWrapper` for common Ethereum logic.

Expand Down
26 changes: 14 additions & 12 deletions packages/keyring-eth-qr/src/qr-keyring-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,24 @@ export class QrKeyringV2
super({
type: KeyringType.Qr,
inner: options.legacyKeyring,
// Placeholder - will be overridden by getter below
// Default capabilities - overridden by getter below
capabilities: HD_MODE_CAPABILITIES,
});
this.entropySource = options.entropySource;
}

// Override the readonly capabilities property with a dynamic getter
// that returns capabilities based on the current device mode.
Object.defineProperty(this, 'capabilities', {
get: (): KeyringCapabilities => {
return this.inner.getMode() === DeviceMode.ACCOUNT
? ACCOUNT_MODE_CAPABILITIES
: HD_MODE_CAPABILITIES;
},
enumerable: true,
configurable: false,
});
/**
* Get the capabilities of this keyring.
*
* Overrides the base class getter to return capabilities dynamically
* based on the current device mode.
*
* @returns The keyring's capabilities.
*/
override get capabilities(): KeyringCapabilities {
return this.inner.getMode() === DeviceMode.ACCOUNT
? ACCOUNT_MODE_CAPABILITIES
: HD_MODE_CAPABILITIES;
}

/**
Expand Down
Loading