From bd6b66d2cba8382711adbe6a6312f295e22c64b6 Mon Sep 17 00:00:00 2001 From: khanti42 Date: Wed, 23 Oct 2024 09:40:28 +0200 Subject: [PATCH] chore(get-starknet): remove `Method not supported` exception for "`on` " 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 <102275989+stanleyyconsensys@users.noreply.github.com> * Update packages/get-starknet/src/wallet.test.ts Co-authored-by: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> --------- Co-authored-by: Stanley Yuen <102275989+stanleyyconsensys@users.noreply.github.com> --- packages/get-starknet/src/wallet.test.ts | 8 ++++---- packages/get-starknet/src/wallet.ts | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/get-starknet/src/wallet.test.ts b/packages/get-starknet/src/wallet.test.ts index ad72a3de..135f4bb0 100644 --- a/packages/get-starknet/src/wallet.test.ts +++ b/packages/get-starknet/src/wallet.test.ts @@ -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(); }); }); }); diff --git a/packages/get-starknet/src/wallet.ts b/packages/get-starknet/src/wallet.ts index 3c313368..63d2fe60 100644 --- a/packages/get-starknet/src/wallet.ts +++ b/packages/get-starknet/src/wallet.ts @@ -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'; @@ -208,12 +209,12 @@ export class MetaMaskSnapWallet implements StarknetWindowObject { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - on() { - throw new Error('Method not supported'); + on(_event: Event, _handleEvent: WalletEventHandlers[Event]): void { + // No operation for now } // eslint-disable-next-line @typescript-eslint/no-unused-vars - off() { - throw new Error('Method not supported'); + off(_event: Event, _handleEvent?: WalletEventHandlers[Event]): void { + // No operation for now } }