Skip to content

Commit

Permalink
chore: refactor storage to hold a connector per namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir committed Dec 5, 2024
1 parent 1021422 commit d3b4ba0
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 198 deletions.
24 changes: 23 additions & 1 deletion packages/appkit-new/src/adapters/ChainAdapterBlueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
} from '@reown/appkit-common'
import type { ChainAdapterConnector } from './ChainAdapterConnector.js'
import {
AccountController,
OptionsController,
ThemeController,
type AccountType,
type AccountControllerState,
type Connector as AppKitConnector,
type AuthConnector,
type Metadata,
Expand All @@ -18,7 +21,7 @@ import type { W3mFrameProvider } from '@reown/appkit-wallet'
import { ConstantsUtil, PresetsUtil } from '@reown/appkit-utils'
import type { AppKitOptions } from '../utils/index.js'
import type { AppKit } from '../client.js'
import { snapshot } from 'valtio'
import { snapshot } from 'valtio/vanilla'

type EventName = 'disconnect' | 'accountChanged' | 'switchNetwork'
type EventData = {
Expand Down Expand Up @@ -152,6 +155,10 @@ export abstract class AdapterBlueprint<
})
}

protected setStatus(status: AccountControllerState['status'], chainNamespace?: ChainNamespace) {
AccountController.setStatus(status, chainNamespace)
}

/**
* Adds an event listener for a specific event.
* @template T
Expand Down Expand Up @@ -211,6 +218,15 @@ export abstract class AdapterBlueprint<
params: AdapterBlueprint.ConnectParams
): Promise<AdapterBlueprint.ConnectResult>

/**
* Gets the accounts for the connected wallet.
* @returns {Promise<AccountType[]>} An array of account objects with their associated type and namespace
*/

public abstract getAccounts(
params: AdapterBlueprint.GetAccountsParams
): Promise<AdapterBlueprint.GetAccountsResult>

/**
* Switches the network.
* @param {AdapterBlueprint.SwitchNetworkParams} params - Network switching parameters
Expand Down Expand Up @@ -507,4 +523,10 @@ export namespace AdapterBlueprint {
chainId: number | string
address: string
}

export type GetAccountsResult = { accounts: AccountType[] }
export type GetAccountsParams = {
id: AppKitConnector['id']
namespace?: ChainNamespace
}
}
Loading

0 comments on commit d3b4ba0

Please sign in to comment.