Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
bangtoven committed Jun 27, 2024
1 parent ce45d78 commit dc33d63
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
1 change: 0 additions & 1 deletion packages/wallet-sdk/src/CoinbaseWalletProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider';
import { standardErrors } from './core/error';
import * as util from './sign/util';
import { AddressString } from ':core/type';

function createProvider() {
return new CoinbaseWalletProvider({
Expand Down
9 changes: 5 additions & 4 deletions packages/wallet-sdk/src/CoinbaseWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@ export class CoinbaseWalletProvider extends EventEmitter implements ProviderInte
}

async disconnect(): Promise<void> {
if (!this.signer) return;
this.signer.disconnect();
if (this.signer) {
this.signer.disconnect();
}
ScopedLocalStorage.clearAll();
this.emit('disconnect', standardErrors.provider.disconnected('User initiated disconnection'));
}

readonly isCoinbaseWallet = true;

protected readonly updateListener = {
protected readonly updateListener = {
onAccountsUpdate: (accounts: AddressString[]) => {
if (areAddressArraysEqual(this.accounts, accounts)) return;
this.emit('accountsChanged', this.accounts);
Expand All @@ -162,7 +163,7 @@ export class CoinbaseWalletProvider extends EventEmitter implements ProviderInte
this.emit('chainChanged', hexStringFromIntNumber(IntNumber(chain.id)));
},
};

private requestSignerSelection(): Promise<SignerType> {
return fetchSignerType({
communicator: this.communicator,
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet-sdk/src/core/provider/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventEmitter } from 'eventemitter3';

import { Method } from './method';
import { AddressString } from ':core/type';
import { AddressString, Chain } from ':core/type';

export interface RequestArguments {
readonly method: Method | string;
Expand Down Expand Up @@ -53,6 +53,8 @@ export interface ConstructorOptions {
}

export interface Signer {
readonly accounts: AddressString[];
readonly chain: Chain;
handshake(): Promise<AddressString[]>;
request<T>(request: RequestArguments): Promise<T>;
disconnect: () => Promise<void>;
Expand Down
9 changes: 0 additions & 9 deletions packages/wallet-sdk/src/sign/interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { RequestArguments } from ':core/provider/interface';
import { AddressString, Chain } from ':core/type';

export interface Signer {
readonly accounts: AddressString[];
readonly chain: Chain;
handshake(): Promise<AddressString[]>;
request<T>(request: RequestArguments): Promise<T>;
disconnect: () => Promise<void>;
}

export interface StateUpdateListener {
onAccountsUpdate: (_: AddressString[]) => void;
onChainUpdate: (_: Chain) => void;
Expand Down
25 changes: 9 additions & 16 deletions packages/wallet-sdk/src/sign/scw/SCWSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ export class SCWSigner implements Signer {

private availableChains?: Chain[];
private _accounts: AddressString[];
private _activeChain: Chain;
private _chain: Chain;
get accounts() {
return this._accounts;
}
get activeChain() {
return this._activeChain;
get chain() {
return this._chain;
}

constructor(params: {
metadata: AppMetadata;
communicator: Communicator;
updateListener: StateUpdateListener;
}) {
this.metadata = params.metadata;
this.communicator = params.communicator;
Expand All @@ -48,7 +49,7 @@ export class SCWSigner implements Signer {

this.storage = new ScopedLocalStorage('CBWSDK', 'SCWStateManager');
this._accounts = this.storage.loadObject(ACCOUNTS_KEY) ?? [];
this._activeChain = this.storage.loadObject(ACTIVE_CHAIN_STORAGE_KEY) || {
this._chain = this.storage.loadObject(ACTIVE_CHAIN_STORAGE_KEY) || {
id: params.metadata.appChainIds?.[0] ?? 1,
};

Expand All @@ -58,14 +59,6 @@ export class SCWSigner implements Signer {
this.decryptResponseMessage = this.decryptResponseMessage.bind(this);
}

get accounts() {
return this.stateManager.accounts;
}

get chain() {
return this.stateManager.activeChain;
}

async handshake(): Promise<AddressString[]> {
const handshakeMessage = await this.createRequestMessage({
handshake: {
Expand Down Expand Up @@ -148,7 +141,7 @@ export class SCWSigner implements Signer {
const encrypted = await encryptContent(
{
action: request,
chainId: this._activeChain.id,
chainId: this._chain.id,
},
sharedSecret
);
Expand Down Expand Up @@ -203,7 +196,7 @@ export class SCWSigner implements Signer {
}));
this.availableChains = chains;
this.storage.storeObject(AVAILABLE_CHAINS_STORAGE_KEY, chains);
this.switchChain(this._activeChain.id);
this.switchChain(this._chain.id);
}

if (capabilities) {
Expand All @@ -214,9 +207,9 @@ export class SCWSigner implements Signer {
private switchChain(chainId: number): boolean {
const chain = this.availableChains?.find((chain) => chain.id === chainId);
if (!chain) return false;
if (chain === this._activeChain) return true;
if (chain === this._chain) return true;

this._activeChain = chain;
this._chain = chain;
this.storage.storeObject(ACTIVE_CHAIN_STORAGE_KEY, chain);
this.updateListener.onChainUpdate(chain);
return true;
Expand Down

0 comments on commit dc33d63

Please sign in to comment.