Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions packages/keyring-eth-qr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wraps legacy `QrKeyring` to expose accounts via the unified `KeyringV2` API and the `KeyringAccount` type.
- Extends `EthKeyringWrapper` for common Ethereum logic.

### Changed

- Override `capabilities` getter in `QrKeyringV2` to return capabilities dynamically based on device mode ([#447](https://github.com/MetaMask/accounts/pull/447))
Comment thread
mathieuartu marked this conversation as resolved.
Outdated

## [1.1.0]

### Added
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