Skip to content

Commit a37ca84

Browse files
authored
Signer Cleanup Logic (#1368)
* clean up * await * mockCleanup
1 parent e296efa commit a37ca84

7 files changed

Lines changed: 10 additions & 7 deletions

File tree

packages/wallet-sdk/src/CoinbaseWalletProvider.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function createProvider() {
1313

1414
const mockHandshake = jest.fn();
1515
const mockRequest = jest.fn();
16-
const mockDisconnect = jest.fn();
16+
const mockCleanup = jest.fn();
1717
const mockFetchSignerType = jest.spyOn(util, 'fetchSignerType');
1818
const mockStoreSignerType = jest.spyOn(util, 'storeSignerType');
1919
const mockLoadSignerType = jest.spyOn(util, 'loadSignerType');
@@ -30,7 +30,7 @@ beforeEach(() => {
3030
chainId: 1,
3131
handshake: mockHandshake,
3232
request: mockRequest,
33-
disconnect: mockDisconnect,
33+
cleanup: mockCleanup,
3434
};
3535
});
3636

@@ -148,6 +148,7 @@ describe('Signer configuration', () => {
148148
expect(mockRequest).toHaveBeenCalledWith(request);
149149

150150
await providerLoadedFromStorage.disconnect();
151+
expect(mockCleanup).toHaveBeenCalled();
151152
expect(provider['signer']).toBeNull();
152153
});
153154

@@ -162,6 +163,7 @@ describe('Signer configuration', () => {
162163
await provider.request({ method: 'eth_requestAccounts' });
163164

164165
await provider.disconnect();
166+
expect(mockCleanup).toHaveBeenCalled();
165167
expect(provider['signer']).toBeNull();
166168
});
167169
});

packages/wallet-sdk/src/CoinbaseWalletProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class CoinbaseWalletProvider extends ProviderEventEmitter implements Prov
8787

8888
async disconnect() {
8989
await this.ensureInitialized();
90+
await this.signer?.cleanup();
9091
this.signer = null;
9192
await clearAllStorage();
9293
this.emit('disconnect', standardErrors.provider.disconnected('User initiated disconnection'));

packages/wallet-sdk/src/sign/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { RequestArguments } from ':core/provider/interface';
33
export interface Signer {
44
handshake(): Promise<void>;
55
request(request: RequestArguments): Promise<unknown>;
6-
disconnect: () => Promise<void>;
6+
cleanup: () => Promise<void>;
77
}

packages/wallet-sdk/src/sign/scw/SCWSigner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ describe('SCWSigner', () => {
209209

210210
describe('disconnect', () => {
211211
it('should disconnect successfully', async () => {
212-
await signer.disconnect();
212+
await signer.cleanup();
213213

214214
expect(storageClearSpy).toHaveBeenCalled();
215215
expect(mockKeyManager.clear).toHaveBeenCalled();

packages/wallet-sdk/src/sign/scw/SCWSigner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class SCWSigner implements Signer {
159159
return result.value;
160160
}
161161

162-
async disconnect() {
162+
async cleanup() {
163163
await this.storage.clear();
164164
await this.keyManager.clear();
165165
this.accounts = [];

packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('LegacyProvider', () => {
4747
const spy = jest.spyOn(relay, 'resetAndReload');
4848

4949
const provider = createAdapter({ relay });
50-
await provider.disconnect();
50+
await provider.cleanup();
5151
expect(spy).toHaveBeenCalled();
5252
});
5353

packages/wallet-sdk/src/sign/walletlink/WalletLinkSigner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class WalletLinkSigner implements Signer {
207207
}
208208
}
209209

210-
public async disconnect() {
210+
public async cleanup() {
211211
this.callback = null;
212212
if (this._relay) {
213213
this._relay.resetAndReload();

0 commit comments

Comments
 (0)