Skip to content

Commit

Permalink
chore(get-starknet): remove Method not supported exception for "`on…
Browse files Browse the repository at this point in the history
…` " and "`off`" event handlers (#402)

* chore: fix missing access to requestParams in call to revamped rpc

* chore: fix on off event should not throw

* Update packages/get-starknet/src/wallet.test.ts

Co-authored-by: Stanley Yuen <[email protected]>

* Update packages/get-starknet/src/wallet.test.ts

Co-authored-by: Stanley Yuen <[email protected]>

---------

Co-authored-by: Stanley Yuen <[email protected]>
  • Loading branch information
khanti42 and stanleyyconsensys authored Oct 23, 2024
1 parent a834beb commit bd6b66d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/get-starknet/src/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,18 @@ describe('MetaMaskSnapWallet', () => {
});

describe('on', () => {
it('throws `Method not supported` error', async () => {
it('does nothing and not throw any error', async () => {
const wallet = createWallet();

expect(() => wallet.on()).toThrow('Method not supported');
expect(() => wallet.on('accountsChanged', jest.fn())).not.toThrow();
});
});

describe('off', () => {
it('throws `Method not supported` error', async () => {
it('does nothing and not throw any error', async () => {
const wallet = createWallet();

expect(() => wallet.off()).toThrow('Method not supported');
expect(() => wallet.off('accountsChanged', jest.fn())).not.toThrow();
});
});
});
11 changes: 6 additions & 5 deletions packages/get-starknet/src/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MutexInterface } from 'async-mutex';
import { Mutex } from 'async-mutex';
import { type RpcMessage, type WalletEvents, type StarknetWindowObject } from 'get-starknet-core';
import type { WalletEventHandlers } from 'get-starknet-core';
import { type RpcMessage, type StarknetWindowObject } from 'get-starknet-core';
import type { AccountInterface, ProviderInterface } from 'starknet';
import { Provider } from 'starknet';

Expand Down Expand Up @@ -208,12 +209,12 @@ export class MetaMaskSnapWallet implements StarknetWindowObject {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
on<Event extends WalletEvents>() {
throw new Error('Method not supported');
on<Event extends keyof WalletEventHandlers>(_event: Event, _handleEvent: WalletEventHandlers[Event]): void {
// No operation for now
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
off<Event extends WalletEvents>() {
throw new Error('Method not supported');
off<Event extends keyof WalletEventHandlers>(_event: Event, _handleEvent?: WalletEventHandlers[Event]): void {
// No operation for now
}
}

0 comments on commit bd6b66d

Please sign in to comment.